Search in sources :

Example 1 with JaxWsImplementorInfo

use of org.apache.cxf.jaxws.support.JaxWsImplementorInfo in project cxf by apache.

the class WrapperClassGeneratorTest method testForXmlList.

@org.junit.Test
public void testForXmlList() throws Exception {
    JaxWsImplementorInfo implInfo = new JaxWsImplementorInfo(AddNumbersImpl.class);
    JaxWsServiceFactoryBean jaxwsFac = new JaxWsServiceFactoryBean(implInfo);
    jaxwsFac.setBus(BusFactory.getDefaultBus());
    Service service = jaxwsFac.create();
    ServiceInfo serviceInfo = service.getServiceInfos().get(0);
    InterfaceInfo interfaceInfo = serviceInfo.getInterface();
    OperationInfo inf = interfaceInfo.getOperations().iterator().next();
    Class<?> requestClass = inf.getInput().getMessagePart(0).getTypeClass();
    Class<?> responseClass = inf.getOutput().getMessagePart(0).getTypeClass();
    // Create request wrapper Object
    List<String> partNames = Arrays.asList(new String[] { "arg0" });
    List<String> elTypeNames = Arrays.asList(new String[] { "list" });
    List<Class<?>> partClasses = Arrays.asList(new Class<?>[] { List.class });
    String className = requestClass.getName();
    className = className.substring(0, className.lastIndexOf(".") + 1);
    WrapperHelper wh = new JAXBDataBinding().createWrapperHelper(requestClass, null, partNames, elTypeNames, partClasses);
    List<Object> paraList = new ArrayList<>();
    List<String> valueList = new ArrayList<>();
    valueList.add("str1");
    valueList.add("str2");
    valueList.add("str3");
    paraList.add(valueList);
    Object requestObj = wh.createWrapperObject(paraList);
    // Create response wrapper Object
    partNames = Arrays.asList(new String[] { "return" });
    elTypeNames = Arrays.asList(new String[] { "list" });
    partClasses = Arrays.asList(new Class<?>[] { List.class });
    className = responseClass.getName();
    className = className.substring(0, className.lastIndexOf(".") + 1);
    wh = new JAXBDataBinding().createWrapperHelper(responseClass, null, partNames, elTypeNames, partClasses);
    List<Object> resPara = new ArrayList<>();
    List<Integer> intValueList = new ArrayList<>();
    intValueList.add(1);
    intValueList.add(2);
    intValueList.add(3);
    resPara.add(intValueList);
    Object responseObj = wh.createWrapperObject(resPara);
    JAXBContext jaxbContext = JAXBContext.newInstance(requestClass, responseClass);
    java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream();
    Marshaller marshaller = jaxbContext.createMarshaller();
    // check marshall wrapper
    marshaller.marshal(requestObj, bout);
    String expected = "<arg0>str1 str2 str3</arg0>";
    assertTrue("The generated request wrapper class does not contain the correct annotations", bout.toString().contains(expected));
    bout.reset();
    marshaller.marshal(responseObj, bout);
    expected = "<return>1</return><return>2</return><return>3</return>";
    assertTrue("The generated response wrapper class is not correct", bout.toString().contains(expected));
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) ArrayList(java.util.ArrayList) JAXBContext(javax.xml.bind.JAXBContext) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) WrapperHelper(org.apache.cxf.databinding.WrapperHelper) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) ArrayList(java.util.ArrayList) List(java.util.List) Marshaller(javax.xml.bind.Marshaller) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) Service(org.apache.cxf.service.Service) JaxWsImplementorInfo(org.apache.cxf.jaxws.support.JaxWsImplementorInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo)

Example 2 with JaxWsImplementorInfo

use of org.apache.cxf.jaxws.support.JaxWsImplementorInfo 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 JaxWsImplementorInfo

use of org.apache.cxf.jaxws.support.JaxWsImplementorInfo in project cxf by apache.

the class JaxWsServerFactoryBean method createBindingInfo.

