diff --git a/README.md b/README.md index b3b9f7a..27c2744 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Features Background ---------- This library was imported from [roskart/dropwizard-jaxws](https://github.com/roskart/dropwizard-jaxws), which -as of Novermber 2023 seems to be no longer maintained by the original creator. +as of November 2023 seems to be no longer maintained by the original creator. Since we are still using this library in our services which use Dropwizard and Jakarta XML Web Services, we decided to import the original repository and continue maintaining it for our own use, and anyone else who might want to use it. _We make no guarantees whatsoever about how long we will maintain it, and also plan to make our own changes such as changing the base package name to org.kiwiproject to be consistent with our other libraries._ @@ -38,7 +38,7 @@ now a standalone (normal) repository. Migrating from roskart/dropwizard-jaxws --------------------------------------- -_Note that as of November 7, 2023 we have not yet released an initial version._ +_Note that as of November 7, 2023, we have not yet released an initial version._ There are two things you need to do in order to migrate. First, change the Maven coordinates so that the groupId is org.kiwiproject, the artifactId is dropwizard-jakarta-xml-ws, and choose the latest version. @@ -314,7 +314,7 @@ under kiwiproject 🥝._ ### v0.3.0 - Updated JAXWSBundle API: introduced EndpointBuilder and ClientBuilder. -- Added suport for CXF interceptors. +- Added support for CXF interceptors. ### v0.2.0 diff --git a/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/JaxWsExampleApplication.java b/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/JaxWsExampleApplication.java index d780529..ae8b569 100644 --- a/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/JaxWsExampleApplication.java +++ b/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/JaxWsExampleApplication.java @@ -106,7 +106,7 @@ public void run(JaxWsExampleApplicationConfiguration jaxWsExampleApplicationConf .enableMtom() ); - // RESTful resource that invokes WsdlFirstService on localhost and uses client side Jakarta XML Web Services handler. + // A RESTful resource that invokes WsdlFirstService on localhost and uses client side Jakarta XML Web Services handler. environment.jersey().register(new AccessWsdlFirstServiceResource( jaxWsBundle.getClient( new ClientBuilder<>( @@ -114,7 +114,7 @@ public void run(JaxWsExampleApplicationConfiguration jaxWsExampleApplicationConf "http://localhost:8080/soap/wsdlfirst") .handlers(new WsdlFirstClientHandler())))); - // RESTful resource that invokes MtomService on localhost + // A RESTful resource that invokes MtomService on localhost environment.jersey().register(new AccessMtomServiceResource( jaxWsBundle.getClient( new ClientBuilder<>( @@ -122,7 +122,7 @@ public void run(JaxWsExampleApplicationConfiguration jaxWsExampleApplicationConf "http://localhost:8080/soap/mtom") .enableMtom()))); - // RESTful resource that invokes JavaFirstService on localhost and uses basic authentication and + // A RESTful resource that invokes JavaFirstService on localhost and uses basic authentication and // client side CXF interceptors. environment.jersey().register(new AccessProtectedServiceResource( jaxWsBundle.getClient( diff --git a/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/core/Person.java b/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/core/Person.java index fecabfd..75e3e07 100644 --- a/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/core/Person.java +++ b/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/core/Person.java @@ -1,5 +1,5 @@ /** - * This class is copied from drowpizard-example + * This class is copied from dropwizard-example */ package com.roskart.dropwizard.jaxws.example.core; diff --git a/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/resources/AccessMtomServiceResource.java b/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/resources/AccessMtomServiceResource.java index ce49a60..b8ba53b 100644 --- a/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/resources/AccessMtomServiceResource.java +++ b/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/resources/AccessMtomServiceResource.java @@ -20,7 +20,7 @@ @Produces(MediaType.APPLICATION_JSON) public class AccessMtomServiceResource { - MtomService mtomServiceClient; + final MtomService mtomServiceClient; public AccessMtomServiceResource(MtomService mtomServiceClient) { this.mtomServiceClient = mtomServiceClient; diff --git a/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/resources/AccessProtectedServiceResource.java b/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/resources/AccessProtectedServiceResource.java index 3d625f0..b5f345e 100644 --- a/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/resources/AccessProtectedServiceResource.java +++ b/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/resources/AccessProtectedServiceResource.java @@ -9,14 +9,14 @@ import jakarta.xml.ws.BindingProvider; /** - * Dropwizard resource that invokes JavaFirstService SOAP web service using basic authentication. + * A Dropwizard resource that invokes JavaFirstService SOAP web service using basic authentication. */ @Path("/javafirstclient") @Produces(MediaType.APPLICATION_JSON) public class AccessProtectedServiceResource { - JavaFirstService javaFirstService; + final JavaFirstService javaFirstService; public AccessProtectedServiceResource(JavaFirstService javaFirstService) { this.javaFirstService = javaFirstService; diff --git a/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/resources/AccessWsdlFirstServiceResource.java b/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/resources/AccessWsdlFirstServiceResource.java index 0bdecfa..5c5bbea 100644 --- a/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/resources/AccessWsdlFirstServiceResource.java +++ b/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/resources/AccessWsdlFirstServiceResource.java @@ -11,7 +11,7 @@ import ws.example.jaxws.dropwizard.roskart.com.wsdlfirstservice.WsdlFirstService; /** - * Dropwizard resource that invokes WsdlFirstService SOAP web service. + * A Dropwizard resource that invokes WsdlFirstService SOAP web service. * * @see WsdlFirstClientHandler */ @@ -19,7 +19,7 @@ @Produces(MediaType.APPLICATION_JSON) public class AccessWsdlFirstServiceResource { - WsdlFirstService wsdlFirstServiceClient; + final WsdlFirstService wsdlFirstServiceClient; public AccessWsdlFirstServiceResource(WsdlFirstService wsdlFirstServiceClient) { this.wsdlFirstServiceClient = wsdlFirstServiceClient; diff --git a/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/ws/MtomServiceImpl.java b/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/ws/MtomServiceImpl.java index d85bb15..5d74232 100644 --- a/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/ws/MtomServiceImpl.java +++ b/dropwizard-jaxws-example/src/main/java/com/roskart/dropwizard/jaxws/example/ws/MtomServiceImpl.java @@ -13,7 +13,7 @@ import java.io.IOException; import java.io.UncheckedIOException; -@MTOM // @MTOM annotation is not necessary if you invoke enableMtom on EndopointBuilder +@MTOM // @MTOM annotation is not necessary if you invoke enableMtom on EndpointBuilder @WebService(endpointInterface = "ws.example.jaxws.dropwizard.roskart.com.mtomservice.MtomService", targetNamespace = "http://com.roskart.dropwizard.jaxws.example.ws/MtomService", name = "MtomService", diff --git a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/AbstractInvoker.java b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/AbstractInvoker.java index a880602..d1af246 100644 --- a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/AbstractInvoker.java +++ b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/AbstractInvoker.java @@ -10,7 +10,7 @@ */ public abstract class AbstractInvoker implements Invoker { - protected Invoker underlying; + protected final Invoker underlying; protected AbstractInvoker(Invoker underlying) { this.underlying = underlying; diff --git a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/ClientBuilder.java b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/ClientBuilder.java index 80d0c45..a15ff8e 100644 --- a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/ClientBuilder.java +++ b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/ClientBuilder.java @@ -12,8 +12,8 @@ */ public class ClientBuilder extends AbstractBuilder { - Class serviceClass; - String address; + final Class serviceClass; + final String address; private int connectTimeout = 500; private int receiveTimeout = 2000; ImmutableList handlers; @@ -46,13 +46,13 @@ public String getBindingId() { /** * Create new ClientBuilder. Endpoint will be published relative to the CXF servlet path. * - * @param serviceClass Service interface class.. + * @param serviceClass Service interface class. * @param address Endpoint URL address.. */ public ClientBuilder(Class serviceClass, String address) { checkArgument(serviceClass != null, "ServiceClass is null"); checkArgument(address != null, "Address is null"); - checkArgument((address).trim().length() > 0, "Address is empty"); + checkArgument(!address.isBlank(), "Address is empty"); this.serviceClass = serviceClass; this.address = address; } diff --git a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/EndpointBuilder.java b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/EndpointBuilder.java index 82aa2a6..1a646fb 100644 --- a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/EndpointBuilder.java +++ b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/EndpointBuilder.java @@ -13,8 +13,8 @@ */ public class EndpointBuilder extends AbstractBuilder { - private String path; - private Object service; + private final String path; + private final Object service; private String publishedEndpointUrl; SessionFactory sessionFactory; BasicAuthentication authentication; @@ -53,7 +53,7 @@ public Map getProperties() { public EndpointBuilder(String path, Object service) { checkArgument(service != null, "Service is null"); checkArgument(path != null, "Path is null"); - checkArgument((path).trim().length() > 0, "Path is empty"); + checkArgument(!path.isBlank(), "Path is empty"); if (!path.startsWith("local:")) { // local transport is used in tests path = (path.startsWith("/")) ? path : "/" + path; } diff --git a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/InstrumentedInvokerFactory.java b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/InstrumentedInvokerFactory.java index 8392522..63c599b 100644 --- a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/InstrumentedInvokerFactory.java +++ b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/InstrumentedInvokerFactory.java @@ -17,7 +17,7 @@ * Provides factory method for creating instrumented CXF invoker chain. * * @see com.roskart.dropwizard.jaxws.InstrumentedInvokers - * @see com.codahale.metrics.jersey.InstrumentedResourceMethodDispatchProvider + * @see com.codahale.metrics.jersey3.InstrumentedResourceMethodApplicationListener */ public class InstrumentedInvokerFactory { diff --git a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/InstrumentedInvokers.java b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/InstrumentedInvokers.java index 4c0af16..bf26211 100644 --- a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/InstrumentedInvokers.java +++ b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/InstrumentedInvokers.java @@ -22,7 +22,7 @@ private InstrumentedInvokers() { */ public static class TimedInvoker extends AbstractInvoker { - private ImmutableMap timers; + private final ImmutableMap timers; public TimedInvoker(Invoker underlying, ImmutableMap timers) { super(underlying); @@ -31,7 +31,7 @@ public TimedInvoker(Invoker underlying, ImmutableMap timers) { public Object invoke(Exchange exchange, Object o) { - Object result = null; + Object result; String methodname = this.getTargetMethod(exchange).getName(); if (timers.containsKey(methodname)) { @@ -54,7 +54,7 @@ public Object invoke(Exchange exchange, Object o) { */ public static class MeteredInvoker extends AbstractInvoker { - private ImmutableMap meters; + private final ImmutableMap meters; public MeteredInvoker(Invoker underlying, ImmutableMap meters) { super(underlying); @@ -76,8 +76,8 @@ public Object invoke(Exchange exchange, Object o) { } public static class ExceptionMeter { - private Meter meter; - private Class exceptionClass; + private final Meter meter; + private final Class exceptionClass; public ExceptionMeter(Meter meter, Class exceptionClass) { this.meter = meter; @@ -98,7 +98,7 @@ public Class getExceptionClass() { */ public static class ExceptionMeteredInvoker extends AbstractInvoker { - private ImmutableMap meters; + private final ImmutableMap meters; public ExceptionMeteredInvoker(Invoker underlying, ImmutableMap meters) { super(underlying); diff --git a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/JAXWSBundle.java b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/JAXWSBundle.java index 03d38d7..dca6153 100644 --- a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/JAXWSBundle.java +++ b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/JAXWSBundle.java @@ -16,8 +16,8 @@ public class JAXWSBundle implements ConfiguredBundle { protected static final String DEFAULT_PATH = "/soap"; - protected JAXWSEnvironment jaxwsEnvironment; - protected String servletPath; + protected final JAXWSEnvironment jaxwsEnvironment; + protected final String servletPath; /** * Create a new bundle instance. Service endpoints are published relative to '/soap'. @@ -88,7 +88,7 @@ public EndpointImpl publishEndpoint(EndpointBuilder endpointBuilder) { * @param path Relative endpoint path. * @param service Service implementation. * @return javax.xml.ws.Endpoint - * @deprecated Use the {@link #publishEndpoint(EndpointBuilder)} publishEndpoint} method instead. + * @deprecated Use the {@link #publishEndpoint(EndpointBuilder) publishEndpoint} method instead. */ @Deprecated(since = "0.5.0") public EndpointImpl publishEndpoint(String path, Object service) { @@ -103,7 +103,7 @@ public EndpointImpl publishEndpoint(String path, Object service) { * @param service Service implementation. * @param sessionFactory Hibernate session factory. * @return javax.xml.ws.Endpoint - * @deprecated Use the {@link #publishEndpoint(EndpointBuilder)} publishEndpoint} method instead. + * @deprecated Use the {@link #publishEndpoint(EndpointBuilder) publishEndpoint} method instead. */ @Deprecated(since = "0.5.0") public EndpointImpl publishEndpoint(String path, Object service, SessionFactory sessionFactory) { @@ -118,7 +118,7 @@ public EndpointImpl publishEndpoint(String path, Object service, SessionFactory * @param service Service implementation. * @param authentication BasicAuthentication implementation. * @return javax.xml.ws.Endpoint - * @deprecated Use the {@link #publishEndpoint(EndpointBuilder)} publishEndpoint} method instead. + * @deprecated Use the {@link #publishEndpoint(EndpointBuilder) publishEndpoint} method instead. */ @Deprecated(since = "0.5.0") public EndpointImpl publishEndpoint(String path, Object service, BasicAuthentication authentication) { @@ -135,7 +135,7 @@ public EndpointImpl publishEndpoint(String path, Object service, BasicAuthentica * @param auth BasicAuthentication implementation. * @param sessionFactory Hibernate session factory. * @return javax.xml.ws.Endpoint - * @deprecated Use the {@link #publishEndpoint(EndpointBuilder)} publishEndpoint} method instead. + * @deprecated Use the {@link #publishEndpoint(EndpointBuilder) publishEndpoint} method instead. */ @Deprecated(since = "0.5.0") public EndpointImpl publishEndpoint(String path, Object service, BasicAuthentication auth, @@ -157,7 +157,7 @@ public EndpointImpl publishEndpoint(String path, Object service, BasicAuthentica * @param handlers Client side Jakarta XML Web Services handlers. Optional. * @param Service interface type. * @return Jakarta XML Web Services client proxy. - * @deprecated Use the {@link #getClient(ClientBuilder)} getClient} method instead. + * @deprecated Use the {@link #getClient(ClientBuilder) getClient} method instead. */ @Deprecated(since = "0.5.0") public T getClient(Class serviceClass, String address, Handler... handlers) { diff --git a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/UnitOfWorkInvoker.java b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/UnitOfWorkInvoker.java index cc65cc8..8cc1d3e 100644 --- a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/UnitOfWorkInvoker.java +++ b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/UnitOfWorkInvoker.java @@ -21,7 +21,7 @@ public class UnitOfWorkInvoker extends AbstractInvoker { private final SessionFactory sessionFactory; - ImmutableMap unitOfWorkMethods; + final ImmutableMap unitOfWorkMethods; public UnitOfWorkInvoker(Invoker underlying, ImmutableMap unitOfWorkMethods, SessionFactory sessionFactory) { @@ -64,7 +64,7 @@ public Object invoke(Exchange exchange, Object o) { } /** - * @see io.dropwizard.hibernate.UnitOfWorkAspect#beginTransaction() + * @see io.dropwizard.hibernate.UnitOfWorkAspect#beginTransaction(UnitOfWork, Session) */ private void beginTransaction(Session session, UnitOfWork unitOfWork) { if (unitOfWork.transactional()) { @@ -82,7 +82,7 @@ private void configureSession(Session session, UnitOfWork unitOfWork) { } /** - * @see io.dropwizard.hibernate.UnitOfWorkAspect#rollbackTransaction() + * @see io.dropwizard.hibernate.UnitOfWorkAspect#rollbackTransaction(UnitOfWork, Session) */ private void rollbackTransaction(Session session, UnitOfWork unitOfWork) { if (unitOfWork.transactional()) { @@ -94,7 +94,7 @@ private void rollbackTransaction(Session session, UnitOfWork unitOfWork) { } /** - * @see io.dropwizard.hibernate.UnitOfWorkAspect#commitTransaction() + * @see io.dropwizard.hibernate.UnitOfWorkAspect#commitTransaction(UnitOfWork, Session) */ private void commitTransaction(Session session, UnitOfWork unitOfWork) { if (unitOfWork.transactional()) { diff --git a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/UnitOfWorkInvokerFactory.java b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/UnitOfWorkInvokerFactory.java index 0f8caed..79d85ce 100644 --- a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/UnitOfWorkInvokerFactory.java +++ b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/UnitOfWorkInvokerFactory.java @@ -26,7 +26,7 @@ public Invoker create(Object service, Invoker rootInvoker, SessionFactory sessio Invoker invoker = rootInvoker; - if (unitOfWorkMethods.size() > 0) { + if (!unitOfWorkMethods.isEmpty()) { invoker = new UnitOfWorkInvoker(invoker, unitOfWorkMethods, sessionFactory); } diff --git a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/ValidatingInvoker.java b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/ValidatingInvoker.java index 37b47b4..df9c594 100644 --- a/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/ValidatingInvoker.java +++ b/dropwizard-jaxws/src/main/java/com/roskart/dropwizard/jaxws/ValidatingInvoker.java @@ -27,7 +27,7 @@ public class ValidatingInvoker extends AbstractInvoker { private static final Class[] EMPTY_CLASS_ARRAY = {}; private static final Class[] DEFAULT_GROUP_ARRAY = new Class[] { Default.class }; - private Validator validator; + private final Validator validator; public ValidatingInvoker(Invoker underlying, Validator validator) { super(underlying); diff --git a/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/BasicAuthenticationInterceptorTest.java b/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/BasicAuthenticationInterceptorTest.java index 58720c1..096dc17 100644 --- a/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/BasicAuthenticationInterceptorTest.java +++ b/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/BasicAuthenticationInterceptorTest.java @@ -27,6 +27,11 @@ class BasicAuthenticationInterceptorTest { + // Suppress warning about "hard-coded" password + @SuppressWarnings("java:S2068") + private static final String CORRECT_PASSWORD = "secret"; + private static final String USERNAME = "username"; + @Mock private InterceptorChain interceptorChainMock; @Mock @@ -40,14 +45,12 @@ class BasicAuthenticationInterceptorTest { @Mock private OutputStream outputStreamMock; - private BasicAuthentication basicAuthentication = new BasicAuthentication(new BasicAuthenticator(), "TOP_SECRET"); - // Suppress warning about "hard-coded" password - @SuppressWarnings("squid:S2068") - private static final String CORRECT_PASSWORD = "secret"; - private static final String USERNAME = "username"; + private BasicAuthentication basicAuthentication; @BeforeEach void setup() throws IOException { + basicAuthentication = new BasicAuthentication(new BasicAuthenticator(), "TOP_SECRET"); + MockitoAnnotations.openMocks(this); when(destinationMock.getBackChannel(any())).thenReturn(conduitMock); when(outMessageMock.getContent(OutputStream.class)).thenReturn(outputStreamMock); @@ -65,7 +68,7 @@ void shouldAuthenticateValidUser() { } @Test - void shouldReturnUnathorizedCodeForInvalidCredentials() { + void shouldReturnUnauthorizedCodeForInvalidCredentials() { BasicAuthenticationInterceptor target = new BasicAuthenticationInterceptor(); target.setAuthenticator(basicAuthentication); Message message = createMessageWithUsernameAndPassword(USERNAME, "foo"); diff --git a/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/ClientBuilderTest.java b/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/ClientBuilderTest.java index 518d1b6..96cf152 100644 --- a/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/ClientBuilderTest.java +++ b/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/ClientBuilderTest.java @@ -34,9 +34,9 @@ void buildClient() { assertThat(builder.getConnectTimeout()).isEqualTo(1234); assertThat(builder.getReceiveTimeout()).isEqualTo(5678); assertThat(builder.getBindingId()).isEqualTo("binding id"); - assertThat(builder.getCxfInInterceptors()).contains(new Interceptor[] { inInterceptor, inInterceptor }); - assertThat(builder.getCxfInFaultInterceptors()).contains(new Interceptor[] { inFaultInterceptor, inFaultInterceptor }); - assertThat(builder.getCxfOutInterceptors()).contains(new Interceptor[] { outInterceptor, outInterceptor }); - assertThat(builder.getCxfOutFaultInterceptors()).contains(new Interceptor[] { outFaultInterceptor, outFaultInterceptor }); + assertThat(builder.getCxfInInterceptors()).contains(inInterceptor, inInterceptor); + assertThat(builder.getCxfInFaultInterceptors()).contains(inFaultInterceptor, inFaultInterceptor); + assertThat(builder.getCxfOutInterceptors()).contains(outInterceptor, outInterceptor); + assertThat(builder.getCxfOutFaultInterceptors()).contains(outFaultInterceptor, outFaultInterceptor); } } diff --git a/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/EndpointBuilderTest.java b/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/EndpointBuilderTest.java index d542a98..a9ba8cc 100644 --- a/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/EndpointBuilderTest.java +++ b/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/EndpointBuilderTest.java @@ -41,10 +41,10 @@ void buildEndpoint() { assertThat(builder.publishedEndpointUrl()).isEqualTo(publishedUrl); assertThat(builder.getAuthentication()).isEqualTo(basicAuth); assertThat(builder.getSessionFactory()).isEqualTo(sessionFactory); - assertThat(builder.getCxfInInterceptors()).contains(new Interceptor[] { inInterceptor, inInterceptor }); - assertThat(builder.getCxfInFaultInterceptors()).contains(new Interceptor[] { inFaultInterceptor, inFaultInterceptor }); - assertThat(builder.getCxfOutInterceptors()).contains(new Interceptor[] { outInterceptor, outInterceptor }); - assertThat(builder.getCxfOutFaultInterceptors()).contains(new Interceptor[] { outFaultInterceptor, outFaultInterceptor }); + assertThat(builder.getCxfInInterceptors()).contains(inInterceptor, inInterceptor); + assertThat(builder.getCxfInFaultInterceptors()).contains(inFaultInterceptor, inFaultInterceptor); + assertThat(builder.getCxfOutInterceptors()).contains(outInterceptor, outInterceptor); + assertThat(builder.getCxfOutFaultInterceptors()).contains(outFaultInterceptor, outFaultInterceptor); assertThat(builder.getProperties()).containsEntry("key", "value"); } } diff --git a/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/InstrumentedInvokerFactoryTest.java b/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/InstrumentedInvokerFactoryTest.java index 2bd99b9..d3b051f 100644 --- a/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/InstrumentedInvokerFactoryTest.java +++ b/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/InstrumentedInvokerFactoryTest.java @@ -2,7 +2,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatRuntimeException; -import static org.assertj.core.api.Assertions.fail; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.contains; import static org.mockito.Mockito.mock; @@ -27,7 +26,7 @@ class InstrumentedInvokerFactoryTest { // Test service implementation - class InstrumentedService { + static class InstrumentedService { public String foo() { return "fooReturn"; @@ -46,7 +45,7 @@ public String timed() { @ExceptionMetered public String exceptionMetered(boolean doThrow) { if (doThrow) { - throw new RuntimeException("Runtime exception occured"); + throw new RuntimeException("Runtime exception occurred"); } else { return "exceptionMeteredReturn"; } @@ -84,7 +83,7 @@ public Object invoke(Exchange exchange, Object o) { } public class ExceptionMeteredInvoker implements Invoker { - private boolean doThrow; + private final boolean doThrow; public ExceptionMeteredInvoker(boolean doThrow) { this.doThrow = doThrow; @@ -107,7 +106,7 @@ private void setTargetMethod(Exchange exchange, String methodName, Class... p when(oi.getProperty(Method.class.getName())) .thenReturn(InstrumentedService.class.getMethod(methodName, parameterTypes)); } catch (Exception e) { - fail("setTargetMethod failed", e); + throw new RuntimeException("setTargetMethod failed", e); } } @@ -205,7 +204,7 @@ void exceptionMeteredAnnotation() { long oldmetervalue = meter.getCount(); long oldexceptionmetervalue = exceptionmeter.getCount(); - // Invoke InstrumentedResource.exceptionMetered without exception beeing thrown + // Invoke InstrumentedResource.exceptionMetered without exception being thrown Invoker invoker = invokerBuilder.create(instrumentedService, new ExceptionMeteredInvoker(false)); this.setTargetMethod(exchange, "exceptionMetered", boolean.class); // simulate CXF behavior @@ -217,7 +216,7 @@ void exceptionMeteredAnnotation() { assertThat(meter.getCount()).isEqualTo(oldmetervalue); assertThat(exceptionmeter.getCount()).isEqualTo(oldexceptionmetervalue); - // Invoke InstrumentedResource.exceptionMetered with exception beeing thrown + // Invoke InstrumentedResource.exceptionMetered with exception being thrown var throwingInvoker = invokerBuilder.create(instrumentedService, new ExceptionMeteredInvoker(true)); diff --git a/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/JAXWSBundleTest.java b/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/JAXWSBundleTest.java index a470458..32371a9 100644 --- a/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/JAXWSBundleTest.java +++ b/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/JAXWSBundleTest.java @@ -25,15 +25,22 @@ class JAXWSBundleTest { - Environment environment = mock(Environment.class); - Bootstrap bootstrap = mock(Bootstrap.class); - ServletEnvironment servletEnvironment = mock(ServletEnvironment.class); - ServletRegistration.Dynamic servlet = mock(ServletRegistration.Dynamic.class); - JAXWSEnvironment jaxwsEnvironment = mock(JAXWSEnvironment.class); - LifecycleEnvironment lifecycleEnvironment = mock(LifecycleEnvironment.class); + Environment environment; + Bootstrap bootstrap; + ServletEnvironment servletEnvironment; + ServletRegistration.Dynamic servlet; + JAXWSEnvironment jaxwsEnvironment; + LifecycleEnvironment lifecycleEnvironment; @BeforeEach void setUp() { + environment = mock(Environment.class); + bootstrap = mock(Bootstrap.class); + servletEnvironment = mock(ServletEnvironment.class); + servlet = mock(ServletRegistration.Dynamic.class); + jaxwsEnvironment = mock(JAXWSEnvironment.class); + lifecycleEnvironment = mock(LifecycleEnvironment.class); + when(environment.servlets()).thenReturn(servletEnvironment); when(environment.lifecycle()).thenReturn(lifecycleEnvironment); when(bootstrap.getMetricRegistry()).thenReturn(mock(MetricRegistry.class)); diff --git a/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/JAXWSEnvironmentTest.java b/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/JAXWSEnvironmentTest.java index 46712e5..1a80980 100644 --- a/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/JAXWSEnvironmentTest.java +++ b/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/JAXWSEnvironmentTest.java @@ -50,15 +50,16 @@ class JAXWSEnvironmentTest { + private static final String SOAP_REQUEST_FILE_NAME = "test-soap-request.xml"; + private JAXWSEnvironment jaxwsEnvironment; - private Invoker mockInvoker = mock(Invoker.class); - private TestUtilities testutils = new TestUtilities(JAXWSEnvironmentTest.class); - private DummyService service = new DummyService(); - InstrumentedInvokerFactory mockInvokerBuilder = mock(InstrumentedInvokerFactory.class); - UnitOfWorkInvokerFactory mockUnitOfWorkInvokerBuilder = mock(UnitOfWorkInvokerFactory.class); + private Invoker mockInvoker; + private TestUtilities testutils; + private DummyService service; + InstrumentedInvokerFactory mockInvokerBuilder; + UnitOfWorkInvokerFactory mockUnitOfWorkInvokerBuilder; private int mockBasicAuthInterceptorInvoked; - private String soapRequest = "test-soap-request.xml"; // DummyInterface is used by getClient test @WebService @@ -69,7 +70,7 @@ public interface DummyInterface { } // TestInterceptor is used for testing CXF interceptors - class TestInterceptor extends AbstractPhaseInterceptor { + static class TestInterceptor extends AbstractPhaseInterceptor { private int invocationCount = 0; public TestInterceptor(String phase) { @@ -91,6 +92,12 @@ void setup() { ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger("org.apache.cxf")).setLevel(Level.INFO); + mockInvoker = mock(Invoker.class); + testutils = new TestUtilities(JAXWSEnvironmentTest.class); + service = new DummyService(); + mockInvokerBuilder = mock(InstrumentedInvokerFactory.class); + mockUnitOfWorkInvokerBuilder = mock(UnitOfWorkInvokerFactory.class); + jaxwsEnvironment = new JAXWSEnvironment("soap") { /* We create BasicAuthenticationInterceptor mock manually, because Mockito provided mock @@ -144,7 +151,7 @@ void publishEndpoint() throws Exception { verifyNoInteractions(mockUnitOfWorkInvokerBuilder); Node soapResponse = testutils.invoke("local://path", - LocalTransportFactory.TRANSPORT_ID, soapRequest); + LocalTransportFactory.TRANSPORT_ID, SOAP_REQUEST_FILE_NAME); verify(mockInvoker).invoke(any(Exchange.class), any()); @@ -167,7 +174,7 @@ void publishEndpointWithAnotherEnvironment() throws Exception { verifyNoInteractions(mockUnitOfWorkInvokerBuilder); Node soapResponse = testutils.invoke("local://path", - LocalTransportFactory.TRANSPORT_ID, soapRequest); + LocalTransportFactory.TRANSPORT_ID, SOAP_REQUEST_FILE_NAME); verify(mockInvoker).invoke(any(Exchange.class), any()); @@ -185,7 +192,7 @@ void publishEndpointWithAuthentication() throws Exception { verifyNoInteractions(mockUnitOfWorkInvokerBuilder); Node soapResponse = testutils.invoke("local://path", - LocalTransportFactory.TRANSPORT_ID, soapRequest); + LocalTransportFactory.TRANSPORT_ID, SOAP_REQUEST_FILE_NAME); verify(mockInvoker).invoke(any(Exchange.class), any()); @@ -205,7 +212,7 @@ void publishEndpointWithHibernateInvoker() throws Exception { verify(mockUnitOfWorkInvokerBuilder).create(any(), any(Invoker.class), any(SessionFactory.class)); Node soapResponse = testutils.invoke("local://path", - LocalTransportFactory.TRANSPORT_ID, soapRequest); + LocalTransportFactory.TRANSPORT_ID, SOAP_REQUEST_FILE_NAME); verify(mockInvoker).invoke(any(Exchange.class), any()); @@ -227,7 +234,7 @@ void publishEndpointWithCxfInterceptors() throws Exception { verify(mockInvokerBuilder).create(any(), any(Invoker.class)); Node soapResponse = testutils.invoke("local://path", - LocalTransportFactory.TRANSPORT_ID, soapRequest); + LocalTransportFactory.TRANSPORT_ID, SOAP_REQUEST_FILE_NAME); verify(mockInvoker).invoke(any(Exchange.class), any()); assertThat(inInterceptor.getInvocationCount()).isEqualTo(1); @@ -237,7 +244,7 @@ void publishEndpointWithCxfInterceptors() throws Exception { testutils.assertValid("/soap:Envelope/soap:Body/a:fooResponse", soapResponse); soapResponse = testutils.invoke("local://path", - LocalTransportFactory.TRANSPORT_ID, soapRequest); + LocalTransportFactory.TRANSPORT_ID, SOAP_REQUEST_FILE_NAME); verify(mockInvoker, times(2)).invoke(any(Exchange.class), any()); assertThat(inInterceptor.getInvocationCount()).isEqualTo(2); @@ -257,7 +264,7 @@ void publishEndpointWithMtom() throws Exception { verify(mockInvokerBuilder).create(any(), any(Invoker.class)); - byte[] response = testutils.invokeBytes("local://path", LocalTransportFactory.TRANSPORT_ID, soapRequest); + byte[] response = testutils.invokeBytes("local://path", LocalTransportFactory.TRANSPORT_ID, SOAP_REQUEST_FILE_NAME); verify(mockInvoker).invoke(any(Exchange.class), any()); @@ -303,7 +310,7 @@ void publishEndpointWithProperties() throws Exception { verifyNoInteractions(mockUnitOfWorkInvokerBuilder); Node soapResponse = testutils.invoke("local://path", - LocalTransportFactory.TRANSPORT_ID, soapRequest); + LocalTransportFactory.TRANSPORT_ID, SOAP_REQUEST_FILE_NAME); verify(mockInvoker).invoke(any(Exchange.class), any()); @@ -330,7 +337,7 @@ void publishEndpointWithPublishedUrlPrefix() throws WSDLException { } @Test - void publishEndpointWithInvalidArguments() throws Exception { + void publishEndpointWithInvalidArguments() { assertThatIllegalArgumentException() .isThrownBy(() -> new EndpointBuilder("foo", null)) diff --git a/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/UnitOfWorkInvokerFactoryTest.java b/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/UnitOfWorkInvokerFactoryTest.java index bb541fd..b4e144c 100644 --- a/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/UnitOfWorkInvokerFactoryTest.java +++ b/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/UnitOfWorkInvokerFactoryTest.java @@ -2,7 +2,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatRuntimeException; -import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -25,7 +24,7 @@ class UnitOfWorkInvokerFactoryTest { - class FooService { + static class FooService { public String foo() { return "foo return"; } @@ -47,8 +46,22 @@ public Object invoke(Exchange exchange, Object o) { } } + static class BarService { + public String bar() { + return "bar"; + } + } + + public class BarInvoker implements Invoker { + + @Override + public Object invoke(Exchange exchange, Object o) { + return barService.bar(); + } + } + public class UnitOfWorkInvoker implements Invoker { - private boolean doThrow = false; + private final boolean doThrow; public UnitOfWorkInvoker(boolean doThrow) { this.doThrow = doThrow; @@ -62,6 +75,7 @@ public Object invoke(Exchange exchange, Object o) { UnitOfWorkInvokerFactory invokerBuilder; FooService fooService; + BarService barService; SessionFactory sessionFactory; Session session; Transaction transaction; @@ -70,7 +84,7 @@ public Object invoke(Exchange exchange, Object o) { Exchange exchange; @BeforeEach - void setup() { + void setUp() { exchange = mock(Exchange.class); BindingOperationInfo boi = mock(BindingOperationInfo.class); when(exchange.getBindingOperationInfo()).thenReturn(boi); @@ -78,6 +92,7 @@ void setup() { when(boi.getOperationInfo()).thenReturn(oi); invokerBuilder = new UnitOfWorkInvokerFactory(); fooService = new FooService(); + barService = new BarService(); sessionFactory = mock(SessionFactory.class); session = mock(Session.class); when(sessionFactory.openSession()).thenReturn(session); @@ -90,21 +105,21 @@ void setup() { * Utility method that mimics runtime CXF behaviour. Enables AbstractInvoker.getTargetMethod to work properly * during the test. */ - private void setTargetMethod(Exchange exchange, String methodName, Class... parameterTypes) { + private void setTargetMethod(Exchange exchange, Class serviceClass, String methodName, Class... parameterTypes) { try { OperationInfo oi = exchange.getBindingOperationInfo().getOperationInfo(); when(oi.getProperty(Method.class.getName())) - .thenReturn(FooService.class.getMethod(methodName, parameterTypes)); + .thenReturn(serviceClass.getMethod(methodName, parameterTypes)); } catch (Exception e) { - fail("setTargetMethod failed", e); + throw new RuntimeException("setTargetMethod failed", e); } } @Test void noAnnotation() { - Invoker invoker = invokerBuilder.create(fooService, new FooInvoker(), null); - this.setTargetMethod(exchange, "foo"); // simulate CXF behavior + Invoker invoker = invokerBuilder.create(fooService, new FooInvoker(), sessionFactory); + this.setTargetMethod(exchange, FooService.class, "foo"); // simulate CXF behavior Object result = invoker.invoke(exchange, null); assertThat(result).isEqualTo("foo return"); @@ -114,11 +129,24 @@ void noAnnotation() { verifyNoInteractions(transaction); } + @Test + void shouldCallService_WhenNoMethodsAreAnnotatedWith_UnitOfWork() { + var invoker = invokerBuilder.create(barService, new BarInvoker(), sessionFactory); + this.setTargetMethod(exchange, BarService.class, "bar"); + + var result = invoker.invoke(exchange, null); + assertThat(result).isEqualTo("bar"); + + verifyNoInteractions(sessionFactory); + verifyNoInteractions(session); + verifyNoInteractions(transaction); + } + @Test void unitOfWorkAnnotation() { // use underlying invoker which invokes fooService.unitOfWork(false) Invoker invoker = invokerBuilder.create(fooService, new UnitOfWorkInvoker(false), sessionFactory); - this.setTargetMethod(exchange, "unitOfWork", boolean.class); // simulate CXF behavior + this.setTargetMethod(exchange, FooService.class, "unitOfWork", boolean.class); // simulate CXF behavior Object result = invoker.invoke(exchange, null); assertThat(result).isEqualTo("unitOfWork return"); @@ -133,7 +161,7 @@ void unitOfWorkAnnotation() { void unitOfWorkWithException() { // use underlying invoker which invokes fooService.unitOfWork(true) - exception is thrown Invoker invoker = invokerBuilder.create(fooService, new UnitOfWorkInvoker(true), sessionFactory); - this.setTargetMethod(exchange, "unitOfWork", boolean.class); // simulate CXF behavior + this.setTargetMethod(exchange, FooService.class, "unitOfWork", boolean.class); // simulate CXF behavior assertThatRuntimeException() .isThrownBy(() -> invoker.invoke(exchange, null)) diff --git a/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/ValidatingInvokerTest.java b/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/ValidatingInvokerTest.java index 32f4df8..ab47ca2 100644 --- a/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/ValidatingInvokerTest.java +++ b/dropwizard-jaxws/src/test/java/com/roskart/dropwizard/jaxws/ValidatingInvokerTest.java @@ -1,7 +1,6 @@ package com.roskart.dropwizard.jaxws; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -14,7 +13,6 @@ import jakarta.validation.ValidationException; import jakarta.validation.constraints.NotEmpty; import jakarta.xml.ws.AsyncHandler; -import jakarta.xml.ws.Response; import org.apache.cxf.annotations.UseAsyncMethod; import org.apache.cxf.message.Exchange; import org.apache.cxf.message.Message; @@ -34,9 +32,9 @@ class ValidatingInvokerTest { Invoker underlying; Exchange exchange; - class ChildParam { + static class ChildParam { @NotEmpty - private String foo; + private final String foo; public ChildParam(String foo) { this.foo = foo; @@ -48,25 +46,26 @@ public boolean isNotJohn() { } } - class RootParam1 { + static class RootParam1 { @Valid - private ChildParam child; + private final ChildParam child; public RootParam1(ChildParam childParam) { this.child = childParam; } } - class RootParam2 { + static class RootParam2 { @NotEmpty - private String foo; + private final String foo; public RootParam2(String foo) { this.foo = foo; } } - class DummyService { + @SuppressWarnings("unused") + static class DummyService { public void noParams() { } @@ -109,7 +108,7 @@ private void setTargetMethod(Exchange exchange, String methodName, Class... p when(oi.getProperty(Method.class.getName())) .thenReturn(DummyService.class.getMethod(methodName, parameterTypes)); } catch (Exception e) { - fail("setTargetMethod failed", e); + throw new RuntimeException("setTargetMethod failed", e); } } @@ -134,23 +133,17 @@ void invokeWithoutValidation() { } @Test - void invokeWithAsycHandler() { + void invokeWithAsyncHandler() { setTargetMethod(exchange, "asyncMethod", String.class); - List params = Arrays.asList(null, new AsyncHandler() { - @Override - public void handleResponse(Response res) { - - } + List params = Arrays.asList(null, (AsyncHandler) res -> { + // no-op }); invoker.invoke(exchange, params); verify(underlying).invoke(exchange, params); - params = Arrays.asList("foo", new AsyncHandler() { - @Override - public void handleResponse(Response res) { - - } + params = Arrays.asList("foo", (AsyncHandler) res -> { + // no-op }); invoker.invoke(exchange, params); verify(underlying).invoke(exchange, params);