From a65988c79ed615c3a03df4aed6800f6b3aed60f9 Mon Sep 17 00:00:00 2001 From: Steven Mahieu Date: Tue, 8 Oct 2024 10:58:03 +0200 Subject: [PATCH] jakarta upgrade --- oxalis-api/pom.xml | 14 +- .../network/oxalis/api/inject/NamedImpl.java | 2 +- .../oxalis/api/lookup/LookupService.java | 12 -- .../oxalis/api/outbound/MessageSender.java | 15 -- .../api/outbound/TransmissionService.java | 31 +--- .../oxalis/api/outbound/Transmitter.java | 13 -- .../network/oxalis/api/settings/Settings.java | 2 +- .../api/statistics/StatisticsService.java | 5 +- .../api/timestamp/TimestampProvider.java | 4 - .../java/network/oxalis/api/util/Type.java | 2 +- .../oxalis/api/inject/NamedImplTest.java | 2 +- oxalis-commons/pom.xml | 38 ++--- .../commons/error/FullErrorTracker.java | 2 +- .../commons/error/QuietErrorTracker.java | 2 +- .../commons/error/SilentErrorTracker.java | 2 +- .../oxalis/commons/guice/OxalisModule.java | 2 +- .../oxalis/commons/http/ApacheHttpModule.java | 10 +- .../oxalis/commons/mode/ModeModule.java | 2 +- .../oxalis/commons/mode/ModeProvider.java | 14 +- .../mode/OxalisCertificateValidator.java | 25 +-- .../oxalis/commons/mode/OxalisCrlFetcher.java | 12 +- .../commons/mode/OxalisOcspFetcher.java | 12 +- .../commons/persist/DefaultPersister.java | 2 +- .../persist/DefaultPersisterHandler.java | 2 +- .../oxalis/commons/persist/NoopPersister.java | 2 +- .../oxalis/commons/persist/TempPersister.java | 2 +- .../statistics/NoopStatisticsService.java | 3 +- .../commons/tracing/BraveTracerProvider.java | 27 ---- .../tracing/NoopSpanProcessorProvider.java | 39 +++++ ...racingConf.java => OpenTelemetryConf.java} | 6 +- .../tracing/OpenTelemetryTracerProvider.java | 22 +++ ...jReporter.java => Slf4jSpanProcessor.java} | 33 ++-- .../oxalis/commons/tracing/SpanManager.java | 29 ++++ .../commons/tracing/SpanManagerImpl.java | 33 ++++ .../oxalis/commons/tracing/Traceable.java | 4 +- .../oxalis/commons/tracing/TracingModule.java | 50 +++--- .../transformer/NoopContentDetector.java | 2 +- .../oxalis/commons/util/ClosableSpan.java | 7 + .../commons/util/OpenTelemetryUtils.java | 41 +++++ .../statistics/NoopStatisticsServiceTest.java | 2 +- .../SystemTimestampProviderTest.java | 5 +- ...rTest.java => Slf4JSpanProcessorTest.java} | 11 +- .../oxalis/commons/tracing/TraceableTest.java | 5 +- .../main/java/network/oxalis/server/Main.java | 2 +- .../sendregning/oxalis/TransmissionTask.java | 144 ++++++++---------- oxalis-dist/oxalis-war/pom.xml | 4 +- .../oxalis/dist/war/WarGuiceFilter.java | 10 +- .../dist/war/WarServletContextListener.java | 2 +- oxalis-extension/oxalis-as2/pom.xml | 16 +- .../oxalis/as2/inbound/As2InboundHandler.java | 13 +- .../oxalis/as2/inbound/As2InboundModule.java | 2 +- .../oxalis/as2/inbound/As2Servlet.java | 68 +++++---- .../oxalis/as2/outbound/As2MessageSender.java | 69 ++++----- .../as2/outbound/As2MessageSenderFacade.java | 15 +- .../network/oxalis/as2/util/HeaderUtil.java | 2 +- .../network/oxalis/as2/util/MdnBuilder.java | 10 +- .../as2/util/MdnMimeMessageInspector.java | 6 +- .../oxalis/as2/util/MimeMessageHelper.java | 14 +- .../oxalis/as2/util/SMimeMessageFactory.java | 18 +-- .../oxalis/as2/util/SignedMessage.java | 12 +- .../network/oxalis/as2/SimpleServerTest.java | 2 +- .../as2/inbound/As2InboundHandlerTest.java | 14 +- .../as2/util/MdnMimeMessageInspectorTest.java | 2 +- .../as2/util/MimeMessageHelperTest.java | 10 +- .../as2/util/SMimeMessageFactoryTest.java | 8 +- .../oxalis/as2/util/TestDataGenerator.java | 8 +- .../as2/verification/InternetHeadersTest.java | 2 +- .../example/LoggingTransmissionVerifier.java | 2 +- .../oxalis-extension-testbed/pom.xml | 29 +--- .../oxalis/ext/testbed/v1/TestbedFilter.java | 10 +- .../oxalis/ext/testbed/v1/TestbedJaxb.java | 8 +- .../testbed/v1/TestbedPersisterHandler.java | 2 +- .../oxalis/ext/testbed/v1/TestbedSender.java | 4 +- .../oxalis/ext/testbed/v1/TestbedServlet.java | 12 +- oxalis-inbound/pom.xml | 16 +- .../network/oxalis/inbound/InboundModule.java | 23 ++- .../oxalis/inbound/servlet/HomeServlet.java | 6 +- .../oxalis/inbound/servlet/StatusServlet.java | 6 +- .../DefaultOpenTelemetryTracingFilter.java | 39 +++++ .../tracing/OpenTelemetryServletConf.java | 18 +-- .../tracing/OpenTelemetryTracingFilter.java | 6 + .../inbound/servlet/HomeServletTest.java | 2 +- .../inbound/servlet/StatusServletTest.java | 2 +- .../oxalis/sniffer/sbdh/ParseSbdhTest.java | 6 +- .../oxalis/persistence/api/Platform.java | 2 +- .../datasource/JndiDataSourceProvider.java | 2 +- oxalis-legacy/oxalis-statistics/pom.xml | 4 +- .../statistics/inbound/StatisticsServlet.java | 12 +- .../jdbc/RawStatisticsRepositoryHSqlImpl.java | 2 +- .../RawStatisticsRepositoryMsSqlImpl.java | 2 +- .../RawStatisticsRepositoryMySqlImpl.java | 2 +- .../RawStatisticsRepositoryOracleImpl.java | 2 +- .../service/DefaultStatisticsService.java | 12 +- .../inbound/StatisticsServletTest.java | 2 +- .../jdbc/RawStatisticsRepositoryTest.java | 2 +- oxalis-outbound/pom.xml | 2 +- .../transformer/XmlContentWrapper.java | 2 +- .../DefaultTransmissionService.java | 17 +-- .../transmission/DefaultTransmitter.java | 97 ++++++------ .../transmission/TransmissionModule.java | 2 +- .../TransmissionRequestBuilder.java | 83 +++++----- .../TransmissionRequestFactory.java | 109 ++++++------- .../DefaultTransmissionServiceTest.java | 5 +- .../transmission/DefaultTransmitterTest.java | 2 +- .../TransmissionRequestFactoryMockTest.java | 2 +- .../TransmissionRequestFactoryTest.java | 2 +- oxalis-test/pom.xml | 17 +-- .../network/oxalis/test/asd/AsdServlet.java | 6 +- .../test/jetty/AbstractJettyServerTest.java | 2 +- .../oxalis/test/lookup/MockLookupModule.java | 5 +- pom.xml | 104 ++++++------- 111 files changed, 870 insertions(+), 825 deletions(-) delete mode 100644 oxalis-commons/src/main/java/network/oxalis/commons/tracing/BraveTracerProvider.java create mode 100644 oxalis-commons/src/main/java/network/oxalis/commons/tracing/NoopSpanProcessorProvider.java rename oxalis-commons/src/main/java/network/oxalis/commons/tracing/{TracingConf.java => OpenTelemetryConf.java} (90%) create mode 100644 oxalis-commons/src/main/java/network/oxalis/commons/tracing/OpenTelemetryTracerProvider.java rename oxalis-commons/src/main/java/network/oxalis/commons/tracing/{Slf4jReporter.java => Slf4jSpanProcessor.java} (59%) create mode 100644 oxalis-commons/src/main/java/network/oxalis/commons/tracing/SpanManager.java create mode 100644 oxalis-commons/src/main/java/network/oxalis/commons/tracing/SpanManagerImpl.java create mode 100644 oxalis-commons/src/main/java/network/oxalis/commons/util/ClosableSpan.java create mode 100644 oxalis-commons/src/main/java/network/oxalis/commons/util/OpenTelemetryUtils.java rename oxalis-commons/src/test/java/network/oxalis/commons/tracing/{Slf4jReporterTest.java => Slf4JSpanProcessorTest.java} (79%) create mode 100644 oxalis-inbound/src/main/java/network/oxalis/inbound/tracing/DefaultOpenTelemetryTracingFilter.java rename oxalis-commons/src/main/java/network/oxalis/commons/tracing/BraveConf.java => oxalis-inbound/src/main/java/network/oxalis/inbound/tracing/OpenTelemetryServletConf.java (77%) create mode 100644 oxalis-inbound/src/main/java/network/oxalis/inbound/tracing/OpenTelemetryTracingFilter.java diff --git a/oxalis-api/pom.xml b/oxalis-api/pom.xml index eab8c7d60..cb5e3ceed 100644 --- a/oxalis-api/pom.xml +++ b/oxalis-api/pom.xml @@ -75,10 +75,14 @@ peppol-common - + - io.opentracing - opentracing-api + io.opentelemetry + opentelemetry-api + + + io.opentelemetry + opentelemetry-sdk @@ -90,8 +94,8 @@ - javax.inject - javax.inject + jakarta.inject + jakarta.inject-api diff --git a/oxalis-api/src/main/java/network/oxalis/api/inject/NamedImpl.java b/oxalis-api/src/main/java/network/oxalis/api/inject/NamedImpl.java index 721501df2..3fc832708 100644 --- a/oxalis-api/src/main/java/network/oxalis/api/inject/NamedImpl.java +++ b/oxalis-api/src/main/java/network/oxalis/api/inject/NamedImpl.java @@ -22,7 +22,7 @@ package network.oxalis.api.inject; -import javax.inject.Named; +import jakarta.inject.Named; import java.lang.annotation.Annotation; /** diff --git a/oxalis-api/src/main/java/network/oxalis/api/lookup/LookupService.java b/oxalis-api/src/main/java/network/oxalis/api/lookup/LookupService.java index 395be5e32..291f07e10 100644 --- a/oxalis-api/src/main/java/network/oxalis/api/lookup/LookupService.java +++ b/oxalis-api/src/main/java/network/oxalis/api/lookup/LookupService.java @@ -22,7 +22,6 @@ package network.oxalis.api.lookup; -import io.opentracing.Span; import network.oxalis.api.lang.OxalisTransmissionException; import network.oxalis.vefa.peppol.common.model.Endpoint; import network.oxalis.vefa.peppol.common.model.Header; @@ -45,15 +44,4 @@ public interface LookupService { */ Endpoint lookup(Header header) throws OxalisTransmissionException; - /** - * Performs lookup using metadata from content to be sent. - * - * @param header Metadata from content. - * @param root Current trace. - * @return Endpoint information to be used when transmitting content. - * @throws OxalisTransmissionException Thrown if no endpoint metadata were detected using metadata. - */ - default Endpoint lookup(Header header, Span root) throws OxalisTransmissionException { - return lookup(header); - } } diff --git a/oxalis-api/src/main/java/network/oxalis/api/outbound/MessageSender.java b/oxalis-api/src/main/java/network/oxalis/api/outbound/MessageSender.java index 338a18906..9756815ae 100644 --- a/oxalis-api/src/main/java/network/oxalis/api/outbound/MessageSender.java +++ b/oxalis-api/src/main/java/network/oxalis/api/outbound/MessageSender.java @@ -22,7 +22,6 @@ package network.oxalis.api.outbound; -import io.opentracing.Span; import network.oxalis.api.lang.OxalisTransmissionException; /** @@ -45,18 +44,4 @@ public interface MessageSender { */ TransmissionResponse send(TransmissionRequest transmissionRequest) throws OxalisTransmissionException; - /** - * Protocol specific transmission of transmission requested. (With tracing.) - * - * @param transmissionRequest Requested transmission to take place. - * @param root Current trace. - * @return Response content of a successful transmission. - * @throws OxalisTransmissionException Thrown when transmission was not sent according to protocol specific rules or - * because something went wrong during transmission. - */ - default TransmissionResponse send(TransmissionRequest transmissionRequest, Span root) - throws OxalisTransmissionException { - return send(transmissionRequest); - } - } diff --git a/oxalis-api/src/main/java/network/oxalis/api/outbound/TransmissionService.java b/oxalis-api/src/main/java/network/oxalis/api/outbound/TransmissionService.java index 7b56fccba..df8500338 100644 --- a/oxalis-api/src/main/java/network/oxalis/api/outbound/TransmissionService.java +++ b/oxalis-api/src/main/java/network/oxalis/api/outbound/TransmissionService.java @@ -22,9 +22,8 @@ package network.oxalis.api.outbound; -import io.opentracing.Span; -import network.oxalis.api.lang.OxalisTransmissionException; import network.oxalis.api.lang.OxalisContentException; +import network.oxalis.api.lang.OxalisTransmissionException; import network.oxalis.api.tag.Tag; import java.io.IOException; @@ -79,33 +78,5 @@ default TransmissionResponse send(InputStream inputStream) TransmissionResponse send(InputStream inputStream, Tag tag) throws IOException, OxalisTransmissionException, OxalisContentException; - /** - * Sends content found in the InputStream. - * - * @param inputStream InputStream containing content to be sent. - * @param root Current trace. - * @return Transmission response containing information from the performed transmission. - * @throws IOException Thrown on any IO exception. - * @throws OxalisTransmissionException Thrown if there were any problems making Oxalis unable to send the content. - */ - default TransmissionResponse send(InputStream inputStream, Span root) - throws IOException, OxalisTransmissionException, OxalisContentException { - return send(inputStream, Tag.NONE); - } - - /** - * Sends content found in the InputStream. - * - * @param inputStream InputStream containing content to be sent. - * @param tag Tag defined by client. - * @param root Current trace. - * @return Transmission response containing information from the performed transmission. - * @throws IOException Thrown on any IO exception. - * @throws OxalisTransmissionException Thrown if there were any problems making Oxalis unable to send the content. - */ - default TransmissionResponse send(InputStream inputStream, Tag tag, Span root) - throws IOException, OxalisTransmissionException, OxalisContentException { - return send(inputStream, tag); - } } diff --git a/oxalis-api/src/main/java/network/oxalis/api/outbound/Transmitter.java b/oxalis-api/src/main/java/network/oxalis/api/outbound/Transmitter.java index 01c420814..01ee5906e 100644 --- a/oxalis-api/src/main/java/network/oxalis/api/outbound/Transmitter.java +++ b/oxalis-api/src/main/java/network/oxalis/api/outbound/Transmitter.java @@ -22,7 +22,6 @@ package network.oxalis.api.outbound; -import io.opentracing.Span; import network.oxalis.api.lang.OxalisTransmissionException; /** @@ -47,16 +46,4 @@ public interface Transmitter { */ TransmissionResponse transmit(TransmissionMessage transmissionMessage) throws OxalisTransmissionException; - /** - * Transmit content of transmission request. (With tracing.) - * - * @param transmissionMessage Content to be transmitted. - * @param root Current trace. - * @return Result of transmission. - * @throws OxalisTransmissionException Thrown when transmission fails. - */ - default TransmissionResponse transmit(TransmissionMessage transmissionMessage, Span root) - throws OxalisTransmissionException { - return transmit(transmissionMessage); - } } diff --git a/oxalis-api/src/main/java/network/oxalis/api/settings/Settings.java b/oxalis-api/src/main/java/network/oxalis/api/settings/Settings.java index 6024654ae..d4346b8b1 100644 --- a/oxalis-api/src/main/java/network/oxalis/api/settings/Settings.java +++ b/oxalis-api/src/main/java/network/oxalis/api/settings/Settings.java @@ -24,7 +24,7 @@ import network.oxalis.api.inject.NamedImpl; -import javax.inject.Named; +import jakarta.inject.Named; import java.nio.file.Path; /** diff --git a/oxalis-api/src/main/java/network/oxalis/api/statistics/StatisticsService.java b/oxalis-api/src/main/java/network/oxalis/api/statistics/StatisticsService.java index 7ae2a95e2..117de9d32 100644 --- a/oxalis-api/src/main/java/network/oxalis/api/statistics/StatisticsService.java +++ b/oxalis-api/src/main/java/network/oxalis/api/statistics/StatisticsService.java @@ -22,10 +22,9 @@ package network.oxalis.api.statistics; -import io.opentracing.Span; +import network.oxalis.api.inbound.InboundMetadata; import network.oxalis.api.outbound.TransmissionRequest; import network.oxalis.api.outbound.TransmissionResponse; -import network.oxalis.api.inbound.InboundMetadata; /** * @author erlend @@ -33,7 +32,7 @@ */ public interface StatisticsService { - void persist(TransmissionRequest transmissionRequest, TransmissionResponse transmissionResponse, Span root); + void persist(TransmissionRequest transmissionRequest, TransmissionResponse transmissionResponse); void persist(InboundMetadata inboundMetadata); } diff --git a/oxalis-api/src/main/java/network/oxalis/api/timestamp/TimestampProvider.java b/oxalis-api/src/main/java/network/oxalis/api/timestamp/TimestampProvider.java index d14d893e1..223ce325e 100644 --- a/oxalis-api/src/main/java/network/oxalis/api/timestamp/TimestampProvider.java +++ b/oxalis-api/src/main/java/network/oxalis/api/timestamp/TimestampProvider.java @@ -22,7 +22,6 @@ package network.oxalis.api.timestamp; -import io.opentracing.Span; import network.oxalis.api.lang.TimestampException; import network.oxalis.api.model.Direction; @@ -35,7 +34,4 @@ public interface TimestampProvider { Timestamp generate(byte[] content, Direction direction) throws TimestampException; - default Timestamp generate(byte[] content, Direction direction, Span span) throws TimestampException { - return generate(content, direction); - } } diff --git a/oxalis-api/src/main/java/network/oxalis/api/util/Type.java b/oxalis-api/src/main/java/network/oxalis/api/util/Type.java index 7de56636d..8f40fcc4a 100644 --- a/oxalis-api/src/main/java/network/oxalis/api/util/Type.java +++ b/oxalis-api/src/main/java/network/oxalis/api/util/Type.java @@ -28,7 +28,7 @@ import java.lang.annotation.Target; /** - * This annotation works as a replacement of {@link javax.inject.Named} to allow for multiple + * This annotation works as a replacement of {@link jakarta.inject.Named} to allow for multiple * names for a given implementation. Used in combination with OxalisModule. * * @author erlend diff --git a/oxalis-api/src/test/java/network/oxalis/api/inject/NamedImplTest.java b/oxalis-api/src/test/java/network/oxalis/api/inject/NamedImplTest.java index a44f3f380..bbbe5ab7e 100644 --- a/oxalis-api/src/test/java/network/oxalis/api/inject/NamedImplTest.java +++ b/oxalis-api/src/test/java/network/oxalis/api/inject/NamedImplTest.java @@ -25,7 +25,7 @@ import org.testng.Assert; import org.testng.annotations.Test; -import javax.inject.Named; +import jakarta.inject.Named; /** * @author erlend diff --git a/oxalis-commons/pom.xml b/oxalis-commons/pom.xml index 54f6087ff..6eb69fe2f 100644 --- a/oxalis-commons/pom.xml +++ b/oxalis-commons/pom.xml @@ -49,7 +49,6 @@ - network.oxalis @@ -61,6 +60,13 @@ test + + + jakarta.servlet + jakarta.servlet-api + provided + + org.slf4j @@ -96,36 +102,20 @@ org.apache.httpcomponents httpclient - - - - io.zipkin.brave - brave - - io.zipkin.reporter2 - zipkin-sender-urlconnection + io.opentelemetry.instrumentation + opentelemetry-apache-httpclient-4.3 - - - - io.opentracing - opentracing-noop - + - io.opentracing.contrib - opentracing-apache-httpclient + io.opentelemetry + opentelemetry-api - io.opentracing.contrib - opentracing-spanmanager + io.opentelemetry + opentelemetry-sdk - - io.opentracing.brave - brave-opentracing - - diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/error/FullErrorTracker.java b/oxalis-commons/src/main/java/network/oxalis/commons/error/FullErrorTracker.java index 181129fb6..547ccea27 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/error/FullErrorTracker.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/error/FullErrorTracker.java @@ -27,7 +27,7 @@ import network.oxalis.api.model.Direction; import network.oxalis.api.util.Type; -import javax.inject.Singleton; +import jakarta.inject.Singleton; import java.util.UUID; /** diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/error/QuietErrorTracker.java b/oxalis-commons/src/main/java/network/oxalis/commons/error/QuietErrorTracker.java index f864a426c..9fbfc5fb3 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/error/QuietErrorTracker.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/error/QuietErrorTracker.java @@ -27,7 +27,7 @@ import network.oxalis.api.model.Direction; import network.oxalis.api.util.Type; -import javax.inject.Singleton; +import jakarta.inject.Singleton; import java.util.UUID; /** diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/error/SilentErrorTracker.java b/oxalis-commons/src/main/java/network/oxalis/commons/error/SilentErrorTracker.java index 305c40f84..121888306 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/error/SilentErrorTracker.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/error/SilentErrorTracker.java @@ -4,7 +4,7 @@ import network.oxalis.api.model.Direction; import network.oxalis.api.util.Type; -import javax.inject.Singleton; +import jakarta.inject.Singleton; import java.util.UUID; /** diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/guice/OxalisModule.java b/oxalis-commons/src/main/java/network/oxalis/commons/guice/OxalisModule.java index a0966997e..96b0e8ed5 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/guice/OxalisModule.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/guice/OxalisModule.java @@ -38,7 +38,7 @@ public abstract class OxalisModule extends AbstractModule { /** * Binds an implementation to an interface using the {@link Type} annotation as replacement - * for {@link javax.inject.Named}. + * for {@link jakarta.inject.Named}. * * @param cls Interface used for binding. * @param impl Implementation with {@link Type} annotation. diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/http/ApacheHttpModule.java b/oxalis-commons/src/main/java/network/oxalis/commons/http/ApacheHttpModule.java index 8fe691130..3c2e5fff2 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/http/ApacheHttpModule.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/http/ApacheHttpModule.java @@ -24,8 +24,8 @@ import com.google.inject.Provides; import com.google.inject.Singleton; -import io.opentracing.Tracer; -import io.opentracing.contrib.apache.http.client.TracingHttpClientBuilder; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.apachehttpclient.v4_3.ApacheHttpClientTelemetry; import network.oxalis.api.settings.Settings; import network.oxalis.commons.guice.OxalisModule; import network.oxalis.commons.util.OxalisVersion; @@ -72,8 +72,10 @@ protected RequestConfig getRequestConfig(Settings settings) { @Provides protected CloseableHttpClient getHttpClient(PoolingHttpClientConnectionManager connectionManager, - RequestConfig requestConfig, Tracer tracer) { - HttpClientBuilder httpClientBuilder = new TracingHttpClientBuilder().withTracer(tracer); + RequestConfig requestConfig, OpenTelemetry openTelemetry) { + HttpClientBuilder httpClientBuilder = ApacheHttpClientTelemetry.builder(openTelemetry) + .build() + .newHttpClientBuilder(); httpClientBuilder.setUserAgent(USER_AGENT); diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/mode/ModeModule.java b/oxalis-commons/src/main/java/network/oxalis/commons/mode/ModeModule.java index c3ac50721..b09009210 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/mode/ModeModule.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/mode/ModeModule.java @@ -36,7 +36,7 @@ import network.oxalis.vefa.peppol.security.api.CertificateValidator; import org.apache.http.client.config.RequestConfig; -import javax.inject.Named; +import jakarta.inject.Named; import java.io.IOException; import java.io.InputStream; import java.security.KeyStore; diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/mode/ModeProvider.java b/oxalis-commons/src/main/java/network/oxalis/commons/mode/ModeProvider.java index d45041b5e..a61e6faac 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/mode/ModeProvider.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/mode/ModeProvider.java @@ -25,12 +25,11 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.typesafe.config.Config; -import io.opentracing.Span; -import io.opentracing.Tracer; -import io.opentracing.contrib.spanmanager.DefaultSpanManager; -import network.oxalis.pkix.ocsp.api.OcspFetcher; -import network.oxalis.commons.certvalidator.api.CrlFetcher; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.Tracer; import network.oxalis.api.lang.OxalisLoadingException; +import network.oxalis.commons.certvalidator.api.CrlFetcher; +import network.oxalis.pkix.ocsp.api.OcspFetcher; import network.oxalis.vefa.peppol.common.lang.PeppolLoadingException; import network.oxalis.vefa.peppol.mode.Mode; import network.oxalis.vefa.peppol.security.ModeDetector; @@ -65,8 +64,7 @@ public class ModeProvider implements Provider { @Override public Mode get() { - Span span = tracer.buildSpan("Mode detection").start(); - DefaultSpanManager.getInstance().activate(span); + Span span = tracer.spanBuilder("Mode detection").startSpan(); try { Map objectStorage = new HashMap<>(); objectStorage.put("ocsp_fetcher", ocspFetcher); @@ -76,7 +74,7 @@ public Mode get() { } catch (PeppolLoadingException e) { throw new OxalisLoadingException("Unable to detect mode.", e); } finally { - span.finish(); + span.end(); } } } diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/mode/OxalisCertificateValidator.java b/oxalis-commons/src/main/java/network/oxalis/commons/mode/OxalisCertificateValidator.java index fc4cd6e15..0310858aa 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/mode/OxalisCertificateValidator.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/mode/OxalisCertificateValidator.java @@ -2,9 +2,8 @@ import com.google.inject.Inject; import com.google.inject.Singleton; -import io.opentracing.Span; -import io.opentracing.Tracer; -import io.opentracing.contrib.spanmanager.DefaultSpanManager; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.Tracer; import network.oxalis.vefa.peppol.common.code.Service; import network.oxalis.vefa.peppol.security.api.CertificateValidator; import network.oxalis.vefa.peppol.security.lang.PeppolSecurityException; @@ -29,25 +28,15 @@ public OxalisCertificateValidator(CertificateValidator certificateValidator, Tra @Override public void validate(Service service, X509Certificate certificate) throws PeppolSecurityException { - Span span = tracer.buildSpan("Validate certificate").start(); - perform(service, certificate, span); - } - - public void validate(Service service, X509Certificate certificate, Span root) throws PeppolSecurityException { - Span span = tracer.buildSpan("Validate certificate").asChildOf(root).start(); - perform(service, certificate, span); - } - - private void perform(Service service, X509Certificate certificate, Span span) throws PeppolSecurityException { - DefaultSpanManager.getInstance().activate(span); - + Span span = tracer.spanBuilder("Validate certificate").startSpan(); try { - span.setTag("subject", certificate.getSubjectX500Principal().toString()); - span.setTag("issuer", certificate.getIssuerX500Principal().toString()); + span.setAttribute("subject", certificate.getSubjectX500Principal().toString()); + span.setAttribute("issuer", certificate.getIssuerX500Principal().toString()); this.certificateValidator.validate(service, certificate); } finally { - span.finish(); + span.end(); } } + } diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/mode/OxalisCrlFetcher.java b/oxalis-commons/src/main/java/network/oxalis/commons/mode/OxalisCrlFetcher.java index 2ec416690..f0f59ec30 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/mode/OxalisCrlFetcher.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/mode/OxalisCrlFetcher.java @@ -25,9 +25,8 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; -import io.opentracing.contrib.apache.http.client.Constants; -import io.opentracing.contrib.spanmanager.DefaultSpanManager; -import io.opentracing.contrib.spanmanager.SpanManager; +import io.opentelemetry.api.trace.Span; +import jakarta.inject.Named; import network.oxalis.commons.certvalidator.api.CertificateValidationException; import network.oxalis.commons.certvalidator.api.CrlCache; import network.oxalis.commons.certvalidator.util.CrlUtils; @@ -38,7 +37,6 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.protocol.BasicHttpContext; -import javax.inject.Named; import java.io.IOException; import java.net.URI; import java.security.cert.CRLException; @@ -70,11 +68,11 @@ public OxalisCrlFetcher(CrlCache crlCache) { @Override protected X509CRL httpDownload(String url) throws CertificateValidationException { try { - SpanManager.ManagedSpan span = DefaultSpanManager.getInstance().current(); + Span span = Span.current(); BasicHttpContext basicHttpContext = new BasicHttpContext(); - if (span.getSpan() != null) - basicHttpContext.setAttribute(Constants.PARENT_CONTEXT, span.getSpan().context()); + if (span != null) + basicHttpContext.setAttribute("OxalisCrlFetcher.parentSpanContext", span.getSpanContext()); HttpGet httpGet = new HttpGet(URI.create(url)); httpGet.setConfig(requestConfig); diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/mode/OxalisOcspFetcher.java b/oxalis-commons/src/main/java/network/oxalis/commons/mode/OxalisOcspFetcher.java index 43ccec45f..31eed4e16 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/mode/OxalisOcspFetcher.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/mode/OxalisOcspFetcher.java @@ -25,9 +25,8 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; -import io.opentracing.contrib.apache.http.client.Constants; -import io.opentracing.contrib.spanmanager.DefaultSpanManager; -import io.opentracing.contrib.spanmanager.SpanManager; +import io.opentelemetry.api.trace.Span; +import jakarta.inject.Named; import network.oxalis.pkix.ocsp.api.OcspFetcher; import network.oxalis.pkix.ocsp.api.OcspFetcherResponse; import org.apache.http.client.config.RequestConfig; @@ -37,7 +36,6 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.protocol.BasicHttpContext; -import javax.inject.Named; import java.io.IOException; import java.io.InputStream; import java.net.URI; @@ -61,11 +59,11 @@ public class OxalisOcspFetcher implements OcspFetcher { @Override public OcspFetcherResponse fetch(URI uri, byte[] content) throws IOException { - SpanManager.ManagedSpan span = DefaultSpanManager.getInstance().current(); + Span span = Span.current(); BasicHttpContext basicHttpContext = new BasicHttpContext(); - if (span.getSpan() != null) - basicHttpContext.setAttribute(Constants.PARENT_CONTEXT, span.getSpan().context()); + if (span != null) + basicHttpContext.setAttribute("OxalisOcspFetcher.parentSpanContext", span.getSpanContext()); HttpPost httpPost = new HttpPost(uri); httpPost.setHeader("Content-Type", "application/ocsp-request"); diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/persist/DefaultPersister.java b/oxalis-commons/src/main/java/network/oxalis/commons/persist/DefaultPersister.java index 8bd75d7d7..ff98719a6 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/persist/DefaultPersister.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/persist/DefaultPersister.java @@ -35,7 +35,7 @@ import network.oxalis.commons.filesystem.FileUtils; import network.oxalis.vefa.peppol.common.model.Header; -import javax.inject.Singleton; +import jakarta.inject.Singleton; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/persist/DefaultPersisterHandler.java b/oxalis-commons/src/main/java/network/oxalis/commons/persist/DefaultPersisterHandler.java index dc5159821..d1a89a708 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/persist/DefaultPersisterHandler.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/persist/DefaultPersisterHandler.java @@ -32,7 +32,7 @@ import network.oxalis.api.util.Type; import network.oxalis.vefa.peppol.common.model.Header; -import javax.inject.Singleton; +import jakarta.inject.Singleton; import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/persist/NoopPersister.java b/oxalis-commons/src/main/java/network/oxalis/commons/persist/NoopPersister.java index c5ef709b5..3a729858d 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/persist/NoopPersister.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/persist/NoopPersister.java @@ -29,7 +29,7 @@ import network.oxalis.api.util.Type; import network.oxalis.vefa.peppol.common.model.Header; -import javax.inject.Singleton; +import jakarta.inject.Singleton; import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/persist/TempPersister.java b/oxalis-commons/src/main/java/network/oxalis/commons/persist/TempPersister.java index e5908853e..8c67e861e 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/persist/TempPersister.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/persist/TempPersister.java @@ -34,7 +34,7 @@ import network.oxalis.commons.filesystem.FileUtils; import network.oxalis.vefa.peppol.common.model.Header; -import javax.inject.Singleton; +import jakarta.inject.Singleton; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/statistics/NoopStatisticsService.java b/oxalis-commons/src/main/java/network/oxalis/commons/statistics/NoopStatisticsService.java index 1471ff8cd..49c39d06a 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/statistics/NoopStatisticsService.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/statistics/NoopStatisticsService.java @@ -23,7 +23,6 @@ package network.oxalis.commons.statistics; import com.google.inject.Singleton; -import io.opentracing.Span; import network.oxalis.api.inbound.InboundMetadata; import network.oxalis.api.outbound.TransmissionRequest; import network.oxalis.api.outbound.TransmissionResponse; @@ -39,7 +38,7 @@ public class NoopStatisticsService implements StatisticsService { @Override public void persist(TransmissionRequest transmissionRequest, - TransmissionResponse transmissionResponse, Span root) { + TransmissionResponse transmissionResponse) { // No action. } diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/tracing/BraveTracerProvider.java b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/BraveTracerProvider.java deleted file mode 100644 index ecf85db61..000000000 --- a/oxalis-commons/src/main/java/network/oxalis/commons/tracing/BraveTracerProvider.java +++ /dev/null @@ -1,27 +0,0 @@ -package network.oxalis.commons.tracing; - -import brave.Tracing; -import brave.opentracing.BraveTracer; -import com.google.inject.Inject; -import com.google.inject.Provider; -import io.opentracing.Tracer; -import zipkin2.reporter.Reporter; - -/** - * @author erlend - */ -public class BraveTracerProvider implements Provider { - - @Inject - private Reporter reporter; - - @Override - public Tracer get() { - Tracing tracing = Tracing.newBuilder() - .localServiceName("Oxalis") - .spanReporter(reporter) - .build(); - - return BraveTracer.create(tracing); - } -} diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/tracing/NoopSpanProcessorProvider.java b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/NoopSpanProcessorProvider.java new file mode 100644 index 000000000..905ed1c54 --- /dev/null +++ b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/NoopSpanProcessorProvider.java @@ -0,0 +1,39 @@ +package network.oxalis.commons.tracing; + +import com.google.inject.Provider; +import io.opentelemetry.context.Context; +import io.opentelemetry.sdk.trace.ReadWriteSpan; +import io.opentelemetry.sdk.trace.ReadableSpan; +import io.opentelemetry.sdk.trace.SpanProcessor; + +public class NoopSpanProcessorProvider implements Provider { + + @Override + public SpanProcessor get() { + return new SpanProcessor() { + @Override + public void onStart(Context parentContext, ReadWriteSpan span) { + } + + @Override + public boolean isStartRequired() { + return false; + } + + @Override + public void onEnd(ReadableSpan span) { + } + + @Override + public boolean isEndRequired() { + return false; + } + + @Override + public String toString() { + return "NoopSpanProcessor{}"; + } + }; + } + +} diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/tracing/TracingConf.java b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/OpenTelemetryConf.java similarity index 90% rename from oxalis-commons/src/main/java/network/oxalis/commons/tracing/TracingConf.java rename to oxalis-commons/src/main/java/network/oxalis/commons/tracing/OpenTelemetryConf.java index db7de14e4..0809dd53d 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/tracing/TracingConf.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/OpenTelemetryConf.java @@ -30,10 +30,10 @@ * @author erlend */ @Title("Tracing") -public enum TracingConf { +public enum OpenTelemetryConf { - @Path("oxalis.tracing.tracer") + @Path("oxalis.tracing.open-telemetry.span-processor") @DefaultValue("noop") - TRACER, + SPAN_PROCESSOR, } diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/tracing/OpenTelemetryTracerProvider.java b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/OpenTelemetryTracerProvider.java new file mode 100644 index 000000000..3899bc570 --- /dev/null +++ b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/OpenTelemetryTracerProvider.java @@ -0,0 +1,22 @@ +package network.oxalis.commons.tracing; + +import com.google.inject.Inject; +import com.google.inject.Provider; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.trace.Tracer; + +/** + * @author erlend + */ +public class OpenTelemetryTracerProvider implements Provider { + + @Inject + private OpenTelemetry openTelemetry; + + @Override + public Tracer get() { + return openTelemetry.getTracerProvider() + .get("network.oxalis.commons.tracing.OpenTelemetryTracer"); + } + +} diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/tracing/Slf4jReporter.java b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/Slf4jSpanProcessor.java similarity index 59% rename from oxalis-commons/src/main/java/network/oxalis/commons/tracing/Slf4jReporter.java rename to oxalis-commons/src/main/java/network/oxalis/commons/tracing/Slf4jSpanProcessor.java index 721affef6..1dc0b3ad2 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/tracing/Slf4jReporter.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/Slf4jSpanProcessor.java @@ -23,13 +23,15 @@ package network.oxalis.commons.tracing; import com.google.inject.Singleton; +import io.opentelemetry.context.Context; +import io.opentelemetry.sdk.trace.ReadWriteSpan; +import io.opentelemetry.sdk.trace.ReadableSpan; +import io.opentelemetry.sdk.trace.SpanProcessor; import lombok.extern.slf4j.Slf4j; import network.oxalis.api.util.Type; -import zipkin2.Span; -import zipkin2.reporter.Reporter; /** - * Implementation of ZipKin Reporter putting tracing data in SLF4J logger. + * Implementation of SpanProcessor writing tracing data to the SLF4J logger. * * @author erlend * @since 4.0.0 @@ -37,13 +39,26 @@ @Slf4j @Singleton @Type("slf4j") -public class Slf4jReporter implements Reporter { +public class Slf4jSpanProcessor implements SpanProcessor { - /** - * {@inheritDoc} - */ @Override - public void report(Span span) { - log.info("{}", span); + public void onStart(Context parentContext, ReadWriteSpan span) { + log.info("start {}", span); } + + @Override + public boolean isStartRequired() { + return true; + } + + @Override + public void onEnd(ReadableSpan span) { + log.info("end {}", span); + } + + @Override + public boolean isEndRequired() { + return true; + } + } diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/tracing/SpanManager.java b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/SpanManager.java new file mode 100644 index 000000000..6824a71e8 --- /dev/null +++ b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/SpanManager.java @@ -0,0 +1,29 @@ +package network.oxalis.commons.tracing; + +import io.opentelemetry.api.trace.Span; +import network.oxalis.commons.util.ClosableSpan; + +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; + +public interface SpanManager { + + T runWithinSpan(String spanName, Function function); + + default T runWithinSpan(String spanName, Supplier function) { + return runWithinSpan(spanName, span -> { + return function.get(); + }); + } + + default void runWithinSpan(String spanName, Consumer function) { + runWithinSpan(spanName, span -> { + function.accept(span); + return null; + }); + } + + ClosableSpan startClosableSpan(String spanName); + +} diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/tracing/SpanManagerImpl.java b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/SpanManagerImpl.java new file mode 100644 index 000000000..849db5a22 --- /dev/null +++ b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/SpanManagerImpl.java @@ -0,0 +1,33 @@ +package network.oxalis.commons.tracing; + +import com.google.inject.Inject; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.Tracer; +import network.oxalis.commons.util.ClosableSpan; + +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; + +public class SpanManagerImpl implements SpanManager { + + @Inject + private Tracer tracer; + + public T runWithinSpan(String spanName, Function function) { + if (spanName == null) { + throw new IllegalStateException("spanName needs to be set"); + } + Span span = tracer.spanBuilder(spanName).startSpan(); + try { + return function.apply(span); + } finally { + span.end(); + } + } + + public ClosableSpan startClosableSpan(String spanName) { + return tracer.spanBuilder(spanName).startSpan()::end; + } + +} diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/tracing/Traceable.java b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/Traceable.java index f139006b1..cb738bd03 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/tracing/Traceable.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/Traceable.java @@ -22,7 +22,7 @@ package network.oxalis.commons.tracing; -import io.opentracing.Tracer; +import io.opentelemetry.api.trace.Tracer; /** * Simple abstract class making {@link Tracer} object available in a standardized manner for classes extending this @@ -34,7 +34,7 @@ public abstract class Traceable { /** - * Zipkin tracer implementation. + * Open Telemetry implementation. */ protected final Tracer tracer; diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/tracing/TracingModule.java b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/TracingModule.java index b971eab1c..c41c6d9f1 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/tracing/TracingModule.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/tracing/TracingModule.java @@ -26,23 +26,20 @@ import com.google.inject.Key; import com.google.inject.Provides; import com.google.inject.Singleton; -import com.google.inject.name.Named; import com.google.inject.name.Names; -import io.opentracing.Tracer; -import io.opentracing.noop.NoopTracerFactory; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.trace.Tracer; +import io.opentelemetry.sdk.trace.SpanProcessor; import network.oxalis.api.settings.Settings; import network.oxalis.commons.guice.ImplLoader; import network.oxalis.commons.guice.OxalisModule; -import zipkin2.reporter.AsyncReporter; -import zipkin2.reporter.Reporter; -import zipkin2.reporter.urlconnection.URLConnectionSender; +import network.oxalis.commons.util.OpenTelemetryUtils; /** *

- * Available reports (brave.reporter): + * Available span processors (oxalis.tracing.open-telemetry.span-processor): *

    - *
  • console
  • - *
  • http
  • + *
  • noop(default)
  • *
  • slf4j
  • *
* @@ -53,37 +50,30 @@ public class TracingModule extends OxalisModule { @Override protected void configure() { - bindSettings(BraveConf.class); - bindSettings(TracingConf.class); + bindSettings(OpenTelemetryConf.class); - bind(Key.get(Tracer.class, Names.named("noop"))) - .toProvider(NoopTracerFactory::create); - bind(Key.get(Tracer.class, Names.named("brave"))) - .toProvider(BraveTracerProvider.class); + bind(Key.get(SpanProcessor.class, Names.named("noop"))) + .toProvider(NoopSpanProcessorProvider.class); + bind(Key.get(SpanProcessor.class, Names.named("slf4j"))) + .to(Slf4jSpanProcessor.class); - bind(Key.get(Reporter.class, Names.named("console"))) - .toProvider(() -> Reporter.CONSOLE); - bindTyped(Reporter.class, Slf4jReporter.class); - } + bind(Key.get(Tracer.class)) + .toProvider(OpenTelemetryTracerProvider.class); - @Provides - @Singleton - @Named("http") - protected Reporter getHttpReporter(Settings settings) { - return AsyncReporter - .builder(URLConnectionSender.create(settings.getString(BraveConf.HTTP))) - .build(); + bind(Key.get(SpanManager.class)) + .to(SpanManagerImpl.class); } @Provides @Singleton - protected Reporter getReporter(Injector injector, Settings settings) { - return ImplLoader.get(injector, Reporter.class, settings, BraveConf.REPORTER); + protected SpanProcessor getSpanProcessor(Injector injector, Settings settings) { + return ImplLoader.get(injector, SpanProcessor.class, settings, OpenTelemetryConf.SPAN_PROCESSOR); } @Provides @Singleton - protected Tracer getTracer(Injector injector, Settings settings) { - return ImplLoader.get(injector, Tracer.class, settings, TracingConf.TRACER); + protected OpenTelemetry openTelemetry(SpanProcessor spanProcessor) { + return OpenTelemetryUtils.initOpenTelemetry(spanProcessor); } + } diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/transformer/NoopContentDetector.java b/oxalis-commons/src/main/java/network/oxalis/commons/transformer/NoopContentDetector.java index b3d0820fa..ca5e5e341 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/transformer/NoopContentDetector.java +++ b/oxalis-commons/src/main/java/network/oxalis/commons/transformer/NoopContentDetector.java @@ -27,7 +27,7 @@ import network.oxalis.api.util.Type; import network.oxalis.vefa.peppol.common.model.Header; -import javax.inject.Singleton; +import jakarta.inject.Singleton; import java.io.InputStream; /** diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/util/ClosableSpan.java b/oxalis-commons/src/main/java/network/oxalis/commons/util/ClosableSpan.java new file mode 100644 index 000000000..448a919d1 --- /dev/null +++ b/oxalis-commons/src/main/java/network/oxalis/commons/util/ClosableSpan.java @@ -0,0 +1,7 @@ +package network.oxalis.commons.util; + +import java.io.Closeable; + +public interface ClosableSpan extends Closeable { + void close(); +} diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/util/OpenTelemetryUtils.java b/oxalis-commons/src/main/java/network/oxalis/commons/util/OpenTelemetryUtils.java new file mode 100644 index 000000000..c0d048bc9 --- /dev/null +++ b/oxalis-commons/src/main/java/network/oxalis/commons/util/OpenTelemetryUtils.java @@ -0,0 +1,41 @@ +package network.oxalis.commons.util; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.common.AttributeType; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.internal.InternalAttributeKeyImpl; +import io.opentelemetry.sdk.OpenTelemetrySdk; +import io.opentelemetry.sdk.resources.Resource; +import io.opentelemetry.sdk.trace.SdkTracerProvider; +import io.opentelemetry.sdk.trace.SpanProcessor; + +public final class OpenTelemetryUtils { + + private static final String SERVICE_NAME = "oxalis"; + public static final String SERVICE_NAME_ATTRIBUTE_KEY = "service.name"; + + private OpenTelemetryUtils() { + } + + private static OpenTelemetry openTelemetry; + + public static OpenTelemetry initOpenTelemetry(SpanProcessor spanProcessor) { + if (openTelemetry == null) { + Resource serviceNameResource = + Resource.create(Attributes.of(InternalAttributeKeyImpl.create(SERVICE_NAME_ATTRIBUTE_KEY, AttributeType.STRING), SERVICE_NAME)); + + SdkTracerProvider tracerProvider = + SdkTracerProvider.builder() + .addSpanProcessor(spanProcessor) + .setResource(Resource.getDefault().merge(serviceNameResource)) + .build(); + openTelemetry = OpenTelemetrySdk.builder().setTracerProvider(tracerProvider).buildAndRegisterGlobal(); + + // add a shutdown hook to shut down the SDK + Runtime.getRuntime().addShutdownHook(new Thread(tracerProvider::close)); + } + + return openTelemetry; + } + +} diff --git a/oxalis-commons/src/test/java/network/oxalis/commons/statistics/NoopStatisticsServiceTest.java b/oxalis-commons/src/test/java/network/oxalis/commons/statistics/NoopStatisticsServiceTest.java index 4a6f11063..be1f7483c 100644 --- a/oxalis-commons/src/test/java/network/oxalis/commons/statistics/NoopStatisticsServiceTest.java +++ b/oxalis-commons/src/test/java/network/oxalis/commons/statistics/NoopStatisticsServiceTest.java @@ -31,7 +31,7 @@ public class NoopStatisticsServiceTest { @Test public void simple() { - statisticsService.persist(null, null, null); + statisticsService.persist(null, null); statisticsService.persist(null); } } diff --git a/oxalis-commons/src/test/java/network/oxalis/commons/timestamp/SystemTimestampProviderTest.java b/oxalis-commons/src/test/java/network/oxalis/commons/timestamp/SystemTimestampProviderTest.java index da153ad79..53f4a273c 100644 --- a/oxalis-commons/src/test/java/network/oxalis/commons/timestamp/SystemTimestampProviderTest.java +++ b/oxalis-commons/src/test/java/network/oxalis/commons/timestamp/SystemTimestampProviderTest.java @@ -23,7 +23,7 @@ package network.oxalis.commons.timestamp; import com.google.inject.Inject; -import io.opentracing.Tracer; +import io.opentelemetry.api.trace.Tracer; import network.oxalis.api.model.Direction; import network.oxalis.api.timestamp.Timestamp; import network.oxalis.api.timestamp.TimestampProvider; @@ -51,8 +51,7 @@ public void simpleWithoutTracer() throws Exception { @Test public void simpleWithTracer() throws Exception { - Timestamp timestamp = timestampProvider.generate("Hello World!".getBytes(), Direction.IN, - tracer.buildSpan("test").start()); + Timestamp timestamp = timestampProvider.generate("Hello World!".getBytes(), Direction.IN); Assert.assertNotNull(timestamp.getDate()); Assert.assertFalse(timestamp.getReceipt().isPresent()); diff --git a/oxalis-commons/src/test/java/network/oxalis/commons/tracing/Slf4jReporterTest.java b/oxalis-commons/src/test/java/network/oxalis/commons/tracing/Slf4JSpanProcessorTest.java similarity index 79% rename from oxalis-commons/src/test/java/network/oxalis/commons/tracing/Slf4jReporterTest.java rename to oxalis-commons/src/test/java/network/oxalis/commons/tracing/Slf4JSpanProcessorTest.java index 5cc5a0ab6..a5ef6ba94 100644 --- a/oxalis-commons/src/test/java/network/oxalis/commons/tracing/Slf4jReporterTest.java +++ b/oxalis-commons/src/test/java/network/oxalis/commons/tracing/Slf4JSpanProcessorTest.java @@ -24,10 +24,15 @@ import org.testng.annotations.Test; -public class Slf4jReporterTest { +public class Slf4JSpanProcessorTest { @Test - public void simple() { - new Slf4jReporter().report(null); + public void simpleStart() { + new Slf4jSpanProcessor().onStart(null, null); + } + + @Test + public void simpleEnd() { + new Slf4jSpanProcessor().onEnd(null); } } diff --git a/oxalis-commons/src/test/java/network/oxalis/commons/tracing/TraceableTest.java b/oxalis-commons/src/test/java/network/oxalis/commons/tracing/TraceableTest.java index 368e29bb8..969ee6ca8 100644 --- a/oxalis-commons/src/test/java/network/oxalis/commons/tracing/TraceableTest.java +++ b/oxalis-commons/src/test/java/network/oxalis/commons/tracing/TraceableTest.java @@ -22,8 +22,7 @@ package network.oxalis.commons.tracing; -import io.opentracing.Tracer; -import io.opentracing.noop.NoopTracerFactory; +import io.opentelemetry.api.trace.Tracer; import org.testng.Assert; import org.testng.annotations.Test; @@ -31,7 +30,7 @@ public class TraceableTest { @Test public void simple() { - Tracer tracer = NoopTracerFactory.create(); + Tracer tracer = spanName -> null; Traceable traceable = new Traceable(tracer) { }; diff --git a/oxalis-dist/oxalis-server/src/main/java/network/oxalis/server/Main.java b/oxalis-dist/oxalis-server/src/main/java/network/oxalis/server/Main.java index fe4c21c17..11ef13a79 100644 --- a/oxalis-dist/oxalis-server/src/main/java/network/oxalis/server/Main.java +++ b/oxalis-dist/oxalis-server/src/main/java/network/oxalis/server/Main.java @@ -38,7 +38,7 @@ import org.eclipse.jetty.servlet.DefaultServlet; import org.eclipse.jetty.servlet.ServletContextHandler; -import javax.servlet.DispatcherType; +import jakarta.servlet.DispatcherType; import java.util.EnumSet; /** diff --git a/oxalis-dist/oxalis-standalone/src/main/java/eu/sendregning/oxalis/TransmissionTask.java b/oxalis-dist/oxalis-standalone/src/main/java/eu/sendregning/oxalis/TransmissionTask.java index 98dd99639..3d357bf93 100644 --- a/oxalis-dist/oxalis-standalone/src/main/java/eu/sendregning/oxalis/TransmissionTask.java +++ b/oxalis-dist/oxalis-standalone/src/main/java/eu/sendregning/oxalis/TransmissionTask.java @@ -22,8 +22,6 @@ package eu.sendregning.oxalis; -import io.opentracing.Span; -import io.opentracing.Tracer; import lombok.extern.slf4j.Slf4j; import network.oxalis.api.evidence.EvidenceFactory; import network.oxalis.api.lang.EvidenceException; @@ -32,10 +30,16 @@ import network.oxalis.api.outbound.TransmissionResponse; import network.oxalis.api.outbound.Transmitter; import network.oxalis.commons.filesystem.FileUtils; +import network.oxalis.commons.tracing.SpanManager; +import network.oxalis.commons.util.ClosableSpan; import network.oxalis.outbound.transmission.TransmissionRequestBuilder; import network.oxalis.vefa.peppol.common.model.Endpoint; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.nio.file.Files; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; @@ -53,21 +57,18 @@ public class TransmissionTask implements Callable { private final File xmlPayloadFile; private final EvidenceFactory evidenceFactory; - - private final Tracer tracer; + private final SpanManager spanManager; public TransmissionTask(TransmissionParameters params, File xmlPayloadFile) { this.params = params; this.xmlPayloadFile = xmlPayloadFile; - this.evidenceFactory = params.getOxalisOutboundComponent().getEvidenceFactory(); - this.tracer = params.getOxalisOutboundComponent().getInjector().getInstance(Tracer.class); + this.spanManager = params.getOxalisOutboundComponent().getInjector().getInstance(SpanManager.class); } @Override public TransmissionResult call() throws Exception { - Span span = tracer.buildSpan("standalone").start(); - try { + try (ClosableSpan ignored = spanManager.startClosableSpan("standalone")) { TransmissionResponse transmissionResponse; long duration = 0; @@ -75,95 +76,85 @@ public TransmissionResult call() throws Exception { try (InputStream inputStream = Files.newInputStream(xmlPayloadFile.toPath())) { transmissionResponse = params.getOxalisOutboundComponent() .getTransmissionService() - .send(inputStream, params.getTag(), span); + .send(inputStream, params.getTag()); } } else { - TransmissionRequest transmissionRequest = createTransmissionRequest(span); + TransmissionRequest transmissionRequest = createTransmissionRequest(); - Transmitter transmitter; - Span span1 = tracer.buildSpan("get transmitter").asChildOf(span).start(); - try { - transmitter = params.getOxalisOutboundComponent().getTransmitter(); - } finally { - span1.finish(); - } + Transmitter transmitter = spanManager.runWithinSpan("get transmitter", + () -> params.getOxalisOutboundComponent().getTransmitter()); // Performs the transmission long start = System.nanoTime(); transmissionResponse = performTransmission( - params.getEvidencePath(), transmitter, transmissionRequest, span); + params.getEvidencePath(), transmitter, transmissionRequest); long elapsed = System.nanoTime() - start; duration = TimeUnit.MILLISECONDS.convert(elapsed, TimeUnit.NANOSECONDS); return new TransmissionResult(duration, transmissionResponse.getTransmissionIdentifier()); } return new TransmissionResult(duration, transmissionResponse.getTransmissionIdentifier()); - } finally { - span.finish(); } } - protected TransmissionRequest createTransmissionRequest(Span root) { - Span span = tracer.buildSpan("create transmission request").asChildOf(root).start(); - try { - // creates a transmission request builder and enables trace - TransmissionRequestBuilder requestBuilder = - params.getOxalisOutboundComponent().getTransmissionRequestBuilder(); + protected TransmissionRequest createTransmissionRequest() { + return spanManager.runWithinSpan("create transmission request", span -> { + try { + // creates a transmission request builder and enables trace + TransmissionRequestBuilder requestBuilder = + params.getOxalisOutboundComponent().getTransmissionRequestBuilder(); - requestBuilder.setTransmissionBuilderOverride(true); + requestBuilder.setTransmissionBuilderOverride(true); - // add receiver participant - if (params.getReceiver().isPresent()) { - requestBuilder.receiver(params.getReceiver().get()); - } + // add receiver participant + if (params.getReceiver().isPresent()) { + requestBuilder.receiver(params.getReceiver().get()); + } - // add sender participant - if (params.getSender().isPresent()) { - requestBuilder.sender(params.getSender().get()); - } + // add sender participant + if (params.getSender().isPresent()) { + requestBuilder.sender(params.getSender().get()); + } - if (params.getDocType().isPresent()) { - requestBuilder.documentType(params.getDocType().get()); - } + if (params.getDocType().isPresent()) { + requestBuilder.documentType(params.getDocType().get()); + } - if (params.getProcessIdentifier().isPresent()) { - requestBuilder.processType(params.getProcessIdentifier().get()); - } + if (params.getProcessIdentifier().isPresent()) { + requestBuilder.processType(params.getProcessIdentifier().get()); + } - // Supplies the payload - try (InputStream inputStream = new FileInputStream(xmlPayloadFile)) { - requestBuilder.payLoad(inputStream); - } + // Supplies the payload + try (InputStream inputStream = new FileInputStream(xmlPayloadFile)) { + requestBuilder.payLoad(inputStream); + } - // Overrides the destination URL if so requested - if (params.getEndpoint().isPresent()) { - final Endpoint endpoint = params.getEndpoint().get(); - requestBuilder.overrideAs2Endpoint(endpoint); - } + // Overrides the destination URL if so requested + if (params.getEndpoint().isPresent()) { + final Endpoint endpoint = params.getEndpoint().get(); + requestBuilder.overrideAs2Endpoint(endpoint); + } - // Specifying the details completed, creates the transmission request - return requestBuilder.build(span); - } catch (Exception e) { - span.setTag("exception", String.valueOf(e.getMessage())); - System.out.println(); - System.out.println("Message failed : " + e.getMessage()); - //e.printStackTrace(); - System.out.println(); - return null; - } finally { - span.finish(); - } + // Specifying the details completed, creates the transmission request + return requestBuilder.build(); + } catch (Exception e) { + span.setAttribute("exception", String.valueOf(e.getMessage())); + System.out.println(); + System.out.println("Message failed : " + e.getMessage()); + System.out.println(); + return null; + } + }); } protected TransmissionResponse performTransmission(File evidencePath, Transmitter transmitter, - TransmissionRequest transmissionRequest, Span root) + TransmissionRequest transmissionRequest) throws OxalisTransmissionException, EvidenceException, IOException { - Span span = tracer.buildSpan("transmission").asChildOf(root).start(); - try { + try (ClosableSpan ignore = spanManager.startClosableSpan("transmission")) { // ... and performs the transmission long start = System.nanoTime(); - TransmissionResponse transmissionResponse = transmitter.transmit(transmissionRequest, span); + TransmissionResponse transmissionResponse = transmitter.transmit(transmissionRequest); long elapsed = System.nanoTime() - start; long durartionInMs = TimeUnit.MILLISECONDS.convert(elapsed, TimeUnit.NANOSECONDS); @@ -176,25 +167,22 @@ protected TransmissionResponse performTransmission(File evidencePath, Transmitte durartionInMs )); - saveEvidence(transmissionResponse, evidencePath, span); + saveEvidence(transmissionResponse, evidencePath); return transmissionResponse; - } finally { - span.finish(); } } - protected void saveEvidence(TransmissionResponse transmissionResponse, File evidencePath, Span root) + protected void saveEvidence(TransmissionResponse transmissionResponse, File evidencePath) throws IOException, EvidenceException { - Span span = tracer.buildSpan("save evidence").asChildOf(root).start(); + try (ClosableSpan ignore = spanManager.startClosableSpan("save evidence")) { - String transIdent = FileUtils.filterString(transmissionResponse.getTransmissionIdentifier().toString()); - File evidenceFile = new File(evidencePath, transIdent + ".receipt.dat"); + String transIdent = FileUtils.filterString(transmissionResponse.getTransmissionIdentifier().toString()); + File evidenceFile = new File(evidencePath, transIdent + ".receipt.dat"); - try (OutputStream outputStream = Files.newOutputStream(evidenceFile.toPath())) { - evidenceFactory.write(outputStream, transmissionResponse); - } finally { - span.finish(); + try (OutputStream outputStream = Files.newOutputStream(evidenceFile.toPath())) { + evidenceFactory.write(outputStream, transmissionResponse); + } } } } diff --git a/oxalis-dist/oxalis-war/pom.xml b/oxalis-dist/oxalis-war/pom.xml index 565e64d6a..8caeae11c 100644 --- a/oxalis-dist/oxalis-war/pom.xml +++ b/oxalis-dist/oxalis-war/pom.xml @@ -34,8 +34,8 @@ - javax.servlet - javax.servlet-api + jakarta.servlet + jakarta.servlet-api provided diff --git a/oxalis-dist/oxalis-war/src/main/java/network/oxalis/dist/war/WarGuiceFilter.java b/oxalis-dist/oxalis-war/src/main/java/network/oxalis/dist/war/WarGuiceFilter.java index 7ae725ca2..00b7dd321 100644 --- a/oxalis-dist/oxalis-war/src/main/java/network/oxalis/dist/war/WarGuiceFilter.java +++ b/oxalis-dist/oxalis-war/src/main/java/network/oxalis/dist/war/WarGuiceFilter.java @@ -2,11 +2,11 @@ import com.google.inject.servlet.GuiceFilter; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.annotation.WebFilter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.annotation.WebFilter; import java.io.IOException; /** diff --git a/oxalis-dist/oxalis-war/src/main/java/network/oxalis/dist/war/WarServletContextListener.java b/oxalis-dist/oxalis-war/src/main/java/network/oxalis/dist/war/WarServletContextListener.java index c8a49b487..994efb06f 100644 --- a/oxalis-dist/oxalis-war/src/main/java/network/oxalis/dist/war/WarServletContextListener.java +++ b/oxalis-dist/oxalis-war/src/main/java/network/oxalis/dist/war/WarServletContextListener.java @@ -2,7 +2,7 @@ import network.oxalis.inbound.OxalisGuiceContextListener; -import javax.servlet.annotation.WebListener; +import jakarta.servlet.annotation.WebListener; /** * @author erlend diff --git a/oxalis-extension/oxalis-as2/pom.xml b/oxalis-extension/oxalis-as2/pom.xml index 3d4b8bb86..28a5c5a26 100644 --- a/oxalis-extension/oxalis-as2/pom.xml +++ b/oxalis-extension/oxalis-as2/pom.xml @@ -56,8 +56,8 @@ - javax.servlet - javax.servlet-api + jakarta.servlet + jakarta.servlet-api provided @@ -71,7 +71,7 @@ org.bouncycastle - bcmail-jdk18on + bcjmail-jdk18on @@ -90,10 +90,14 @@ provided - + - io.opentracing.contrib - opentracing-web-servlet-filter + io.opentelemetry + opentelemetry-api + + + io.opentelemetry + opentelemetry-sdk diff --git a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/inbound/As2InboundHandler.java b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/inbound/As2InboundHandler.java index 321e70ba9..8e7e3031c 100644 --- a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/inbound/As2InboundHandler.java +++ b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/inbound/As2InboundHandler.java @@ -23,7 +23,8 @@ package network.oxalis.as2.inbound; import com.google.inject.Inject; -import io.opentracing.Span; +import jakarta.mail.internet.InternetHeaders; +import jakarta.mail.internet.MimeMessage; import network.oxalis.api.header.HeaderParser; import network.oxalis.api.identifier.MessageIdGenerator; import network.oxalis.api.inbound.InboundService; @@ -43,15 +44,17 @@ import network.oxalis.as2.code.MdnHeader; import network.oxalis.as2.lang.OxalisAs2InboundException; import network.oxalis.as2.model.Mic; -import network.oxalis.as2.util.*; +import network.oxalis.as2.util.MdnBuilder; +import network.oxalis.as2.util.MessageIdUtil; +import network.oxalis.as2.util.SMimeDigestMethod; +import network.oxalis.as2.util.SMimeMessageFactory; +import network.oxalis.as2.util.SignedMessage; import network.oxalis.commons.mode.OxalisCertificateValidator; import network.oxalis.vefa.peppol.common.code.Service; import network.oxalis.vefa.peppol.common.model.Digest; import network.oxalis.vefa.peppol.common.model.Header; import network.oxalis.vefa.peppol.security.lang.PeppolSecurityException; -import javax.mail.internet.InternetHeaders; -import javax.mail.internet.MimeMessage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; @@ -115,7 +118,7 @@ public As2InboundHandler(InboundService inboundService, TimestampProvider timest * @param mimeMessage supplies the MIME message * @return MDN object to signal if everything is ok or if some error occurred while receiving */ - public MimeMessage receive(InternetHeaders httpHeaders, MimeMessage mimeMessage, Span root) throws OxalisAs2InboundException { + public MimeMessage receive(InternetHeaders httpHeaders, MimeMessage mimeMessage) throws OxalisAs2InboundException { TransmissionIdentifier transmissionIdentifier = null; Header header = null; Path payloadPath = null; diff --git a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/inbound/As2InboundModule.java b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/inbound/As2InboundModule.java index 3837395d6..f7e669723 100644 --- a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/inbound/As2InboundModule.java +++ b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/inbound/As2InboundModule.java @@ -26,7 +26,7 @@ import com.google.inject.name.Names; import com.google.inject.servlet.ServletModule; -import javax.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServlet; /** * Guice module providing AS2 implementation for inbound. diff --git a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/inbound/As2Servlet.java b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/inbound/As2Servlet.java index 96ff09b8c..ea1d0e238 100644 --- a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/inbound/As2Servlet.java +++ b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/inbound/As2Servlet.java @@ -26,27 +26,29 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; -import io.opentracing.Span; -import io.opentracing.SpanContext; -import io.opentracing.Tracer; -import io.opentracing.contrib.web.servlet.filter.TracingFilter; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.Tracer; +import jakarta.mail.Header; +import jakarta.mail.MessagingException; +import jakarta.mail.internet.InternetHeaders; +import jakarta.mail.internet.MimeMessage; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import network.oxalis.api.error.ErrorTracker; import network.oxalis.api.model.Direction; import network.oxalis.as2.code.As2Header; import network.oxalis.as2.code.MdnHeader; import network.oxalis.as2.lang.OxalisAs2InboundException; -import network.oxalis.as2.util.*; +import network.oxalis.as2.util.MdnBuilder; +import network.oxalis.as2.util.MimeMessageHelper; +import network.oxalis.as2.util.SMimeDigestMethod; +import network.oxalis.as2.util.SMimeMessageFactory; +import network.oxalis.as2.util.SignedMessage; import network.oxalis.commons.security.CertificateUtils; import org.slf4j.MDC; -import javax.mail.Header; -import javax.mail.MessagingException; -import javax.mail.internet.InternetHeaders; -import javax.mail.internet.MimeMessage; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.security.cert.X509Certificate; import java.util.Collections; @@ -117,14 +119,11 @@ protected void doPost(final HttpServletRequest request, final HttpServletRespons return; } - SpanContext spanContext = (SpanContext) request.getAttribute(TracingFilter.SERVER_SPAN_CONTEXT); - - Span root = tracer.buildSpan("as2servlet.post").asChildOf(spanContext).start(); - + Span root = tracer.spanBuilder("as2servlet.post").startSpan(); // Receives the data, validates the headers, signature etc., invokes the persistence handler // and finally returns the MdnData to be sent back to the caller try { - root.setTag("message-id", request.getHeader("message-id")); + root.setAttribute("message-id", request.getHeader("message-id")); MDC.put("message-id", request.getHeader("message-id")); // Read all headers @@ -139,20 +138,27 @@ protected void doPost(final HttpServletRequest request, final HttpServletRespons // Performs the actual reception of the message by parsing the HTTP POST request // persisting the payload etc. - Span span = tracer.buildSpan("as2message").asChildOf(root).start(); - MimeMessage mdn = inboundHandlerProvider.get().receive(headers, mimeMessage, span); - span.finish(); + Span mimeMessageSpan = tracer.spanBuilder("as2message").startSpan(); + MimeMessage mdn; + try { + mdn = inboundHandlerProvider.get().receive(headers, mimeMessage); + } finally { + mimeMessageSpan.end(); + } // Returns the MDN - span = tracer.buildSpan("mdn").asChildOf(root).start(); - writeMdn(response, mdn, HttpServletResponse.SC_OK); - span.finish(); + Span mdnSpan = tracer.spanBuilder("mdn").startSpan(); + try { + writeMdn(response, mdn, HttpServletResponse.SC_OK); + } finally { + mdnSpan.end(); + } } catch (OxalisAs2InboundException e) { String identifier = errorTracker.track(Direction.IN, e, true); - root.setTag("identifier", identifier); - root.setTag("exception", String.valueOf(e.getMessage())); + root.setAttribute("identifier", identifier); + root.setAttribute("exception", String.valueOf(e.getMessage())); // Begin builder MdnBuilder mdnBuilder = MdnBuilder.newInstance(mimeMessage); @@ -176,14 +182,14 @@ protected void doPost(final HttpServletRequest request, final HttpServletRespons } catch (Exception e) { String identifier = errorTracker.track(Direction.IN, e, false); - root.setTag("identifier", identifier); - root.setTag("exception", String.valueOf(e.getMessage())); + root.setAttribute("identifier", identifier); + root.setAttribute("exception", String.valueOf(e.getMessage())); // Unexpected internal error, cannot proceed, return HTTP 500 and partly MDN to indicating the problem - writeFailureWithExplanation(request, response, e); + writeFailureWithExplanation(request, response); } finally { MDC.remove("message-id"); - root.finish(); + root.end(); } } @@ -193,7 +199,7 @@ protected void writeMdn(HttpServletResponse response, MimeMessage mdn, int statu response.setStatus(status); // Add headers and collect header names. - Map headers = Collections.list((Enumeration) mdn.getAllHeaders()).stream() + Map headers = Collections.list((Enumeration) mdn.getAllHeaders()).stream() .map(Header.class::cast) .collect(Collectors.toMap(Header::getName, Header::getValue)); @@ -210,7 +216,7 @@ protected void writeMdn(HttpServletResponse response, MimeMessage mdn, int statu /** * If the AS2 message processing failed with an exception, we have an internal error and act accordingly */ - void writeFailureWithExplanation(HttpServletRequest request, HttpServletResponse response, Exception e) + void writeFailureWithExplanation(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); diff --git a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/outbound/As2MessageSender.java b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/outbound/As2MessageSender.java index 56144f761..633050367 100644 --- a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/outbound/As2MessageSender.java +++ b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/outbound/As2MessageSender.java @@ -26,9 +26,12 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.name.Named; -import io.opentracing.Span; -import io.opentracing.Tracer; -import io.opentracing.contrib.apache.http.client.Constants; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.Tracer; +import jakarta.mail.MessagingException; +import jakarta.mail.internet.InternetHeaders; +import jakarta.mail.internet.MimeBodyPart; +import jakarta.mail.internet.MimeMessage; import lombok.extern.slf4j.Slf4j; import network.oxalis.api.identifier.MessageIdGenerator; import network.oxalis.api.lang.OxalisSecurityException; @@ -42,10 +45,16 @@ import network.oxalis.api.timestamp.TimestampProvider; import network.oxalis.as2.code.As2Header; import network.oxalis.as2.code.MdnHeader; +import network.oxalis.as2.lang.OxalisAs2Exception; import network.oxalis.as2.model.As2DispositionNotificationOptions; import network.oxalis.as2.model.Mic; -import network.oxalis.as2.util.*; -import network.oxalis.as2.lang.OxalisAs2Exception; +import network.oxalis.as2.util.As2DateUtil; +import network.oxalis.as2.util.MdnMimeMessageInspector; +import network.oxalis.as2.util.MessageIdUtil; +import network.oxalis.as2.util.MimeMessageHelper; +import network.oxalis.as2.util.SMimeDigestMethod; +import network.oxalis.as2.util.SMimeMessageFactory; +import network.oxalis.as2.util.SignedMessage; import network.oxalis.commons.security.CertificateUtils; import network.oxalis.commons.tracing.Traceable; import network.oxalis.vefa.peppol.common.model.Digest; @@ -62,10 +71,6 @@ import org.apache.http.protocol.BasicHttpContext; import org.apache.http.util.EntityUtils; -import javax.mail.MessagingException; -import javax.mail.internet.InternetHeaders; -import javax.mail.internet.MimeBodyPart; -import javax.mail.internet.MimeMessage; import javax.net.ssl.SSLHandshakeException; import java.io.IOException; import java.io.InputStream; @@ -115,8 +120,6 @@ class As2MessageSender extends Traceable { private TransmissionIdentifier transmissionIdentifier; - private Span root; - private Digest outboundMic; /** @@ -145,24 +148,24 @@ public As2MessageSender(Provider httpClientProvider, X509Ce this.fromIdentifier = CertificateUtils.extractCommonName(certificate); } - public TransmissionResponse send(TransmissionRequest transmissionRequest, Span root) + public TransmissionResponse send(TransmissionRequest transmissionRequest) throws OxalisTransmissionException { this.transmissionRequest = transmissionRequest; - this.root = tracer.buildSpan("Send AS2 message").asChildOf(root).start(); + Span root = tracer.spanBuilder("Send AS2 message").startSpan(); try { return sendHttpRequest(prepareHttpRequest()); } catch (OxalisTransmissionException e) { - this.root.setTag("exception", e.getMessage()); + root.setAttribute("exception", e.getMessage()); throw e; } finally { - root.finish(); + root.end(); } } @SuppressWarnings("unchecked") protected HttpPost prepareHttpRequest() throws OxalisTransmissionException { - Span span = tracer.buildSpan("request").asChildOf(root).start(); + Span span = tracer.spanBuilder("request").startSpan(); try { // Create the body part of the MIME message containing our content to be transmitted. MimeBodyPart mimeBodyPart = MimeMessageHelper @@ -173,8 +176,8 @@ protected HttpPost prepareHttpRequest() throws OxalisTransmissionException { transmissionRequest.getEndpoint().getTransportProfile()); outboundMic = MimeMessageHelper.calculateMic(mimeBodyPart, digestMethod); - span.setTag("mic", outboundMic.toString()); - span.setTag("endpoint url", transmissionRequest.getEndpoint().getAddress().toString()); + span.setAttribute("mic", outboundMic.toString()); + span.setAttribute("endpoint url", transmissionRequest.getEndpoint().getAddress().toString()); // Create Message-Id String messageId = messageIdGenerator.generate(transmissionRequest); @@ -182,7 +185,7 @@ protected HttpPost prepareHttpRequest() throws OxalisTransmissionException { if (!MessageIdUtil.verify(messageId)) throw new OxalisTransmissionException("Invalid Message-ID '" + messageId + "' generated."); - span.setTag("message-id", messageId); + span.setAttribute("message-id", messageId); transmissionIdentifier = TransmissionIdentifier.fromHeader(messageId); // Create a complete S/MIME message using the body part containing our content as the @@ -196,8 +199,8 @@ protected HttpPost prepareHttpRequest() throws OxalisTransmissionException { //} // Get all headers in S/MIME message. - Map headers = ((List) Collections.list(signedMimeMessage.getAllHeaders())).stream() - .collect(Collectors.toMap(javax.mail.Header::getName, h -> h.getValue().replace("\r\n\t", ""))); + Map headers = ((List) Collections.list(signedMimeMessage.getAllHeaders())).stream() + .collect(Collectors.toMap(jakarta.mail.Header::getName, h -> h.getValue().replace("\r\n\t", ""))); // Clear headers in MIME content for (String name : headers.keySet()) @@ -228,45 +231,43 @@ protected HttpPost prepareHttpRequest() throws OxalisTransmissionException { } catch (MessagingException | IOException e) { throw new OxalisTransmissionException("Unexpected error during preparation of AS2 message.", e); } finally { - span.finish(); + span.end(); } } protected TransmissionResponse sendHttpRequest(HttpPost httpPost) throws OxalisTransmissionException { - Span span = tracer.buildSpan("execute").asChildOf(root).start(); + Span span = tracer.spanBuilder("execute").startSpan(); try (CloseableHttpClient httpClient = httpClientProvider.get()) { BasicHttpContext basicHttpContext = new BasicHttpContext(); - basicHttpContext.setAttribute(Constants.PARENT_CONTEXT, span.context()); + basicHttpContext.setAttribute("spanContext", span.getSpanContext()); CloseableHttpResponse response = httpClient.execute(httpPost, basicHttpContext); - span.finish(); - return handleResponse(response); } catch (SocketTimeoutException e) { - span.setTag("exception", String.valueOf(e.getMessage())); + span.setAttribute("exception", String.valueOf(e.getMessage())); throw new OxalisTransmissionException("Receiving server has not sent anything back within SOCKET_TIMEOUT", transmissionRequest.getEndpoint().getAddress(), e); } catch (HttpHostConnectException e) { - span.setTag("exception", e.getMessage()); + span.setAttribute("exception", e.getMessage()); throw new OxalisTransmissionException("Receiving server does not seem to be running.", transmissionRequest.getEndpoint().getAddress(), e); } catch (SSLHandshakeException e) { - span.setTag("exception", e.getMessage()); + span.setAttribute("exception", e.getMessage()); throw new OxalisTransmissionException("Possible invalid SSL Certificate at the other end.", transmissionRequest.getEndpoint().getAddress(), e); } catch (IOException e) { - span.setTag("exception", String.valueOf(e.getMessage())); + span.setAttribute("exception", String.valueOf(e.getMessage())); throw new OxalisTransmissionException(transmissionRequest.getEndpoint().getAddress(), e); } finally { - span.finish(); + span.end(); } } protected TransmissionResponse handleResponse(CloseableHttpResponse closeableHttpResponse) throws OxalisTransmissionException { - Span span = tracer.buildSpan("response").asChildOf(root).start(); + Span span = tracer.spanBuilder("response").startSpan(); try (CloseableHttpResponse response = closeableHttpResponse) { - span.setTag("code", String.valueOf(response.getStatusLine().getStatusCode())); + span.setAttribute("code", String.valueOf(response.getStatusLine().getStatusCode())); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { log.error("AS2 HTTP POST expected HTTP OK, but got : {} from {}", @@ -331,7 +332,7 @@ protected TransmissionResponse handleResponse(CloseableHttpResponse closeableHtt } catch (NoSuchAlgorithmException | MessagingException e) { throw new OxalisTransmissionException(String.format("Unable to parseOld received MDN: %s", e.getMessage()), e); } finally { - span.finish(); + span.end(); } } diff --git a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/outbound/As2MessageSenderFacade.java b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/outbound/As2MessageSenderFacade.java index 32b84d8eb..4579728fd 100644 --- a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/outbound/As2MessageSenderFacade.java +++ b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/outbound/As2MessageSenderFacade.java @@ -24,8 +24,8 @@ import com.google.inject.Inject; import com.google.inject.Provider; -import io.opentracing.Span; -import io.opentracing.Tracer; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.Tracer; import network.oxalis.api.lang.OxalisTransmissionException; import network.oxalis.api.outbound.MessageSender; import network.oxalis.api.outbound.TransmissionRequest; @@ -44,17 +44,12 @@ public As2MessageSenderFacade(Tracer tracer, Provider messageS @Override public TransmissionResponse send(TransmissionRequest transmissionRequest) throws OxalisTransmissionException { - Span span = tracer.buildSpan(getClass().getSimpleName()).start(); + Span span = tracer.spanBuilder(getClass().getSimpleName()).startSpan(); try { - return send(transmissionRequest, span); + return messageSenderProvider.get().send(transmissionRequest); } finally { - span.finish(); + span.end(); } } - @Override - public TransmissionResponse send(TransmissionRequest transmissionRequest, Span root) - throws OxalisTransmissionException { - return messageSenderProvider.get().send(transmissionRequest, root); - } } diff --git a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/HeaderUtil.java b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/HeaderUtil.java index 28dcad5f8..c898ba624 100644 --- a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/HeaderUtil.java +++ b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/HeaderUtil.java @@ -22,7 +22,7 @@ package network.oxalis.as2.util; -import javax.mail.internet.InternetHeaders; +import jakarta.mail.internet.InternetHeaders; /** * @author steinar diff --git a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/MdnBuilder.java b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/MdnBuilder.java index f596b2189..4e8dff65e 100644 --- a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/MdnBuilder.java +++ b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/MdnBuilder.java @@ -28,11 +28,11 @@ import network.oxalis.as2.code.MdnHeader; import network.oxalis.commons.util.OxalisVersion; -import javax.mail.MessagingException; -import javax.mail.internet.InternetHeaders; -import javax.mail.internet.MimeBodyPart; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMultipart; +import jakarta.mail.MessagingException; +import jakarta.mail.internet.InternetHeaders; +import jakarta.mail.internet.MimeBodyPart; +import jakarta.mail.internet.MimeMessage; +import jakarta.mail.internet.MimeMultipart; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Base64; diff --git a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/MdnMimeMessageInspector.java b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/MdnMimeMessageInspector.java index 622f07f24..f22405d42 100644 --- a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/MdnMimeMessageInspector.java +++ b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/MdnMimeMessageInspector.java @@ -27,9 +27,9 @@ import network.oxalis.as2.model.Mic; import org.apache.commons.codec.binary.Base64InputStream; -import javax.mail.BodyPart; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMultipart; +import jakarta.mail.BodyPart; +import jakarta.mail.internet.MimeMessage; +import jakarta.mail.internet.MimeMultipart; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; diff --git a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/MimeMessageHelper.java b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/MimeMessageHelper.java index a2c7c7671..e650b09d6 100644 --- a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/MimeMessageHelper.java +++ b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/MimeMessageHelper.java @@ -26,13 +26,13 @@ import network.oxalis.commons.bouncycastle.BCHelper; import network.oxalis.vefa.peppol.common.model.Digest; -import javax.activation.DataHandler; -import javax.mail.MessagingException; -import javax.mail.Session; -import javax.mail.internet.InternetHeaders; -import javax.mail.internet.MimeBodyPart; -import javax.mail.internet.MimeMessage; -import javax.mail.util.ByteArrayDataSource; +import jakarta.activation.DataHandler; +import jakarta.mail.MessagingException; +import jakarta.mail.Session; +import jakarta.mail.internet.InternetHeaders; +import jakarta.mail.internet.MimeBodyPart; +import jakarta.mail.internet.MimeMessage; +import jakarta.mail.util.ByteArrayDataSource; import java.io.*; import java.security.DigestOutputStream; import java.security.MessageDigest; diff --git a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/SMimeMessageFactory.java b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/SMimeMessageFactory.java index 518ebc85c..22d2f21e2 100644 --- a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/SMimeMessageFactory.java +++ b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/SMimeMessageFactory.java @@ -38,15 +38,15 @@ import org.bouncycastle.operator.OperatorCreationException; import org.bouncycastle.util.Store; -import javax.activation.DataHandler; -import javax.activation.DataSource; -import javax.activation.MimeType; -import javax.mail.MessagingException; -import javax.mail.Session; -import javax.mail.internet.MimeBodyPart; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMultipart; -import javax.mail.util.ByteArrayDataSource; +import jakarta.activation.DataHandler; +import jakarta.activation.DataSource; +import jakarta.activation.MimeType; +import jakarta.mail.MessagingException; +import jakarta.mail.Session; +import jakarta.mail.internet.MimeBodyPart; +import jakarta.mail.internet.MimeMessage; +import jakarta.mail.internet.MimeMultipart; +import jakarta.mail.util.ByteArrayDataSource; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.security.PrivateKey; diff --git a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/SignedMessage.java b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/SignedMessage.java index 007dcd9ee..48e662952 100644 --- a/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/SignedMessage.java +++ b/oxalis-extension/oxalis-as2/src/main/java/network/oxalis/as2/util/SignedMessage.java @@ -20,12 +20,12 @@ import org.bouncycastle.operator.OperatorCreationException; import org.bouncycastle.util.CollectionStore; -import javax.mail.MessagingException; -import javax.mail.Session; -import javax.mail.internet.ContentType; -import javax.mail.internet.MimeBodyPart; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMultipart; +import jakarta.mail.MessagingException; +import jakarta.mail.Session; +import jakarta.mail.internet.ContentType; +import jakarta.mail.internet.MimeBodyPart; +import jakarta.mail.internet.MimeMessage; +import jakarta.mail.internet.MimeMultipart; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; diff --git a/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/SimpleServerTest.java b/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/SimpleServerTest.java index 2c7f3a3df..2e8b41008 100644 --- a/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/SimpleServerTest.java +++ b/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/SimpleServerTest.java @@ -44,7 +44,7 @@ import org.testng.Assert; import org.testng.annotations.Test; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URI; diff --git a/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/inbound/As2InboundHandlerTest.java b/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/inbound/As2InboundHandlerTest.java index d53e7d87d..48df107d6 100644 --- a/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/inbound/As2InboundHandlerTest.java +++ b/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/inbound/As2InboundHandlerTest.java @@ -23,7 +23,7 @@ package network.oxalis.as2.inbound; import com.google.inject.Inject; -import io.opentracing.Tracer; +import io.opentelemetry.api.trace.Tracer; import network.oxalis.api.inbound.InboundService; import network.oxalis.api.lang.OxalisTransmissionException; import network.oxalis.api.model.Direction; @@ -47,10 +47,10 @@ import org.testng.annotations.Guice; import org.testng.annotations.Test; -import javax.mail.MessagingException; -import javax.mail.internet.InternetHeaders; -import javax.mail.internet.MimeBodyPart; -import javax.mail.internet.MimeMessage; +import jakarta.mail.MessagingException; +import jakarta.mail.internet.InternetHeaders; +import jakarta.mail.internet.MimeBodyPart; +import jakarta.mail.internet.MimeMessage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -93,7 +93,7 @@ public void setUp() throws Exception { Mockito.doReturn(new Timestamp(new Date(), null)).when(mockTimestampProvider) .generate(Mockito.any(), Mockito.any(Direction.class)); Mockito.doReturn(new Timestamp(new Date(), null)).when(mockTimestampProvider) - .generate(Mockito.any(), Mockito.any(Direction.class), Mockito.any()); + .generate(Mockito.any(), Mockito.any(Direction.class)); String ourCommonName = CertificateUtils.extractCommonName(certificate); @@ -118,7 +118,7 @@ mockTimestampProvider, new OxalisCertificateValidator(CertificateValidator.EMPTY new DefaultMessageIdGenerator("test"), new SbdhHeaderParser()); MimeMessage mimeMessage = MimeMessageHelper.parse(inputStream, headers); - as2InboundHandler.receive(headers, mimeMessage, tracer.buildSpan("test").start()); + as2InboundHandler.receive(headers, mimeMessage); } diff --git a/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/util/MdnMimeMessageInspectorTest.java b/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/util/MdnMimeMessageInspectorTest.java index 3bd408035..74d918b85 100644 --- a/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/util/MdnMimeMessageInspectorTest.java +++ b/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/util/MdnMimeMessageInspectorTest.java @@ -24,7 +24,7 @@ import org.testng.annotations.Test; -import javax.mail.internet.MimeMessage; +import jakarta.mail.internet.MimeMessage; import java.io.InputStream; import java.util.Map; diff --git a/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/util/MimeMessageHelperTest.java b/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/util/MimeMessageHelperTest.java index b8b876347..221455ae1 100644 --- a/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/util/MimeMessageHelperTest.java +++ b/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/util/MimeMessageHelperTest.java @@ -34,11 +34,11 @@ import org.bouncycastle.util.Store; import org.testng.annotations.Test; -import javax.activation.MimeType; -import javax.mail.BodyPart; -import javax.mail.MessagingException; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMultipart; +import jakarta.activation.MimeType; +import jakarta.mail.BodyPart; +import jakarta.mail.MessagingException; +import jakarta.mail.internet.MimeMessage; +import jakarta.mail.internet.MimeMultipart; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; diff --git a/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/util/SMimeMessageFactoryTest.java b/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/util/SMimeMessageFactoryTest.java index 1a6a57b5f..5cfc97c26 100644 --- a/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/util/SMimeMessageFactoryTest.java +++ b/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/util/SMimeMessageFactoryTest.java @@ -28,10 +28,10 @@ import org.testng.annotations.Guice; import org.testng.annotations.Test; -import javax.activation.MimeType; -import javax.mail.BodyPart; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMultipart; +import jakarta.activation.MimeType; +import jakarta.mail.BodyPart; +import jakarta.mail.internet.MimeMessage; +import jakarta.mail.internet.MimeMultipart; import java.io.InputStream; import java.io.StringWriter; import java.security.PrivateKey; diff --git a/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/util/TestDataGenerator.java b/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/util/TestDataGenerator.java index 1dab2582f..18c1dff49 100644 --- a/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/util/TestDataGenerator.java +++ b/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/util/TestDataGenerator.java @@ -27,10 +27,10 @@ import network.oxalis.as2.code.As2Header; import network.oxalis.commons.security.CertificateUtils; -import javax.mail.MessagingException; -import javax.mail.internet.InternetHeaders; -import javax.mail.internet.MimeBodyPart; -import javax.mail.internet.MimeMessage; +import jakarta.mail.MessagingException; +import jakarta.mail.internet.InternetHeaders; +import jakarta.mail.internet.MimeBodyPart; +import jakarta.mail.internet.MimeMessage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/verification/InternetHeadersTest.java b/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/verification/InternetHeadersTest.java index 1374f6852..43d93485a 100644 --- a/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/verification/InternetHeadersTest.java +++ b/oxalis-extension/oxalis-as2/src/test/java/network/oxalis/as2/verification/InternetHeadersTest.java @@ -24,7 +24,7 @@ import org.testng.annotations.Test; -import javax.mail.internet.InternetHeaders; +import jakarta.mail.internet.InternetHeaders; import java.util.TreeMap; import static org.testng.Assert.assertEquals; diff --git a/oxalis-extension/oxalis-extension-example/src/main/java/network/oxalis/ext/example/LoggingTransmissionVerifier.java b/oxalis-extension/oxalis-extension-example/src/main/java/network/oxalis/ext/example/LoggingTransmissionVerifier.java index 71abea22f..989c5a7bc 100644 --- a/oxalis-extension/oxalis-extension-example/src/main/java/network/oxalis/ext/example/LoggingTransmissionVerifier.java +++ b/oxalis-extension/oxalis-extension-example/src/main/java/network/oxalis/ext/example/LoggingTransmissionVerifier.java @@ -28,7 +28,7 @@ import network.oxalis.api.util.Type; import network.oxalis.vefa.peppol.common.model.Header; -import javax.inject.Singleton; +import jakarta.inject.Singleton; /** * This is a simple implementation of {@link TransmissionVerifier} where each message is logged. diff --git a/oxalis-extension/oxalis-extension-testbed/pom.xml b/oxalis-extension/oxalis-extension-testbed/pom.xml index ab6c2b36a..96678efaf 100644 --- a/oxalis-extension/oxalis-extension-testbed/pom.xml +++ b/oxalis-extension/oxalis-extension-testbed/pom.xml @@ -11,21 +11,14 @@ Oxalis :: Ext :: Testbed connector - - 2.3.3 - 2.3.3 - - jakarta.xml.bind jakarta.xml.bind-api - ${jakarta.xml.bind-api-version} com.sun.xml.bind jaxb-impl - ${jaxb-impl-version} runtime @@ -41,8 +34,8 @@ - javax.servlet - javax.servlet-api + jakarta.servlet + jakarta.servlet-api provided @@ -50,9 +43,9 @@ - org.jvnet.jaxb2.maven2 - maven-jaxb2-plugin - 0.14.0 + org.jvnet.jaxb + jaxb-maven-plugin + 4.0.8 @@ -71,18 +64,6 @@ - - - jakarta.xml.bind - jakarta.xml.bind-api - 2.3.3 - - - com.sun.xml.bind - jaxb-impl - 2.3.3 - - org.codehaus.mojo diff --git a/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedFilter.java b/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedFilter.java index 8f83f3d4f..931417952 100644 --- a/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedFilter.java +++ b/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedFilter.java @@ -4,11 +4,11 @@ import com.google.inject.Singleton; import lombok.extern.slf4j.Slf4j; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpFilter; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpFilter; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; import java.util.stream.Collectors; diff --git a/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedJaxb.java b/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedJaxb.java index b6dad1332..d1324f863 100644 --- a/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedJaxb.java +++ b/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedJaxb.java @@ -2,10 +2,10 @@ import network.oxalis.ext.testbed.v1.jaxb.*; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Marshaller; +import jakarta.xml.bind.Unmarshaller; /** * @author erlend diff --git a/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedPersisterHandler.java b/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedPersisterHandler.java index 84377fc92..29593af2f 100644 --- a/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedPersisterHandler.java +++ b/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedPersisterHandler.java @@ -13,7 +13,7 @@ import network.oxalis.ext.testbed.v1.jaxb.InboundType; import network.oxalis.vefa.peppol.common.model.Header; -import javax.inject.Named; +import jakarta.inject.Named; import java.io.File; import java.io.IOException; import java.io.InputStream; diff --git a/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedSender.java b/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedSender.java index ce1d06fcf..fe636c920 100644 --- a/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedSender.java +++ b/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedSender.java @@ -14,8 +14,8 @@ import org.apache.http.entity.ContentType; import org.apache.http.impl.client.CloseableHttpClient; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBException; +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedServlet.java b/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedServlet.java index 59e75bf30..9fce4ab4a 100644 --- a/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedServlet.java +++ b/oxalis-extension/oxalis-extension-testbed/src/main/java/network/oxalis/ext/testbed/v1/TestbedServlet.java @@ -15,12 +15,12 @@ import network.oxalis.outbound.transmission.TransmissionRequestFactory; import network.oxalis.vefa.peppol.common.model.TransportProfile; -import javax.inject.Named; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.xml.bind.JAXBException; +import jakarta.inject.Named; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.xml.bind.JAXBException; import javax.xml.transform.stream.StreamSource; import java.io.ByteArrayInputStream; import java.io.IOException; diff --git a/oxalis-inbound/pom.xml b/oxalis-inbound/pom.xml index e171525df..9ba9b3825 100644 --- a/oxalis-inbound/pom.xml +++ b/oxalis-inbound/pom.xml @@ -70,8 +70,8 @@ - javax.servlet - javax.servlet-api + jakarta.servlet + jakarta.servlet-api provided @@ -99,13 +99,17 @@ org.bouncycastle - bcmail-jdk18on + bcjmail-jdk18on - + - io.opentracing.contrib - opentracing-web-servlet-filter + io.opentelemetry + opentelemetry-api + + + io.opentelemetry + opentelemetry-sdk diff --git a/oxalis-inbound/src/main/java/network/oxalis/inbound/InboundModule.java b/oxalis-inbound/src/main/java/network/oxalis/inbound/InboundModule.java index de29d5e57..508c186b8 100644 --- a/oxalis-inbound/src/main/java/network/oxalis/inbound/InboundModule.java +++ b/oxalis-inbound/src/main/java/network/oxalis/inbound/InboundModule.java @@ -22,14 +22,21 @@ package network.oxalis.inbound; +import com.google.inject.Injector; +import com.google.inject.Key; import com.google.inject.Provides; import com.google.inject.Singleton; +import com.google.inject.name.Names; import com.google.inject.servlet.ServletModule; -import io.opentracing.Tracer; -import io.opentracing.contrib.web.servlet.filter.TracingFilter; import network.oxalis.api.inbound.InboundService; +import network.oxalis.api.settings.Settings; +import network.oxalis.commons.guice.ImplLoader; +import network.oxalis.commons.settings.SettingsBuilder; import network.oxalis.inbound.servlet.HomeServlet; import network.oxalis.inbound.servlet.StatusServlet; +import network.oxalis.inbound.tracing.DefaultOpenTelemetryTracingFilter; +import network.oxalis.inbound.tracing.OpenTelemetryServletConf; +import network.oxalis.inbound.tracing.OpenTelemetryTracingFilter; /** * @author erlend @@ -38,17 +45,23 @@ public class InboundModule extends ServletModule { @Override protected void configureServlets() { - filter("/*").through(TracingFilter.class); + SettingsBuilder.with(binder(), OpenTelemetryServletConf.class); + + filter("/*").through(OpenTelemetryTracingFilter.class); serve("/").with(HomeServlet.class); serve("/status").with(StatusServlet.class); bind(InboundService.class).to(DefaultInboundService.class); + + bind(Key.get(OpenTelemetryTracingFilter.class, Names.named("default"))) + .to(DefaultOpenTelemetryTracingFilter.class); } @Provides @Singleton - protected TracingFilter getTracingFilter(Tracer tracer) { - return new TracingFilter(tracer); + protected OpenTelemetryTracingFilter getOpenTelemetryTracingFilter(Injector injector, Settings settings) { + return ImplLoader.get(injector, OpenTelemetryTracingFilter.class, settings, OpenTelemetryServletConf.TRACING_FILTER); } + } diff --git a/oxalis-inbound/src/main/java/network/oxalis/inbound/servlet/HomeServlet.java b/oxalis-inbound/src/main/java/network/oxalis/inbound/servlet/HomeServlet.java index a00122072..65fc71835 100644 --- a/oxalis-inbound/src/main/java/network/oxalis/inbound/servlet/HomeServlet.java +++ b/oxalis-inbound/src/main/java/network/oxalis/inbound/servlet/HomeServlet.java @@ -24,9 +24,9 @@ import com.google.inject.Singleton; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; @Singleton diff --git a/oxalis-inbound/src/main/java/network/oxalis/inbound/servlet/StatusServlet.java b/oxalis-inbound/src/main/java/network/oxalis/inbound/servlet/StatusServlet.java index e4e0dce78..984b607c8 100644 --- a/oxalis-inbound/src/main/java/network/oxalis/inbound/servlet/StatusServlet.java +++ b/oxalis-inbound/src/main/java/network/oxalis/inbound/servlet/StatusServlet.java @@ -28,9 +28,9 @@ import network.oxalis.commons.util.OxalisVersion; import network.oxalis.vefa.peppol.mode.Mode; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.security.cert.X509Certificate; diff --git a/oxalis-inbound/src/main/java/network/oxalis/inbound/tracing/DefaultOpenTelemetryTracingFilter.java b/oxalis-inbound/src/main/java/network/oxalis/inbound/tracing/DefaultOpenTelemetryTracingFilter.java new file mode 100644 index 000000000..87e180cfb --- /dev/null +++ b/oxalis-inbound/src/main/java/network/oxalis/inbound/tracing/DefaultOpenTelemetryTracingFilter.java @@ -0,0 +1,39 @@ +package network.oxalis.inbound.tracing; + +import com.google.inject.Inject; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import lombok.extern.slf4j.Slf4j; +import network.oxalis.commons.tracing.SpanManager; +import network.oxalis.commons.util.ClosableSpan; + +import java.io.IOException; + +@Slf4j +public class DefaultOpenTelemetryTracingFilter implements OpenTelemetryTracingFilter { + + @Inject + private SpanManager spanManager; + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + String rootSpanName = deriveSpanName(servletRequest); + try (ClosableSpan ignore = spanManager.startClosableSpan(rootSpanName)) { + filterChain.doFilter(servletRequest, servletResponse); + } + } + + private String deriveSpanName(ServletRequest servletRequest) { + if (servletRequest instanceof HttpServletRequest) { + HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; + return String.format("%s - %s", httpServletRequest.getMethod(), httpServletRequest.getRequestURI()); + } else { + log.warn("unable to determine span name from {}, fall back to \"default\"", servletRequest.getClass()); + return "default"; + } + } + +} diff --git a/oxalis-commons/src/main/java/network/oxalis/commons/tracing/BraveConf.java b/oxalis-inbound/src/main/java/network/oxalis/inbound/tracing/OpenTelemetryServletConf.java similarity index 77% rename from oxalis-commons/src/main/java/network/oxalis/commons/tracing/BraveConf.java rename to oxalis-inbound/src/main/java/network/oxalis/inbound/tracing/OpenTelemetryServletConf.java index 33722cf26..8b8a3b846 100644 --- a/oxalis-commons/src/main/java/network/oxalis/commons/tracing/BraveConf.java +++ b/oxalis-inbound/src/main/java/network/oxalis/inbound/tracing/OpenTelemetryServletConf.java @@ -20,25 +20,19 @@ * permissions and limitations under the Licence. */ -package network.oxalis.commons.tracing; +package network.oxalis.inbound.tracing; import network.oxalis.api.settings.DefaultValue; -import network.oxalis.api.settings.Nullable; import network.oxalis.api.settings.Path; import network.oxalis.api.settings.Title; /** * @author erlend */ -@Title("Tracing") -public enum BraveConf { - - @Path("oxalis.tracing.brave.reporter") - @DefaultValue("noop") - REPORTER, - - @Path("oxalis.tracing.brave.http") - @Nullable - HTTP +@Title("ServletTracing") +public enum OpenTelemetryServletConf { + @Path("oxalis.tracing.open-telemetry.tracing-filter") + @DefaultValue("default") + TRACING_FILTER, } diff --git a/oxalis-inbound/src/main/java/network/oxalis/inbound/tracing/OpenTelemetryTracingFilter.java b/oxalis-inbound/src/main/java/network/oxalis/inbound/tracing/OpenTelemetryTracingFilter.java new file mode 100644 index 000000000..fa69eb1b1 --- /dev/null +++ b/oxalis-inbound/src/main/java/network/oxalis/inbound/tracing/OpenTelemetryTracingFilter.java @@ -0,0 +1,6 @@ +package network.oxalis.inbound.tracing; + +import jakarta.servlet.Filter; + +public interface OpenTelemetryTracingFilter extends Filter { +} diff --git a/oxalis-inbound/src/test/java/network/oxalis/inbound/servlet/HomeServletTest.java b/oxalis-inbound/src/test/java/network/oxalis/inbound/servlet/HomeServletTest.java index 6a9620a0d..05b389e04 100644 --- a/oxalis-inbound/src/test/java/network/oxalis/inbound/servlet/HomeServletTest.java +++ b/oxalis-inbound/src/test/java/network/oxalis/inbound/servlet/HomeServletTest.java @@ -28,7 +28,7 @@ import org.testng.Assert; import org.testng.annotations.Test; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import java.net.HttpURLConnection; import java.net.URL; diff --git a/oxalis-inbound/src/test/java/network/oxalis/inbound/servlet/StatusServletTest.java b/oxalis-inbound/src/test/java/network/oxalis/inbound/servlet/StatusServletTest.java index 6533dd654..524dc2f0a 100644 --- a/oxalis-inbound/src/test/java/network/oxalis/inbound/servlet/StatusServletTest.java +++ b/oxalis-inbound/src/test/java/network/oxalis/inbound/servlet/StatusServletTest.java @@ -28,7 +28,7 @@ import org.testng.Assert; import org.testng.annotations.Test; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import java.net.HttpURLConnection; import java.net.URL; diff --git a/oxalis-legacy/oxalis-document-sniffer/src/test/java/network/oxalis/sniffer/sbdh/ParseSbdhTest.java b/oxalis-legacy/oxalis-document-sniffer/src/test/java/network/oxalis/sniffer/sbdh/ParseSbdhTest.java index 4ddfba099..ac51f2c00 100644 --- a/oxalis-legacy/oxalis-document-sniffer/src/test/java/network/oxalis/sniffer/sbdh/ParseSbdhTest.java +++ b/oxalis-legacy/oxalis-document-sniffer/src/test/java/network/oxalis/sniffer/sbdh/ParseSbdhTest.java @@ -26,9 +26,9 @@ import network.oxalis.peppol.sbdh.jaxb.StandardBusinessDocument; import org.testng.annotations.Test; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.Unmarshaller; +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.Unmarshaller; import java.io.File; import java.io.FileInputStream; import java.net.URL; diff --git a/oxalis-legacy/oxalis-persistence/src/main/java/network/oxalis/persistence/api/Platform.java b/oxalis-legacy/oxalis-persistence/src/main/java/network/oxalis/persistence/api/Platform.java index 681d9c8a5..41279fae3 100644 --- a/oxalis-legacy/oxalis-persistence/src/main/java/network/oxalis/persistence/api/Platform.java +++ b/oxalis-legacy/oxalis-persistence/src/main/java/network/oxalis/persistence/api/Platform.java @@ -24,7 +24,7 @@ import network.oxalis.api.inject.NamedImpl; -import javax.inject.Named; +import jakarta.inject.Named; /** * @author erlend diff --git a/oxalis-legacy/oxalis-persistence/src/main/java/network/oxalis/persistence/datasource/JndiDataSourceProvider.java b/oxalis-legacy/oxalis-persistence/src/main/java/network/oxalis/persistence/datasource/JndiDataSourceProvider.java index d6d5ea613..b72d7342f 100644 --- a/oxalis-legacy/oxalis-persistence/src/main/java/network/oxalis/persistence/datasource/JndiDataSourceProvider.java +++ b/oxalis-legacy/oxalis-persistence/src/main/java/network/oxalis/persistence/datasource/JndiDataSourceProvider.java @@ -27,7 +27,7 @@ import network.oxalis.api.settings.Settings; import network.oxalis.persistence.util.PersistenceConf; -import javax.inject.Inject; +import jakarta.inject.Inject; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; diff --git a/oxalis-legacy/oxalis-statistics/pom.xml b/oxalis-legacy/oxalis-statistics/pom.xml index 32cefb14f..fef1fe670 100644 --- a/oxalis-legacy/oxalis-statistics/pom.xml +++ b/oxalis-legacy/oxalis-statistics/pom.xml @@ -83,8 +83,8 @@ - javax.servlet - javax.servlet-api + jakarta.servlet + jakarta.servlet-api provided diff --git a/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/inbound/StatisticsServlet.java b/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/inbound/StatisticsServlet.java index 5f2204985..5959443af 100644 --- a/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/inbound/StatisticsServlet.java +++ b/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/inbound/StatisticsServlet.java @@ -30,12 +30,12 @@ import network.oxalis.statistics.security.StatisticsKeyTool; import org.joda.time.DateTime; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; import java.security.PublicKey; diff --git a/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryHSqlImpl.java b/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryHSqlImpl.java index 433977017..d85343810 100644 --- a/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryHSqlImpl.java +++ b/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryHSqlImpl.java @@ -29,7 +29,7 @@ import network.oxalis.statistics.api.StatisticsGranularity; import network.oxalis.statistics.api.StatisticsTransformer; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.sql.*; import java.util.Date; diff --git a/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryMsSqlImpl.java b/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryMsSqlImpl.java index 333bc745f..5605817d9 100644 --- a/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryMsSqlImpl.java +++ b/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryMsSqlImpl.java @@ -26,7 +26,7 @@ import network.oxalis.persistence.api.JdbcTxManager; import network.oxalis.statistics.api.StatisticsGranularity; -import javax.inject.Inject; +import jakarta.inject.Inject; /** * This is RawStatisticsRepository implementation for running the statistics database on MsSql backend, through Jdbc. diff --git a/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryMySqlImpl.java b/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryMySqlImpl.java index 68d08e190..3105723e4 100644 --- a/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryMySqlImpl.java +++ b/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryMySqlImpl.java @@ -26,7 +26,7 @@ import network.oxalis.persistence.annotation.Repository; import network.oxalis.statistics.api.StatisticsGranularity; -import javax.inject.Inject; +import jakarta.inject.Inject; /** * This is RawStatisticsRepository implementation for running the statistics database on MySql backend, through JDBC. diff --git a/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryOracleImpl.java b/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryOracleImpl.java index 400d5b6c8..7d0a178d8 100644 --- a/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryOracleImpl.java +++ b/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryOracleImpl.java @@ -28,7 +28,7 @@ import network.oxalis.statistics.api.StatisticsGranularity; import network.oxalis.statistics.util.DataSourceHelper; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.sql.*; /** diff --git a/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/service/DefaultStatisticsService.java b/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/service/DefaultStatisticsService.java index b7e5e9566..14c74ed72 100644 --- a/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/service/DefaultStatisticsService.java +++ b/oxalis-legacy/oxalis-statistics/src/main/java/network/oxalis/statistics/service/DefaultStatisticsService.java @@ -24,8 +24,8 @@ import com.google.inject.Inject; import com.google.inject.Singleton; -import io.opentracing.Span; -import io.opentracing.Tracer; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.Tracer; import lombok.extern.slf4j.Slf4j; import network.oxalis.api.inbound.InboundMetadata; import network.oxalis.api.model.AccessPointIdentifier; @@ -54,8 +54,8 @@ public DefaultStatisticsService(RawStatisticsRepository rawStatisticsRepository, } @Override - public void persist(TransmissionRequest transmissionRequest, TransmissionResponse transmissionResponse, Span root) { - Span span = tracer.buildSpan("persist statistics").asChildOf(root).start(); + public void persist(TransmissionRequest transmissionRequest, TransmissionResponse transmissionResponse) { + Span span = tracer.spanBuilder("persist statistics").startSpan(); try { String protocolName = transmissionRequest.getEndpoint().getTransportProfile().getIdentifier(); String receivingAccessPointCommonName = transmissionRequest.getEndpoint().getCertificate() != null ? CertificateUtils @@ -74,10 +74,10 @@ public void persist(TransmissionRequest transmissionRequest, TransmissionRespons rawStatisticsRepository.persist(rawStatistics); } catch (Exception ex) { - span.setTag("exception", String.valueOf(ex.getMessage())); + span.setAttribute("exception", String.valueOf(ex.getMessage())); log.error("Persisting DefaultRawStatistics about outbound transmission failed : {}", ex.getMessage(), ex); } finally { - span.finish(); + span.end(); } } diff --git a/oxalis-legacy/oxalis-statistics/src/test/java/network/oxalis/statistics/inbound/StatisticsServletTest.java b/oxalis-legacy/oxalis-statistics/src/test/java/network/oxalis/statistics/inbound/StatisticsServletTest.java index 66145c88d..d60749d86 100644 --- a/oxalis-legacy/oxalis-statistics/src/test/java/network/oxalis/statistics/inbound/StatisticsServletTest.java +++ b/oxalis-legacy/oxalis-statistics/src/test/java/network/oxalis/statistics/inbound/StatisticsServletTest.java @@ -28,7 +28,7 @@ import org.testng.Assert; import org.testng.annotations.Test; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import java.net.HttpURLConnection; import java.net.URL; diff --git a/oxalis-legacy/oxalis-statistics/src/test/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryTest.java b/oxalis-legacy/oxalis-statistics/src/test/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryTest.java index a8de2657a..06b9b1ac1 100644 --- a/oxalis-legacy/oxalis-statistics/src/test/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryTest.java +++ b/oxalis-legacy/oxalis-statistics/src/test/java/network/oxalis/statistics/jdbc/RawStatisticsRepositoryTest.java @@ -29,7 +29,7 @@ import org.testng.annotations.Guice; import org.testng.annotations.Test; -import javax.inject.Inject; +import jakarta.inject.Inject; import static org.testng.Assert.assertNotNull; diff --git a/oxalis-outbound/pom.xml b/oxalis-outbound/pom.xml index 26bfddc6f..db6952da6 100644 --- a/oxalis-outbound/pom.xml +++ b/oxalis-outbound/pom.xml @@ -57,7 +57,7 @@ network.oxalis oxalis-as4 - 6.6.0 + 6.7.1-SNAPSHOT test diff --git a/oxalis-outbound/src/main/java/network/oxalis/outbound/transformer/XmlContentWrapper.java b/oxalis-outbound/src/main/java/network/oxalis/outbound/transformer/XmlContentWrapper.java index 454bd718e..2a4584206 100644 --- a/oxalis-outbound/src/main/java/network/oxalis/outbound/transformer/XmlContentWrapper.java +++ b/oxalis-outbound/src/main/java/network/oxalis/outbound/transformer/XmlContentWrapper.java @@ -30,7 +30,7 @@ import network.oxalis.vefa.peppol.sbdh.lang.SbdhException; import network.oxalis.vefa.peppol.sbdh.util.XMLStreamUtils; -import javax.inject.Singleton; +import jakarta.inject.Singleton; import javax.xml.stream.XMLStreamException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; diff --git a/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/DefaultTransmissionService.java b/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/DefaultTransmissionService.java index 11d993b62..8ee2bbbb2 100644 --- a/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/DefaultTransmissionService.java +++ b/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/DefaultTransmissionService.java @@ -24,14 +24,14 @@ import com.google.inject.Inject; import com.google.inject.Singleton; -import io.opentracing.Span; -import io.opentracing.Tracer; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.Tracer; import network.oxalis.api.lang.OxalisContentException; import network.oxalis.api.lang.OxalisTransmissionException; -import network.oxalis.api.tag.Tag; import network.oxalis.api.outbound.TransmissionResponse; import network.oxalis.api.outbound.TransmissionService; import network.oxalis.api.outbound.Transmitter; +import network.oxalis.api.tag.Tag; import network.oxalis.commons.tracing.Traceable; import java.io.IOException; @@ -66,17 +66,12 @@ public DefaultTransmissionService(TransmissionRequestFactory transmissionRequest @Override public TransmissionResponse send(InputStream inputStream, Tag tag) throws IOException, OxalisTransmissionException, OxalisContentException { - Span root = tracer.buildSpan("TransmissionService").start(); + Span root = tracer.spanBuilder("TransmissionService").startSpan(); try { - return send(inputStream, tag, root); + return transmitter.transmit(transmissionRequestFactory.newInstance(inputStream, tag)); } finally { - root.finish(); + root.end(); } } - @Override - public TransmissionResponse send(InputStream inputStream, Tag tag, Span root) - throws IOException, OxalisTransmissionException, OxalisContentException { - return transmitter.transmit(transmissionRequestFactory.newInstance(inputStream, tag, root), root); - } } diff --git a/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/DefaultTransmitter.java b/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/DefaultTransmitter.java index 52994285d..88b68b754 100644 --- a/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/DefaultTransmitter.java +++ b/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/DefaultTransmitter.java @@ -23,13 +23,17 @@ package network.oxalis.outbound.transmission; import com.google.inject.Inject; -import io.opentracing.Span; -import io.opentracing.Tracer; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.Tracer; import network.oxalis.api.error.ErrorTracker; import network.oxalis.api.lang.OxalisTransmissionException; import network.oxalis.api.lookup.LookupService; import network.oxalis.api.model.Direction; -import network.oxalis.api.outbound.*; +import network.oxalis.api.outbound.MessageSender; +import network.oxalis.api.outbound.TransmissionMessage; +import network.oxalis.api.outbound.TransmissionRequest; +import network.oxalis.api.outbound.TransmissionResponse; +import network.oxalis.api.outbound.Transmitter; import network.oxalis.api.statistics.StatisticsService; import network.oxalis.api.transmission.TransmissionVerifier; import network.oxalis.commons.mode.OxalisCertificateValidator; @@ -82,34 +86,20 @@ public DefaultTransmitter(MessageSenderFactory messageSenderFactory, StatisticsS this.errorTracker = errorTracker; } - /** - * {@inheritDoc} - */ - @Override - public TransmissionResponse transmit(TransmissionMessage transmissionMessage, Span root) - throws OxalisTransmissionException { - Span span = tracer.buildSpan("transmit").asChildOf(root).start(); - try { - return perform(transmissionMessage, span); - } finally { - span.finish(); - } - } - /** * {@inheritDoc} */ @Override public TransmissionResponse transmit(TransmissionMessage transmissionMessage) throws OxalisTransmissionException { - Span root = tracer.buildSpan("transmit").start(); + Span span = tracer.spanBuilder("transmit").startSpan(); try { - return perform(transmissionMessage, root); + return perform(transmissionMessage); } finally { - root.finish(); + span.end(); } } - private TransmissionResponse perform(TransmissionMessage transmissionMessage, Span root) + private TransmissionResponse perform(TransmissionMessage transmissionMessage) throws OxalisTransmissionException { try { if (transmissionMessage == null) @@ -124,37 +114,14 @@ private TransmissionResponse perform(TransmissionMessage transmissionMessage, Sp // Validate provided certificate if (transmissionRequest.getEndpoint().getCertificate() == null) throw new OxalisTransmissionException("Certificate of receiving access point is not provided."); - certificateValidator.validate(Service.AP, transmissionRequest.getEndpoint().getCertificate(), root); + certificateValidator.validate(Service.AP, transmissionRequest.getEndpoint().getCertificate()); } else { - // Perform lookup using header. - Span span = tracer.buildSpan("Fetch endpoint information").asChildOf(root).start(); - Endpoint endpoint; - try { - endpoint = lookupService.lookup(transmissionMessage.getHeader(), span); - span.setTag("transport profile", endpoint.getTransportProfile().getIdentifier()); - transmissionRequest = new DefaultTransmissionRequest(transmissionMessage, endpoint); - } catch (OxalisTransmissionException e) { - span.setTag("exception", e.getMessage()); - throw e; - } finally { - span.finish(); - } + transmissionRequest = performLookupUserHeaders(transmissionMessage); } - Span span = tracer.buildSpan("send message").asChildOf(root).start(); - TransmissionResponse transmissionResponse; - try { - TransportProfile transportProfile = transmissionRequest.getEndpoint().getTransportProfile(); - MessageSender messageSender = messageSenderFactory.getMessageSender(transportProfile); - transmissionResponse = messageSender.send(transmissionRequest, span); - } catch (OxalisTransmissionException e) { - span.setTag("exception", e.getMessage()); - throw e; - } finally { - span.finish(); - } + TransmissionResponse transmissionResponse = sendMessage(transmissionRequest); - statisticsService.persist(transmissionRequest, transmissionResponse, root); + statisticsService.persist(transmissionRequest, transmissionResponse); return transmissionResponse; } catch (PeppolSecurityException e) { @@ -168,4 +135,38 @@ private TransmissionResponse perform(TransmissionMessage transmissionMessage, Sp throw e; } } + + private TransmissionRequest performLookupUserHeaders(TransmissionMessage transmissionMessage) throws OxalisTransmissionException { + TransmissionRequest transmissionRequest; + Span span = tracer.spanBuilder("Fetch endpoint information").startSpan(); + Endpoint endpoint; + try { + endpoint = lookupService.lookup(transmissionMessage.getHeader()); + span.setAttribute("transport profile", endpoint.getTransportProfile().getIdentifier()); + transmissionRequest = new DefaultTransmissionRequest(transmissionMessage, endpoint); + } catch (OxalisTransmissionException e) { + span.setAttribute("exception", e.getMessage()); + throw e; + } finally { + span.end(); + } + return transmissionRequest; + } + + private TransmissionResponse sendMessage(TransmissionRequest transmissionRequest) throws OxalisTransmissionException { + Span span = tracer.spanBuilder("send message").startSpan(); + TransmissionResponse transmissionResponse; + try { + TransportProfile transportProfile = transmissionRequest.getEndpoint().getTransportProfile(); + MessageSender messageSender = messageSenderFactory.getMessageSender(transportProfile); + transmissionResponse = messageSender.send(transmissionRequest); + } catch (OxalisTransmissionException e) { + span.setAttribute("exception", e.getMessage()); + throw e; + } finally { + span.end(); + } + return transmissionResponse; + } + } diff --git a/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/TransmissionModule.java b/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/TransmissionModule.java index 051e0507d..852baa3a5 100644 --- a/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/TransmissionModule.java +++ b/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/TransmissionModule.java @@ -31,7 +31,7 @@ import network.oxalis.outbound.transformer.XmlContentWrapper; import network.oxalis.vefa.peppol.common.model.TransportProfile; -import javax.inject.Singleton; +import jakarta.inject.Singleton; import java.util.List; /** diff --git a/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/TransmissionRequestBuilder.java b/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/TransmissionRequestBuilder.java index 14f73d3fa..f23350db1 100644 --- a/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/TransmissionRequestBuilder.java +++ b/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/TransmissionRequestBuilder.java @@ -24,8 +24,7 @@ import com.google.common.io.ByteStreams; import com.google.inject.Inject; -import io.opentracing.Span; -import io.opentracing.Tracer; +import io.opentelemetry.api.trace.Tracer; import lombok.extern.slf4j.Slf4j; import network.oxalis.api.header.HeaderParser; import network.oxalis.api.lang.OxalisContentException; @@ -36,10 +35,15 @@ import network.oxalis.api.tag.Tag; import network.oxalis.api.tag.TagGenerator; import network.oxalis.api.transformer.ContentDetector; +import network.oxalis.commons.util.ClosableSpan; import network.oxalis.sniffer.PeppolStandardBusinessHeader; import network.oxalis.sniffer.identifier.InstanceId; import network.oxalis.sniffer.sbdh.SbdhWrapper; -import network.oxalis.vefa.peppol.common.model.*; +import network.oxalis.vefa.peppol.common.model.C1CountryIdentifier; +import network.oxalis.vefa.peppol.common.model.DocumentTypeIdentifier; +import network.oxalis.vefa.peppol.common.model.Endpoint; +import network.oxalis.vefa.peppol.common.model.ParticipantIdentifier; +import network.oxalis.vefa.peppol.common.model.ProcessIdentifier; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -161,15 +165,6 @@ public TransmissionRequestBuilder tag(Tag tag) { return this; } - public TransmissionRequest build(Span root) throws OxalisTransmissionException, OxalisContentException { - Span span = tracer.buildSpan("build").asChildOf(root).start(); - try { - return build(); - } finally { - span.finish(); - } - } - /** * Builds the actual {@link TransmissionRequest}. *

@@ -185,45 +180,47 @@ public TransmissionRequest build(Span root) throws OxalisTransmissionException, * @return Prepared transmission request. */ public TransmissionRequest build() throws OxalisTransmissionException, OxalisContentException { - if (payload.length < 2) - throw new OxalisTransmissionException("You have forgotten to provide payload"); + try (ClosableSpan ignored = tracer.spanBuilder("build").startSpan()::end) { + if (payload.length < 2) + throw new OxalisTransmissionException("You have forgotten to provide payload"); + + PeppolStandardBusinessHeader optionalParsedSbdh = null; + try { + optionalParsedSbdh = + new PeppolStandardBusinessHeader(headerParser.parse(new ByteArrayInputStream(payload))); + } catch (OxalisContentException e) { + // No action. + } - PeppolStandardBusinessHeader optionalParsedSbdh = null; - try { - optionalParsedSbdh = - new PeppolStandardBusinessHeader(headerParser.parse(new ByteArrayInputStream(payload))); - } catch (OxalisContentException e) { - // No action. - } + // Calculates the effectiveStandardBusinessHeader to be used + effectiveStandardBusinessHeader = makeEffectiveSbdh( + Optional.ofNullable(optionalParsedSbdh), suppliedHeaderFields); - // Calculates the effectiveStandardBusinessHeader to be used - effectiveStandardBusinessHeader = makeEffectiveSbdh( - Optional.ofNullable(optionalParsedSbdh), suppliedHeaderFields); + // If the endpoint has not been overridden by the caller, look up the endpoint address in + // the SMP using the data supplied in the payload + if (isEndpointSuppliedByCaller() && isOverrideAllowed()) { + log.warn("Endpoint was set by caller not retrieved from SMP, make sure this is intended behaviour."); + } else { + Endpoint endpoint = lookupService.lookup(effectiveStandardBusinessHeader.toVefa()); - // If the endpoint has not been overridden by the caller, look up the endpoint address in - // the SMP using the data supplied in the payload - if (isEndpointSuppliedByCaller() && isOverrideAllowed()) { - log.warn("Endpoint was set by caller not retrieved from SMP, make sure this is intended behaviour."); - } else { - Endpoint endpoint = lookupService.lookup(effectiveStandardBusinessHeader.toVefa(), null); + if (isEndpointSuppliedByCaller() && !this.endpoint.equals(endpoint)) { + throw new IllegalStateException("You are not allowed to override the EndpointAddress from SMP."); + } - if (isEndpointSuppliedByCaller() && !this.endpoint.equals(endpoint)) { - throw new IllegalStateException("You are not allowed to override the EndpointAddress from SMP."); + this.endpoint = endpoint; } - this.endpoint = endpoint; - } + // make sure payload is encapsulated in SBDH + if (optionalParsedSbdh == null) { + // Wraps the payload with an SBDH, as this is required for AS2 + payload = wrapPayLoadWithSBDH(new ByteArrayInputStream(payload), effectiveStandardBusinessHeader); + } - // make sure payload is encapsulated in SBDH - if (optionalParsedSbdh == null) { - // Wraps the payload with an SBDH, as this is required for AS2 - payload = wrapPayLoadWithSBDH(new ByteArrayInputStream(payload), effectiveStandardBusinessHeader); + // Transfers all the properties of this object into the newly created TransmissionRequest + return new DefaultTransmissionRequest( + getEffectiveStandardBusinessHeader().toVefa(), getPayload(), + getEndpoint(), tagGenerator.generate(Direction.OUT, tag)); } - - // Transfers all the properties of this object into the newly created TransmissionRequest - return new DefaultTransmissionRequest( - getEffectiveStandardBusinessHeader().toVefa(), getPayload(), - getEndpoint(), tagGenerator.generate(Direction.OUT, tag)); } /** diff --git a/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/TransmissionRequestFactory.java b/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/TransmissionRequestFactory.java index d2aebf258..9f4d23c7e 100644 --- a/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/TransmissionRequestFactory.java +++ b/oxalis-outbound/src/main/java/network/oxalis/outbound/transmission/TransmissionRequestFactory.java @@ -22,8 +22,9 @@ package network.oxalis.outbound.transmission; -import io.opentracing.Span; -import io.opentracing.Tracer; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.Tracer; +import jakarta.inject.Inject; import network.oxalis.api.header.HeaderParser; import network.oxalis.api.lang.OxalisContentException; import network.oxalis.api.model.Direction; @@ -36,7 +37,6 @@ import network.oxalis.commons.tracing.Traceable; import network.oxalis.vefa.peppol.common.model.Header; -import javax.inject.Inject; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -72,80 +72,67 @@ public TransmissionMessage newInstance(InputStream inputStream) public TransmissionMessage newInstance(InputStream inputStream, Tag tag) throws IOException, OxalisContentException { - Span root = tracer.buildSpan(getClass().getSimpleName()).start(); + Span span = tracer.spanBuilder(getClass().getSimpleName()).startSpan(); try { - return perform(inputStream, tag, root); + return perform(inputStream, tag); } finally { - root.finish(); + span.end(); } } - public TransmissionMessage newInstance(InputStream inputStream, Span root) + private TransmissionMessage perform(InputStream inputStream, Tag tag) throws IOException, OxalisContentException { - return newInstance(inputStream, Tag.NONE, root); + PeekingInputStream peekingInputStream = new PeekingInputStream(inputStream); + try { + Header header = readHeaderFromSbdh(peekingInputStream); + return new DefaultTransmissionMessage(header, peekingInputStream.newInputStream(), + tagGenerator.generate(Direction.OUT, tag)); + } catch (OxalisContentException e) { + byte[] payload = peekingInputStream.getContent(); + Header header = detectHeaderFromContent(payload); + InputStream wrappedContent = wrapContentInSbdh(header, payload); + return new DefaultTransmissionMessage(header, wrappedContent, tagGenerator.generate(Direction.OUT, tag)); + } } - public TransmissionMessage newInstance(InputStream inputStream, Tag tag, Span root) - throws IOException, OxalisContentException { - Span span = tracer.buildSpan(getClass().getSimpleName()).asChildOf(root).start(); + private Header readHeaderFromSbdh(PeekingInputStream peekingInputStream) throws OxalisContentException { + Span span = tracer.spanBuilder("Reading SBDH").startSpan(); try { - return perform(inputStream, tag, span); + Header header = headerParser.parse(peekingInputStream); + span.setAttribute("identifier", header.getIdentifier().getIdentifier()); + return header; + } catch (OxalisContentException e) { + span.setAttribute("exception", e.getMessage()); + throw e; } finally { - span.finish(); + span.end(); } - } - private TransmissionMessage perform(InputStream inputStream, Tag tag, Span root) - throws IOException, OxalisContentException { - PeekingInputStream peekingInputStream = new PeekingInputStream(inputStream); + } - // Read header from content to send. - Header header; + private Header detectHeaderFromContent(byte[] payload) throws OxalisContentException { + Span span = tracer.spanBuilder("Detect SBDH from content").startSpan(); try { - // Read header from SBDH. - Span span = tracer.buildSpan("Reading SBDH").asChildOf(root).start(); - try { - header = headerParser.parse(peekingInputStream); - span.setTag("identifier", header.getIdentifier().getIdentifier()); - } catch (OxalisContentException e) { - span.setTag("exception", e.getMessage()); - throw e; - } finally { - span.finish(); - } - - // Create transmission request. - return new DefaultTransmissionMessage(header, peekingInputStream.newInputStream(), - tagGenerator.generate(Direction.OUT, tag)); + Header header = contentDetector.parse(new ByteArrayInputStream(payload)); + span.setAttribute("identifier", header.getIdentifier().getIdentifier()); + return header; } catch (OxalisContentException e) { - byte[] payload = peekingInputStream.getContent(); + span.setAttribute("exception", e.getMessage()); + throw e; + } finally { + span.end(); + } + } - // Detect header from content. - Span span = tracer.buildSpan("Detect SBDH from content").asChildOf(root).start(); - try { - header = contentDetector.parse(new ByteArrayInputStream(payload)); - span.setTag("identifier", header.getIdentifier().getIdentifier()); - } catch (OxalisContentException ex) { - span.setTag("exception", ex.getMessage()); - throw new OxalisContentException(ex.getMessage(), ex); - } finally { - span.finish(); - } - - // Wrap content in SBDH. - span = tracer.buildSpan("Wrap content in SBDH").asChildOf(root).start(); - InputStream wrappedContent; - try { - wrappedContent = contentWrapper.wrap(new ByteArrayInputStream(payload), header); - } catch (OxalisContentException ex) { - span.setTag("exception", ex.getMessage()); - throw ex; - } finally { - span.finish(); - } - - // Create transmission request. - return new DefaultTransmissionMessage(header, wrappedContent, tagGenerator.generate(Direction.OUT, tag)); + private InputStream wrapContentInSbdh(Header header, byte[] payload) throws IOException, OxalisContentException { + Span span = tracer.spanBuilder("Wrap content in SBDH").startSpan(); + try { + return contentWrapper.wrap(new ByteArrayInputStream(payload), header); + } catch (OxalisContentException e) { + span.setAttribute("exception", e.getMessage()); + throw e; + } finally { + span.end(); } } } diff --git a/oxalis-outbound/src/test/java/network/oxalis/outbound/transmission/DefaultTransmissionServiceTest.java b/oxalis-outbound/src/test/java/network/oxalis/outbound/transmission/DefaultTransmissionServiceTest.java index 8a4a390c0..9de1ac916 100644 --- a/oxalis-outbound/src/test/java/network/oxalis/outbound/transmission/DefaultTransmissionServiceTest.java +++ b/oxalis-outbound/src/test/java/network/oxalis/outbound/transmission/DefaultTransmissionServiceTest.java @@ -25,7 +25,6 @@ import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.util.Modules; -import io.opentracing.Span; import network.oxalis.api.lang.OxalisTransmissionException; import network.oxalis.api.lookup.LookupService; import network.oxalis.api.outbound.TransmissionResponse; @@ -43,7 +42,7 @@ public class DefaultTransmissionServiceTest { - private Injector injector = Guice.createInjector( + private final Injector injector = Guice.createInjector( Modules.override(new GuiceModuleLoader()).with(new MockLookupModule())); private LookupService lookupService; @@ -72,7 +71,7 @@ public void simple() throws Exception { @Test(expectedExceptions = OxalisTransmissionException.class, enabled = false) public void simpleTriggerException() throws Exception { Mockito.reset(lookupService); - Mockito.when(lookupService.lookup(Mockito.any(Header.class), Mockito.any(Span.class))) + Mockito.when(lookupService.lookup(Mockito.any(Header.class))) .thenThrow(new OxalisTransmissionException("From unit test.")); transmissionService.send(getClass().getResourceAsStream("/ehf-bii05-t10-valid-invoice.xml")); diff --git a/oxalis-outbound/src/test/java/network/oxalis/outbound/transmission/DefaultTransmitterTest.java b/oxalis-outbound/src/test/java/network/oxalis/outbound/transmission/DefaultTransmitterTest.java index eca715d62..3c0e440af 100644 --- a/oxalis-outbound/src/test/java/network/oxalis/outbound/transmission/DefaultTransmitterTest.java +++ b/oxalis-outbound/src/test/java/network/oxalis/outbound/transmission/DefaultTransmitterTest.java @@ -24,7 +24,7 @@ import com.google.inject.Inject; import com.google.inject.name.Named; -import io.opentracing.Tracer; +import io.opentelemetry.api.trace.Tracer; import network.oxalis.api.lang.OxalisTransmissionException; import network.oxalis.api.lookup.LookupService; import network.oxalis.api.outbound.TransmissionRequest; diff --git a/oxalis-outbound/src/test/java/network/oxalis/outbound/transmission/TransmissionRequestFactoryMockTest.java b/oxalis-outbound/src/test/java/network/oxalis/outbound/transmission/TransmissionRequestFactoryMockTest.java index 12ab57d23..e0fc942f9 100644 --- a/oxalis-outbound/src/test/java/network/oxalis/outbound/transmission/TransmissionRequestFactoryMockTest.java +++ b/oxalis-outbound/src/test/java/network/oxalis/outbound/transmission/TransmissionRequestFactoryMockTest.java @@ -32,7 +32,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.io.ByteArrayInputStream; import java.io.InputStream; diff --git a/oxalis-outbound/src/test/java/network/oxalis/outbound/transmission/TransmissionRequestFactoryTest.java b/oxalis-outbound/src/test/java/network/oxalis/outbound/transmission/TransmissionRequestFactoryTest.java index 15eb519c4..83ad9cfe6 100644 --- a/oxalis-outbound/src/test/java/network/oxalis/outbound/transmission/TransmissionRequestFactoryTest.java +++ b/oxalis-outbound/src/test/java/network/oxalis/outbound/transmission/TransmissionRequestFactoryTest.java @@ -29,7 +29,7 @@ import org.testng.annotations.Guice; import org.testng.annotations.Test; -import javax.inject.Inject; +import jakarta.inject.Inject; import java.io.InputStream; @Guice(modules = GuiceModuleLoader.class) diff --git a/oxalis-test/pom.xml b/oxalis-test/pom.xml index 8badbc92f..6e97ba465 100644 --- a/oxalis-test/pom.xml +++ b/oxalis-test/pom.xml @@ -73,7 +73,7 @@ org.bouncycastle - bcmail-jdk18on + bcjmail-jdk18on test @@ -103,15 +103,8 @@ - javax.servlet - javax.servlet-api - provided - - - - - io.zipkin.brave - brave + jakarta.servlet + jakarta.servlet-api provided @@ -129,6 +122,10 @@ org.apache.httpcomponents httpclient + + io.opentelemetry.instrumentation + opentelemetry-apache-httpclient-4.3 + diff --git a/oxalis-test/src/main/java/network/oxalis/test/asd/AsdServlet.java b/oxalis-test/src/main/java/network/oxalis/test/asd/AsdServlet.java index 174e32c9a..d3c02afdb 100644 --- a/oxalis-test/src/main/java/network/oxalis/test/asd/AsdServlet.java +++ b/oxalis-test/src/main/java/network/oxalis/test/asd/AsdServlet.java @@ -14,9 +14,9 @@ import network.oxalis.api.timestamp.TimestampProvider; import network.oxalis.vefa.peppol.common.model.Header; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.file.Path; diff --git a/oxalis-test/src/main/java/network/oxalis/test/jetty/AbstractJettyServerTest.java b/oxalis-test/src/main/java/network/oxalis/test/jetty/AbstractJettyServerTest.java index ef21e9d80..bd75b3c5a 100644 --- a/oxalis-test/src/main/java/network/oxalis/test/jetty/AbstractJettyServerTest.java +++ b/oxalis-test/src/main/java/network/oxalis/test/jetty/AbstractJettyServerTest.java @@ -31,7 +31,7 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; -import javax.servlet.DispatcherType; +import jakarta.servlet.DispatcherType; import java.util.EnumSet; public abstract class AbstractJettyServerTest { diff --git a/oxalis-test/src/main/java/network/oxalis/test/lookup/MockLookupModule.java b/oxalis-test/src/main/java/network/oxalis/test/lookup/MockLookupModule.java index 32792657b..04e3fc49e 100644 --- a/oxalis-test/src/main/java/network/oxalis/test/lookup/MockLookupModule.java +++ b/oxalis-test/src/main/java/network/oxalis/test/lookup/MockLookupModule.java @@ -24,7 +24,7 @@ import com.google.inject.AbstractModule; import com.google.inject.Provides; -import io.opentracing.Span; +import jakarta.inject.Singleton; import network.oxalis.api.lang.OxalisTransmissionException; import network.oxalis.api.lookup.LookupService; import network.oxalis.test.security.CertificateMock; @@ -33,7 +33,6 @@ import network.oxalis.vefa.peppol.common.model.TransportProfile; import org.mockito.Mockito; -import javax.inject.Singleton; import java.net.URI; public class MockLookupModule extends AbstractModule { @@ -49,8 +48,6 @@ public static void resetService() { Mockito.reset(lookupService); Mockito.when(lookupService.lookup(Mockito.any(Header.class))).thenReturn(endpoint); - Mockito.when(lookupService.lookup(Mockito.any(Header.class), Mockito.any(Span.class))).thenReturn(endpoint); - } catch (OxalisTransmissionException e) { // No action } diff --git a/pom.xml b/pom.xml index c9eb0e98c..6217ada0b 100644 --- a/pom.xml +++ b/pom.xml @@ -71,27 +71,22 @@ 32.0.1-jre 5.0.4 2.12.2 - 5.1.0 - 1 + 7.0.0 + 2.0.1 2.9.0 1.78.1 - 3.7.0 - 4.0.1 - 1.6.7 - 1.2.2 + 3.7.1-SNAPSHOT + 6.1.0 + 2.0.1 + 2.1.3 + 4.0.2 + 4.0.0 4.5.13 1.15 - 10.0.16 + 11.0.24 2.7.3 2.3.230 2.7.1 - 0.33.0 - 1.0.0 - 0.3.3 - 0.4.1 - 0.0.5 - 5.14.1 - 2.16.3 7.7.1 4.11.0 @@ -239,11 +234,21 @@ guice-servlet ${google.guice.version} - - javax.inject - javax.inject - ${javax.inject.version} + jakarta.xml.bind + jakarta.xml.bind-api + ${jakarta.xml.bind-api.version} + + + com.sun.xml.bind + jaxb-impl + ${jaxb-impl-version} + runtime + + + jakarta.inject + jakarta.inject-api + ${jakarta.inject-api.version} @@ -255,7 +260,7 @@ org.bouncycastle - bcmail-jdk18on + bcjmail-jdk18on ${bouncycastle.version} @@ -302,15 +307,22 @@ - javax.servlet - javax.servlet-api - ${javax.servlet-api.version} + jakarta.servlet + jakarta.servlet-api + ${jakarta.servlet-api.version} + provided com.sun.mail jakarta.mail ${jakarta.mail.version} + + + com.sun.activation + jakarta.activation + + jakarta.activation @@ -369,48 +381,18 @@ ${hsqldb.version} - - - io.opentracing - opentracing-api - ${opentracing.version} - - - io.opentracing - opentracing-noop - ${opentracing.version} - - - io.opentracing.brave - brave-opentracing - ${brave-opentracing.version} - - - io.opentracing.contrib - opentracing-apache-httpclient - ${opentracing-apache-httpclient.version} - - - io.opentracing.contrib - opentracing-web-servlet-filter - ${opentracing-web-servlet-filter.version} - - - io.opentracing.contrib - opentracing-spanmanager - ${opentracing-spanmanager.version} - - - + - io.zipkin.brave - brave - ${brave.version} + io.opentelemetry + opentelemetry-bom + 1.42.1 + pom + import - io.zipkin.reporter2 - zipkin-sender-urlconnection - ${zipkin-sender-urlconnection.version} + io.opentelemetry.instrumentation + opentelemetry-apache-httpclient-4.3 + 2.8.0-alpha