@Override
protected BindingInfo createBindingInfo() {
    JaxWsServiceFactoryBean sf = (JaxWsServiceFactoryBean) getServiceFactory();
    JaxWsImplementorInfo implInfo = sf.getJaxWsImplementorInfo();
    String jaxBid = implInfo.getBindingType();
    String binding = getBindingId();
    if (binding == null) {
        binding = jaxBid;
        setBindingId(binding);
    }
    if (binding.equals(SOAPBinding.SOAP11HTTP_BINDING) || binding.equals(SOAPBinding.SOAP11HTTP_MTOM_BINDING)) {
        binding = "http://schemas.xmlsoap.org/wsdl/soap/";
        setBindingId(binding);
        if (getBindingConfig() == null) {
            setBindingConfig(new JaxWsSoapBindingConfiguration(sf));
        }
    } else if (binding.equals(SOAPBinding.SOAP12HTTP_MTOM_BINDING)) {
        binding = SOAPBinding.SOAP12HTTP_BINDING;
        setBindingId(binding);
        if (getBindingConfig() == null) {
            setBindingConfig(new JaxWsSoapBindingConfiguration(sf));
        }
    }
    if (getBindingConfig() instanceof JaxWsSoapBindingConfiguration) {
        JaxWsSoapBindingConfiguration conf = (JaxWsSoapBindingConfiguration) getBindingConfig();
        if (jaxBid.equals(SOAPBinding.SOAP12HTTP_BINDING)) {
            conf.setVersion(Soap12.getInstance());
        }
        if (jaxBid.equals(SOAPBinding.SOAP12HTTP_MTOM_BINDING)) {
            conf.setVersion(Soap12.getInstance());
            conf.setMtomEnabled(true);
        }
        if (jaxBid.equals(SOAPBinding.SOAP11HTTP_MTOM_BINDING)) {
            conf.setMtomEnabled(true);
        }
        if (transportId != null) {
            conf.setTransportURI(transportId);
        }
        conf.setJaxWsServiceFactoryBean(sf);
    }
    BindingInfo bindingInfo = super.createBindingInfo();
    if (implInfo.isWebServiceProvider()) {
        bindingInfo.getService().setProperty("soap.force.doclit.bare", Boolean.TRUE);
        if (this.getServiceFactory().isPopulateFromClass()) {
            for (EndpointInfo ei : bindingInfo.getService().getEndpoints()) {
                ei.setProperty("soap.no.validate.parts", Boolean.TRUE);
            }
            // Provider, but no wsdl.  Synthetic ops
            for (BindingOperationInfo op : bindingInfo.getOperations()) {
                op.setProperty("operation.is.synthetic", Boolean.TRUE);
                op.getOperationInfo().setProperty("operation.is.synthetic", Boolean.TRUE);
            }
        }
    }
    return bindingInfo;
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) JaxWsImplementorInfo(org.apache.cxf.jaxws.support.JaxWsImplementorInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) BindingInfo(org.apache.cxf.service.model.BindingInfo) JaxWsSoapBindingConfiguration(org.apache.cxf.jaxws.binding.soap.JaxWsSoapBindingConfiguration)

Example 4 with JaxWsImplementorInfo

use of org.apache.cxf.jaxws.support.JaxWsImplementorInfo 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)

Example 5 with JaxWsImplementorInfo

use of org.apache.cxf.jaxws.support.JaxWsImplementorInfo in project cxf by apache.

the class CodeFirstWSDLTest method createService.

private Definition createService(Class<?> clazz) throws Exception {
    JaxWsImplementorInfo info = new JaxWsImplementorInfo(clazz);
    ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean(info);
    Bus bus = getBus();
    bean.setBus(bus);
    Service service = bean.create();
    InterfaceInfo i = service.getServiceInfos().get(0).getInterface();
    assertEquals(5, i.getOperations().size());
    ServerFactoryBean svrFactory = new ServerFactoryBean();
    svrFactory.setBus(bus);
    svrFactory.setServiceFactory(bean);
    svrFactory.setServiceBean(clazz.newInstance());
    svrFactory.setAddress(address);
    svrFactory.create();
    Collection<BindingInfo> bindings = service.getServiceInfos().get(0).getBindings();
    assertEquals(1, bindings.size());
    ServiceWSDLBuilder wsdlBuilder = new ServiceWSDLBuilder(bus, service.getServiceInfos().get(0));
    return wsdlBuilder.build();
}
Also used : Bus(org.apache.cxf.Bus) JaxWsImplementorInfo(org.apache.cxf.jaxws.support.JaxWsImplementorInfo) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) BindingInfo(org.apache.cxf.service.model.BindingInfo) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder)

Aggregations

JaxWsImplementorInfo (org.apache.cxf.jaxws.support.JaxWsImplementorInfo)8 JaxWsServiceFactoryBean (org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean)6 Bus (org.apache.cxf.Bus)3 Service (org.apache.cxf.service.Service)3 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)3 ServerImpl (org.apache.cxf.endpoint.ServerImpl)2 BindingInfo (org.apache.cxf.service.model.BindingInfo)2 ReflectionServiceFactoryBean (org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean)2 Test (org.junit.Test)2 File (java.io.File)1 URI (java.net.URI)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 WebService (javax.jws.WebService)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 QName (javax.xml.namespace.QName)1 Binding (org.apache.cxf.binding.Binding)1 SoapBinding (org.apache.cxf.binding.soap.SoapBinding)1