Search in sources :

Example 1 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/2014.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 | UnexpectedErrorFault | ExceededRequestSizeFault e) {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.failedToInitClient", e.getLocalizedMessage()), e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) WebServiceException(javax.xml.ws.WebServiceException) GetDataCenterUrlsResponse(com.netsuite.webservices.v2014_2.platform.messages.GetDataCenterUrlsResponse) ArrayList(java.util.ArrayList) DataCenterUrls(com.netsuite.webservices.v2014_2.platform.core.DataCenterUrls) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) UnexpectedErrorFault(com.netsuite.webservices.v2014_2.platform.UnexpectedErrorFault) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) NetSuitePortType(com.netsuite.webservices.v2014_2.platform.NetSuitePortType) NetSuiteErrorCode(org.talend.components.netsuite.NetSuiteErrorCode) NetSuiteService(com.netsuite.webservices.v2014_2.platform.NetSuiteService) LoggingFeature(org.apache.cxf.feature.LoggingFeature) WebServiceFeature(javax.xml.ws.WebServiceFeature) GetDataCenterUrlsRequest(com.netsuite.webservices.v2014_2.platform.messages.GetDataCenterUrlsRequest) ExceededRequestSizeFault(com.netsuite.webservices.v2014_2.platform.ExceededRequestSizeFault)

Example 2 with WebServiceFeature

use of javax.xml.ws.WebServiceFeature in project scout.rt by eclipse.

the class PortProducer method provide.

/**
 * Creates a new Port to interact with the webservice endpoint.
 */
@Override
public PORT provide() {
    try {
        // Create the service
        final Constructor<? extends Service> constructor = m_serviceClazz.getConstructor(URL.class, QName.class);
        @SuppressWarnings("unchecked") final SERVICE service = (SERVICE) constructor.newInstance(m_wsdlLocation, new QName(m_targetNamespace, m_serviceName));
        // Install the handler chain
        service.setHandlerResolver(new HandlerResolver() {

            @Override
            public List<Handler> getHandlerChain(final PortInfo portInfo) {
                final List<Handler<? extends MessageContext>> handlerChain = new ArrayList<>();
                m_initializer.initHandlers(handlerChain);
                for (int i = 0; i < handlerChain.size(); i++) {
                    handlerChain.set(i, proxyHandler(handlerChain.get(i)));
                }
                @SuppressWarnings("unchecked") final List<Handler> handlers = TypeCastUtility.castValue(handlerChain, List.class);
                return handlers;
            }
        });
        // Install implementor specific webservice features
        final List<WebServiceFeature> webServiceFeatures = new ArrayList<>();
        m_initializer.initWebServiceFeatures(webServiceFeatures);
        // Create the port
        return service.getPort(m_portTypeClazz, CollectionUtility.toArray(webServiceFeatures, WebServiceFeature.class));
    } catch (final ReflectiveOperationException e) {
        throw new WebServiceException("Failed to instantiate webservice stub.", e);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) PortInfo(javax.xml.ws.handler.PortInfo) HandlerResolver(javax.xml.ws.handler.HandlerResolver) WebServiceFeature(javax.xml.ws.WebServiceFeature) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with WebServiceFeature

use of javax.xml.ws.WebServiceFeature in project jbossws-cxf by jbossws.

the class HelperUsignThreadLocal method run.

public Integer run(final URL wsdlURL, final String strategyName, final int size, final int calls) {
    final WebServiceFeature feature;
    final String strategy;
    if (strategyName != null) {
        feature = convertToFeature(strategyName);
        strategy = strategyName;
    } else {
        feature = null;
        strategy = System.getProperty(Constants.JBWS_CXF_JAXWS_CLIENT_BUS_STRATEGY, null);
    }
    final BusCounter busCounter = new BusCounter();
    final ThreadLocal<HelloWs> port = createPortThreadLocal(wsdlURL, feature, busCounter);
    final ThreadFactory threadFactory = new ThreadFactory() {

        private AtomicInteger i = new AtomicInteger(0);

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, "JBWS3373-TL-thread-" + i.getAndIncrement() + "-" + strategy);
        }
    };
    ExecutorService es = Executors.newFixedThreadPool(size, threadFactory);
    List<Client> clients = new ArrayList<HelperUsignThreadLocal.Client>();
    for (int i = 0; i < calls; i++) {
        clients.add(new Client(port));
    }
    int count = 0;
    try {
        List<Future<Boolean>> futures = es.invokeAll(clients);
        for (Future<Boolean> f : futures) {
            if (f.get()) {
                count++;
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        es.shutdown();
    }
    if (count != calls) {
        throw new RuntimeException((calls - count) + " client invocation(s) failed!");
    }
    return busCounter.getCount();
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ArrayList(java.util.ArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WebServiceFeature(javax.xml.ws.WebServiceFeature) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future)

Example 4 with WebServiceFeature

use of javax.xml.ws.WebServiceFeature in project jbossws-cxf by jbossws.

the class CXFServiceObjectFactoryJAXWS method getFeatures.

private WebServiceFeature[] getFeatures(final UnifiedPortComponentRefMetaData portComponentRefMD) {
    List<WebServiceFeature> features = new LinkedList<WebServiceFeature>();
    // configure @Addressing feature
    if (portComponentRefMD.isAddressingAnnotationSpecified()) {
        final boolean enabled = portComponentRefMD.isAddressingEnabled();
        final boolean required = portComponentRefMD.isAddressingRequired();
        final String refResponses = portComponentRefMD.getAddressingResponses();
        AddressingFeature.Responses responses = AddressingFeature.Responses.ALL;
        if ("ANONYMOUS".equals(refResponses))
            responses = AddressingFeature.Responses.ANONYMOUS;
        if ("NON_ANONYMOUS".equals(refResponses))
            responses = AddressingFeature.Responses.NON_ANONYMOUS;
        features.add(new AddressingFeature(enabled, required, responses));
    }
    // configure @MTOM feature
    if (portComponentRefMD.isMtomEnabled()) {
        features.add(new MTOMFeature(true, portComponentRefMD.getMtomThreshold()));
    }
    // configure @RespectBinding feature
    if (portComponentRefMD.isRespectBindingAnnotationSpecified()) {
        final boolean enabled = portComponentRefMD.isRespectBindingEnabled();
        features.add(new RespectBindingFeature(enabled));
    }
    return features.size() == 0 ? null : features.toArray(new WebServiceFeature[] {});
}
Also used : AddressingFeature(javax.xml.ws.soap.AddressingFeature) MTOMFeature(javax.xml.ws.soap.MTOMFeature) RespectBindingFeature(javax.xml.ws.RespectBindingFeature) WebServiceFeature(javax.xml.ws.WebServiceFeature) LinkedList(java.util.LinkedList)

Example 5 with WebServiceFeature

use of javax.xml.ws.WebServiceFeature in project jbossws-cxf by jbossws.

the class CXFServiceObjectFactoryJAXWS method instantiateService.

private Service instantiateService(final UnifiedServiceRefMetaData serviceRefMD, final Class<?> serviceClass) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, WSFException {
    final List<WebServiceFeature> featuresList = getFeatures(serviceRefMD);
    // force THREAD_BUS strategy so that the bus created before for this specific ref is used
    if (!ClientBusSelector.getDefaultStrategy().equals(Constants.THREAD_BUS_STRATEGY)) {
        featuresList.add(new UseThreadBusFeature());
    }
    final WebServiceFeature[] features = featuresList.size() == 0 ? null : featuresList.toArray(new WebServiceFeature[] {});
    final QName serviceQName = this.getServiceQName(serviceRefMD, serviceClass);
    URL wsdlURL = this.getWsdlURL(serviceRefMD, serviceClass);
    if (wsdlURL == null) {
        final String deployedServiceAddress = serviceRefMD.getDeployedServiceAddress(serviceQName);
        if (deployedServiceAddress != null) {
            try {
                wsdlURL = new URL(deployedServiceAddress + "?wsdl");
            } catch (MalformedURLException e) {
                // ignore
                Logger.getLogger(CXFServiceObjectFactoryJAXWS.class).trace(e);
            }
        }
    }
    Service target = null;
    if (serviceClass == Service.class) {
        // Generic javax.xml.ws.Service
        if (wsdlURL != null) {
            if (features != null) {
                target = Service.create(wsdlURL, serviceQName, features);
            } else {
                target = Service.create(wsdlURL, serviceQName);
            }
        } else {
            throw Messages.MESSAGES.cannotCreateServiceWithoutWsdlLocation(serviceRefMD);
        }
    } else {
        // Generated javax.xml.ws.Service subclass
        if (wsdlURL != null) {
            if (features != null) {
                try {
                    Constructor<?> ctor = serviceClass.getConstructor(new Class[] { URL.class, QName.class, WebServiceFeature[].class });
                    target = (Service) ctor.newInstance(new Object[] { wsdlURL, serviceQName, features });
                } catch (NoSuchMethodException nsme) {
                    throw org.jboss.wsf.stack.cxf.Messages.MESSAGES.missingJAXWS22ServiceConstructor(serviceClass.getName(), nsme);
                }
            } else {
                Constructor<?> ctor = serviceClass.getConstructor(new Class[] { URL.class, QName.class });
                target = (Service) ctor.newInstance(new Object[] { wsdlURL, serviceQName });
            }
        } else {
            if (features != null) {
                try {
                    Constructor<?> ctor = serviceClass.getConstructor(new Class[] { WebServiceFeature[].class });
                    target = (Service) ctor.newInstance(new Object[] { features });
                } catch (NoSuchMethodException nsme) {
                    throw org.jboss.wsf.stack.cxf.Messages.MESSAGES.missingJAXWS22ServiceConstructor(serviceClass.getName(), nsme);
                }
            } else {
                target = (Service) serviceClass.newInstance();
            }
        }
    }
    return target;
}
Also used : MalformedURLException(java.net.MalformedURLException) UseThreadBusFeature(org.jboss.wsf.stack.cxf.client.UseThreadBusFeature) QName(javax.xml.namespace.QName) WebServiceFeature(javax.xml.ws.WebServiceFeature) Service(javax.xml.ws.Service) URL(java.net.URL)

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