Skip to content

Commit

Permalink
Merge pull request #104 from de4a-wp5/iteration2-dev
Browse files Browse the repository at this point in the history
Iteration2 dev
  • Loading branch information
phax authored Aug 18, 2022
2 parents 8c38543 + 7e1257e commit 9a96332
Show file tree
Hide file tree
Showing 17 changed files with 178 additions and 84 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ Once you have deployed the `war` file, there are several **checks to ensure that

# News and Noteworthy

* v0.2.3 - 2022-08-18
* The `/service/ial` queries no longer require the `application/xml` Content Type
* Updated the Iteration 1 code bindings to avoid conflicting paths (de4a-iem 0.1.13)
* Fixed bugs in the default page of the Connector - now all properties are shown
* Made the IAL remote query more resilient
* v0.2.2 - 2022-08-16
* Updated to de4a-commons 0.2.12
* Updated to de4a-connector-ng 0.2.7 with improved configurability
Expand Down
20 changes: 20 additions & 0 deletions build-and-run-docker.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@echo off

set JAVA_HOME=C:\Program Files\Eclipse Adoptium\jdk-11.0.16.8-hotspot
call mvn clean install
if errorlevel 1 goto error

cd de4a-connector
docker build --pull -t de4a/connector:iteration2 .
if errorlevel 1 goto error

docker stop de4a_conncector_it2 && docker rm de4a_conncector_it2
docker run -d -p 8080:8080 --name de4a_conncector_it2 de4a/connector:iteration2
if errorlevel 1 goto error

goto end

:error
pause

:end
24 changes: 24 additions & 0 deletions build-release-docker.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@echo off

:: The version to release
set VER=0.2.3

cd de4a-connector
docker build --pull -t de4a/connector:%VER% .
if errorlevel 1 goto error

echo Login to Docker Hub with user phelger
docker login -u phelger
if errorlevel 1 goto error

docker push de4a/connector:%VER%
if errorlevel 1 goto error

docker logout

goto end

:error
pause

:end
45 changes: 23 additions & 22 deletions de4a-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
<dependency>
<groupId>eu.de4a</groupId>
<artifactId>de4a-iem</artifactId>
<version>0.1.12</version>
</dependency>

<!-- DE4A IAL -->
Expand Down Expand Up @@ -147,29 +146,32 @@
</exclusion>
</exclusions>
</dependency>
<!-- JUnit 4 for testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<!-- JUnit 4 for testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<targetPath>${project.build.directory}/classes</targetPath>
</resource>
<resource>
<directory>${basedir}/src/main/webapp</directory>
<targetPath>${project.build.directory}/webapp-classes</targetPath>
</resource>
<resource>
<directory>${basedir}/src/test/resources</directory>
<targetPath>${project.build.directory}/test-classes</targetPath>
</resource>
</resources>
<finalName>de4a-connector</finalName>

<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<targetPath>${project.build.directory}/classes</targetPath>
</resource>
<resource>
<directory>${basedir}/src/main/webapp</directory>
<targetPath>${project.build.directory}/webapp-classes</targetPath>
</resource>
<resource>
<directory>${basedir}/src/test/resources</directory>
<targetPath>${project.build.directory}/test-classes</targetPath>
</resource>
</resources>

<plugins>
<plugin>
Expand All @@ -187,6 +189,5 @@
</executions>
</plugin>
</plugins>
<finalName>de4a-connector</finalName>
</build>
</project>
41 changes: 41 additions & 0 deletions de4a-connector/src/main/java/eu/de4a/connector/JSPHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package eu.de4a.connector;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.helger.commons.string.StringHelper;
import com.helger.dcng.api.DcngConfig;

