|
20 | 20 | import jakarta.json.Json; |
21 | 21 | import jakarta.json.JsonObject; |
22 | 22 | import jakarta.json.JsonObjectBuilder; |
| 23 | +import jakarta.json.JsonValue; |
23 | 24 | import jakarta.ws.rs.BadRequestException; |
24 | 25 |
|
25 | 26 | import org.apache.http.client.methods.CloseableHttpResponse; |
@@ -73,12 +74,20 @@ public COARNotifyRelationshipAnnouncement( |
73 | 74 | */ |
74 | 75 | public void processMessage(JsonObject msgObject) { |
75 | 76 | // Extract subject, object, and relationship from the message |
76 | | - String subjectId = extractField(msgObject, subjectKey); |
77 | | - String objectId = extractField(msgObject, objectKey); |
78 | | - String relationshipId = extractField(msgObject, relationshipKey); |
| 77 | + String subjectId; |
| 78 | + String objectId; |
| 79 | + String relationshipId; |
| 80 | + try { |
| 81 | + // Extract subject, object, and relationship from the message |
| 82 | + subjectId = extractField(msgObject, subjectKey); |
| 83 | + objectId = extractField(msgObject, objectKey); |
| 84 | + relationshipId = extractField(msgObject, relationshipKey); |
79 | 85 |
|
80 | | - if (subjectId == null || objectId == null || relationshipId == null) { |
81 | | - throw new BadRequestException("Can't find the subject, relationship or object in the message - ignoring"); |
| 86 | + if (subjectId == null || objectId == null || relationshipId == null) { |
| 87 | + throw new BadRequestException("Can't find the subject, relationship or object in the message - ignoring"); |
| 88 | + } |
| 89 | + } catch (Exception e) { |
| 90 | + throw new BadRequestException("Failed to parse subject, relationship or object from the message - ignoring", e); |
82 | 91 | } |
83 | 92 |
|
84 | 93 | // Get metadata about the citing resource |
@@ -112,7 +121,15 @@ public void processMessage(JsonObject msgObject) { |
112 | 121 | * Extract a field value from the message object. |
113 | 122 | */ |
114 | 123 | private String extractField(JsonObject msgObject, String key) { |
115 | | - return msgObject.containsKey(key) ? msgObject.getString(key) : null; |
| 124 | + if (msgObject.containsKey(key)) { |
| 125 | + JsonValue value = msgObject.get(key); |
| 126 | + if (value.getValueType() == JsonValue.ValueType.OBJECT) { |
| 127 | + return ((JsonObject) value).getString("@id", null); |
| 128 | + } else if (value.getValueType() == JsonValue.ValueType.STRING) { |
| 129 | + return msgObject.getString(key); |
| 130 | + } |
| 131 | + } |
| 132 | + return null; |
116 | 133 | } |
117 | 134 |
|
118 | 135 | /** |
|
0 commit comments