Skip to content

Commit

Permalink
Misc. code cleanup (#24)
Browse files Browse the repository at this point in the history
* Remove redundant warning suppression annotations in endpointBuilder
* Resolve use of raw Map type in case in BasicAuthenticationInterceptor
* Minor code reformatting in InstrumentedInvokerFactory for readability
* Use assertThatIllegalArgumentException in JAXWSBundleTest and in
JAXWSEnvironmentTest
* Use assertThatRuntimeException in UnitOfWorkInvokerFactoryTest
* Fix raw usage of AsyncHandler in ValidatingInvokerTest
* Suppress unused var warning in JaxWsExampleApplication#run
* Fix deprecated code warnings in PersonDAO
* Change AccessMtomServiceResource to throw UncheckedIOException instead
of just RuntimeException
  • Loading branch information
sleberknight authored Nov 6, 2023
1 parent 50c8c1f commit f375156
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void initialize(Bootstrap<JaxWsExampleApplicationConfiguration> bootstrap
public void run(JaxWsExampleApplicationConfiguration jaxWsExampleApplicationConfiguration, Environment environment) {

// Hello world service
@SuppressWarnings("unused")
EndpointImpl e = jaxWsBundle.publishEndpoint(
new EndpointBuilder("/simple", new SimpleService()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public PersonDAO(SessionFactory sessionFactory) {
try {
sess.beginTransaction();
sess.createNativeQuery("create table people(id bigint primary key auto_increment not null, " +
"fullname varchar(256) not null, jobtitle varchar(256) not null);").executeUpdate();
sess.createNativeQuery("create sequence hibernate_sequence").executeUpdate();
"fullname varchar(256) not null, jobtitle varchar(256) not null);", Void.class).executeUpdate();
sess.createNativeQuery("create sequence hibernate_sequence", Void.class).executeUpdate();
}
finally {
sess.getTransaction().commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


import java.io.IOException;
import java.io.UncheckedIOException;

import jakarta.activation.DataHandler;
import jakarta.mail.util.ByteArrayDataSource;
Expand Down Expand Up @@ -43,7 +44,7 @@ public String getFoo() {
IOUtils.readStringFromStream(hr.getBinary().getInputStream());
}
catch (IOException e) {
throw new RuntimeException(e);
throw new UncheckedIOException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private void sendErrorResponse(Message message, int responseCode) {
outMessage.put(Message.RESPONSE_CODE, responseCode);
// Set the response headers
@SuppressWarnings("unchecked")
Map<String, List<String>> responseHeaders = (Map)message.get(Message.PROTOCOL_HEADERS);
var responseHeaders = (Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS);
if (responseHeaders != null) {
responseHeaders.put("WWW-Authenticate", Collections.singletonList("Basic realm=" + authentication.getRealm()));
responseHeaders.put("Content-length", Collections.singletonList("0"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,12 @@ public EndpointBuilder authentication(BasicAuthentication authentication) {

@Override
@SafeVarargs
@SuppressWarnings("unchecked")
public final EndpointBuilder cxfInInterceptors(Interceptor<? extends Message>... interceptors) {
return (EndpointBuilder)super.cxfInInterceptors(interceptors);
}

@Override
@SafeVarargs
@SuppressWarnings("unchecked")
public final EndpointBuilder cxfInFaultInterceptors(Interceptor<? extends Message>... interceptors) {
return (EndpointBuilder)super.cxfInFaultInterceptors(interceptors);
}
Expand All @@ -102,7 +100,6 @@ public final EndpointBuilder cxfOutInterceptors(Interceptor<? extends Message>..

@Override
@SafeVarargs
@SuppressWarnings("unchecked")
public final EndpointBuilder cxfOutFaultInterceptors(Interceptor<? extends Message>... interceptors) {
return (EndpointBuilder)super.cxfOutFaultInterceptors(interceptors);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ private String chooseName(String explicitName, boolean absolute, Method method,
if (absolute) {
return explicitName;
}
return metricRegistry.name(method.getDeclaringClass(), explicitName);
return MetricRegistry.name(method.getDeclaringClass(), explicitName);
}
return metricRegistry.name(metricRegistry.name(method.getDeclaringClass(),
return MetricRegistry.name(
MetricRegistry.name(method.getDeclaringClass(),
method.getName()),
suffixes);
suffixes
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import jakarta.servlet.ServletRegistration;
import jakarta.servlet.http.HttpServlet;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -65,12 +64,9 @@ void constructorArgumentChecks() {
void initializeAndRun() {
JAXWSBundle<?> jaxwsBundle = new JAXWSBundle<>("/soap", jaxwsEnvironment);

try {
jaxwsBundle.run(null, null);
}
catch (Exception e) {
assertThat(e).isInstanceOf(IllegalArgumentException.class);
}
assertThatIllegalArgumentException()
.isThrownBy(() -> jaxwsBundle.run(null, null))
.withMessage("Environment is null");

jaxwsBundle.initialize(bootstrap);
verify(jaxwsEnvironment).setInstrumentedInvokerBuilder(any(InstrumentedInvokerFactory.class));
Expand All @@ -91,12 +87,9 @@ protected String getPublishedEndpointUrlPrefix(Configuration configuration) {
}
};

try {
jaxwsBundle.run(null, null);
}
catch (Exception e) {
assertThat(e).isInstanceOf(IllegalArgumentException.class);
}
assertThatIllegalArgumentException()
.isThrownBy(() -> jaxwsBundle.run(null, null))
.withMessage("Environment is null");

jaxwsBundle.initialize(bootstrap);
verify(jaxwsEnvironment).setInstrumentedInvokerBuilder(any(InstrumentedInvokerFactory.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.HashMap;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
Expand Down Expand Up @@ -329,30 +330,24 @@ void publishEndpointWithPublishedUrlPrefix() throws WSDLException {
@Test
void publishEndpointWithInvalidArguments() throws Exception {

try {
jaxwsEnvironment.publishEndpoint(new EndpointBuilder("foo", null));
}
catch (IllegalArgumentException e) {
}
assertThatIllegalArgumentException()
.isThrownBy(() -> new EndpointBuilder("foo", null))
.withMessage("Service is null");

try {
jaxwsEnvironment.publishEndpoint(new EndpointBuilder(null, service));
}
catch (IllegalArgumentException e) {
}
assertThatIllegalArgumentException()
.isThrownBy(() -> new EndpointBuilder(null, service))
.withMessage("Path is null");

try {
jaxwsEnvironment.publishEndpoint(new EndpointBuilder(" ", service));
}
catch (IllegalArgumentException e) {
}
assertThatIllegalArgumentException()
.isThrownBy(() -> new EndpointBuilder(" ", service))
.withMessage("Path is empty");
}

@Test
void getClient() {

String address = "http://address";
Handler handler = mock(Handler.class);
var address = "http://address";
var handler = mock(Handler.class);

// simple
DummyInterface clientProxy = jaxwsEnvironment.getClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.lang.reflect.Method;

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;
Expand Down Expand Up @@ -130,14 +131,11 @@ 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, "unitOfWork", boolean.class); // simulate CXF behavior

try {
invoker.invoke(exchange, null);
}
catch (Exception e) {
assertThat(e.getMessage()).isEqualTo("Uh oh");
}
assertThatRuntimeException()
.isThrownBy(() -> invoker.invoke(exchange, null))
.withMessage("Uh oh");

verify(session, times(1)).beginTransaction();
verify(transaction, times(0)).commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,21 @@ public RootParam2(String foo) {
class DummyService {
public void noParams() {
}

public void noValidation(RootParam1 rootParam1, RootParam2 rootParam2) {
}

public void withValidation(@Valid RootParam1 rootParam1, @Valid RootParam2 rootParam2) {
}

public void withDropwizardValidation(@Validated() String foo) {
}

@UseAsyncMethod
public void asyncMethod(String foo) {
}
public void asyncMethodAsync(String foo, AsyncHandler asyncHandler) {

public void asyncMethodAsync(String foo, AsyncHandler<String> asyncHandler) {
}
}

Expand Down Expand Up @@ -129,18 +134,18 @@ void invokeWithoutValidation() {
void invokeWithAsycHandler() {
setTargetMethod(exchange, "asyncMethod", String.class);

List<Object> params = Arrays.<Object>asList(null, new AsyncHandler(){
List<Object> params = Arrays.<Object>asList(null, new AsyncHandler<String>() {
@Override
public void handleResponse(Response res) {
public void handleResponse(Response<String> res) {

}
});
invoker.invoke(exchange, params);
verify(underlying).invoke(exchange, params);

params = Arrays.asList("foo", new AsyncHandler(){
params = Arrays.asList("foo", new AsyncHandler<String>() {
@Override
public void handleResponse(Response res) {
public void handleResponse(Response<String> res) {

}
});
Expand Down

0 comments on commit f375156

Please sign in to comment.