Skip to content

Commit

Permalink
Fix some of the code analysis problems flagged by IntelliJ (#48)
Browse files Browse the repository at this point in the history
* Make fields final
* Make inner classes static
* Remove redundant initializers
* Initialize test class fields in setup method
* Remove redundant array initializers
* Use lambdas instead of anonymous inner classes
* Grammatical fixes and fix spelling errors
* Fix a few javadoc problems
  • Loading branch information
sleberknight authored Nov 8, 2023
1 parent 7d805f9 commit eea1da6
Show file tree
Hide file tree
Showing 24 changed files with 153 additions and 116 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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._

Expand All @@ -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.
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,23 @@ 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<>(
WsdlFirstService.class,
"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<>(
MtomService.class,
"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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@Produces(MediaType.APPLICATION_JSON)
public class AccessMtomServiceResource {

MtomService mtomServiceClient;
final MtomService mtomServiceClient;

public AccessMtomServiceResource(MtomService mtomServiceClient) {
this.mtomServiceClient = mtomServiceClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
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
*/
@Path("/wsdlfirstclient")
@Produces(MediaType.APPLICATION_JSON)
public class AccessWsdlFirstServiceResource {

WsdlFirstService wsdlFirstServiceClient;
final WsdlFirstService wsdlFirstServiceClient;

public AccessWsdlFirstServiceResource(WsdlFirstService wsdlFirstServiceClient) {
this.wsdlFirstServiceClient = wsdlFirstServiceClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public abstract class AbstractInvoker implements Invoker {

protected Invoker underlying;
protected final Invoker underlying;

protected AbstractInvoker(Invoker underlying) {
this.underlying = underlying;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/
public class ClientBuilder<T> extends AbstractBuilder {

Class<T> serviceClass;
String address;
final Class<T> serviceClass;
final String address;
private int connectTimeout = 500;
private int receiveTimeout = 2000;
ImmutableList<Handler> handlers;
Expand Down Expand Up @@ -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<T> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,7 +53,7 @@ public Map<String, Object> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private InstrumentedInvokers() {
*/
public static class TimedInvoker extends AbstractInvoker {

private ImmutableMap<String, Timer> timers;
private final ImmutableMap<String, Timer> timers;

public TimedInvoker(Invoker underlying, ImmutableMap<String, Timer> timers) {
super(underlying);
Expand All @@ -31,7 +31,7 @@ public TimedInvoker(Invoker underlying, ImmutableMap<String, Timer> timers) {

public Object invoke(Exchange exchange, Object o) {

Object result = null;
Object result;
String methodname = this.getTargetMethod(exchange).getName();

if (timers.containsKey(methodname)) {
Expand All @@ -54,7 +54,7 @@ public Object invoke(Exchange exchange, Object o) {
*/
public static class MeteredInvoker extends AbstractInvoker {

private ImmutableMap<String, Meter> meters;
private final ImmutableMap<String, Meter> meters;

public MeteredInvoker(Invoker underlying, ImmutableMap<String, Meter> meters) {
super(underlying);
Expand All @@ -76,8 +76,8 @@ public Object invoke(Exchange exchange, Object o) {
}

public static class ExceptionMeter {
private Meter meter;
private Class<? extends Throwable> exceptionClass;
private final Meter meter;
private final Class<? extends Throwable> exceptionClass;

public ExceptionMeter(Meter meter, Class<? extends Throwable> exceptionClass) {
this.meter = meter;
Expand All @@ -98,7 +98,7 @@ public Class<? extends Throwable> getExceptionClass() {
*/
public static class ExceptionMeteredInvoker extends AbstractInvoker {

private ImmutableMap<String, ExceptionMeter> meters;
private final ImmutableMap<String, ExceptionMeter> meters;

public ExceptionMeteredInvoker(Invoker underlying, ImmutableMap<String, ExceptionMeter> meters) {
super(underlying);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
public class JAXWSBundle<C> implements ConfiguredBundle<C> {

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'.
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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,
Expand All @@ -157,7 +157,7 @@ public EndpointImpl publishEndpoint(String path, Object service, BasicAuthentica
* @param handlers Client side Jakarta XML Web Services handlers. Optional.
* @param <T> 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> T getClient(Class<T> serviceClass, String address, Handler... handlers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class UnitOfWorkInvoker extends AbstractInvoker {

private final SessionFactory sessionFactory;
ImmutableMap<String, UnitOfWork> unitOfWorkMethods;
final ImmutableMap<String, UnitOfWork> unitOfWorkMethods;

public UnitOfWorkInvoker(Invoker underlying, ImmutableMap<String, UnitOfWork> unitOfWorkMethods,
SessionFactory sessionFactory) {
Expand Down Expand Up @@ -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()) {
Expand All @@ -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()) {
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -65,7 +68,7 @@ void shouldAuthenticateValidUser() {
}

@Test
void shouldReturnUnathorizedCodeForInvalidCredentials() {
void shouldReturnUnauthorizedCodeForInvalidCredentials() {
BasicAuthenticationInterceptor target = new BasicAuthenticationInterceptor();
target.setAuthenticator(basicAuthentication);
Message message = createMessageWithUsernameAndPassword(USERNAME, "foo");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading

0 comments on commit eea1da6

Please sign in to comment.