Search in sources :

Example 21 with GreeterImpl

use of org.apache.hello_world_soap_http.GreeterImpl in project cxf by apache.

the class EndpointImplTest method testAddWSAFeature.

@Test
public void testAddWSAFeature() throws Exception {
    GreeterImpl greeter = new GreeterImpl();
    JaxWsServiceFactoryBean serviceFactory = new JaxWsServiceFactoryBean();
    serviceFactory.setBus(getBus());
    serviceFactory.setInvoker(new BeanInvoker(greeter));
    serviceFactory.setServiceClass(GreeterImpl.class);
    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());
        }
        assertTrue(serviceFactory.getFeatures().size() == 1);
        assertTrue(serviceFactory.getFeatures().get(0) instanceof WSAddressingFeature);
    }
}
Also used : JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) BeanInvoker(org.apache.cxf.service.invoker.BeanInvoker) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) BusException(org.apache.cxf.BusException) Test(org.junit.Test)

Example 22 with GreeterImpl

use of org.apache.hello_world_soap_http.GreeterImpl in project cxf by apache.

the class EndpointImplTest method testEndpointStop.

@Test
public void testEndpointStop() throws Exception {
    String address = "http://localhost:8080/test";
    GreeterImpl greeter = new GreeterImpl();
    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.
        }
    }
}
Also used : GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) WebServiceContext(javax.xml.ws.WebServiceContext) BusException(org.apache.cxf.BusException) Test(org.junit.Test)

Example 23 with GreeterImpl

use of org.apache.hello_world_soap_http.GreeterImpl in project cxf by apache.

the class ConfiguredEndpointTest method doTestDefaultServerEndpoint.

private void doTestDefaultServerEndpoint() {
    Object implementor = new GreeterImpl();
    EndpointImpl ei = (EndpointImpl) (javax.xml.ws.Endpoint.create(implementor));
    ei.publish("http://localhost/greeter");
    JaxWsEndpointImpl endpoint = (JaxWsEndpointImpl) ei.getEndpoint();
    assertEquals("Unexpected bean name", PORT_NAME.toString() + ".endpoint", endpoint.getBeanName());
    assertFalse("Unexpected value for property validating", Boolean.TRUE.equals(endpoint.get(Message.SCHEMA_VALIDATION_ENABLED)));
    List<Interceptor<? extends Message>> interceptors = endpoint.getInInterceptors();
    assertNull("Unexpected test interceptor", findTestInterceptor(interceptors));
    interceptors = endpoint.getOutInterceptors();
    assertNull("Unexpected test interceptor", findTestInterceptor(interceptors));
    interceptors = endpoint.getInFaultInterceptors();
    assertNull("Unexpected test interceptor", findTestInterceptor(interceptors));
    interceptors = endpoint.getOutFaultInterceptors();
    assertNull("Unexpected test interceptor", findTestInterceptor(interceptors));
    org.apache.cxf.service.ServiceImpl svc = (org.apache.cxf.service.ServiceImpl) endpoint.getService();
    assertEquals("Unexpected bean name", SERVICE_NAME.toString(), svc.getBeanName());
    interceptors = svc.getInInterceptors();
    assertNull("Unexpected test interceptor", findTestInterceptor(interceptors));
    interceptors = svc.getOutInterceptors();
    assertNull("Unexpected test interceptor", findTestInterceptor(interceptors));
    interceptors = svc.getInFaultInterceptors();
    assertNull("Unexpected test interceptor", findTestInterceptor(interceptors));
    interceptors = svc.getOutFaultInterceptors();
    assertNull("Unexpected test interceptor", findTestInterceptor(interceptors));
}
Also used : Message(org.apache.cxf.message.Message) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor)

Example 24 with GreeterImpl

use of org.apache.hello_world_soap_http.GreeterImpl in project cxf by apache.

the class ConfiguredEndpointTest method doTestConfiguredServerEndpoint.

