Skip to content

Commit

Permalink
FDP-1811: Log messages instead of exceptions when a connection can't …
Browse files Browse the repository at this point in the history
…be found

Signed-off-by: Jasper Kamerling <[email protected]>
  • Loading branch information
jasperkamerling committed Dec 7, 2023
1 parent 537a951 commit 1d14ae8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 1d14ae8

Please sign in to comment.