Search in sources :

Example 1 with Hello

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());
    }
}
Also used : QName(javax.xml.namespace.QName) ArrayServiceImpl(org.apache.cxf.jaxws.service.ArrayServiceImpl) FooServiceImpl(org.apache.cxf.jaxws.service.FooServiceImpl) ArrayList(java.util.ArrayList) Hello(org.apache.cxf.jaxws.service.Hello) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) HelloInterface(org.apache.cxf.jaxws.service.HelloInterface) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Example 2 with Hello

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();
}
Also used : Binding(javax.xml.ws.Binding) Endpoint(javax.xml.ws.Endpoint) Hello(org.apache.cxf.jaxws.service.Hello) Test(org.junit.Test)

Example 3 with Hello

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");
    }
}
Also used : Hello(org.apache.cxf.jaxws.service.Hello) Test(org.junit.Test)

Example 4 with 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());
}
Also used : Hello(org.apache.cxf.jaxws.service.Hello) Test(org.junit.Test)

Example 5 with Hello

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);
}
Also used : Soap12(org.apache.cxf.binding.soap.Soap12) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.jaxws.EndpointImpl) Hello(org.apache.cxf.jaxws.service.Hello) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) DataBinding(org.apache.cxf.databinding.DataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) BindingConfiguration(org.apache.cxf.binding.BindingConfiguration) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) 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