private void doTestConfiguredServerEndpoint(Object expectedValidionValue, String configFile) {
    SpringBusFactory sf = new SpringBusFactory();
    factory = sf;
    BusFactory.setDefaultBus(null);
    BusFactory.setDefaultBus(sf.createBus(configFile));
    initializeBus();
    System.setProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME, SpringBusFactory.class.getName());
    Object implementor = new GreeterImpl();
    EndpointImpl ei = (EndpointImpl) (javax.xml.ws.Endpoint.create(implementor));
    ei.publish("http://localhost/greeter");
    JaxWsEndpointImpl endpoint = (JaxWsEndpointImpl) ei.getEndpoint();
    assertEquals("Unexpected bean name", PORT_NAME.toString() + ".endpoint", endpoint.getBeanName());
    assertEquals("Unexpected value for property validating", expectedValidionValue, ei.getProperties().get(Message.SCHEMA_VALIDATION_ENABLED));
    List<Interceptor<? extends Message>> interceptors = endpoint.getInInterceptors();
    assertEquals("Unexpected number of interceptors.", 5, interceptors.size());
    assertEquals("Unexpected interceptor id.", "endpoint-in", findTestInterceptor(interceptors).getId());
    interceptors = endpoint.getOutInterceptors();
    assertEquals("Unexpected number of interceptors.", 5, interceptors.size());
    assertEquals("Unexpected interceptor id.", "endpoint-out", findTestInterceptor(interceptors).getId());
    interceptors = endpoint.getInFaultInterceptors();
    assertEquals("Unexpected number of interceptors.", 2, interceptors.size());
    assertEquals("Unexpected interceptor id.", "endpoint-in-fault", findTestInterceptor(interceptors).getId());
    interceptors = endpoint.getOutFaultInterceptors();
    assertEquals("Unexpected number of interceptors.", 2, interceptors.size());
    assertEquals("Unexpected interceptor id.", "endpoint-out-fault", findTestInterceptor(interceptors).getId());
    org.apache.cxf.service.ServiceImpl svc = (org.apache.cxf.service.ServiceImpl) endpoint.getService();
    assertEquals("Unexpected bean name.", SERVICE_NAME.toString(), svc.getBeanName());
    interceptors = svc.getInInterceptors();
    assertEquals("Unexpected number of interceptors.", 1, interceptors.size());
    assertEquals("Unexpected interceptor id.", "service-in", findTestInterceptor(interceptors).getId());
    interceptors = svc.getOutInterceptors();
    assertEquals("Unexpected number of interceptors.", 1, interceptors.size());
    assertEquals("Unexpected interceptor id.", "service-out", findTestInterceptor(interceptors).getId());
    interceptors = svc.getInFaultInterceptors();
    assertEquals("Unexpected number of interceptors.", 1, interceptors.size());
    assertEquals("Unexpected interceptor id.", "service-in-fault", findTestInterceptor(interceptors).getId());
    interceptors = svc.getOutFaultInterceptors();
    assertEquals("Unexpected number of interceptors.", 1, interceptors.size());
    assertEquals("Unexpected interceptor id.", "service-out-fault", findTestInterceptor(interceptors).getId());
}
Also used : Message(org.apache.cxf.message.Message) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor)

Example 25 with GreeterImpl

use of org.apache.hello_world_soap_http.GreeterImpl in project cxf by apache.

the class EndpointReferenceTest method testEndpointGetEndpointReferenceSOAPBinding.

@Test
public void testEndpointGetEndpointReferenceSOAPBinding() throws Exception {
    GreeterImpl greeter = new GreeterImpl();
    try (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();
    }
}
Also used : InputStream(java.io.InputStream) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) Element(org.w3c.dom.Element) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) Document(org.w3c.dom.Document) EndpointReference(javax.xml.ws.EndpointReference) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) Test(org.junit.Test)

Aggregations

GreeterImpl (org.apache.hello_world_soap_http.GreeterImpl)28 Test (org.junit.Test)17 URL (java.net.URL)7 BeanInvoker (org.apache.cxf.service.invoker.BeanInvoker)7 InputStream (java.io.InputStream)6 JaxWsServiceFactoryBean (org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean)6 Document (org.w3c.dom.Document)6 EndpointReference (javax.xml.ws.EndpointReference)5 W3CEndpointReference (javax.xml.ws.wsaddressing.W3CEndpointReference)5 ReflectionServiceFactoryBean (org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean)5 BusException (org.apache.cxf.BusException)4 ServerFactoryBean (org.apache.cxf.frontend.ServerFactoryBean)4 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)4 Service (org.apache.cxf.service.Service)4 QName (javax.xml.namespace.QName)3 DOMSource (javax.xml.transform.dom.DOMSource)3 WebServiceContext (javax.xml.ws.WebServiceContext)3 WebServiceFeature (javax.xml.ws.WebServiceFeature)3 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)3 EndpointImpl (org.apache.cxf.jaxws.EndpointImpl)3