Search in sources :

Example 1 with ServerImpl

use of org.apache.cxf.endpoint.ServerImpl in project cxf by apache.

the class ProviderServiceFactoryTest method testSOAPBindingFromCode.

@Test
public void testSOAPBindingFromCode() throws Exception {
    JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    bean.setServiceClass(SOAPSourcePayloadProvider.class);
    bean.setBus(getBus());
    bean.setInvoker(new JAXWSMethodInvoker(new SOAPSourcePayloadProvider()));
    Service service = bean.create();
    assertEquals("SOAPSourcePayloadProviderService", service.getName().getLocalPart());
    InterfaceInfo intf = service.getServiceInfos().get(0).getInterface();
    assertNotNull(intf);
    assertEquals(1, intf.getOperations().size());
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setBus(getBus());
    svrFactory.setServiceFactory(bean);
    String address = "local://localhost:9000/test";
    svrFactory.setAddress(address);
    ServerImpl server = (ServerImpl) svrFactory.create();
    // See if our endpoint was created correctly
    assertEquals(1, service.getServiceInfos().get(0).getEndpoints().size());
    Endpoint endpoint = server.getEndpoint();
    Binding binding = endpoint.getBinding();
    assertTrue(binding instanceof SoapBinding);
    SoapBindingInfo sb = (SoapBindingInfo) endpoint.getEndpointInfo().getBinding();
    assertEquals("document", sb.getStyle());
    assertEquals(false, bean.isWrapped());
    assertEquals(1, sb.getOperations().size());
    Node res = invoke(address, LocalTransportFactory.TRANSPORT_ID, "/org/apache/cxf/jaxws/sayHi.xml");
    addNamespace("j", "http://service.jaxws.cxf.apache.org/");
    assertValid("/s:Envelope/s:Body/j:sayHi", res);
}
Also used : Binding(org.apache.cxf.binding.Binding) SoapBinding(org.apache.cxf.binding.soap.SoapBinding) XMLBinding(org.apache.cxf.binding.xml.XMLBinding) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) Node(org.w3c.dom.Node) Service(org.apache.cxf.service.Service) JAXWSMethodInvoker(org.apache.cxf.jaxws.JAXWSMethodInvoker) SoapBinding(org.apache.cxf.binding.soap.SoapBinding) ServerImpl(org.apache.cxf.endpoint.ServerImpl) Endpoint(org.apache.cxf.endpoint.Endpoint) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) Test(org.junit.Test) AbstractJaxWsTest(org.apache.cxf.jaxws.AbstractJaxWsTest)

Example 2 with ServerImpl

use of org.apache.cxf.endpoint.ServerImpl in project cxf by apache.

the class EndpointImpl method getServer.

public synchronized ServerImpl getServer(String addr) {
    if (server == null) {
        checkProperties();
        ClassLoaderHolder loader = null;
        try {
            if (bus != null) {
                ClassLoader newLoader = bus.getExtension(ClassLoader.class);
                if (newLoader != null) {
                    loader = ClassLoaderUtils.setThreadContextClassloader(newLoader);
                }
            }
            // Initialize the endpointName so we can do configureObject
            QName origEpn = endpointName;
            if (endpointName == null) {
                JaxWsImplementorInfo implInfo = new JaxWsImplementorInfo(getImplementorClass());
                endpointName = implInfo.getEndpointName();
            }
            if (serviceFactory != null) {
                serverFactory.setServiceFactory(serviceFactory);
            }
            /*if (serviceName != null) {
                    serverFactory.getServiceFactory().setServiceName(serviceName);
                }*/
            configureObject(this);
            endpointName = origEpn;
            // Set up the server factory
            serverFactory.setAddress(addr);
            serverFactory.setStart(false);
            serverFactory.setEndpointName(endpointName);
            serverFactory.setServiceBean(implementor);
            serverFactory.setBus(bus);
            serverFactory.setFeatures(getFeatures());
            serverFactory.setInvoker(invoker);
            serverFactory.setSchemaLocations(schemaLocations);
            if (serverFactory.getProperties() != null) {
                serverFactory.getProperties().putAll(properties);
            } else {
                serverFactory.setProperties(properties);
            }
            // have supplied their own.
            if (getWsdlLocation() != null) {
                serverFactory.setWsdlURL(getWsdlLocation());
            }
            if (bindingUri != null) {
                serverFactory.setBindingId(bindingUri);
            }
            if (serviceName != null) {
                serverFactory.getServiceFactory().setServiceName(serviceName);
            }
            if (implementorClass != null) {
                serverFactory.setServiceClass(implementorClass);
            }
            if (executor != null) {
                serverFactory.getServiceFactory().setExecutor(executor);
            }
            if (!handlers.isEmpty()) {
                serverFactory.addHandlers(handlers);
            }
            configureObject(serverFactory);
            server = serverFactory.create();
            org.apache.cxf.endpoint.Endpoint endpoint = getEndpoint();
            if (in != null) {
                endpoint.getInInterceptors().addAll(in);
            }
            if (out != null) {
                endpoint.getOutInterceptors().addAll(out);
            }
            if (inFault != null) {
                endpoint.getInFaultInterceptors().addAll(inFault);
            }
            if (outFault != null) {
                endpoint.getOutFaultInterceptors().addAll(outFault);
            }
            if (properties != null) {
                endpoint.putAll(properties);
            }
            configureObject(endpoint.getService());
            configureObject(endpoint);
            this.service = endpoint.getService();
            if (getWsdlLocation() == null) {
                // hold onto the wsdl location so cache won't clear till we go away
                setWsdlLocation(serverFactory.getWsdlURL());
            }
            if (serviceName == null) {
                setServiceName(serverFactory.getServiceFactory().getServiceQName());
            }
            if (endpointName == null) {
                endpointName = endpoint.getEndpointInfo().getName();
            }
        } finally {
            if (loader != null) {
                loader.reset();
            }
        }
    }
    return (ServerImpl) server;
}
Also used : JaxWsImplementorInfo(org.apache.cxf.jaxws.support.JaxWsImplementorInfo) ServerImpl(org.apache.cxf.endpoint.ServerImpl) QName(javax.xml.namespace.QName) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)

