Search in sources :

Example 16 with WebServiceFeature

use of javax.xml.ws.WebServiceFeature in project cxf by apache.

the class ServiceImpl method createPort.

protected <T> T createPort(QName portName, EndpointReferenceType epr, Class<T> serviceEndpointInterface, WebServiceFeature... features) {
    LOG.log(Level.FINE, "creating port for portName", portName);
    LOG.log(Level.FINE, "endpoint reference:", epr);
    LOG.log(Level.FINE, "endpoint interface:", serviceEndpointInterface);
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    JaxWsClientFactoryBean clientFac = (JaxWsClientFactoryBean) proxyFac.getClientFactoryBean();
    JaxWsServiceFactoryBean serviceFactory = (JaxWsServiceFactoryBean) proxyFac.getServiceFactory();
    List<WebServiceFeature> f = getAllFeatures(features);
    proxyFac.initFeatures();
    if (f != null) {
        serviceFactory.setWsFeatures(f);
    }
    proxyFac.setBus(bus);
    proxyFac.setServiceClass(serviceEndpointInterface);
    proxyFac.setServiceName(serviceName);
    if (epr != null && epr.getAddress() != null && epr.getAddress().getValue() != null) {
        clientFac.setAddress(epr.getAddress().getValue());
    }
    if (wsdlURL != null) {
        proxyFac.setWsdlURL(wsdlURL);
    }
    configureObject(proxyFac);
    configureObject(clientFac);
    if (portName == null) {
        QName portTypeName = getPortTypeName(serviceEndpointInterface);
        Service service = serviceFactory.getService();
        if (service == null) {
            serviceFactory.setServiceClass(serviceEndpointInterface);
            serviceFactory.setBus(getBus());
            service = serviceFactory.create();
        }
        EndpointInfo ei = ServiceModelUtil.findBestEndpointInfo(portTypeName, service.getServiceInfos());
        if (ei != null) {
            portName = ei.getName();
        } else {
            portName = serviceFactory.getEndpointName();
        }
    }
    serviceFactory.setEndpointName(portName);
    if (epr != null) {
        clientFac.setEndpointReference(epr);
    }
    PortInfoImpl portInfo = portInfos.get(portName);
    if (portInfo != null) {
        clientFac.setBindingId(portInfo.getBindingID());
        clientFac.setAddress(portInfo.getAddress());
    }
    // configureObject(portName.toString() + ".jaxws-client.proxyFactory", proxyFac);
    if (clazz != ServiceImpl.class) {
        // handlerchain should be on the generated Service object
        proxyFac.setLoadHandlers(false);
    }
    Object obj = proxyFac.create();
    // Configure the Service
    Service service = serviceFactory.getService();
    configureObject(service);
    // Configure the JaxWsEndpoitnImpl
    Client client = ClientProxy.getClient(obj);
    client.getEndpoint().setExecutor(executor);
    client.setExecutor(executor);
    JaxWsEndpointImpl jaxwsEndpoint = (JaxWsEndpointImpl) client.getEndpoint();
    configureObject(jaxwsEndpoint);
    @SuppressWarnings("rawtypes") List<Handler> hc = jaxwsEndpoint.getJaxwsBinding().getHandlerChain();
    hc.addAll(handlerResolver.getHandlerChain(portInfos.get(portName)));
    jaxwsEndpoint.getJaxwsBinding().setHandlerChain(hc);
    LOG.log(Level.FINE, "created proxy", obj);
    if (portInfo == null) {
        addPort(portName, clientFac.getBindingId(), clientFac.getAddress());
    }
    return serviceEndpointInterface.cast(obj);
}
Also used : JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) Handler(javax.xml.ws.handler.Handler) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) WebServiceFeature(javax.xml.ws.WebServiceFeature) PortInfoImpl(org.apache.cxf.jaxws.handler.PortInfoImpl) Client(org.apache.cxf.endpoint.Client)

Example 17 with WebServiceFeature

use of javax.xml.ws.WebServiceFeature in project cxf by apache.

the class JaxWsServiceFactoryBeanTest method testMtomFeature.

