Search in sources :

Example 6 with Hello

use of org.apache.cxf.jaxws.service.Hello in project cxf by apache.

the class CodeFirstTest method testEndpoint.

@Test
public void testEndpoint() throws Exception {
    Hello service = new Hello();
    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);
    }
}
Also used : Executor(java.util.concurrent.Executor) Hello(org.apache.cxf.jaxws.service.Hello) Node(org.w3c.dom.Node) Test(org.junit.Test)

Example 7 with Hello

use of org.apache.cxf.jaxws.service.Hello in project cxf by apache.

the class CodeFirstTest method testException.

@Test
public void testException() throws Exception {
    Hello serviceImpl = new Hello();
    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.
        }
    }
}
Also used : AddNumbersException(org.apache.cxf.jaxws.service.AddNumbersException) AddNumbersSubException(org.apache.cxf.jaxws.service.AddNumbersSubException) Hello(org.apache.cxf.jaxws.service.Hello) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) QName(javax.xml.namespace.QName) ArrayServiceImpl(org.apache.cxf.jaxws.service.ArrayServiceImpl) FooServiceImpl(org.apache.cxf.jaxws.service.FooServiceImpl) HelloInterface(org.apache.cxf.jaxws.service.HelloInterface) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Test(org.junit.Test)

Example 8 with Hello

use of org.apache.cxf.jaxws.service.Hello in project cxf by apache.

the class JaxWsServerFactoryBeanTest method testPostConstructBlocked.

@Test
public void testPostConstructBlocked() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceClass(Hello.class);
    Hello bean = new Hello();
    factory.setServiceBean(bean);
    String address = "http://localhost:9001/jaxwstest";
    factory.setAddress(address);
    factory.setBlockPostConstruct(true);
    factory.create();
    assertFalse("PostConstruct is called", bean.isPostConstructCalled());
}
Also used : Hello(org.apache.cxf.jaxws.service.Hello) Test(org.junit.Test)

Aggregations

Hello (org.apache.cxf.jaxws.service.Hello)8 Test (org.junit.Test)8 QName (javax.xml.namespace.QName)3 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)2 ArrayServiceImpl (org.apache.cxf.jaxws.service.ArrayServiceImpl)2 FooServiceImpl (org.apache.cxf.jaxws.service.FooServiceImpl)2 HelloInterface (org.apache.cxf.jaxws.service.HelloInterface)2 ArrayList (java.util.ArrayList)1 Executor (java.util.concurrent.Executor)1 Binding (javax.xml.ws.Binding)1 Endpoint (javax.xml.ws.Endpoint)1 BindingConfiguration (org.apache.cxf.binding.BindingConfiguration)1 Soap12 (org.apache.cxf.binding.soap.Soap12)1 SoapBindingConfiguration (org.apache.cxf.binding.soap.SoapBindingConfiguration)1 DataBinding (org.apache.cxf.databinding.DataBinding)1 SourceDataBinding (org.apache.cxf.databinding.source.SourceDataBinding)1 Client (org.apache.cxf.endpoint.Client)1 LoggingFeature (org.apache.cxf.ext.logging.LoggingFeature)1 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)1 JAXBDataBinding (org.apache.cxf.jaxb.JAXBDataBinding)1