Search in sources :

Example 16 with GreeterImpl

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

the class WSAFeatureTest method testServerFactory.

@Test
public void testServerFactory() {
    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
    sf.getFeatures().add(new WSAddressingFeature());
    sf.setServiceBean(new GreeterImpl());
    sf.setAddress("http://localhost:" + PORT + "/test");
    sf.setStart(false);
    sf.setBus(getBus());
    Server server = sf.create();
    Endpoint endpoint = server.getEndpoint();
    checkAddressInterceptors(endpoint.getInInterceptors());
}
Also used : WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) Server(org.apache.cxf.endpoint.Server) Endpoint(org.apache.cxf.endpoint.Endpoint) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) Test(org.junit.Test) AbstractCXFTest(org.apache.cxf.test.AbstractCXFTest)

Example 17 with GreeterImpl

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

the class JaxWsServiceFactoryBeanTest method testEndpoint.

@Test
public void testEndpoint() throws Exception {
    ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(resource);
    bean.setWsdlURL(resource.toString());
    Bus bus = getBus();
    bean.setBus(bus);
    bean.setServiceClass(GreeterImpl.class);
    BeanInvoker invoker = new BeanInvoker(new GreeterImpl());
    bean.setInvoker(invoker);
    Service service = bean.create();
    String ns = "http://apache.org/hello_world_soap_http";
    assertEquals("SOAPService", service.getName().getLocalPart());
    assertEquals(ns, service.getName().getNamespaceURI());
    InterfaceInfo intf = service.getServiceInfos().get(0).getInterface();
    OperationInfo op = intf.getOperation(new QName(ns, "sayHi"));
    Class<?> wrapper = op.getInput().getMessageParts().get(0).getTypeClass();
    assertNotNull(wrapper);
    wrapper = op.getOutput().getMessageParts().get(0).getTypeClass();
    assertNotNull(wrapper);
    assertEquals(invoker, service.getInvoker());
    op = intf.getOperation(new QName(ns, "testDocLitFault"));
    Collection<FaultInfo> faults = op.getFaults();
    assertEquals(2, faults.size());
    FaultInfo f = op.getFault(new QName(ns, "BadRecordLitFault"));
    assertNotNull(f);
    Class<?> c = f.getProperty(Class.class.getName(), Class.class);
    assertNotNull(c);
    assertEquals(1, f.getMessageParts().size());
    MessagePartInfo mpi = f.getMessagePartByIndex(0);
    assertNotNull(mpi.getTypeClass());
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) Bus(org.apache.cxf.Bus) FaultInfo(org.apache.cxf.service.model.FaultInfo) QName(javax.xml.namespace.QName) BeanInvoker(org.apache.cxf.service.invoker.BeanInvoker) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) URL(java.net.URL) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean) Test(org.junit.Test) AbstractJaxWsTest(org.apache.cxf.jaxws.AbstractJaxWsTest)

Example 18 with GreeterImpl

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

the class EndpointReferenceTest method testEndpointGetEndpointReferenceW3C.

@Test
public void testEndpointGetEndpointReferenceW3C() 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(W3CEndpointReference.class, 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)

Example 19 with GreeterImpl

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

the class JaxWsClientTest method testEndpoint.

@Test
public void testEndpoint() throws Exception {
    ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(resource);
    bean.setWsdlURL(resource.toString());
    bean.setBus(getBus());
    bean.setServiceClass(GreeterImpl.class);
    GreeterImpl greeter = new GreeterImpl();
    BeanInvoker invoker = new BeanInvoker(greeter);
    bean.setInvoker(invoker);
    Service service = bean.create();
    String namespace = "http://apache.org/hello_world_soap_http";
    EndpointInfo ei = service.getServiceInfos().get(0).getEndpoint(new QName(namespace, "SoapPort"));
    JaxWsEndpointImpl endpoint = new JaxWsEndpointImpl(getBus(), service, ei);
    ClientImpl client = new ClientImpl(getBus(), endpoint);
    BindingOperationInfo bop = ei.getBinding().getOperation(new QName(namespace, "sayHi"));
    assertNotNull(bop);
    bop = bop.getUnwrappedOperation();
    assertNotNull(bop);
    MessagePartInfo part = bop.getOutput().getMessageParts().get(0);
    assertEquals(0, part.getIndex());
    d.setMessageObserver(new MessageReplayObserver("sayHiResponse.xml"));
    Object[] ret = client.invoke(bop, new Object[] { "hi" }, null);
    assertNotNull(ret);
    assertEquals("Wrong number of return objects", 1, ret.length);
    // test fault handling
    bop = ei.getBinding().getOperation(new QName(namespace, "testDocLitFault"));
    bop = bop.getUnwrappedOperation();
    d.setMessageObserver(new MessageReplayObserver("testDocLitFault.xml"));
    try {
        client.invoke(bop, new Object[] { "BadRecordLitFault" }, null);
        fail("Should have returned a fault!");
    } catch (BadRecordLitFault fault) {
        assertEquals("foo", fault.getFaultInfo().trim());
        assertEquals("Hadrian did it.", fault.getMessage());
    }
    try {
        client.getEndpoint().getOutInterceptors().add(new NestedFaultThrower());
        client.getEndpoint().getOutInterceptors().add(new FaultThrower());
        client.invoke(bop, new Object[] { "BadRecordLitFault" }, null);
        fail("Should have returned a fault!");
    } catch (Fault fault) {
        assertTrue(fault.getMessage().indexOf("Foo") >= 0);
    }
    client.close();
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) QName(javax.xml.namespace.QName) BeanInvoker(org.apache.cxf.service.invoker.BeanInvoker) Service(org.apache.cxf.service.Service) ClientImpl(org.apache.cxf.endpoint.ClientImpl) BadRecordLitFault(org.apache.hello_world_soap_http.BadRecordLitFault) Fault(org.apache.cxf.interceptor.Fault) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) URL(java.net.URL) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BadRecordLitFault(org.apache.hello_world_soap_http.BadRecordLitFault) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean) Test(org.junit.Test)

Example 20 with GreeterImpl

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

the class EndpointImplTest method testEndpoint.

@Test
public void testEndpoint() 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);
        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
        }
    }
}
Also used : GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) WebServiceContext(javax.xml.ws.WebServiceContext) BusException(org.apache.cxf.BusException) Source(javax.xml.transform.Source) 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