From 1d14ae8e44d8fd8803d341e0e2288bf80275d627 Mon Sep 17 00:00:00 2001 From: Jasper Kamerling Date: Thu, 7 Dec 2023 13:10:23 +0100 Subject: [PATCH] FDP-1811: Log messages instead of exceptions when a connection can't be found Signed-off-by: Jasper Kamerling --- .../services/ClientCommunicationService.java | 72 ++++++++++--------- .../services/ConnectionCacheService.java | 16 ++--- .../soap/endpoints/SoapEndpoint.java | 14 ++-- 3 files changed, 50 insertions(+), 52 deletions(-) diff --git a/application/src/main/java/org/gxf/soapbridge/application/services/ClientCommunicationService.java b/application/src/main/java/org/gxf/soapbridge/application/services/ClientCommunicationService.java index 91a423f..8b1c236 100644 --- a/application/src/main/java/org/gxf/soapbridge/application/services/ClientCommunicationService.java +++ b/application/src/main/java/org/gxf/soapbridge/application/services/ClientCommunicationService.java @@ -17,48 +17,50 @@ @Service public class ClientCommunicationService { - private static final Logger LOGGER = LoggerFactory.getLogger(ClientCommunicationService.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ClientCommunicationService.class); - /** Service used to cache incoming connections from client applications. */ - private final ConnectionCacheService connectionCacheService; + /** + * Service used to cache incoming connections from client applications. + */ + private final ConnectionCacheService connectionCacheService; - /** Service used to sign and/or verify the content of queue messages. */ - private final SigningService signingService; + /** + * Service used to sign and/or verify the content of queue messages. + */ + private final SigningService signingService; - public ClientCommunicationService( - final ConnectionCacheService connectionCacheService, final SigningService signingService) { - this.connectionCacheService = connectionCacheService; - this.signingService = signingService; - } + public ClientCommunicationService( + final ConnectionCacheService connectionCacheService, final SigningService signingService) { + this.connectionCacheService = connectionCacheService; + this.signingService = signingService; + } + + /** + * Process an incoming queue message. The content of the message has to be verified by the {@link + * SigningService}. Then a response from GXF will set for the pending connection from a client. + * + * @param proxyServerResponseMessage The incoming queue message to process. + */ + public void handleIncomingResponse(final ProxyServerResponseMessage proxyServerResponseMessage) { + final boolean isValid = + signingService.verifyContent( + proxyServerResponseMessage.constructString(), + proxyServerResponseMessage.getSignature()); - /** - * Process an incoming queue message. The content of the message has to be verified by the {@link - * SigningService}. Then a response from GXF will set for the pending connection from a client. - * - * @param proxyServerResponseMessage The incoming queue message to process. - */ - public void handleIncomingResponse(final ProxyServerResponseMessage proxyServerResponseMessage) { - final boolean isValid = - signingService.verifyContent( - proxyServerResponseMessage.constructString(), - proxyServerResponseMessage.getSignature()); + final Connection connection = + connectionCacheService.findConnection(proxyServerResponseMessage.getConnectionId()); + + if (connection == null) { + LOGGER.error("No connection found in cache for id: {}", proxyServerResponseMessage.getConnectionId()); + return; + } - try { - final Connection connection = - connectionCacheService.findConnection(proxyServerResponseMessage.getConnectionId()); - if (connection != null) { if (isValid) { - LOGGER.debug("Connection valid, set SOAP response"); - connection.setSoapResponse(proxyServerResponseMessage.getSoapResponse()); + LOGGER.debug("Connection valid, set SOAP response"); + connection.setSoapResponse(proxyServerResponseMessage.getSoapResponse()); } else { - LOGGER.error("ProxyServerResponseMessage failed to pass security check."); - connection.setSoapResponse("Security check has failed."); + LOGGER.error("ProxyServerResponseMessage failed to pass security check."); + connection.setSoapResponse("Security check has failed."); } - } else { - LOGGER.error("No connection found in cache for id."); - } - } catch (final ConnectionNotFoundInCacheException e) { - LOGGER.error("ConnectionNotFoundInCacheException", e); } - } } diff --git a/application/src/main/java/org/gxf/soapbridge/application/services/ConnectionCacheService.java b/application/src/main/java/org/gxf/soapbridge/application/services/ConnectionCacheService.java index 94dd9b5..928c880 100644 --- a/application/src/main/java/org/gxf/soapbridge/application/services/ConnectionCacheService.java +++ b/application/src/main/java/org/gxf/soapbridge/application/services/ConnectionCacheService.java @@ -5,6 +5,7 @@ import java.util.concurrent.ConcurrentHashMap; +import jakarta.annotation.Nullable; import jakarta.annotation.PostConstruct; import org.gxf.soapbridge.monitoring.MonitoringService; import org.gxf.soapbridge.soap.clients.Connection; @@ -53,19 +54,12 @@ public Connection cacheConnection() { * * @param connectionId The key for the {@link Connection} instance obtained by calling {@link * ConnectionCacheService#cacheConnection()}. - * @return A {@link Connection} instance. - * @throws ConnectionNotFoundInCacheException In case the connection is not present in the {@link - * ConnectionCacheService#cache}. + * @return A {@link Connection} instance. If no connection with the id is present return null. */ - public Connection findConnection(final String connectionId) - throws ConnectionNotFoundInCacheException { + @Nullable + public Connection findConnection(final String connectionId) { LOGGER.debug("Trying to find connection with connectionId: {}", connectionId); - final Connection connection = cache.get(connectionId); - if (connection == null) { - throw new ConnectionNotFoundInCacheException( - String.format("Unable to find connection for connectionId: %s", connectionId)); - } - return connection; + return cache.get(connectionId); } /** diff --git a/application/src/main/java/org/gxf/soapbridge/soap/endpoints/SoapEndpoint.java b/application/src/main/java/org/gxf/soapbridge/soap/endpoints/SoapEndpoint.java index 3ca18f9..ed46dc0 100644 --- a/application/src/main/java/org/gxf/soapbridge/soap/endpoints/SoapEndpoint.java +++ b/application/src/main/java/org/gxf/soapbridge/soap/endpoints/SoapEndpoint.java @@ -243,14 +243,16 @@ private Integer shouldUseCustomTimeOut(final String soapPayload) { private String readResponse(final String connectionId) throws ServletException { final String soap; - try { - final Connection connection = connectionCacheService.findConnection(connectionId); - soap = connection.getSoapResponse(); - connectionCacheService.removeConnection(connectionId); - } catch (final ConnectionNotFoundInCacheException e) { - LOGGER.error("Unexpected error while trying to find a cached connection", e); + + final Connection connection = connectionCacheService.findConnection(connectionId); + + if (connection == null) { + LOGGER.error("Unexpected error while trying to find a cached connection for id: {}", connectionId); throw new ServletException("Unable to obtain response"); } + + soap = connection.getSoapResponse(); + connectionCacheService.removeConnection(connectionId); return soap; }