Skip to content

Commit fe0a23e

Browse files
Merge pull request #35 from protegeproject/fix-forms-download
Fix forms download
2 parents 59d7af5 + fd7e88f commit fe0a23e

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<dependency>
7878
<groupId>edu.stanford.protege</groupId>
7979
<artifactId>webprotege-ipc</artifactId>
80-
<version>2.0.1</version>
80+
<version>2.0.2</version>
8181
</dependency>
8282

8383
<dependency>

src/main/java/edu/stanford/protege/webprotege/gateway/FormsController.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ public FormsController(RpcClient rpcClient, ObjectMapper objectMapper) {
3939
@GetMapping("/data/projects/{projectId}/forms")
4040
public ResponseEntity<Map<String, Object>> getForms(@PathVariable(PROJECT_ID) ProjectId projectId,
4141
@AuthenticationPrincipal Jwt jwt) {
42-
return rpcClient.call(jwt, GET_FORM_DESCRIPTORS, Map.of(PROJECT_ID, projectId));
42+
try {
43+
CorrelationMDCUtil.setCorrelationId(UUID.randomUUID().toString());
44+
return rpcClient.call(jwt, GET_FORM_DESCRIPTORS, Map.of(PROJECT_ID, projectId));
45+
} finally {
46+
CorrelationMDCUtil.clearCorrelationId();
47+
}
4348
}
4449

4550
@PostMapping("/data/projects/{projectId}/forms")

src/main/java/edu/stanford/protege/webprotege/gateway/RpcRequestProcessor.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import org.jetbrains.annotations.Nullable;
1111
import org.slf4j.Logger;
1212
import org.slf4j.LoggerFactory;
13+
import org.springframework.amqp.AmqpTimeoutException;
14+
import org.springframework.amqp.core.AmqpMessageReturnedException;
15+
import org.springframework.amqp.core.AmqpReplyTimeoutException;
1316
import org.springframework.beans.factory.annotation.Value;
1417
import org.springframework.http.HttpStatus;
1518
import org.springframework.http.HttpStatusCode;
@@ -19,6 +22,8 @@
1922
import java.util.Collections;
2023
import java.util.Map;
2124
import java.util.concurrent.CompletableFuture;
25+
import java.util.concurrent.CompletionException;
26+
import java.util.concurrent.TimeoutException;
2227

2328
/**
2429
* Matthew Horridge
@@ -76,9 +81,19 @@ private CompletableFuture<RpcResponse> sendMessage(RpcRequest request, String ac
7681
payload, userId);
7782
return reply
7883
.exceptionally(e -> {
79-
// Convert all exceptions to a ResponseStatusException
84+
if(e instanceof CompletionException completionException) {
85+
if(completionException.getCause() instanceof AmqpReplyTimeoutException timeoutException) {
86+
logger.error("Timeout while waiting for reply to message on channel {}: {}", request.methodName(), timeoutException.getMessage(), e);
87+
throw new ResponseStatusException(HttpStatus.GATEWAY_TIMEOUT, "Timed out while waiting for reply to message on channel " + request.methodName(), timeoutException);
88+
}
89+
else if(completionException.getCause() instanceof AmqpMessageReturnedException messageReturnedException) {
90+
logger.error("Message returned: {}", messageReturnedException.getMessage(), e);
91+
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Message to channel " + request.methodName() + " was returned");
92+
}
93+
}
8094
logger.error("Error during send and receive: {}. Returning failed future with ResponseStatusException HTTP 500 Internal Server Error", e.getMessage(), e);
8195
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage(), e);
96+
8297
})
8398
.thenCompose(msg -> {
8499
try {

0 commit comments

Comments
 (0)