Skip to content

Commit

Permalink
Rename internal fields, vars, etc. so they don't include "jaxws" (#78)
Browse files Browse the repository at this point in the history
Rename fields, local vars, parameters, etc. so they don't include
"jaxws" in them. For now, I have chosen to use "jws" to stand for
Jakarta XML Web Services, which I think is easier to read than "jxws",
e.g. jwsEnvironment

Fix issue in README that referred tot eh old "jaxws" directory in the
section on building an uber JAR.

Also, rename dropwizard-jaxws-changelog.md to
legacy-dropwizard-jaxws-changelog.md, mainly so that it is more clear
that it is a historical artifact.

Closes #77
  • Loading branch information
sleberknight authored Nov 12, 2023
1 parent fee8cd9 commit 3f28890
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 66 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ configuration:
</transformer>
```

For example on building fat jar, see `dropwizard-jaxws-example/pom.xml`.
For example on building fat jar, see `dropwizard-jakarta-xml-ws-example/pom.xml`.

When using Gradle and a recent version of [shadowJar](https://github.com/johnrengelman/shadow) use the following snippet:

Expand All @@ -230,6 +230,6 @@ Changelog

The original repository listed its complete change log at the end of this README.

We have moved it [here](dropwizard-jaxws-changelog.md) for historical purposes.
We have moved it [here](legacy-dropwizard-jaxws-changelog.md) for historical purposes.

Releases in this repository use [GitHub releases](https://github.com/kiwiproject/dropwizard-jakarta-xml-ws/releases).
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class JAXWSBundle<C> implements ConfiguredBundle<C> {

protected static final String DEFAULT_PATH = "/soap";
protected final JAXWSEnvironment jaxwsEnvironment;
protected final JAXWSEnvironment jwsEnvironment;
protected final String servletPath;

/**
Expand All @@ -38,35 +38,35 @@ public JAXWSBundle(String servletPath) {
* Create a new bundle instance using the provided JAXWSEnvironment. Service endpoints are
* published relative to the provided servletPath.
*
* @param servletPath Root path for service endpoints. Leading slash is required.
* @param jaxwsEnvironment Valid JAXWSEnvironment.
* @param servletPath Root path for service endpoints. Leading slash is required.
* @param jwsEnvironment Valid JAXWSEnvironment.
*/
public JAXWSBundle(String servletPath, JAXWSEnvironment jaxwsEnvironment) {
public JAXWSBundle(String servletPath, JAXWSEnvironment jwsEnvironment) {
checkArgument(servletPath != null, "Servlet path is null");
checkArgument(servletPath.startsWith("/"), "%s is not an absolute path", servletPath);
checkArgument(jaxwsEnvironment != null, "jaxwsEnvironment is null");
checkArgument(jwsEnvironment != null, "jwsEnvironment is null");
this.servletPath = servletPath.endsWith("/") ? servletPath + "*" : servletPath + "/*";
this.jaxwsEnvironment = jaxwsEnvironment;
this.jwsEnvironment = jwsEnvironment;
}

@Override
public void initialize(Bootstrap<?> bootstrap) {
this.jaxwsEnvironment.setInstrumentedInvokerBuilder(
this.jwsEnvironment.setInstrumentedInvokerBuilder(
new InstrumentedInvokerFactory(bootstrap.getMetricRegistry()));
}

@Override
public void run(C configuration, Environment environment) {
checkArgument(environment != null, "Environment is null");
environment.servlets().addServlet("CXF Servlet " + jaxwsEnvironment.getDefaultPath(),
jaxwsEnvironment.buildServlet()).addMapping(servletPath);
environment.servlets().addServlet("CXF Servlet " + jwsEnvironment.getDefaultPath(),
jwsEnvironment.buildServlet()).addMapping(servletPath);

environment.lifecycle().addServerLifecycleListener(
server -> jaxwsEnvironment.logEndpoints());
server -> jwsEnvironment.logEndpoints());

String publishedEndpointUrlPrefix = getPublishedEndpointUrlPrefix(configuration);
if (publishedEndpointUrlPrefix != null) {
jaxwsEnvironment.setPublishedEndpointUrlPrefix(publishedEndpointUrlPrefix);
jwsEnvironment.setPublishedEndpointUrlPrefix(publishedEndpointUrlPrefix);
}
}

Expand All @@ -78,7 +78,7 @@ public void run(C configuration, Environment environment) {
*/
public EndpointImpl publishEndpoint(EndpointBuilder endpointBuilder) {
checkArgument(endpointBuilder != null, "EndpointBuilder is null");
return this.jaxwsEnvironment.publishEndpoint(endpointBuilder);
return this.jwsEnvironment.publishEndpoint(endpointBuilder);
}

/**
Expand All @@ -90,7 +90,7 @@ public EndpointImpl publishEndpoint(EndpointBuilder endpointBuilder) {
*/
public <T> T getClient(ClientBuilder<T> clientBuilder) {
checkArgument(clientBuilder != null, "ClientBuilder is null");
return jaxwsEnvironment.getClient(clientBuilder);
return jwsEnvironment.getClient(clientBuilder);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class JAXWSBundleTest {
Bootstrap<?> bootstrap;
ServletEnvironment servletEnvironment;
ServletRegistration.Dynamic servlet;
JAXWSEnvironment jaxwsEnvironment;
JAXWSEnvironment jwsEnvironment;
LifecycleEnvironment lifecycleEnvironment;

@BeforeEach
Expand All @@ -38,124 +38,124 @@ void setUp() {
bootstrap = mock(Bootstrap.class);
servletEnvironment = mock(ServletEnvironment.class);
servlet = mock(ServletRegistration.Dynamic.class);
jaxwsEnvironment = mock(JAXWSEnvironment.class);
jwsEnvironment = mock(JAXWSEnvironment.class);
lifecycleEnvironment = mock(LifecycleEnvironment.class);

when(environment.servlets()).thenReturn(servletEnvironment);
when(environment.lifecycle()).thenReturn(lifecycleEnvironment);
when(bootstrap.getMetricRegistry()).thenReturn(mock(MetricRegistry.class));
when(servletEnvironment.addServlet(anyString(), any(HttpServlet.class))).thenReturn(servlet);
when(jaxwsEnvironment.buildServlet()).thenReturn(mock(HttpServlet.class));
when(jaxwsEnvironment.getDefaultPath()).thenReturn("/soap");
when(jwsEnvironment.buildServlet()).thenReturn(mock(HttpServlet.class));
when(jwsEnvironment.getDefaultPath()).thenReturn("/soap");
}

@Test
void constructorArgumentChecks() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new JAXWSBundle<>(null, jaxwsEnvironment))
.isThrownBy(() -> new JAXWSBundle<>(null, jwsEnvironment))
.withMessage("Servlet path is null");

assertThatIllegalArgumentException()
.isThrownBy(() -> new JAXWSBundle<>("soap", jaxwsEnvironment))
.isThrownBy(() -> new JAXWSBundle<>("soap", jwsEnvironment))
.withMessage("soap is not an absolute path");

assertThatIllegalArgumentException()
.isThrownBy(() -> new JAXWSBundle<>("/soap", null))
.withMessage("jaxwsEnvironment is null");
.withMessage("jwsEnvironment is null");

assertThatCode(() -> new JAXWSBundle<>("/soap", jaxwsEnvironment))
assertThatCode(() -> new JAXWSBundle<>("/soap", jwsEnvironment))
.doesNotThrowAnyException();
}

@Test
void initializeAndRun() {
JAXWSBundle<?> jaxwsBundle = new JAXWSBundle<>("/soap", jaxwsEnvironment);
JAXWSBundle<?> jwsBundle = new JAXWSBundle<>("/soap", jwsEnvironment);

assertThatIllegalArgumentException()
.isThrownBy(() -> jaxwsBundle.run(null, null))
.isThrownBy(() -> jwsBundle.run(null, null))
.withMessage("Environment is null");

jaxwsBundle.initialize(bootstrap);
verify(jaxwsEnvironment).setInstrumentedInvokerBuilder(any(InstrumentedInvokerFactory.class));
jwsBundle.initialize(bootstrap);
verify(jwsEnvironment).setInstrumentedInvokerBuilder(any(InstrumentedInvokerFactory.class));

jaxwsBundle.run(null, environment);
jwsBundle.run(null, environment);
verify(servletEnvironment).addServlet(startsWith("CXF Servlet"), any(Servlet.class));
verify(lifecycleEnvironment).addServerLifecycleListener(any(ServerLifecycleListener.class));
verify(servlet).addMapping("/soap/*");
verify(jaxwsEnvironment, never()).setPublishedEndpointUrlPrefix(anyString());
verify(jwsEnvironment, never()).setPublishedEndpointUrlPrefix(anyString());
}

@Test
void initializeAndRunWithPublishedEndpointUrlPrefix() {
JAXWSBundle<?> jaxwsBundle = new JAXWSBundle<Configuration>("/soap", jaxwsEnvironment) {
JAXWSBundle<?> jwsBundle = new JAXWSBundle<Configuration>("/soap", jwsEnvironment) {
@Override
protected String getPublishedEndpointUrlPrefix(Configuration configuration) {
return "http://some/prefix";
}
};

assertThatIllegalArgumentException()
.isThrownBy(() -> jaxwsBundle.run(null, null))
.isThrownBy(() -> jwsBundle.run(null, null))
.withMessage("Environment is null");

jaxwsBundle.initialize(bootstrap);
verify(jaxwsEnvironment).setInstrumentedInvokerBuilder(any(InstrumentedInvokerFactory.class));
jwsBundle.initialize(bootstrap);
verify(jwsEnvironment).setInstrumentedInvokerBuilder(any(InstrumentedInvokerFactory.class));

jaxwsBundle.run(null, environment);
jwsBundle.run(null, environment);
verify(servletEnvironment).addServlet(startsWith("CXF Servlet"), any(Servlet.class));
verify(lifecycleEnvironment).addServerLifecycleListener(any(ServerLifecycleListener.class));
verify(servlet).addMapping("/soap/*");
verify(jaxwsEnvironment).setPublishedEndpointUrlPrefix("http://some/prefix");
verify(jwsEnvironment).setPublishedEndpointUrlPrefix("http://some/prefix");
}

@Test
void publishEndpoint() {

JAXWSBundle<?> jaxwsBundle = new JAXWSBundle<>("/soap", jaxwsEnvironment);
JAXWSBundle<?> jwsBundle = new JAXWSBundle<>("/soap", jwsEnvironment);
Object service = new Object();
assertThatIllegalArgumentException()
.isThrownBy(() -> jaxwsBundle.publishEndpoint(new EndpointBuilder("foo", null)))
.isThrownBy(() -> jwsBundle.publishEndpoint(new EndpointBuilder("foo", null)))
.withMessage("Service is null");

assertThatIllegalArgumentException()
.isThrownBy(() -> jaxwsBundle.publishEndpoint(new EndpointBuilder(null, service)))
.isThrownBy(() -> jwsBundle.publishEndpoint(new EndpointBuilder(null, service)))
.withMessage("Path is null");

assertThatIllegalArgumentException()
.isThrownBy(() -> jaxwsBundle.publishEndpoint(new EndpointBuilder(" ", service)))
.isThrownBy(() -> jwsBundle.publishEndpoint(new EndpointBuilder(" ", service)))
.withMessage("Path is empty");

EndpointBuilder builder = mock(EndpointBuilder.class);
jaxwsBundle.publishEndpoint(builder);
verify(jaxwsEnvironment).publishEndpoint(builder);
jwsBundle.publishEndpoint(builder);
verify(jwsEnvironment).publishEndpoint(builder);
}

@Test
void getClient() {

JAXWSBundle<?> jaxwsBundle = new JAXWSBundle<>("/soap", jaxwsEnvironment);
JAXWSBundle<?> jwsBundle = new JAXWSBundle<>("/soap", jwsEnvironment);

Class<?> cls = Object.class;
String url = "http://foo";

assertThatIllegalArgumentException()
.isThrownBy(() -> jaxwsBundle.getClient(new ClientBuilder<>(null, null)))
.isThrownBy(() -> jwsBundle.getClient(new ClientBuilder<>(null, null)))
.withMessage("ServiceClass is null");

assertThatIllegalArgumentException()
.isThrownBy(() -> jaxwsBundle.getClient(new ClientBuilder<>(null, url)))
.isThrownBy(() -> jwsBundle.getClient(new ClientBuilder<>(null, url)))
.withMessage("ServiceClass is null");

assertThatIllegalArgumentException()
.isThrownBy(() -> jaxwsBundle.getClient(new ClientBuilder<>(cls, null)))
.isThrownBy(() -> jwsBundle.getClient(new ClientBuilder<>(cls, null)))
.withMessage("Address is null");

assertThatIllegalArgumentException()
.isThrownBy(() -> jaxwsBundle.getClient(new ClientBuilder<>(cls, " ")))
.isThrownBy(() -> jwsBundle.getClient(new ClientBuilder<>(cls, " ")))
.withMessage("Address is empty");

ClientBuilder<?> builder = new ClientBuilder<>(cls, url);
jaxwsBundle.getClient(builder);
verify(jaxwsEnvironment).getClient(builder);
jwsBundle.getClient(builder);
verify(jwsEnvironment).getClient(builder);
}
}
Loading

0 comments on commit 3f28890

Please sign in to comment.