public final class JSPHelper
{
private JSPHelper ()
{}

@Nonnull
public static String formatted (@Nullable final String s)
{
String ret = "<span class=\"param-value";
if ("true".equals (s))
ret += " value-true";
else
if ("false".equals (s))
ret += " value-false";
else
if (StringHelper.hasText (s))
ret += " value";
ret += "\">";

if (StringHelper.hasText (s))
ret += s;
else
ret += "<em>not set</em>";
ret += "</span>";
return ret;
}

@Nonnull
public static String formattedProp (@Nullable final String sProp)
{
return formatted (DcngConfig.getConfig ().getAsString (sProp));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package eu.de4a.connector.api.controller;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nonnull;
import javax.validation.Valid;
Expand Down Expand Up @@ -111,13 +109,13 @@ private static <T> T _conversionBytesWithCatching (final InputStream obj,
final RequestExtractMultiEvidenceIMType aNewRequest = LegacyAPIHelper.convertOldToNewRequest_DR (aOldRequest);

//additional parameter for it1 message identification
final List<AdditionalParameterType> aList = new ArrayList<>();
final AdditionalParameterType addParam = new AdditionalParameterType();
addParam.setLabel("iteration");
addParam.setValue("1");
addParam.setType(AdditionalParameterTypeType.YES_NO);
aList.add(addParam);
aNewRequest.getRequestEvidenceIMItemAtIndex(0).setAdditionalParameter(aList);
{
final AdditionalParameterType addParam = new AdditionalParameterType();
addParam.setLabel("iteration");
addParam.setValue("1");
addParam.setType(AdditionalParameterTypeType.YES_NO);
aNewRequest.getRequestEvidenceIMItemAtIndex(0).addAdditionalParameter (addParam);
}

final String sNewDocTypeID = aNewRequest.getRequestEvidenceIMItemAtIndex (0).getCanonicalEvidenceTypeId ();
final AS4MessageDTO messageDTO = new AS4MessageDTO (aNewRequest.getDataEvaluator ().getAgentUrn (),
Expand All @@ -126,8 +124,8 @@ private static <T> T _conversionBytesWithCatching (final InputStream obj,
DE4AConstants.PROCESS_ID_REQUEST);

final var aNewRequestMarshaller = DE4ACoreMarshaller.drRequestTransferEvidenceIMMarshaller ();
String requestMetadata = MessageUtils.getLegacyRequestMetadata(aOldRequest.getRequestId(), aOldRequest.getCanonicalEvidenceTypeId());
this.apiManager.processIncomingMessage (ELogMessage.LOG_REQ_IM_LEGACY_DE_DR,
final String requestMetadata = MessageUtils.getLegacyRequestMetadata(aOldRequest.getRequestId(), aOldRequest.getCanonicalEvidenceTypeId());
this.apiManager.processIncomingMessage (ELogMessage.LOG_REQ_IM_LEGACY_DE_DR,
aNewRequest, messageDTO, aNewRequestMarshaller, sNewDocTypeID, requestMetadata);

// Remember request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ public class ServiceController
@Autowired
private ServiceUtils serviceUtils;

@GetMapping (value = "/ial/{cot}", produces = MediaType.APPLICATION_XML_VALUE, consumes = MediaType.APPLICATION_XML_VALUE)
@GetMapping (value = "/ial/{cot}", produces = MediaType.APPLICATION_XML_VALUE)
public ResponseEntity <byte []> lookupRoutingInformation (@Valid @PathVariable @NotNull final String cot)
{
if (LOGGER.isInfoEnabled ())
LOGGER.info ("Request to API /service/ial/" + cot + " received");
LOGGER.info ("Request to API '/service/ial/" + cot + "' received");

// Main query
final ResponseLookupRoutingInformationType aResponse = DcngApiHelper.queryIAL (StringHelper.getExplodedToOrderedSet (",", cot));
if (aResponse == null)
{
final String errorMsg = "Error querying IAL";
final String errorMsg = "Error querying IAL without ATU code";
KafkaClientWrapper.sendError(EFamilyErrorType.CONNECTION_ERROR, EExternalModule.CONNECTOR_DR, EExternalModule.IAL.getLabel(), errorMsg);

// Error case
Expand All @@ -63,12 +63,12 @@ public class ServiceController
.body (IALMarshaller.responseLookupRoutingInformationMarshaller ().getAsBytes (aResponse));
}

@GetMapping (value = "/ial/{cot}/{atu}", produces = MediaType.APPLICATION_XML_VALUE, consumes = MediaType.APPLICATION_XML_VALUE)
@GetMapping (value = "/ial/{cot}/{atu}", produces = MediaType.APPLICATION_XML_VALUE)
public ResponseEntity <byte []> lookupRoutingInformation (@Valid @PathVariable @NotNull final String cot,
@Valid @PathVariable @NotNull final String atu)
{
if (LOGGER.isInfoEnabled ())
LOGGER.info ("Request to API /service/ial/" + cot + "/" + atu + " received");
LOGGER.info ("Request to API '/service/ial/" + cot + "/" + atu + "' received");

// Main query
final ResponseLookupRoutingInformationType aResponse = DcngApiHelper.queryIAL (StringHelper.getExplodedToOrderedSet (",", cot), atu);
Expand All @@ -94,7 +94,7 @@ public class ServiceController
public ResponseEntity <String> reloadAddresses ()
{
if (LOGGER.isInfoEnabled ())
LOGGER.info ("Request to API /service/reload-addresses received");
LOGGER.info ("Request to API '/service/reload-addresses' received");

serviceUtils.reloadParticipantAddresses ();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;

import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import com.helger.commons.collection.ArrayHelper;
import com.helger.commons.http.CHttpHeader;
import com.helger.commons.mime.CMimeType;
import com.helger.dcng.core.http.DcngHttpClientSettings;
import com.helger.httpclient.HttpClientManager;
import com.helger.httpclient.response.ExtendedHttpResponseException;
Expand Down Expand Up @@ -47,8 +46,7 @@ private APIRestUtils ()
try (final HttpClientManager aHCM = HttpClientManager.create (new DcngHttpClientSettings ()))
{
final HttpPost aPost = new HttpPost (url);
aPost.addHeader (CHttpHeader.CONTENT_TYPE, CMimeType.APPLICATION_XML.getAsString ());
aPost.setEntity (new ByteArrayEntity (request));
aPost.setEntity (new ByteArrayEntity (request, ContentType.APPLICATION_XML));
final byte [] aResult = aHCM.execute (aPost, new ResponseHandlerByteArray ());
if (aResult == null || aResult.length == 0)
{
Expand All @@ -68,9 +66,9 @@ private APIRestUtils ()
final ConnectorException exception = aBaseEx.withLayer (ELayerError.COMMUNICATIONS)
.withFamily (EFamilyErrorType.ERROR_RESPONSE)
.withMessageArg (ex.getMessage ());

KafkaClientWrapper.sendError(EFamilyErrorType.ERROR_RESPONSE, exception.getModule(), url, exception.getMessage());

return new ResponseEntity <> (ConnectorExceptionHandler.getResponseErrorObjectBytes (exception),
HttpStatus.resolve (ex.getStatusCode ()));
}
Expand All @@ -81,9 +79,9 @@ private APIRestUtils ()
final ConnectorException exception = aBaseEx.withLayer (ELayerError.COMMUNICATIONS)
.withFamily (EFamilyErrorType.CONNECTION_ERROR)
.withMessageArg (ex.getMessage ());

KafkaClientWrapper.sendError(EFamilyErrorType.CONNECTION_ERROR, exception.getModule(), url, exception.getMessage());

return new ResponseEntity <> (ConnectorExceptionHandler.getResponseErrorObjectBytes (exception), HttpStatus.BAD_REQUEST);
}
}
Expand Down
4 changes: 2 additions & 2 deletions de4a-connector/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ log.metrics.prefix=DE4A METRICS


######################
# IAL/MOR SETTINGS
# IAL SETTINGS
######################
# IDK service base endpoint
idk.endpoint = https://de4a.simplegob.com/ial
Expand Down Expand Up @@ -63,7 +63,6 @@ phase4.dump.incoming.path =
# An OPTIONAL absolute directory path where the outgoing AS4 messages should be dumped to. Disabled by default.
phase4.dump.outgoing.path =


#####################
# LEGACY DO URL
#####################
Expand All @@ -72,4 +71,5 @@ legacy.do.url = https://localhost:8080
###########################################################################################
# Connector identifier (Acronym of the participant's name + '-' + Two-letter country code)
###########################################################################################
# [CHANGEME] use a country specific topic
de4a.connector.id = SGAD-ES
7 changes: 7 additions & 0 deletions de4a-connector/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<!-- DE4A Metrics pattern [prefix][timestamp][Level][Error/Log Code][UC#][Origin][Destiny][Message] -->
<PatternLayout pattern="[DE4A-CONNECTOR][%date{ISO8601}][%-5level] %msg -- %location [%thread]%n" />
</Console>

<RollingFile name="rollingFile"
fileName="${sys:catalina.base}/logs/connector.log"
filePattern="${sys:catalina.base}/logs/history/connector.%d{dd-MMM}.log.gz"
Expand All @@ -19,6 +20,7 @@
</Policies>
<DefaultRolloverStrategy max="5" />
</RollingFile>

<RollingFile name="metricsFile"
fileName="${sys:catalina.base}/logs/metrics-connector.log"
filePattern="${sys:catalina.base}/logs/history/metrics-connector.%d{dd-MMM}.log.gz"
Expand Down Expand Up @@ -59,5 +61,10 @@
<AppenderRef ref="rollingFile" />
<AppenderRef ref="RouterMetrics" />
</Root>
<!--
<Root level="debug">
<AppenderRef ref="STDOUT" />
</Root>
-->
</Loggers>
</Configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ error.400.mimetype={0} Media type {1} is not supported, it's expected {2}
error.400.args.required={0} No 'RequestTransferEvidence' found in the request body
error.400.args.unmarshalling={0} Failed to correctly unmarshalling a RequestTransferEvidence object: {1}

error.connection={0} Connection error with {1} - {2}
error.connection={0} Connection error with {1}
error.response={0} Error on response from {1} - {2}
error.conversion={0} Object conversion error on {1} - {2}
error.database={0} Error accessing/saving data on {1} - {2}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ error.400.mimetype={0} Media type {1} is not supported, it's expected {2}
error.400.args.required={0} No 'RequestTransferEvidence' found in the request body
error.400.args.unmarshalling={0} Failed to correctly unmarshalling a RequestTransferEvidence object: {1}

error.connection={0} Connection error with {1} - {2}
error.connection={0} Connection error with {1}
error.response={0} Error on response from {1} - {2}
error.conversion={0} Object conversion error on {1} - {2}
error.database={0} Error accessing/saving data on {1} - {2}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ error.400.mimetype={0} Media type {1} is not supported, it's expected {2}
error.400.args.required={0} No 'RequestTransferEvidence' found in the request body
error.400.args.unmarshalling={0} Failed to correctly unmarshalling a RequestTransferEvidence object: {1}

error.connection={0} Connection error with {1} - {2}
error.connection={0} Connection error with {1}
error.response={0} Error on response from {1} - {2}
error.conversion={0} Object conversion error on {1} - {2}
error.database={0} Error accessing/saving data on {1} - {2}
Expand Down
Loading

0 comments on commit 9a96332

Please sign in to comment.