Example 3 with ServerImpl

use of org.apache.cxf.endpoint.ServerImpl in project cxf by apache.

the class ServerFactoryTest method testSetDF.

@Test
public void testSetDF() throws Exception {
    ServerFactoryBean svrBean = new ServerFactoryBean();
    svrBean.setAddress("http://localhost/Hello");
    svrBean.setServiceClass(HelloService.class);
    svrBean.setServiceBean(new HelloServiceImpl());
    svrBean.setBus(getBus());
    svrBean.setDestinationFactory(new CustomDestinationFactory(getBus()));
    ServerImpl server = (ServerImpl) svrBean.create();
    assertTrue(server.getDestination() instanceof CustomDestination);
}
Also used : ServerImpl(org.apache.cxf.endpoint.ServerImpl) ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean) Test(org.junit.Test)

Example 4 with ServerImpl

use of org.apache.cxf.endpoint.ServerImpl in project cxf by apache.

the class ServerFactoryTest method testCXF1758.

@Test
public void testCXF1758() throws Exception {
    ServerFactoryBean svrBean = new ServerFactoryBean();
    svrBean.setAddress("http://localhost/Generics");
    svrBean.setServiceBean(new TestServiceImpl<String>() {
    });
    svrBean.setBus(getBus());
    ServerImpl server = (ServerImpl) svrBean.create();
    // XMLUtils.printDOM(getWSDLDocument(server));
    assertValid("//xsd:schema/xsd:complexType[@name='open']/xsd:sequence/" + "xsd:element[@type='xsd:string']", getWSDLDocument(server));
}
Also used : ServerImpl(org.apache.cxf.endpoint.ServerImpl) ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean) Test(org.junit.Test)

Example 5 with ServerImpl

use of org.apache.cxf.endpoint.ServerImpl in project cxf by apache.

the class ProviderServiceFactoryTest method testFromWSDL.

@Test
public void testFromWSDL() throws Exception {
    URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(resource);
    JaxWsImplementorInfo implInfo = new JaxWsImplementorInfo(HWSoapMessageProvider.class);
    JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean(implInfo);
    bean.setWsdlURL(resource.toString());
    Bus bus = getBus();
    bean.setBus(bus);
    bean.setServiceClass(HWSoapMessageProvider.class);
    Service service = bean.create();
    assertTrue(service.getInvoker() instanceof JAXWSMethodInvoker);
    assertEquals("SOAPService", service.getName().getLocalPart());
    assertEquals("http://apache.org/hello_world_soap_http", service.getName().getNamespaceURI());
    InterfaceInfo intf = service.getServiceInfos().get(0).getInterface();
    assertNotNull(intf);
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setBus(bus);
    svrFactory.setServiceFactory(bean);
    svrFactory.setStart(false);
    ServerImpl server = (ServerImpl) svrFactory.create();
    assertTrue(server.getEndpoint().getService().getInvoker() instanceof JAXWSMethodInvoker);
    Endpoint endpoint = server.getEndpoint();
    Binding binding = endpoint.getBinding();
    assertTrue(binding instanceof SoapBinding);
}
Also used : Binding(org.apache.cxf.binding.Binding) SoapBinding(org.apache.cxf.binding.soap.SoapBinding) XMLBinding(org.apache.cxf.binding.xml.XMLBinding) Bus(org.apache.cxf.Bus) JaxWsImplementorInfo(org.apache.cxf.jaxws.support.JaxWsImplementorInfo) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) ServerImpl(org.apache.cxf.endpoint.ServerImpl) Endpoint(org.apache.cxf.endpoint.Endpoint) Service(org.apache.cxf.service.Service) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) JAXWSMethodInvoker(org.apache.cxf.jaxws.JAXWSMethodInvoker) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) URL(java.net.URL) SoapBinding(org.apache.cxf.binding.soap.SoapBinding) Test(org.junit.Test) AbstractJaxWsTest(org.apache.cxf.jaxws.AbstractJaxWsTest)

Aggregations

ServerImpl (org.apache.cxf.endpoint.ServerImpl)12 Test (org.junit.Test)8 Endpoint (org.apache.cxf.endpoint.Endpoint)6 Binding (org.apache.cxf.binding.Binding)4 SoapBinding (org.apache.cxf.binding.soap.SoapBinding)4 XMLBinding (org.apache.cxf.binding.xml.XMLBinding)4 ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)4 AbstractJaxWsTest (org.apache.cxf.jaxws.AbstractJaxWsTest)4 JAXWSMethodInvoker (org.apache.cxf.jaxws.JAXWSMethodInvoker)4 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)4 JaxWsServiceFactoryBean (org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean)4 Service (org.apache.cxf.service.Service)4 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)4 Node (org.w3c.dom.Node)4 Bus (org.apache.cxf.Bus)3 ServerFactoryBean (org.apache.cxf.frontend.ServerFactoryBean)3 IOException (java.io.IOException)2 BusException (org.apache.cxf.BusException)2 SoapBindingInfo (org.apache.cxf.binding.soap.model.SoapBindingInfo)2 EndpointException (org.apache.cxf.endpoint.EndpointException)2