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
eb8eedb4
Commit
eb8eedb4
authored
Nov 22, 2020
by
Komal Makkar
Browse files
adding stack trace for debugging.
parent
98bbd692
Changes
2
Hide whitespace changes
Inline
Side-by-side
notification-core/src/main/java/org/opengroup/osdu/notification/api/PubsubEndpoint.java
View file @
eb8eedb4
...
...
@@ -86,57 +86,61 @@ public class PubsubEndpoint {
@PostMapping
(
"/records-changed"
)
@PreAuthorize
(
"@authorizationFilter.hasAnyPermission('"
+
Config
.
OPS
+
"', '"
+
Config
.
PUBSUB
+
"')"
)
public
ResponseEntity
recordChanged
()
throws
Exception
{
this
.
log
.
info
(
"komakkar recieved recoreds changed request "
);
if
(
this
.
pubsubRequestBodyExtractor
.
isHandshakeRequest
())
{
String
handshakeResponse
=
this
.
pubsubHandshakeHandler
.
getHandshakeResponse
();
return
ResponseEntity
.
ok
(
handshakeResponse
);
}
String
notificationId
=
this
.
pubsubRequestBodyExtractor
.
extractNotificationIdFromRequestBody
();
String
pubsubMessage
=
this
.
pubsubRequestBodyExtractor
.
extractDataFromRequestBody
();
Map
<
String
,
String
>
headerAttributes
=
this
.
pubsubRequestBodyExtractor
.
extractAttributesFromRequestBody
();
Subscription
subscription
=
getSubscriptionFromCache
(
notificationId
);
Secret
secret
=
subscription
.
getSecret
();
String
endpoint
=
subscription
.
getPushEndpoint
();
String
secretType
=
secret
.
getSecretType
();
String
pushUrl
=
""
;
Map
<
String
,
String
>
requestHeader
=
new
HashMap
<>();
if
(
secretType
.
equalsIgnoreCase
(
HMAC_TYPE
))
{
this
.
log
.
info
(
"receiving pubsub message, will send out hmac type request, pubsub message: "
+
pubsubMessage
);
HmacSecret
hmacSecret
=
(
HmacSecret
)
secret
;
String
signedjwt
=
this
.
signatureService
.
getSignedSignature
(
endpoint
,
hmacSecret
.
getValue
());
pushUrl
=
endpoint
+
"?hmac="
+
signedjwt
;
}
else
if
(
secretType
.
equalsIgnoreCase
(
GSA_TYPE
))
{
this
.
log
.
info
(
"receiving pubsub message, will send out gsa type request, pubsub message: "
+
pubsubMessage
);
GsaSecret
gsaSecret
=
(
GsaSecret
)
secret
;
GsaSecretValue
gsaSecretValue
=
gsaSecret
.
getValue
();
JsonParser
jsonParser
=
new
JsonParser
();
JsonElement
root
=
jsonParser
.
parse
(
gsaSecretValue
.
getKey
());
String
keyString
=
root
.
getAsJsonObject
().
toString
();
String
idToken
=
this
.
gsaTokenProvider
.
getIdToken
(
keyString
,
gsaSecretValue
.
getAudience
());
pushUrl
=
endpoint
;
requestHeader
.
put
(
"Authorization"
,
idToken
);
}
this
.
log
.
info
(
"komakkar sending out notification to endpoint: "
+
pushUrl
);
requestHeader
.
put
(
DpsHeaders
.
CONTENT_TYPE
,
"application/json"
);
requestHeader
.
put
(
DpsHeaders
.
CORRELATION_ID
,
headerAttributes
.
get
(
DpsHeaders
.
CORRELATION_ID
));
requestHeader
.
put
(
DpsHeaders
.
DATA_PARTITION_ID
,
headerAttributes
.
get
(
DpsHeaders
.
DATA_PARTITION_ID
));
this
.
log
.
info
(
"komakkar sending out notification to endpoint: "
+
headers
.
toString
());
HttpRequest
request
=
HttpRequest
.
post
().
url
(
pushUrl
).
headers
(
requestHeader
).
body
(
pubsubMessage
).
connectionTimeout
(
WAITING_TIME
).
build
();
HttpResponse
response
=
httpClient
.
send
(
request
);
if
(!
response
.
isSuccessCode
())
{
this
.
log
.
error
(
NOT_ACKNOWLEDGE
);
return
ResponseEntity
.
badRequest
().
body
(
NOT_ACKNOWLEDGE
);
try
{
if
(
this
.
pubsubRequestBodyExtractor
.
isHandshakeRequest
())
{
String
handshakeResponse
=
this
.
pubsubHandshakeHandler
.
getHandshakeResponse
();
return
ResponseEntity
.
ok
(
handshakeResponse
);
}
String
notificationId
=
this
.
pubsubRequestBodyExtractor
.
extractNotificationIdFromRequestBody
();
String
pubsubMessage
=
this
.
pubsubRequestBodyExtractor
.
extractDataFromRequestBody
();
Map
<
String
,
String
>
headerAttributes
=
this
.
pubsubRequestBodyExtractor
.
extractAttributesFromRequestBody
();
Subscription
subscription
=
getSubscriptionFromCache
(
notificationId
);
Secret
secret
=
subscription
.
getSecret
();
String
endpoint
=
subscription
.
getPushEndpoint
();
String
secretType
=
secret
.
getSecretType
();
String
pushUrl
=
""
;
Map
<
String
,
String
>
requestHeader
=
new
HashMap
<>();
if
(
secretType
.
equalsIgnoreCase
(
HMAC_TYPE
))
{
this
.
log
.
info
(
"receiving pubsub message, will send out hmac type request, pubsub message: "
+
pubsubMessage
);
HmacSecret
hmacSecret
=
(
HmacSecret
)
secret
;
String
signedjwt
=
this
.
signatureService
.
getSignedSignature
(
endpoint
,
hmacSecret
.
getValue
());
pushUrl
=
endpoint
+
"?hmac="
+
signedjwt
;
}
else
if
(
secretType
.
equalsIgnoreCase
(
GSA_TYPE
))
{
this
.
log
.
info
(
"receiving pubsub message, will send out gsa type request, pubsub message: "
+
pubsubMessage
);
GsaSecret
gsaSecret
=
(
GsaSecret
)
secret
;
GsaSecretValue
gsaSecretValue
=
gsaSecret
.
getValue
();
JsonParser
jsonParser
=
new
JsonParser
();
JsonElement
root
=
jsonParser
.
parse
(
gsaSecretValue
.
getKey
());
String
keyString
=
root
.
getAsJsonObject
().
toString
();
String
idToken
=
this
.
gsaTokenProvider
.
getIdToken
(
keyString
,
gsaSecretValue
.
getAudience
());
pushUrl
=
endpoint
;
requestHeader
.
put
(
"Authorization"
,
idToken
);
}
this
.
log
.
info
(
"sending out notification to endpoint: "
+
endpoint
);
requestHeader
.
put
(
DpsHeaders
.
CONTENT_TYPE
,
"application/json"
);
requestHeader
.
put
(
DpsHeaders
.
CORRELATION_ID
,
headerAttributes
.
get
(
DpsHeaders
.
CORRELATION_ID
));
requestHeader
.
put
(
DpsHeaders
.
DATA_PARTITION_ID
,
headerAttributes
.
get
(
DpsHeaders
.
DATA_PARTITION_ID
));
this
.
log
.
info
(
"komakkar sending out notification to endpoint: "
+
headers
.
toString
());
HttpRequest
request
=
HttpRequest
.
post
().
url
(
pushUrl
).
headers
(
requestHeader
).
body
(
pubsubMessage
).
connectionTimeout
(
WAITING_TIME
).
build
();
HttpResponse
response
=
httpClient
.
send
(
request
);
if
(!
response
.
isSuccessCode
())
{
this
.
log
.
error
(
NOT_ACKNOWLEDGE
);
return
ResponseEntity
.
badRequest
().
body
(
NOT_ACKNOWLEDGE
);
}
this
.
log
.
info
(
ACKNOWLEDGE
);
return
ResponseEntity
.
ok
(
ACKNOWLEDGE
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
this
.
log
.
info
(
ACKNOWLEDGE
);
return
ResponseEntity
.
ok
(
ACKNOWLEDGE
);
return
ResponseEntity
.
badRequest
().
body
(
NOT_ACKNOWLEDGE
);
}
private
Subscription
getSubscriptionFromCache
(
String
notificationId
)
throws
Exception
{
...
...
testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/api/TestPubsubEndpointHMAC.java
View file @
eb8eedb4
...
...
@@ -59,7 +59,7 @@ public class TestPubsubEndpointHMAC extends PubsubEndpointHMACTests {
return
;
}
// For the following 403 is the exp
c
eted result.
// For the following 403 is the expe
c
ted result.
// Tracking in Issue: https://community.opengroup.org/osdu/platform/system/notification/-/issues/17
@Test
@Override
...
...
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