diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f57d943 --- /dev/null +++ b/.gitignore @@ -0,0 +1,41 @@ +#Maven +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +release.properties +.flattened-pom.xml + +# Eclipse +.project +.classpath +.settings/ +bin/ + +# IntelliJ +.idea +*.ipr +*.iml +*.iws + +# NetBeans +nb-configuration.xml + +# Visual Studio Code +.vscode +.factorypath + +# OSX +.DS_Store + +# Vim +*.swp +*.swo + +# patch +*.orig +*.rej + +# Local environment +.env +/.mvn/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..2abfec5 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Multi-channel Integration Layer Common +Common classes used by services that make up the Multi-channel Intagration Layer of SW Client project. diff --git a/pom.xml b/pom.xml index 70f85ff..dbacd02 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ common - 0.0.6-SNAPSHOT + 0.0.14-SNAPSHOT jar Common classes for Multi-channel Integration Layer of SW Client Project @@ -48,7 +48,7 @@ build generate-code - generate-code-tests + diff --git a/src/main/java/it/gov/pagopa/swclient/mil/dto/CommonHeader.java b/src/main/java/it/gov/pagopa/swclient/mil/dto/CommonHeader.java index 094070a..439fa07 100644 --- a/src/main/java/it/gov/pagopa/swclient/mil/dto/CommonHeader.java +++ b/src/main/java/it/gov/pagopa/swclient/mil/dto/CommonHeader.java @@ -18,6 +18,14 @@ * @author Antonio Tarricone */ public class CommonHeader { + /* + * Request ID + */ + @HeaderParam("RequestId") + @NotNull(message = "RequestId must not be null") + @Pattern(regexp = "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" , message = "RequestId must match {regexp}") + private String requestId; + /* * Version of the required API */ @@ -50,6 +58,22 @@ public class CommonHeader { @Pattern(regexp = "^[0-9a-zA-Z]{8}$", message = "TerminalId must match {regexp}") private String terminalId; + /** + * + * @return + */ + public String getRequestId() { + return requestId; + } + + /** + * + * @param requestId + */ + public void setRequestId(String requestId) { + this.requestId = requestId; + } + /** * * @return @@ -120,6 +144,7 @@ public void setTerminalId(String terminalId) { @Override public String toString() { return new StringJoiner(", ", CommonHeader.class.getSimpleName() + "[", "]") + .add("requestId='" + requestId + "'") .add("version='" + version + "'") .add("acquirerId='" + acquirerId + "'") .add("channel=" + channel) diff --git a/src/main/java/it/gov/pagopa/swclient/mil/util/MappedDiagnosticContextFilter.java b/src/main/java/it/gov/pagopa/swclient/mil/util/MappedDiagnosticContextFilter.java new file mode 100644 index 0000000..fd3a286 --- /dev/null +++ b/src/main/java/it/gov/pagopa/swclient/mil/util/MappedDiagnosticContextFilter.java @@ -0,0 +1,32 @@ +/* + * MappedDiagnosticContextFilter.java + * + * 28 nov 2022 + */ +package it.gov.pagopa.swclient.mil.util; + +import java.io.IOException; + +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerRequestFilter; +import javax.ws.rs.container.PreMatching; +import javax.ws.rs.ext.Provider; + +import org.jboss.logging.MDC; + +/** + * + * @author Antonio Tarricone + */ +@Provider +@PreMatching +public class MappedDiagnosticContextFilter implements ContainerRequestFilter { + @Override + public void filter(ContainerRequestContext requestContext) throws IOException { + String requestId = requestContext.getHeaderString("RequestId"); + if (requestId == null) { + requestId = "null"; + } + MDC.put("requestId", requestId); + } +} diff --git a/src/main/resources/META-INF/beans.xml b/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000..330c7f6 --- /dev/null +++ b/src/main/resources/META-INF/beans.xml @@ -0,0 +1 @@ + \ No newline at end of file