use of org.apache.cxf.jaxws.service.Hello in project cxf by apache.
the class CodeFirstTest method testClient.
@Test
public void testClient() throws Exception {
Hello serviceImpl = new Hello();
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<>();
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());
}
}
use of org.apache.cxf.jaxws.service.Hello in project cxf by apache.
the class EndpointImplTest method testEndpointPublishAfterGetBinding.
@Test
public void testEndpointPublishAfterGetBinding() throws Exception {
Endpoint endpoint = Endpoint.create(new Hello());
Binding binding = endpoint.getBinding();
assertNotNull(binding);
// CXF-6257
endpoint.publish("http://localhost:8080/test");
endpoint.stop();
}
use of org.apache.cxf.jaxws.service.Hello in project cxf by apache.
the class EndpointImplTest method testPublishEndpointPermission.
@Test
public void testPublishEndpointPermission() throws Exception {
Hello service = new Hello();
try (EndpointImpl ep = new EndpointImpl(getBus(), service, (String) null)) {
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");
}
}
use of org.apache.cxf.jaxws.service.Hello in project cxf by apache.
the class JaxWsServerFactoryBeanTest method testPostConstructCalled.
@Test
public void testPostConstructCalled() 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.create();
assertTrue("PostConstruct is not called", bean.isPostConstructCalled());
}
use of org.apache.cxf.jaxws.service.Hello in project cxf by apache.
the class SpringBeansTest method testEndpoints.
@Test
public void testEndpoints() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/jaxws/spring/endpoints.xml" });
EndpointImpl ep = getEndpointImplBean("simple", ctx);
assertNotNull(ep.getImplementor());
assertNotNull(ep.getServer());
ep = getEndpointImplBean("simpleWithAddress", ctx);
if (!(ep.getImplementor() instanceof org.apache.hello_world_soap_http.GreeterImpl)) {
fail("can't get the right implementor object");
}
assertEquals("http://localhost:8080/simpleWithAddress", ep.getServer().getEndpoint().getEndpointInfo().getAddress());
ep = getEndpointImplBean("inlineImplementor", ctx);
if (!(ep.getImplementor() instanceof org.apache.hello_world_soap_http.GreeterImpl)) {
fail("can't get the right implementor object");
}
org.apache.hello_world_soap_http.GreeterImpl impl = (org.apache.hello_world_soap_http.GreeterImpl) ep.getImplementor();
assertEquals("The property was not injected rightly", impl.getPrefix(), "hello");
assertNotNull(ep.getServer());
ep = getEndpointImplBean("inlineInvoker", ctx);
assertTrue(ep.getInvoker() instanceof NullInvoker);
assertTrue(ep.getService().getInvoker() instanceof NullInvoker);
ep = getEndpointImplBean("simpleWithBindingUri", ctx);
assertEquals("get the wrong bindingId", ep.getBindingUri(), "http://cxf.apache.org/bindings/xformat");
assertEquals("get a wrong transportId", "http://cxf.apache.org/transports/local", ep.getTransportId());
ep = getEndpointImplBean("simpleWithBinding", ctx);
BindingConfiguration bc = ep.getBindingConfig();
assertTrue(bc instanceof SoapBindingConfiguration);
SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc;
assertTrue(sbc.getVersion() instanceof Soap12);
assertTrue("the soap configure should set isMtomEnabled to be true", sbc.isMtomEnabled());
ep = getEndpointImplBean("implementorClass", ctx);
assertEquals(Hello.class, ep.getImplementorClass());
assertTrue(ep.getImplementor().getClass() == Object.class);
ep = getEndpointImplBean("epWithProps", ctx);
assertEquals("bar", ep.getProperties().get("foo"));
ep = getEndpointImplBean("classImpl", ctx);
assertTrue(ep.getImplementor() instanceof Hello);
QName name = ep.getServer().getEndpoint().getService().getName();
assertEquals("http://service.jaxws.cxf.apache.org/service", name.getNamespaceURI());
assertEquals("HelloServiceCustomized", name.getLocalPart());
name = ep.getServer().getEndpoint().getEndpointInfo().getName();
assertEquals("http://service.jaxws.cxf.apache.org/endpoint", name.getNamespaceURI());
assertEquals("HelloEndpointCustomized", name.getLocalPart());
Object bean = ctx.getBean("wsdlLocation");
assertNotNull(bean);
ep = getEndpointImplBean("publishedEndpointUrl", ctx);
String expectedEndpointUrl = "http://cxf.apache.org/Greeter";
assertEquals(expectedEndpointUrl, ep.getPublishedEndpointUrl());
ep = getEndpointImplBean("epWithDataBinding", ctx);
DataBinding dataBinding = ep.getDataBinding();
assertTrue(dataBinding instanceof JAXBDataBinding);
assertEquals("The namespace map should have an entry", ((JAXBDataBinding) dataBinding).getNamespaceMap().size(), 1);
// test for existence of Endpoint without an id element
boolean found = false;
String[] names = ctx.getBeanNamesForType(EndpointImpl.class);
for (String n : names) {
if (n.startsWith(EndpointImpl.class.getPackage().getName())) {
found = true;
}
}
assertTrue("Could not find server factory with autogenerated id", found);
ep = getEndpointImplBean("unpublishedEndpoint", ctx);
assertFalse("Unpublished endpoint is published", ep.isPublished());
testInterceptors(ctx);
}
Aggregations