@Test
public void testMtomFeature() throws Exception {
    JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    bean.setBus(getBus());
    bean.setServiceClass(GreeterImpl.class);
    bean.setWsdlURL(getClass().getResource("/wsdl/hello_world.wsdl"));
    bean.setWsFeatures(Arrays.asList(new WebServiceFeature[] { new MTOMFeature() }));
    Service service = bean.create();
    Endpoint endpoint = service.getEndpoints().values().iterator().next();
    assertTrue(endpoint instanceof JaxWsEndpointImpl);
    Binding binding = ((JaxWsEndpointImpl) endpoint).getJaxwsBinding();
    assertTrue(binding instanceof SOAPBinding);
    assertTrue(((SOAPBinding) binding).isMTOMEnabled());
}
Also used : Binding(javax.xml.ws.Binding) SOAPBinding(javax.xml.ws.soap.SOAPBinding) Endpoint(org.apache.cxf.endpoint.Endpoint) MTOMFeature(javax.xml.ws.soap.MTOMFeature) WebServiceFeature(javax.xml.ws.WebServiceFeature) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) SOAPBinding(javax.xml.ws.soap.SOAPBinding) Test(org.junit.Test) AbstractJaxWsTest(org.apache.cxf.jaxws.AbstractJaxWsTest)

Example 18 with WebServiceFeature

use of javax.xml.ws.WebServiceFeature in project cxf by apache.

the class EndpointReferenceTest method testServiceGetPortUsingEndpointReference.

/*
     * Any JAX-WS supported epr metadata MUST match the Service instances
     * ServiceName, otherwise a WebServiceExeption MUST be thrown. Any JAX-WS
     * supported epr metadata MUST match the PortName for the sei, otherwise a
     * WebServiceException MUST be thrown. If the Service instance has an
     * associated WSDL, its WSDL MUST be used to determine any binding
     * information, anyWSDL in a JAX-WS suppported epr metadata MUST be ignored.
     * If the Service instance does not have a WSDL, then any WSDL inlined in
     * the JAX-WS supported metadata of the epr MUST be used to determine
     * binding information. If there is not enough metadata in the Service
     * instance or in the epr metadata to determine a port, then a
     * WebServiceException MUST be thrown.
     */
@Test
public void testServiceGetPortUsingEndpointReference() throws Exception {
    BusFactory.setDefaultBus(getBus());
    GreeterImpl greeter1 = new GreeterImpl();
    try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter1, (String) null)) {
        endpoint.publish("http://localhost:8080/test");
        javax.xml.ws.Service s = javax.xml.ws.Service.create(new QName("http://apache.org/hello_world_soap_http", "SoapPort"));
        InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml");
        Document doc = StaxUtils.read(is);
        DOMSource erXML = new DOMSource(doc);
        EndpointReference endpointReference = EndpointReference.readFrom(erXML);
        WebServiceFeature[] wfs = new WebServiceFeature[] {};
        Greeter greeter = s.getPort(endpointReference, Greeter.class, wfs);
        String response = greeter.greetMe("John");
        assertEquals("Hello John", response);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) Document(org.w3c.dom.Document) EndpointReference(javax.xml.ws.EndpointReference) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) Greeter(org.apache.hello_world_soap_http.Greeter) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) WebServiceFeature(javax.xml.ws.WebServiceFeature) Test(org.junit.Test)

Example 19 with WebServiceFeature

use of javax.xml.ws.WebServiceFeature in project cxf by apache.

the class EndpointReferenceTest method testEndpointReferenceGetPort.

@Test
public void testEndpointReferenceGetPort() throws Exception {
    BusFactory.setDefaultBus(getBus());
    GreeterImpl greeter1 = new GreeterImpl();
    try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter1, (String) null)) {
        endpoint.publish("http://localhost:8080/test");
        InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml");
        Document doc = StaxUtils.read(is);
        DOMSource erXML = new DOMSource(doc);
        EndpointReference endpointReference = EndpointReference.readFrom(erXML);
        WebServiceFeature[] wfs = new WebServiceFeature[] {};
        Greeter greeter = endpointReference.getPort(Greeter.class, wfs);
        String response = greeter.greetMe("John");
        assertEquals("Hello John", response);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) InputStream(java.io.InputStream) Greeter(org.apache.hello_world_soap_http.Greeter) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) WebServiceFeature(javax.xml.ws.WebServiceFeature) Document(org.w3c.dom.Document) EndpointReference(javax.xml.ws.EndpointReference) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) Test(org.junit.Test)

Example 20 with WebServiceFeature

use of javax.xml.ws.WebServiceFeature in project components by Talend.

the class NetSuiteClientServiceImpl method getNetSuitePort.

