Update EndpointImpl to implement AutoCloseable and then use that in tests to make sure things are shutdown
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/6ef5be58 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/6ef5be58 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/6ef5be58 Branch: refs/heads/master Commit: 6ef5be5869eb0c076f8bc8ed30775028a0b314c7 Parents: 36b432c Author: Daniel Kulp <[email protected]> Authored: Fri May 22 13:59:15 2015 -0400 Committer: Daniel Kulp <[email protected]> Committed: Fri May 22 14:14:25 2015 -0400 ---------------------------------------------------------------------- .../cxf/jca/inbound/MDBActivationWork.java | 1 + .../aegis/client/ClientServiceConfigTest.java | 12 +- .../java/org/apache/cxf/jaxws/EndpointImpl.java | 7 +- .../org/apache/cxf/jaxws/CodeFirstTest.java | 317 ++++++++++--------- .../org/apache/cxf/jaxws/EndpointImplTest.java | 223 ++++++------- .../apache/cxf/jaxws/EndpointReferenceTest.java | 236 +++++++------- .../apache/cxf/jaxws/provider/ProviderTest.java | 50 +-- .../factory_pattern/HttpNumberFactoryImpl.java | 1 + .../ManualHttpMulitplexClientServerTest.java | 8 +- .../ManualNumberFactoryImpl.java | 1 + .../MultiplexClientServerTest.java | 9 +- .../MultiplexHttpAddressClientServerTest.java | 7 +- .../factory_pattern/NumberFactoryImpl.java | 13 + .../cxf/systest/ws/addr_responses/Server.java | 9 +- 14 files changed, 481 insertions(+), 413 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/6ef5be58/integration/jca/src/main/java/org/apache/cxf/jca/inbound/MDBActivationWork.java ---------------------------------------------------------------------- diff --git a/integration/jca/src/main/java/org/apache/cxf/jca/inbound/MDBActivationWork.java b/integration/jca/src/main/java/org/apache/cxf/jca/inbound/MDBActivationWork.java index bebaac4..0b7168a 100644 --- a/integration/jca/src/main/java/org/apache/cxf/jca/inbound/MDBActivationWork.java +++ b/integration/jca/src/main/java/org/apache/cxf/jca/inbound/MDBActivationWork.java @@ -220,6 +220,7 @@ public class MDBActivationWork implements Work { */ private Server createServerFromJaxwsEndpoint(JaxWsServerFactoryBean factory) { + @SuppressWarnings("resource") EndpointImpl endpoint = new EndpointImpl(factory.getBus(), null, factory); endpoint.setWsdlLocation(factory.getWsdlURL()); http://git-wip-us.apache.org/repos/asf/cxf/blob/6ef5be58/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/client/ClientServiceConfigTest.java ---------------------------------------------------------------------- diff --git a/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/client/ClientServiceConfigTest.java b/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/client/ClientServiceConfigTest.java index 55a71ec..fcfe88e 100644 --- a/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/client/ClientServiceConfigTest.java +++ b/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/client/ClientServiceConfigTest.java @@ -24,7 +24,6 @@ import javax.xml.ws.Holder; import org.apache.cxf.aegis.AbstractAegisTest; import org.apache.cxf.aegis.databinding.AegisDatabinding; - import org.apache.cxf.frontend.ClientProxyFactoryBean; import org.apache.cxf.frontend.ServerFactoryBean; import org.apache.cxf.jaxws.EndpointImpl; @@ -32,11 +31,13 @@ import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; import org.apache.cxf.service.invoker.BeanInvoker; import org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean; +import org.junit.After; import org.junit.Before; import org.junit.Test; public class ClientServiceConfigTest extends AbstractAegisTest { - + EndpointImpl impl; + @Before public void before() throws Exception { super.setUp(); @@ -53,10 +54,15 @@ public class ClientServiceConfigTest extends AbstractAegisTest { svrFac.create(); Endpoint endpoint = Endpoint.create(new EchoImpl()); - EndpointImpl impl = (EndpointImpl) endpoint; + impl = (EndpointImpl) endpoint; impl.setDataBinding(new AegisDatabinding()); endpoint.publish("local://JaxWsEcho"); } + @After + public void after() throws Exception { + impl.close(); + impl = null; + } @Test public void talkToJaxWsHolder() throws Exception { http://git-wip-us.apache.org/repos/asf/cxf/blob/6ef5be58/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java index 793f6ba..690cbca 100644 --- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java +++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java @@ -79,7 +79,7 @@ import org.apache.cxf.wsdl.WSDLManager; import org.apache.cxf.wsdl11.WSDLServiceBuilder; public class EndpointImpl extends javax.xml.ws.Endpoint - implements InterceptorProvider, Configurable { + implements InterceptorProvider, Configurable, AutoCloseable { /** * This property controls whether the 'publishEndpoint' permission is checked * using only the AccessController (i.e. when SecurityManager is not installed). @@ -855,6 +855,11 @@ public class EndpointImpl extends javax.xml.ws.Endpoint sf.setDestinationFactory(new JAXWSHttpSpiTransportFactory(context)); } publish(context.getPath()); + } + + @Override + public void close() throws Exception { + stop(); } } http://git-wip-us.apache.org/repos/asf/cxf/blob/6ef5be58/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java index 1392adb..f6d5f5b 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java @@ -168,115 +168,118 @@ public class CodeFirstTest extends AbstractJaxWsTest { public void testEndpoint() throws Exception { Hello service = new Hello(); - EndpointImpl ep = new EndpointImpl(getBus(), service, (String) null); - ep.setExecutor(new Executor() { - public void execute(Runnable r) { - new Thread(r).start(); - } - }); - ep.publish("local://localhost:9090/hello"); - - Node res = invoke("local://localhost:9090/hello", - LocalTransportFactory.TRANSPORT_ID, - "sayHi.xml"); - - assertNotNull(res); - - addNamespace("h", "http://service.jaxws.cxf.apache.org/"); - assertValid("//s:Body/h:sayHiResponse/return", res); - - res = invoke("local://localhost:9090/hello", - LocalTransportFactory.TRANSPORT_ID, - "getGreetings.xml"); - - assertNotNull(res); - - addNamespace("h", "http://service.jaxws.cxf.apache.org/"); - assertValid("//s:Body/h:getGreetingsResponse/return[1]", res); - assertValid("//s:Body/h:getGreetingsResponse/return[2]", res); + try (EndpointImpl ep = new EndpointImpl(getBus(), service, (String) null)) { + ep.setExecutor(new Executor() { + public void execute(Runnable r) { + new Thread(r).start(); + } + }); + ep.publish("local://localhost:9090/hello"); + + Node res = invoke("local://localhost:9090/hello", + LocalTransportFactory.TRANSPORT_ID, + "sayHi.xml"); + + assertNotNull(res); + + addNamespace("h", "http://service.jaxws.cxf.apache.org/"); + assertValid("//s:Body/h:sayHiResponse/return", res); + + res = invoke("local://localhost:9090/hello", + LocalTransportFactory.TRANSPORT_ID, + "getGreetings.xml"); + + assertNotNull(res); + + addNamespace("h", "http://service.jaxws.cxf.apache.org/"); + assertValid("//s:Body/h:getGreetingsResponse/return[1]", res); + assertValid("//s:Body/h:getGreetingsResponse/return[2]", res); + } } @Test public void testClient() throws Exception { Hello serviceImpl = new Hello(); - EndpointImpl ep = new EndpointImpl(getBus(), serviceImpl, (String) null); - ep.publish("local://localhost:9090/hello"); - QName serviceName = new QName("http://service.jaxws.cxf.apache.org/", "HelloService"); - QName portName = new QName("http://service.jaxws.cxf.apache.org/", "HelloPort"); - - // need to set the same bus with service , so use the ServiceImpl - ServiceImpl service = new ServiceImpl(getBus(), (URL)null, serviceName, null); - service.addPort(portName, "http://schemas.xmlsoap.org/soap/", "local://localhost:9090/hello"); - - HelloInterface proxy = service.getPort(portName, HelloInterface.class, new LoggingFeature()); - Client client = ClientProxy.getClient(proxy); - boolean found = false; - for (Interceptor<? extends Message> i : client.getOutInterceptors()) { - if (i instanceof LoggingOutInterceptor) { - found = true; + try (EndpointImpl ep = new EndpointImpl(getBus(), serviceImpl, (String) null)) { + ep.publish("local://localhost:9090/hello"); + QName serviceName = new QName("http://service.jaxws.cxf.apache.org/", "HelloService"); + QName portName = new QName("http://service.jaxws.cxf.apache.org/", "HelloPort"); + + // need to set the same bus with service , so use the ServiceImpl + ServiceImpl service = new ServiceImpl(getBus(), (URL)null, serviceName, null); + service.addPort(portName, "http://schemas.xmlsoap.org/soap/", "local://localhost:9090/hello"); + + HelloInterface proxy = service.getPort(portName, HelloInterface.class, new LoggingFeature()); + Client client = ClientProxy.getClient(proxy); + boolean found = false; + for (Interceptor<? extends Message> i : client.getOutInterceptors()) { + if (i instanceof LoggingOutInterceptor) { + found = true; + } } + assertTrue(found); + assertEquals("Get the wrong result", "hello", proxy.sayHi("hello")); + String[] strInput = new String[2]; + strInput[0] = "Hello"; + strInput[1] = "Bonjour"; + String[] strings = proxy.getStringArray(strInput); + assertEquals(strings.length, 2); + assertEquals(strings[0], "HelloHello"); + assertEquals(strings[1], "BonjourBonjour"); + List<String> listInput = new ArrayList<String>(); + listInput.add("Hello"); + listInput.add("Bonjour"); + List<String> list = proxy.getStringList(listInput); + assertEquals(list.size(), 2); + assertEquals(list.get(0), "HelloHello"); + assertEquals(list.get(1), "BonjourBonjour"); + //now the client side can't unmarshal the complex type without binding types annoutation + List<String> result = proxy.getGreetings(); + assertEquals(2, result.size()); } - assertTrue(found); - assertEquals("Get the wrong result", "hello", proxy.sayHi("hello")); - String[] strInput = new String[2]; - strInput[0] = "Hello"; - strInput[1] = "Bonjour"; - String[] strings = proxy.getStringArray(strInput); - assertEquals(strings.length, 2); - assertEquals(strings[0], "HelloHello"); - assertEquals(strings[1], "BonjourBonjour"); - List<String> listInput = new ArrayList<String>(); - listInput.add("Hello"); - listInput.add("Bonjour"); - List<String> list = proxy.getStringList(listInput); - assertEquals(list.size(), 2); - assertEquals(list.get(0), "HelloHello"); - assertEquals(list.get(1), "BonjourBonjour"); - //now the client side can't unmarshal the complex type without binding types annoutation - List<String> result = proxy.getGreetings(); - assertEquals(2, result.size()); } @Test public void testException() throws Exception { Hello serviceImpl = new Hello(); - EndpointImpl ep = new EndpointImpl(getBus(), serviceImpl, (String) null); - ep.publish("local://localhost:9090/hello"); - ep.getServer().getEndpoint().getInInterceptors().add(new LoggingInInterceptor()); - ep.getServer().getEndpoint().getOutInterceptors().add(new LoggingOutInterceptor()); - QName serviceName = new QName("http://service.jaxws.cxf.apache.org/", "HelloService"); - QName portName = new QName("http://service.jaxws.cxf.apache.org/", "HelloPort"); - - // need to set the same bus with service , so use the ServiceImpl - ServiceImpl service = new ServiceImpl(getBus(), (URL)null, serviceName, null); - service.addPort(portName, "http://schemas.xmlsoap.org/soap/", "local://localhost:9090/hello"); - - HelloInterface proxy = service.getPort(portName, HelloInterface.class); - ClientProxy.getClient(proxy).getInFaultInterceptors().add(new LoggingInInterceptor()); - ClientProxy.getClient(proxy).getInInterceptors().add(new LoggingInInterceptor()); - try { - proxy.addNumbers(1, -2); - fail("should throw AddNumbersException"); - } catch (AddNumbersException e) { - assertEquals(e.getInfo(), "Sum is less than 0."); - } - - try { - proxy.addNumbers(1, 99); - fail("should throw AddNumbersSubException"); - } catch (AddNumbersSubException e) { - assertEquals(e.getSubInfo(), "Sum is 100"); - } catch (AddNumbersException e) { - fail("should throw AddNumbersSubException"); - } - try (AutoCloseable c = (AutoCloseable)proxy) { - assertEquals("Result = 2", proxy.addNumbers(1, 1)); - } - try { - proxy.addNumbers(1, 1); - fail("Proxy should be closed"); - } catch (IllegalStateException t) { - //this is expected as the client is closed. + try (EndpointImpl ep = new EndpointImpl(getBus(), serviceImpl, (String) null)) { + ep.publish("local://localhost:9090/hello"); + ep.getServer().getEndpoint().getInInterceptors().add(new LoggingInInterceptor()); + ep.getServer().getEndpoint().getOutInterceptors().add(new LoggingOutInterceptor()); + QName serviceName = new QName("http://service.jaxws.cxf.apache.org/", "HelloService"); + QName portName = new QName("http://service.jaxws.cxf.apache.org/", "HelloPort"); + + // need to set the same bus with service , so use the ServiceImpl + ServiceImpl service = new ServiceImpl(getBus(), (URL)null, serviceName, null); + service.addPort(portName, "http://schemas.xmlsoap.org/soap/", "local://localhost:9090/hello"); + + HelloInterface proxy = service.getPort(portName, HelloInterface.class); + ClientProxy.getClient(proxy).getInFaultInterceptors().add(new LoggingInInterceptor()); + ClientProxy.getClient(proxy).getInInterceptors().add(new LoggingInInterceptor()); + try { + proxy.addNumbers(1, -2); + fail("should throw AddNumbersException"); + } catch (AddNumbersException e) { + assertEquals(e.getInfo(), "Sum is less than 0."); + } + + try { + proxy.addNumbers(1, 99); + fail("should throw AddNumbersSubException"); + } catch (AddNumbersSubException e) { + assertEquals(e.getSubInfo(), "Sum is 100"); + } catch (AddNumbersException e) { + fail("should throw AddNumbersSubException"); + } + try (AutoCloseable c = (AutoCloseable)proxy) { + assertEquals("Result = 2", proxy.addNumbers(1, 1)); + } + try { + proxy.addNumbers(1, 1); + fail("Proxy should be closed"); + } catch (IllegalStateException t) { + //this is expected as the client is closed. + } } } @@ -284,70 +287,72 @@ public class CodeFirstTest extends AbstractJaxWsTest { @Test public void testRpcClient() throws Exception { SayHiImpl serviceImpl = new SayHiImpl(); - EndpointImpl ep = new EndpointImpl(getBus(), serviceImpl, (String) null); - ep.publish("local://localhost:9090/hello"); - - QName serviceName = new QName("http://mynamespace.com/", "SayHiService"); - QName portName = new QName("http://mynamespace.com/", "HelloPort"); - - // need to set the same bus with service , so use the ServiceImpl - ServiceImpl service = new ServiceImpl(getBus(), (URL)null, serviceName, null); - service.addPort(portName, "http://schemas.xmlsoap.org/soap/", "local://localhost:9090/hello"); - - SayHi proxy = service.getPort(portName, SayHi.class); - long res = proxy.sayHi(3); - assertEquals(3, res); - String[] strInput = new String[2]; - strInput[0] = "Hello"; - strInput[1] = "Bonjour"; - String[] strings = proxy.getStringArray(strInput); - assertEquals(strings.length, 2); - assertEquals(strings[0], "HelloHello"); - assertEquals(strings[1], "BonjourBonjour"); - + try (EndpointImpl ep = new EndpointImpl(getBus(), serviceImpl, (String) null)) { + ep.publish("local://localhost:9090/hello"); + + QName serviceName = new QName("http://mynamespace.com/", "SayHiService"); + QName portName = new QName("http://mynamespace.com/", "HelloPort"); + + // need to set the same bus with service , so use the ServiceImpl + ServiceImpl service = new ServiceImpl(getBus(), (URL)null, serviceName, null); + service.addPort(portName, "http://schemas.xmlsoap.org/soap/", "local://localhost:9090/hello"); + + SayHi proxy = service.getPort(portName, SayHi.class); + long res = proxy.sayHi(3); + assertEquals(3, res); + String[] strInput = new String[2]; + strInput[0] = "Hello"; + strInput[1] = "Bonjour"; + String[] strings = proxy.getStringArray(strInput); + assertEquals(strings.length, 2); + assertEquals(strings[0], "HelloHello"); + assertEquals(strings[1], "BonjourBonjour"); + } } + @Test public void testArrayAndList() throws Exception { ArrayServiceImpl serviceImpl = new ArrayServiceImpl(); - EndpointImpl ep = new EndpointImpl(getBus(), serviceImpl, (String) null); - ep.publish("local://localhost:9090/array"); - ep.getServer().getEndpoint().getInInterceptors().add(new LoggingInInterceptor()); - ep.getServer().getEndpoint().getOutInterceptors().add(new LoggingOutInterceptor()); - QName serviceName = new QName("http://service.jaxws.cxf.apache.org/", "ArrayService"); - QName portName = new QName("http://service.jaxws.cxf.apache.org/", "ArrayPort"); - - // need to set the same bus with service , so use the ServiceImpl - ServiceImpl service = new ServiceImpl(getBus(), (URL)null, serviceName, null); - service.addPort(portName, "http://schemas.xmlsoap.org/soap/", "local://localhost:9090/array"); - - ArrayService proxy = service.getPort(portName, ArrayService.class); - String[] arrayOut = proxy.arrayOutput(); - assertEquals(arrayOut.length, 3); - assertEquals(arrayOut[0], "string1"); - assertEquals(arrayOut[1], "string2"); - assertEquals(arrayOut[2], "string3"); - String[] arrayIn = new String[3]; - arrayIn[0] = "string1"; - arrayIn[1] = "string2"; - arrayIn[2] = "string3"; - assertEquals(proxy.arrayInput(arrayIn), "string1string2string3"); - arrayOut = proxy.arrayInputAndOutput(arrayIn); - assertEquals(arrayOut.length, 3); - assertEquals(arrayOut[0], "string11"); - assertEquals(arrayOut[1], "string22"); - assertEquals(arrayOut[2], "string33"); - - List<String> listOut = proxy.listOutput(); - assertEquals(listOut.size(), 3); - assertEquals(listOut.get(0), "string1"); - assertEquals(listOut.get(1), "string2"); - assertEquals(listOut.get(2), "string3"); - List<String> listIn = new ArrayList<String>(); - listIn.add("list1"); - listIn.add("list2"); - listIn.add("list3"); - assertEquals(proxy.listInput(listIn), "list1list2list3"); + try (EndpointImpl ep = new EndpointImpl(getBus(), serviceImpl, (String) null)) { + ep.publish("local://localhost:9090/array"); + ep.getServer().getEndpoint().getInInterceptors().add(new LoggingInInterceptor()); + ep.getServer().getEndpoint().getOutInterceptors().add(new LoggingOutInterceptor()); + QName serviceName = new QName("http://service.jaxws.cxf.apache.org/", "ArrayService"); + QName portName = new QName("http://service.jaxws.cxf.apache.org/", "ArrayPort"); + + // need to set the same bus with service , so use the ServiceImpl + ServiceImpl service = new ServiceImpl(getBus(), (URL)null, serviceName, null); + service.addPort(portName, "http://schemas.xmlsoap.org/soap/", "local://localhost:9090/array"); + + ArrayService proxy = service.getPort(portName, ArrayService.class); + String[] arrayOut = proxy.arrayOutput(); + assertEquals(arrayOut.length, 3); + assertEquals(arrayOut[0], "string1"); + assertEquals(arrayOut[1], "string2"); + assertEquals(arrayOut[2], "string3"); + String[] arrayIn = new String[3]; + arrayIn[0] = "string1"; + arrayIn[1] = "string2"; + arrayIn[2] = "string3"; + assertEquals(proxy.arrayInput(arrayIn), "string1string2string3"); + arrayOut = proxy.arrayInputAndOutput(arrayIn); + assertEquals(arrayOut.length, 3); + assertEquals(arrayOut[0], "string11"); + assertEquals(arrayOut[1], "string22"); + assertEquals(arrayOut[2], "string33"); + + List<String> listOut = proxy.listOutput(); + assertEquals(listOut.size(), 3); + assertEquals(listOut.get(0), "string1"); + assertEquals(listOut.get(1), "string2"); + assertEquals(listOut.get(2), "string3"); + List<String> listIn = new ArrayList<String>(); + listIn.add("list1"); + listIn.add("list2"); + listIn.add("list3"); + assertEquals(proxy.listInput(listIn), "list1list2list3"); + } } @Test http://git-wip-us.apache.org/repos/asf/cxf/blob/6ef5be58/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointImplTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointImplTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointImplTest.java index 8da2846..40092d1 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointImplTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointImplTest.java @@ -59,34 +59,35 @@ public class EndpointImplTest extends AbstractJaxWsTest { String address = "http://localhost:8080/test"; GreeterImpl greeter = new GreeterImpl(); - EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, (String)null); + try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, (String)null)) { - WebServiceContext ctx = greeter.getContext(); - assertNull(ctx); - try { - endpoint.publish(address); - } catch (IllegalArgumentException ex) { - assertTrue(ex.getCause() instanceof BusException); - assertEquals("BINDING_INCOMPATIBLE_ADDRESS_EXC", ((BusException)ex.getCause()).getCode()); - } - ctx = greeter.getContext(); - - assertNotNull(ctx); - - // Test that we can't change settings through the JAX-WS API after publishing - - try { - endpoint.publish(address); - fail("republished an already published endpoint."); - } catch (IllegalStateException e) { - // expected - } - - try { - endpoint.setMetadata(new ArrayList<Source>(0)); - fail("set metadata on an already published endpoint."); - } catch (IllegalStateException e) { - // expected + WebServiceContext ctx = greeter.getContext(); + assertNull(ctx); + try { + endpoint.publish(address); + } catch (IllegalArgumentException ex) { + assertTrue(ex.getCause() instanceof BusException); + assertEquals("BINDING_INCOMPATIBLE_ADDRESS_EXC", ((BusException)ex.getCause()).getCode()); + } + ctx = greeter.getContext(); + + assertNotNull(ctx); + + // Test that we can't change settings through the JAX-WS API after publishing + + try { + endpoint.publish(address); + fail("republished an already published endpoint."); + } catch (IllegalStateException e) { + // expected + } + + try { + endpoint.setMetadata(new ArrayList<Source>(0)); + fail("set metadata on an already published endpoint."); + } catch (IllegalStateException e) { + // expected + } } } @@ -95,33 +96,33 @@ public class EndpointImplTest extends AbstractJaxWsTest { String address = "http://localhost:8080/test"; GreeterImpl greeter = new GreeterImpl(); - EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, (String)null); - - WebServiceContext ctx = greeter.getContext(); - assertNull(ctx); - try { - endpoint.publish(address); - } catch (IllegalArgumentException ex) { - assertTrue(ex.getCause() instanceof BusException); - assertEquals("BINDING_INCOMPATIBLE_ADDRESS_EXC", ((BusException)ex.getCause()).getCode()); - } - ctx = greeter.getContext(); - - assertNotNull(ctx); - - // Test that calling stop on the Endpoint works - assertTrue(endpoint.isPublished()); - endpoint.stop(); - assertFalse(endpoint.isPublished()); - - // Test that the Endpoint cannot be restarted. - try { - endpoint.publish(address); - fail("stopped endpoint restarted."); - } catch (IllegalStateException e) { - // expected. + try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, (String)null)) { + + WebServiceContext ctx = greeter.getContext(); + assertNull(ctx); + try { + endpoint.publish(address); + } catch (IllegalArgumentException ex) { + assertTrue(ex.getCause() instanceof BusException); + assertEquals("BINDING_INCOMPATIBLE_ADDRESS_EXC", ((BusException)ex.getCause()).getCode()); + } + ctx = greeter.getContext(); + + assertNotNull(ctx); + + // Test that calling stop on the Endpoint works + assertTrue(endpoint.isPublished()); + endpoint.stop(); + assertFalse(endpoint.isPublished()); + + // Test that the Endpoint cannot be restarted. + try { + endpoint.publish(address); + fail("stopped endpoint restarted."); + } catch (IllegalStateException e) { + // expected. + } } - } @@ -133,21 +134,22 @@ public class EndpointImplTest extends AbstractJaxWsTest { serviceFactory.setInvoker(new BeanInvoker(greeter)); serviceFactory.setServiceClass(GreeterImpl.class); - EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, - new JaxWsServerFactoryBean(serviceFactory)); + try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, + new JaxWsServerFactoryBean(serviceFactory))) { - WebServiceContext ctx = greeter.getContext(); - assertNull(ctx); - try { - String address = "http://localhost:8080/test"; - endpoint.publish(address); - } catch (IllegalArgumentException ex) { - assertTrue(ex.getCause() instanceof BusException); - assertEquals("BINDING_INCOMPATIBLE_ADDRESS_EXC", ((BusException)ex.getCause()).getCode()); + WebServiceContext ctx = greeter.getContext(); + assertNull(ctx); + try { + String address = "http://localhost:8080/test"; + endpoint.publish(address); + } catch (IllegalArgumentException ex) { + assertTrue(ex.getCause() instanceof BusException); + assertEquals("BINDING_INCOMPATIBLE_ADDRESS_EXC", ((BusException)ex.getCause()).getCode()); + } + ctx = greeter.getContext(); + + assertNotNull(ctx); } - ctx = greeter.getContext(); - - assertNotNull(ctx); } @Test @@ -158,15 +160,16 @@ public class EndpointImplTest extends AbstractJaxWsTest { serviceFactory.setInvoker(new BeanInvoker(hello)); serviceFactory.setServiceClass(HelloImpl.class); - EndpointImpl endpoint = new EndpointImpl(getBus(), hello, - new JaxWsServerFactoryBean(serviceFactory)); + try (EndpointImpl endpoint = new EndpointImpl(getBus(), hello, + new JaxWsServerFactoryBean(serviceFactory))) { - try { - String address = "http://localhost:8080/test"; - endpoint.publish(address); - } catch (IllegalArgumentException ex) { - assertTrue(ex.getCause() instanceof BusException); - assertEquals("BINDING_INCOMPATIBLE_ADDRESS_EXC", ((BusException)ex.getCause()).getCode()); + try { + String address = "http://localhost:8080/test"; + endpoint.publish(address); + } catch (IllegalArgumentException ex) { + assertTrue(ex.getCause() instanceof BusException); + assertEquals("BINDING_INCOMPATIBLE_ADDRESS_EXC", ((BusException)ex.getCause()).getCode()); + } } } @@ -189,20 +192,21 @@ public class EndpointImplTest extends AbstractJaxWsTest { @Test public void testPublishEndpointPermission() throws Exception { Hello service = new Hello(); - EndpointImpl ep = new EndpointImpl(getBus(), service, (String) null); - - System.setProperty(EndpointImpl.CHECK_PUBLISH_ENDPOINT_PERMISSON_PROPERTY, "true"); + try (EndpointImpl ep = new EndpointImpl(getBus(), service, (String) null)) { - try { + System.setProperty(EndpointImpl.CHECK_PUBLISH_ENDPOINT_PERMISSON_PROPERTY, "true"); + + try { + ep.publish("local://localhost:9090/hello"); + fail("Did not throw exception as expected"); + } catch (SecurityException e) { + // that's expected + } finally { + System.setProperty(EndpointImpl.CHECK_PUBLISH_ENDPOINT_PERMISSON_PROPERTY, "false"); + } + ep.publish("local://localhost:9090/hello"); - fail("Did not throw exception as expected"); - } catch (SecurityException e) { - // that's expected - } finally { - System.setProperty(EndpointImpl.CHECK_PUBLISH_ENDPOINT_PERMISSON_PROPERTY, "false"); } - - ep.publish("local://localhost:9090/hello"); } @Test @@ -213,20 +217,21 @@ public class EndpointImplTest extends AbstractJaxWsTest { serviceFactory.setInvoker(new BeanInvoker(greeter)); serviceFactory.setServiceClass(GreeterImpl.class); - EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, - new JaxWsServerFactoryBean(serviceFactory)); + try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, + new JaxWsServerFactoryBean(serviceFactory))) { - endpoint.getFeatures().add(new WSAddressingFeature()); - try { - String address = "http://localhost:8080/test"; - endpoint.publish(address); - } catch (IllegalArgumentException ex) { - assertTrue(ex.getCause() instanceof BusException); - assertEquals("BINDING_INCOMPATIBLE_ADDRESS_EXC", ((BusException)ex.getCause()).getCode()); + endpoint.getFeatures().add(new WSAddressingFeature()); + try { + String address = "http://localhost:8080/test"; + endpoint.publish(address); + } catch (IllegalArgumentException ex) { + assertTrue(ex.getCause() instanceof BusException); + assertEquals("BINDING_INCOMPATIBLE_ADDRESS_EXC", ((BusException)ex.getCause()).getCode()); + } + + assertTrue(serviceFactory.getFeatures().size() == 1); + assertTrue(serviceFactory.getFeatures().get(0) instanceof WSAddressingFeature); } - - assertTrue(serviceFactory.getFeatures().size() == 1); - assertTrue(serviceFactory.getFeatures().get(0) instanceof WSAddressingFeature); } @Test @@ -237,18 +242,19 @@ public class EndpointImplTest extends AbstractJaxWsTest { serviceFactory.setInvoker(new BeanInvoker(greeter)); serviceFactory.setServiceClass(HelloWsa.class); - EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, - new JaxWsServerFactoryBean(serviceFactory)); - try { - String address = "http://localhost:8080/test"; - endpoint.publish(address); - } catch (IllegalArgumentException ex) { - assertTrue(ex.getCause() instanceof BusException); - assertEquals("BINDING_INCOMPATIBLE_ADDRESS_EXC", ((BusException)ex.getCause()).getCode()); + try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, + new JaxWsServerFactoryBean(serviceFactory))) { + try { + String address = "http://localhost:8080/test"; + endpoint.publish(address); + } catch (IllegalArgumentException ex) { + assertTrue(ex.getCause() instanceof BusException); + assertEquals("BINDING_INCOMPATIBLE_ADDRESS_EXC", ((BusException)ex.getCause()).getCode()); + } + + assertEquals(1, serviceFactory.getFeatures().size()); + assertTrue(serviceFactory.getFeatures().get(0) instanceof WSAddressingFeature); } - - assertEquals(1, serviceFactory.getFeatures().size()); - assertTrue(serviceFactory.getFeatures().get(0) instanceof WSAddressingFeature); } @Test @@ -260,6 +266,7 @@ public class EndpointImplTest extends AbstractJaxWsTest { // CXF-6257 endpoint.publish("http://localhost:8080/test"); + endpoint.stop(); } static class EchoObserver implements MessageObserver { http://git-wip-us.apache.org/repos/asf/cxf/blob/6ef5be58/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointReferenceTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointReferenceTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointReferenceTest.java index 9cc521a..c2de0fc 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointReferenceTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointReferenceTest.java @@ -121,138 +121,143 @@ public class EndpointReferenceTest extends AbstractJaxWsTest { public void testServiceGetPortUsingEndpointReference() throws Exception { BusFactory.setDefaultBus(getBus()); GreeterImpl greeter1 = new GreeterImpl(); - EndpointImpl endpoint = new EndpointImpl(getBus(), greeter1, (String)null); - endpoint.publish("http://localhost:8080/test"); - - javax.xml.ws.Service s = javax.xml.ws.Service - .create(new QName("http://apache.org/hello_world_soap_http", "SoapPort")); - - InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml"); - Document doc = StaxUtils.read(is); - DOMSource erXML = new DOMSource(doc); - EndpointReference endpointReference = EndpointReference.readFrom(erXML); - - WebServiceFeature[] wfs = new WebServiceFeature[] {}; - - Greeter greeter = s.getPort(endpointReference, Greeter.class, wfs); - - String response = greeter.greetMe("John"); - - assertEquals("Hello John", response); + try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter1, (String)null)) { + endpoint.publish("http://localhost:8080/test"); + + javax.xml.ws.Service s = javax.xml.ws.Service + .create(new QName("http://apache.org/hello_world_soap_http", "SoapPort")); + + InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml"); + Document doc = StaxUtils.read(is); + DOMSource erXML = new DOMSource(doc); + EndpointReference endpointReference = EndpointReference.readFrom(erXML); + + WebServiceFeature[] wfs = new WebServiceFeature[] {}; + + Greeter greeter = s.getPort(endpointReference, Greeter.class, wfs); + + String response = greeter.greetMe("John"); + + assertEquals("Hello John", response); + } } @Test public void testEndpointReferenceGetPort() throws Exception { BusFactory.setDefaultBus(getBus()); GreeterImpl greeter1 = new GreeterImpl(); - EndpointImpl endpoint = new EndpointImpl(getBus(), greeter1, (String)null); - endpoint.publish("http://localhost:8080/test"); - - InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml"); - Document doc = StaxUtils.read(is); - DOMSource erXML = new DOMSource(doc); - EndpointReference endpointReference = EndpointReference.readFrom(erXML); - - WebServiceFeature[] wfs = new WebServiceFeature[] {}; - - Greeter greeter = endpointReference.getPort(Greeter.class, wfs); - - String response = greeter.greetMe("John"); - assertEquals("Hello John", response); + try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter1, (String)null)) { + endpoint.publish("http://localhost:8080/test"); + + InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml"); + Document doc = StaxUtils.read(is); + DOMSource erXML = new DOMSource(doc); + EndpointReference endpointReference = EndpointReference.readFrom(erXML); + + WebServiceFeature[] wfs = new WebServiceFeature[] {}; + + Greeter greeter = endpointReference.getPort(Greeter.class, wfs); + + String response = greeter.greetMe("John"); + assertEquals("Hello John", response); + } } @Test public void testEndpointGetEndpointReferenceSOAPBinding() throws Exception { GreeterImpl greeter = new GreeterImpl(); - EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, (String)null); - endpoint.publish("http://localhost:8080/test"); - - InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml"); - Document doc = StaxUtils.read(is); - Element referenceParameters = fetchElementByNameAttribute(doc.getDocumentElement(), - "wsa:ReferenceParameters", - ""); - EndpointReference endpointReference = endpoint.getEndpointReference(referenceParameters); - assertNotNull(endpointReference); - assertTrue(endpointReference instanceof W3CEndpointReference); - - //A returned W3CEndpointReferenceMUST also contain the specified referenceParameters. - //W3CEndpointReference wer = (W3CEndpointReference)endpointReference; - - endpoint.stop(); - } + try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, (String)null)) { + endpoint.publish("http://localhost:8080/test"); - @Test - @Ignore("Not implemented yet") - public void testEndpointGetEndpointReferenceXMLBinding() throws Exception { - org.apache.hello_world_xml_http.bare.Greeter greeter = - new org.apache.hello_world_xml_http.bare.GreeterImpl(); - EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, (String)null); - - endpoint.publish("http://localhost:8080/test"); - - try { InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml"); Document doc = StaxUtils.read(is); Element referenceParameters = fetchElementByNameAttribute(doc.getDocumentElement(), "wsa:ReferenceParameters", ""); - endpoint.getEndpointReference(referenceParameters); - - fail("Did not get expected UnsupportedOperationException"); - } catch (UnsupportedOperationException e) { - //do nothing + EndpointReference endpointReference = endpoint.getEndpointReference(referenceParameters); + assertNotNull(endpointReference); + assertTrue(endpointReference instanceof W3CEndpointReference); + + //A returned W3CEndpointReferenceMUST also contain the specified referenceParameters. + //W3CEndpointReference wer = (W3CEndpointReference)endpointReference; + endpoint.stop(); } - - endpoint.stop(); } @Test - public void testEndpointGetEndpointReferenceW3C() throws Exception { - GreeterImpl greeter = new GreeterImpl(); - EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, (String)null); - - endpoint.publish("http://localhost:8080/test"); - - InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml"); - Document doc = StaxUtils.read(is); - Element referenceParameters = fetchElementByNameAttribute(doc.getDocumentElement(), - "wsa:ReferenceParameters", - ""); - EndpointReference endpointReference = endpoint.getEndpointReference(W3CEndpointReference.class, - referenceParameters); - assertNotNull(endpointReference); - - assertTrue(endpointReference instanceof W3CEndpointReference); - - //A returned W3CEndpointReferenceMUST also contain the specified referenceParameters. - //W3CEndpointReference wer = (W3CEndpointReference)endpointReference; + @Ignore("Not implemented yet") + public void testEndpointGetEndpointReferenceXMLBinding() throws Exception { + org.apache.hello_world_xml_http.bare.Greeter greeter = + new org.apache.hello_world_xml_http.bare.GreeterImpl(); + try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, (String)null)) { - endpoint.stop(); - } + endpoint.publish("http://localhost:8080/test"); + try { + InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml"); + Document doc = StaxUtils.read(is); + Element referenceParameters = fetchElementByNameAttribute(doc.getDocumentElement(), + "wsa:ReferenceParameters", + ""); + endpoint.getEndpointReference(referenceParameters); + + fail("Did not get expected UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + //do nothing + } + + endpoint.stop(); + } + } @Test - public void testEndpointGetEndpointReferenceInvalid() throws Exception { + public void testEndpointGetEndpointReferenceW3C() throws Exception { GreeterImpl greeter = new GreeterImpl(); - EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, (String)null); + try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, (String)null)) { - endpoint.publish("http://localhost:8080/test"); - - try { + endpoint.publish("http://localhost:8080/test"); + InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml"); Document doc = StaxUtils.read(is); Element referenceParameters = fetchElementByNameAttribute(doc.getDocumentElement(), "wsa:ReferenceParameters", ""); - endpoint.getEndpointReference(MyEndpointReference.class, referenceParameters); - - fail("Did not get expected WebServiceException"); - } catch (WebServiceException e) { - // do nothing + EndpointReference endpointReference = endpoint.getEndpointReference(W3CEndpointReference.class, + referenceParameters); + assertNotNull(endpointReference); + + assertTrue(endpointReference instanceof W3CEndpointReference); + + //A returned W3CEndpointReferenceMUST also contain the specified referenceParameters. + //W3CEndpointReference wer = (W3CEndpointReference)endpointReference; + + endpoint.stop(); + } + } + + + @Test + public void testEndpointGetEndpointReferenceInvalid() throws Exception { + GreeterImpl greeter = new GreeterImpl(); + try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, (String)null)) { + + endpoint.publish("http://localhost:8080/test"); + + try { + InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml"); + Document doc = StaxUtils.read(is); + Element referenceParameters = fetchElementByNameAttribute(doc.getDocumentElement(), + "wsa:ReferenceParameters", + ""); + endpoint.getEndpointReference(MyEndpointReference.class, referenceParameters); + + fail("Did not get expected WebServiceException"); + } catch (WebServiceException e) { + // do nothing + } + + endpoint.stop(); } - - endpoint.stop(); } @Test @@ -298,22 +303,23 @@ public class EndpointReferenceTest extends AbstractJaxWsTest { public void testProviderGetPort() throws Exception { BusFactory.setDefaultBus(getBus()); GreeterImpl greeter1 = new GreeterImpl(); - EndpointImpl endpoint = new EndpointImpl(getBus(), greeter1, (String)null); - endpoint.publish("http://localhost:8080/test"); - - ProviderImpl provider = new ProviderImpl(); - - InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml"); - Document doc = StaxUtils.read(is); - DOMSource erXML = new DOMSource(doc); - EndpointReference endpointReference = EndpointReference.readFrom(erXML); - - WebServiceFeature[] wfs = new WebServiceFeature[] {}; - - Greeter greeter = provider.getPort(endpointReference, Greeter.class, wfs); - - String response = greeter.greetMe("John"); - assertEquals("Hello John", response); + try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter1, (String)null)) { + endpoint.publish("http://localhost:8080/test"); + + ProviderImpl provider = new ProviderImpl(); + + InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml"); + Document doc = StaxUtils.read(is); + DOMSource erXML = new DOMSource(doc); + EndpointReference endpointReference = EndpointReference.readFrom(erXML); + + WebServiceFeature[] wfs = new WebServiceFeature[] {}; + + Greeter greeter = provider.getPort(endpointReference, Greeter.class, wfs); + + String response = greeter.greetMe("John"); + assertEquals("Hello John", response); + } } final class MyEndpointReference extends EndpointReference { http://git-wip-us.apache.org/repos/asf/cxf/blob/6ef5be58/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderTest.java index eb25126..5d74c89 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/provider/ProviderTest.java @@ -28,34 +28,36 @@ import org.junit.Test; public class ProviderTest extends AbstractJaxWsTest { @Test public void testInvocation() throws Exception { - EndpointImpl ep = new EndpointImpl(getBus(), new PayloadProvider(), (String) null); - ep.publish("local://localhost:9000/Provider"); - - Node response = invoke("local://localhost:9000/Provider", - LocalTransportFactory.TRANSPORT_ID, - "/org/apache/cxf/jaxws/sayHi.xml"); - - assertNotNull(response); - assertNoFault(response); - - addNamespace("j", "http://service.jaxws.cxf.apache.org/"); - assertValid("//s:Body/j:sayHi", response); + try (EndpointImpl ep = new EndpointImpl(getBus(), new PayloadProvider(), (String) null)) { + ep.publish("local://localhost:9000/Provider"); + + Node response = invoke("local://localhost:9000/Provider", + LocalTransportFactory.TRANSPORT_ID, + "/org/apache/cxf/jaxws/sayHi.xml"); + + assertNotNull(response); + assertNoFault(response); + + addNamespace("j", "http://service.jaxws.cxf.apache.org/"); + assertValid("//s:Body/j:sayHi", response); + } } @Test public void testCXF1852() throws Exception { - EndpointImpl ep = new EndpointImpl(getBus(), new PayloadProvider2(), (String) null); - ep.publish("local://localhost:9001/Provider2"); - - Node response = invoke("local://localhost:9001/Provider2", - LocalTransportFactory.TRANSPORT_ID, - "/org/apache/cxf/jaxws/sayHi.xml"); - - assertNotNull(response); - assertNoFault(response); - - addNamespace("j", "http://service.jaxws.cxf.apache.org/"); - assertValid("//s:Body/j:sayHi", response); + try (EndpointImpl ep = new EndpointImpl(getBus(), new PayloadProvider2(), (String) null)) { + ep.publish("local://localhost:9001/Provider2"); + + Node response = invoke("local://localhost:9001/Provider2", + LocalTransportFactory.TRANSPORT_ID, + "/org/apache/cxf/jaxws/sayHi.xml"); + + assertNotNull(response); + assertNoFault(response); + + addNamespace("j", "http://service.jaxws.cxf.apache.org/"); + assertValid("//s:Body/j:sayHi", response); + } } public static class PayloadProvider2 extends PayloadProvider { http://git-wip-us.apache.org/repos/asf/cxf/blob/6ef5be58/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/HttpNumberFactoryImpl.java ---------------------------------------------------------------------- diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/HttpNumberFactoryImpl.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/HttpNumberFactoryImpl.java index d51c8a0..16af0ad 100644 --- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/HttpNumberFactoryImpl.java +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/HttpNumberFactoryImpl.java @@ -64,6 +64,7 @@ public class HttpNumberFactoryImpl extends NumberFactoryImpl { new EndpointImpl(bus, servant, bindingId, wsdlLocation); ep.setEndpointName(new QName(NUMBER_SERVICE_QNAME.getNamespaceURI(), "NumberPort")); ep.publish(getServantAddressRoot()); + endpoints.add(ep); templateEpr = ep.getServer().getDestination().getAddress(); } } http://git-wip-us.apache.org/repos/asf/cxf/blob/6ef5be58/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/ManualHttpMulitplexClientServerTest.java ---------------------------------------------------------------------- diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/ManualHttpMulitplexClientServerTest.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/ManualHttpMulitplexClientServerTest.java index 0ffeb95..3419adf 100644 --- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/ManualHttpMulitplexClientServerTest.java +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/ManualHttpMulitplexClientServerTest.java @@ -44,6 +44,7 @@ import org.apache.cxf.testutil.common.AbstractBusTestServerBase; import org.apache.cxf.testutil.common.TestUtil; import org.apache.cxf.ws.addressing.EndpointReferenceType; import org.apache.cxf.ws.addressing.EndpointReferenceUtils; + import org.junit.BeforeClass; import org.junit.Test; @@ -55,14 +56,17 @@ public class ManualHttpMulitplexClientServerTest extends AbstractBusClientServer public static class Server extends AbstractBusTestServerBase { Endpoint ep; + ManualNumberFactoryImpl implementor; protected void run() { setBus(BusFactory.getDefaultBus()); - Object implementor = new ManualNumberFactoryImpl(getBus(), PORT); + implementor = new ManualNumberFactoryImpl(getBus(), PORT); ep = Endpoint.publish(FACTORY_ADDRESS, implementor); } - public void tearDown() { + public void tearDown() throws Exception { ep.stop(); ep = null; + implementor.stop(); + implementor = null; } public static void main(String[] args) { http://git-wip-us.apache.org/repos/asf/cxf/blob/6ef5be58/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/ManualNumberFactoryImpl.java ---------------------------------------------------------------------- diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/ManualNumberFactoryImpl.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/ManualNumberFactoryImpl.java index 769d9d8..9d93a2e 100644 --- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/ManualNumberFactoryImpl.java +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/ManualNumberFactoryImpl.java @@ -58,6 +58,7 @@ public class ManualNumberFactoryImpl extends NumberFactoryImpl { new EndpointImpl(bus, servant, bindingId, wsdlLocation); ep.setEndpointName(new QName(NUMBER_SERVICE_QNAME.getNamespaceURI(), "NumberPort")); ep.publish(getServantAddressRoot()); + endpoints.add(ep); templateEpr = ep.getServer().getDestination().getAddress(); } } http://git-wip-us.apache.org/repos/asf/cxf/blob/6ef5be58/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexClientServerTest.java ---------------------------------------------------------------------- diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexClientServerTest.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexClientServerTest.java index 5a50db8..b32a014 100644 --- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexClientServerTest.java +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexClientServerTest.java @@ -54,13 +54,20 @@ public class MultiplexClientServerTest extends AbstractBusClientServerTestBase { public static class Server extends AbstractBusTestServerBase { Endpoint ep; + NumberFactoryImpl implementor; protected void run() { - Object implementor = new NumberFactoryImpl(BusFactory.getDefaultBus(), PORT); + implementor = new NumberFactoryImpl(BusFactory.getDefaultBus(), PORT); ep = Endpoint.publish(FACTORY_ADDRESS, implementor); } public void tearDown() { ep.stop(); ep = null; + try { + implementor.stop(); + } catch (Exception e) { + //ignore + } + implementor = null; } public static void main(String[] args) { http://git-wip-us.apache.org/repos/asf/cxf/blob/6ef5be58/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexHttpAddressClientServerTest.java ---------------------------------------------------------------------- diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexHttpAddressClientServerTest.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexHttpAddressClientServerTest.java index 10994c8..d358eb0 100644 --- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexHttpAddressClientServerTest.java +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexHttpAddressClientServerTest.java @@ -59,14 +59,17 @@ public class MultiplexHttpAddressClientServerTest extends AbstractBusClientServe public static class Server extends AbstractBusTestServerBase { Endpoint ep; + HttpNumberFactoryImpl implementor; protected void run() { setBus(new SpringBusFactory().createBus("org/apache/cxf/systest/factory_pattern/cxf.xml")); - Object implementor = new HttpNumberFactoryImpl(getBus(), PORT); + implementor = new HttpNumberFactoryImpl(getBus(), PORT); ep = Endpoint.publish(FACTORY_ADDRESS, implementor); } - public void tearDown() { + public void tearDown() throws Exception { ep.stop(); ep = null; + implementor.stop(); + implementor = null; } public static void main(String[] args) { http://git-wip-us.apache.org/repos/asf/cxf/blob/6ef5be58/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/NumberFactoryImpl.java ---------------------------------------------------------------------- diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/NumberFactoryImpl.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/NumberFactoryImpl.java index d218440..876cdf1 100644 --- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/NumberFactoryImpl.java +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/NumberFactoryImpl.java @@ -19,6 +19,9 @@ package org.apache.cxf.systest.factory_pattern; +import java.util.LinkedList; +import java.util.List; + import javax.jws.WebService; import javax.xml.namespace.QName; import javax.xml.transform.Source; @@ -49,11 +52,18 @@ public class NumberFactoryImpl implements NumberFactory { protected NumberImpl servant; protected Bus bus; protected String port; + protected List<AutoCloseable> endpoints = new LinkedList<AutoCloseable>(); public NumberFactoryImpl(Bus b, String p) { bus = b; port = p; } + + public void stop() throws Exception { + for (AutoCloseable ep: endpoints) { + ep.close(); + } + } public W3CEndpointReference create(String id) { @@ -92,6 +102,8 @@ public class NumberFactoryImpl implements NumberFactory { servant, bindingId, wsdlLocation); ep.setEndpointName(new QName(NUMBER_SERVICE_QNAME.getNamespaceURI(), "NumberPort")); ep.publish(getServantAddressRoot()); + endpoints.add(ep); + templateEpr = ep.getServer().getDestination().getAddress(); // jms port @@ -102,6 +114,7 @@ public class NumberFactoryImpl implements NumberFactory { ep.publish(); ep.getServer().getEndpoint().getInInterceptors().add(new LoggingInInterceptor()); ep.getServer().getEndpoint().getOutInterceptors().add(new LoggingOutInterceptor()); + endpoints.add(ep); } } http://git-wip-us.apache.org/repos/asf/cxf/blob/6ef5be58/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_responses/Server.java ---------------------------------------------------------------------- diff --git a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_responses/Server.java b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_responses/Server.java index 8eb8ad4..5665656 100644 --- a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_responses/Server.java +++ b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_responses/Server.java @@ -25,15 +25,22 @@ import org.apache.cxf.testutil.common.AbstractBusTestServerBase; public class Server extends AbstractBusTestServerBase { static final String PORT = allocatePort(Server.class); + EndpointImpl ep; protected void run() { Object implementor = new HelloImpl(); String address = "http://localhost:" + PORT + "/wsa/responses"; - EndpointImpl ep = new EndpointImpl(BusFactory.getThreadDefaultBus(), + ep = new EndpointImpl(BusFactory.getThreadDefaultBus(), implementor, null, getWsdl()); ep.publish(address); } + public void tearDown() throws Exception { + if (ep != null) { + ep.close(); + } + ep = null; + } public static void main(String[] args) { try {
