Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
System
Notification
Commits
11a0532b
Commit
11a0532b
authored
Aug 14, 2020
by
Komal Makkar
Browse files
intermediate changes
parent
599e1389
Changes
4
Hide whitespace changes
Inline
Side-by-side
provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/pubsub/EventGridHandshakeHandler.java
0 → 100644
View file @
11a0532b
// Copyright © Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package
org.opengroup.osdu.notification.provider.azure.pubsub
;
import
com.google.gson.JsonArray
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonParser
;
import
org.opengroup.osdu.core.common.model.http.AppException
;
import
org.opengroup.osdu.notification.pubsub.IPubsubHandshakeHandler
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
@Component
@Lazy
public
class
EventGridHandshakeHandler
implements
IPubsubHandshakeHandler
{
private
JsonObject
root
=
null
;
@Autowired
private
HttpServletRequest
request
;
/**
* Extract Handshake response string form Handshake request.
*
* @return validation string
*/
@Override
public
String
getHandshakeResponse
()
{
if
(
this
.
root
==
null
)
{
this
.
root
=
this
.
extractRootJsonElementFromRequestBody
();
}
String
response
=
null
;
try
{
JsonObject
data
=
(
JsonObject
)
this
.
root
.
get
(
"data"
);
String
validationCode
=
data
.
get
(
"validationCode"
).
getAsString
();
JsonObject
jsonResponse
=
new
JsonObject
();
jsonResponse
.
addProperty
(
"ValidationResponse"
,
validationCode
);
response
=
validationCode
.
toString
();
}
catch
(
Exception
exception
)
{
throw
new
AppException
(
HttpStatus
.
INTERNAL_SERVER_ERROR
.
value
(),
"Request payload parsing error"
,
"Unable to parse request payload."
,
exception
);
}
return
response
;
}
/**
* Utility method to extract root element from the request.
*
* @return Root JsonObject
*/
private
JsonObject
extractRootJsonElementFromRequestBody
()
{
try
{
JsonParser
jsonParser
=
new
JsonParser
();
BufferedReader
reader
=
request
.
getReader
();
Stream
<
String
>
lines
=
reader
.
lines
();
String
requestBody
=
lines
.
collect
(
Collectors
.
joining
(
"\n"
));
JsonArray
requestArray
=
(
JsonArray
)
jsonParser
.
parse
(
requestBody
);
JsonElement
rootElement
=
requestArray
.
get
(
0
);
if
(!(
rootElement
instanceof
JsonObject
))
{
throw
new
AppException
(
HttpStatus
.
BAD_REQUEST
.
value
(),
"RequestBody is not JsonObject."
,
"Request Body should be JsonObject to be processed."
);
}
return
rootElement
.
getAsJsonObject
();
}
catch
(
IOException
e
)
{
throw
new
AppException
(
HttpStatus
.
INTERNAL_SERVER_ERROR
.
value
(),
"Request payload parsing error"
,
"Unable to parse request payload."
,
e
);
}
}
}
provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/pubsub/
Pubsub
RequestBodyExtractor.java
→
provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/pubsub/
EventGrid
RequestBodyExtractor.java
View file @
11a0532b
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright © Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package
org.opengroup.osdu.notification.provider.azure.pubsub
;
...
...
@@ -41,8 +39,9 @@ import java.util.stream.Stream;
@Component
@RequestScope
public
class
Pubsub
RequestBodyExtractor
implements
IPubsubRequestBodyExtractor
{
public
class
EventGrid
RequestBodyExtractor
implements
IPubsubRequestBodyExtractor
{
private
static
final
String
INVALID_PUBSUB_MESSAGE
=
"Invalid pubsub message"
;
private
static
final
String
EVENTGRID_VALIDATION_EVENT
=
"Microsoft.EventGrid.SubscriptionValidationEvent"
;
private
static
final
Gson
GSON
=
new
Gson
();
private
MessageContent
messageContent
;
private
JsonObject
root
=
null
;
...
...
@@ -68,24 +67,27 @@ public class PubsubRequestBodyExtractor implements IPubsubRequestBodyExtractor {
}
public
String
extractNotificationIdFromRequestBody
()
{
}
public
boolean
isHandshakeRequest
()
{
if
(
this
.
root
==
null
)
{
this
.
root
=
this
.
extractRootJsonElementFromRequestBody
();
}
JsonElement
subscription
=
this
.
root
.
get
(
"subscription"
);
if
(
subscription
==
null
)
{
throw
new
AppException
(
HttpStatus
.
BAD_REQUEST
.
value
(),
INVALID_PUBSUB_MESSAGE
,
"subscription object not found"
);
try
{
JsonElement
data
=
this
.
root
.
get
(
"eventType"
);
if
(
EVENTGRID_VALIDATION_EVENT
.
equals
(
data
.
getAsString
()))
{
return
true
;
}
}
catch
(
Exception
exception
)
{
throw
new
AppException
(
HttpStatus
.
BAD_REQUEST
.
value
(),
"RequestBody is not JsonObject."
,
"Request Body should be JsonObject to be processed."
);
}
String
[]
fullNotificationId
=
subscription
.
getAsString
().
split
(
"/"
);
return
fullNotificationId
[
fullNotificationId
.
length
-
1
];
}
public
boolean
isHandshakeRequest
()
{
return
false
;
}
private
MessageContent
extractPubsubMessageFromRequestBody
()
{
if
(
this
.
root
==
null
)
{
/* if (this.root == null) {
this.root = this.extractRootJsonElementFromRequestBody();
}
JsonElement message = this.root.get("message");
...
...
@@ -114,7 +116,7 @@ public class PubsubRequestBodyExtractor implements IPubsubRequestBodyExtractor {
String decoded = new String(Base64.getDecoder().decode(data));
content.setData(decoded);
return
content
;
return content;
*/
}
private
JsonObject
extractRootJsonElementFromRequestBody
()
{
...
...
provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/pubsub/PubsubHandshakeHandler.java
deleted
100644 → 0
View file @
599e1389
package
org.opengroup.osdu.notification.provider.azure.pubsub
;
import
org.opengroup.osdu.notification.pubsub.IPubsubHandshakeHandler
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Component
;
@Component
@Lazy
public
class
PubsubHandshakeHandler
implements
IPubsubHandshakeHandler
{
@Override
public
String
getHandshakeResponse
()
{
return
null
;
}
}
testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/util/Config.java
View file @
11a0532b
...
...
@@ -32,21 +32,21 @@ public class Config {
private
static
Config
config
=
new
Config
();
public
static
Config
Instance
()
{
String
env
=
getEnvironment
();
String
env
=
"LOCAL"
;
//
getEnvironment();
config
.
ClientTenant
=
"nonexistenttenant"
;
config
.
IntegrationAudience
=
"245464679631-ktfdfpl147m1mjpbutl00b3cmffissgq.apps.googleusercontent.com"
;
config
.
OsduTenant
=
"opendes"
;
config
.
Topic
=
"records-changed"
;
config
.
hmacSecretValue
=
System
.
getProperty
(
"HMAC_SECRET"
,
System
.
getenv
(
"HMAC_SECRET"
));
config
.
hmacSecretValue
=
"asdf"
;
//
System.getProperty("HMAC_SECRET", System.getenv("HMAC_SECRET"));
if
(
env
.
equalsIgnoreCase
(
"LOCAL"
))
{
//make sure to run register service on a different port. You can also choose to point to Register service that is running in cloud
String
registerUrl
=
"http://localhost:8081/"
;
//must have notification and register services running on different ports
config
.
HostUrl
=
"http://localhost:808
0
/"
;
config
.
HostUrl
=
"http://localhost:808
2
/"
;
config
.
GSAPushUrl
=
registerUrl
+
"/test/gsa-challenge/"
;
config
.
HMACPushUrl
=
registerUrl
+
"/test/challenge/"
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment