Skip to content

Commit

Permalink
Merge branch 'main' into feature/FDP-94-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jasperkamerling authored Jan 12, 2024
2 parents d903b1c + 8803fc2 commit e63fd3f
Show file tree
Hide file tree
Showing 15 changed files with 298 additions and 125 deletions.
8 changes: 3 additions & 5 deletions application/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-logging")
implementation("org.springframework.kafka:spring-kafka")
implementation("com.gxf.utilities:kafka-azure-oauth:0.2")
implementation("com.microsoft.azure:msal4j:1.13.10")
implementation("org.apache.httpcomponents:httpclient:4.5.13") {
implementation("org.apache.httpcomponents:httpclient:4.5.14") {
exclude("commons-logging")
}
implementation(kotlin("reflect"))
Expand All @@ -29,6 +28,7 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-engine")
testImplementation("org.junit.jupiter:junit-jupiter-params")
testImplementation("org.mockito:mockito-junit-jupiter")
testImplementation("org.assertj:assertj-core")

// Generate test and integration test reports
jacocoAggregation(project(":application"))
Expand Down Expand Up @@ -57,9 +57,7 @@ testing {
implementation("org.springframework.kafka:spring-kafka-test")
implementation("org.assertj:assertj-core")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.wiremock:wiremock:3.3.1")

implementation("org.testcontainers:kafka:1.17.6")
implementation("org.wiremock:wiremock-standalone:3.3.1")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import java.time.Duration


@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ComponentScan(basePackages = ["org.gxf.soapbridge"])
@EmbeddedKafka(topics = ["requests", "responses"])
class EndToEndTest(
@LocalServerPort private val soapPort: Int,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package org.gxf.soapbridge.application.services;

import org.gxf.soapbridge.soap.clients.Connection;
import org.gxf.soapbridge.soap.exceptions.ConnectionNotFoundInCacheException;
import org.gxf.soapbridge.valueobjects.ProxyServerResponseMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -17,48 +16,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 @@ -4,8 +4,11 @@
package org.gxf.soapbridge.application.services;

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;
import org.gxf.soapbridge.soap.exceptions.ConnectionNotFoundInCacheException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
Expand All @@ -21,6 +24,17 @@ public class ConnectionCacheService {
*/
private static final ConcurrentHashMap<String, Connection> cache = new ConcurrentHashMap<>();

private final MonitoringService monitoringService;

public ConnectionCacheService(MonitoringService monitoringService) {
this.monitoringService = monitoringService;
}

@PostConstruct
public void postConstructor() {
monitoringService.monitorCacheSize(cache);
}

/**
* Creates a connection and puts it in the cache.
*
Expand All @@ -39,19 +53,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 @@ -50,11 +50,6 @@ public void handleIncomingRequest(final ProxyServerRequestMessage proxyServerReq
final String commonName = proxyServerRequestMessage.getCommonName();
final String soapPayload = proxyServerRequestMessage.getSoapPayload();

final boolean result = soapClient.sendRequest(connectionId, context, commonName, soapPayload);
if (!result) {
LOGGER.error("Unsuccessful at sending request to platform.");
} else {
LOGGER.debug("Successfully sent response message to queue");
}
soapClient.sendRequest(connectionId, context, commonName, soapPayload);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.gxf.soapbridge.valueobjects.ProxyServerResponseMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/** This {@link @Component} class can send SOAP messages to the Platform. */
Expand Down Expand Up @@ -54,10 +55,9 @@ public SoapClient(
* @param context The part of the URL indicating the SOAP web-service.
* @param commonName The common name (organisation identification).
* @param soapPayload The SOAP message to send to the platform.
* @return True if the request has been sent and the response has been received and written to a
* queue, false otherwise.
*/
public boolean sendRequest(
@Async
public void sendRequest(
final String connectionId,
final String context,
final String commonName,
Expand All @@ -70,7 +70,7 @@ public boolean sendRequest(
connection = createConnection(context, soapPayload, commonName);
if (connection == null) {
LOGGER.warn("Could not create connection for sending SOAP request.");
return false;
return;
}

// Send the SOAP payload to the server.
Expand All @@ -89,13 +89,11 @@ public boolean sendRequest(
// Send queue message.
proxyReponseSender.send(responseMessage);

return true;
} catch (final Exception e) {
if (connection != null) {
connection.disconnect();
}
LOGGER.error("Unexpected exception while sending SOAP request", e);
return false;
}
}

Expand Down
Loading

0 comments on commit e63fd3f

Please sign in to comment.