protected NetSuitePortType getNetSuitePort(String defaultEndpointUrl, String account) throws NetSuiteException {
    try {
        URL wsdlLocationUrl = this.getClass().getResource("/wsdl/2016.2/netsuite.wsdl");
        NetSuiteService service = new NetSuiteService(wsdlLocationUrl, NetSuiteService.SERVICE);
        List<WebServiceFeature> features = new ArrayList<>(2);
        if (isMessageLoggingEnabled()) {
            features.add(new LoggingFeature());
        }
        NetSuitePortType port = service.getNetSuitePort(features.toArray(new WebServiceFeature[features.size()]));
        BindingProvider provider = (BindingProvider) port;
        Map<String, Object> requestContext = provider.getRequestContext();
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, defaultEndpointUrl);
        GetDataCenterUrlsRequest dataCenterRequest = new GetDataCenterUrlsRequest();
        dataCenterRequest.setAccount(account);
        DataCenterUrls urls = null;
        GetDataCenterUrlsResponse response = port.getDataCenterUrls(dataCenterRequest);
        if (response != null && response.getGetDataCenterUrlsResult() != null) {
            urls = response.getGetDataCenterUrlsResult().getDataCenterUrls();
        }
        if (urls == null) {
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.couldNotGetWebServiceDomain", defaultEndpointUrl));
        }
        String wsDomain = urls.getWebservicesDomain();
        String endpointUrl = wsDomain.concat(new URL(defaultEndpointUrl).getPath());
        requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
        requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);
        return port;
    } catch (WebServiceException | MalformedURLException | InsufficientPermissionFault | InvalidCredentialsFault | InvalidSessionFault | UnexpectedErrorFault | ExceededRequestSizeFault e) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.failedToInitClient", e.getLocalizedMessage()), e);
    }
}
Also used : InsufficientPermissionFault(com.netsuite.webservices.v2016_2.platform.InsufficientPermissionFault) InvalidCredentialsFault(com.netsuite.webservices.v2016_2.platform.InvalidCredentialsFault) MalformedURLException(java.net.MalformedURLException) WebServiceException(javax.xml.ws.WebServiceException) GetDataCenterUrlsResponse(com.netsuite.webservices.v2016_2.platform.messages.GetDataCenterUrlsResponse) ArrayList(java.util.ArrayList) DataCenterUrls(com.netsuite.webservices.v2016_2.platform.core.DataCenterUrls) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) UnexpectedErrorFault(com.netsuite.webservices.v2016_2.platform.UnexpectedErrorFault) BindingProvider(javax.xml.ws.BindingProvider) InvalidSessionFault(com.netsuite.webservices.v2016_2.platform.InvalidSessionFault) URL(java.net.URL) NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) NetSuiteErrorCode(org.talend.components.netsuite.NetSuiteErrorCode) NetSuiteService(com.netsuite.webservices.v2016_2.platform.NetSuiteService) LoggingFeature(org.apache.cxf.feature.LoggingFeature) WebServiceFeature(javax.xml.ws.WebServiceFeature) GetDataCenterUrlsRequest(com.netsuite.webservices.v2016_2.platform.messages.GetDataCenterUrlsRequest) ExceededRequestSizeFault(com.netsuite.webservices.v2016_2.platform.ExceededRequestSizeFault)

Aggregations

WebServiceFeature (javax.xml.ws.WebServiceFeature)30 ArrayList (java.util.ArrayList)11 MTOMFeature (javax.xml.ws.soap.MTOMFeature)9 QName (javax.xml.namespace.QName)8 URL (java.net.URL)7 WebServiceException (javax.xml.ws.WebServiceException)7 AddressingFeature (javax.xml.ws.soap.AddressingFeature)7 MalformedURLException (java.net.MalformedURLException)6 RespectBindingFeature (javax.xml.ws.RespectBindingFeature)6 LinkedList (java.util.LinkedList)4 Service (javax.xml.ws.Service)4 InputStream (java.io.InputStream)3 NamingException (javax.naming.NamingException)3 DOMSource (javax.xml.transform.dom.DOMSource)3 EndpointReference (javax.xml.ws.EndpointReference)3 Bus (org.apache.cxf.Bus)3 Test (org.junit.Test)3 WSBinding (com.sun.xml.ws.api.WSBinding)2 PrivilegedActionException (java.security.PrivilegedActionException)2 Iterator (java.util.Iterator)2