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);
}
}
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.
}
}
}
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());
}
Aggregations