Search in sources :

Example 1 with HandlerResolver

use of javax.xml.ws.handler.HandlerResolver 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 2 with HandlerResolver

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

the class ServicePool method createElement.

@Override
protected SERVICE createElement() {
    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;
            }
        });
        return service;
    } catch (ReflectiveOperationException e) {
        throw new WebServiceException("Failed to instantiate webservice stub.", e);
    }
}
Also used : PortInfo(javax.xml.ws.handler.PortInfo) HandlerResolver(javax.xml.ws.handler.HandlerResolver) WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with HandlerResolver

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

the class HandlerChainClient method testService1.

public String testService1(String reqStr) throws Exception {
    PortInfo info = new PortInfo() {

        @Override
        public String getBindingID() {
            return "http://schemas.xmlsoap.org/wsdl/soap/http";
        }

        @Override
        public QName getPortName() {
            return null;
        }

        @Override
        public QName getServiceName() {
            return null;
        }
    };
    HandlerResolver resolver = service1.getHandlerResolver();
    @SuppressWarnings("rawtypes") List<Handler> handlerChain = resolver.getHandlerChain(info);
    if ("[LogHandler, AuthorizationHandler, RoutingHandler, MimeHandler]".equals(handlerChain.toString()) == false)
        throw new IllegalStateException("Unexpected resolver handlers: " + handlerChain);
    Endpoint port = service1.getPort(Endpoint.class);
    return port.echo(reqStr);
}
Also used : PortInfo(javax.xml.ws.handler.PortInfo) HandlerResolver(javax.xml.ws.handler.HandlerResolver) Handler(javax.xml.ws.handler.Handler)

Example 4 with HandlerResolver

use of javax.xml.ws.handler.HandlerResolver in project tomee by apache.

the class JaxWsServiceReference method getObject.

public Object getObject() throws NamingException {
    final String referenceClassName = referenceClass != null ? referenceClass.getName() : null;
    final Set<PortAddress> portAddresses = getPortAddressRegistry().getPorts(id, serviceQName, referenceClassName);
    // if we only have one address, use that address for the wsdl and the serviceQName
    URL wsdlUrl = this.wsdlUrl;
    QName serviceQName = this.serviceQName;
    if (portAddresses.size() == 1) {
        final PortAddress portAddress = portAddresses.iterator().next();
        try {
            wsdlUrl = new URL(portAddress.getAddress() + "?wsdl");
        } catch (final MalformedURLException e) {
        // no-op
        }
        serviceQName = portAddress.getServiceQName();
    }
    // add the port addresses to the portRefData
    final Map<QName, PortRefData> portsByQName = new HashMap<>();
    final List<PortRefData> ports = new ArrayList<>(portRefs.size() + portAddresses.size());
    for (final PortRefData portRef : portRefs) {
        final PortRefData port = new PortRefData(portRef);
        if (port.getQName() != null) {
            portsByQName.put(port.getQName(), port);
        }
        ports.add(port);
    }
    // add PortRefData for any portAddress not added above
    for (final PortAddress portAddress : portAddresses) {
        PortRefData port = portsByQName.get(portAddress.getPortQName());
        if (port == null) {
            port = new PortRefData();
            port.setQName(portAddress.getPortQName());
            port.setServiceEndpointInterface(portAddress.getServiceEndpointInterface());
            port.getAddresses().add(portAddress.getAddress());
            ports.add(port);
        } else {
            port.getAddresses().add(portAddress.getAddress());
            if (port.getServiceEndpointInterface() == null) {
                port.setServiceEndpointInterface(portAddress.getServiceEndpointInterface());
            }
        }
    }
    final WebServiceClientCustomizer customizer = SystemInstance.get().getComponent(WebServiceClientCustomizer.class);
    final Properties configuration = properties == null ? new Properties() : properties;
    ProviderWrapper.beforeCreate(ports, customizer, properties);
    Service instance;
    try {
        instance = null;
        if (Service.class.equals(serviceClass)) {
            instance = Service.create(wsdlUrl, serviceQName);
        } else {
            try {
                instance = serviceClass.getConstructor(URL.class, QName.class).newInstance(wsdlUrl, serviceQName);
            } catch (final Throwable e) {
                throw (NamingException) new NamingException("Could not instantiate jax-ws service class " + serviceClass.getName()).initCause(e);
            }
        }
    } finally {
        ProviderWrapper.afterCreate();
    }
    if (!handlerChains.isEmpty()) {
        final HandlerResolver handlerResolver = new HandlerResolverImpl(handlerChains, injections, new InitialContext());
        instance.setHandlerResolver(handlerResolver);
    }
    final Object port;
    if (referenceClass != null && !Service.class.isAssignableFrom(referenceClass)) {
        final WebServiceFeature[] features = customizer == null ? null : customizer.features(serviceQName, configuration);
        // do port lookup
        if (features == null || features.length == 0) {
            port = instance.getPort(referenceClass);
        } else {
            port = instance.getPort(referenceClass, features);
        }
    } else {
        // return service
        port = instance;
    }
    // register the service data so it can be fetched when the service is passed over the EJBd protocol
    final ServiceRefData serviceRefData = new ServiceRefData(id, serviceQName, serviceClass, portQName, referenceClass, wsdlUrl, handlerChains, portRefs);
    ServiceRefData.putServiceRefData(port, serviceRefData);
    return port;
}
Also used : MalformedURLException(java.net.MalformedURLException) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Service(javax.xml.ws.Service) ServiceRefData(org.apache.openejb.core.webservices.ServiceRefData) Properties(java.util.Properties) URL(java.net.URL) InitialContext(javax.naming.InitialContext) HandlerResolverImpl(org.apache.openejb.core.webservices.HandlerResolverImpl) HandlerResolver(javax.xml.ws.handler.HandlerResolver) PortAddress(org.apache.openejb.core.webservices.PortAddress) WebServiceFeature(javax.xml.ws.WebServiceFeature) NamingException(javax.naming.NamingException) PortRefData(org.apache.openejb.core.webservices.PortRefData)

Example 5 with HandlerResolver

use of javax.xml.ws.handler.HandlerResolver in project tomee by apache.

the class WsMetaData method createWebservice.

public Object createWebservice() throws Exception {
    // load service class which is used to construct the port
    Class<? extends Service> serviceClass = loadClass(serviceClassName).asSubclass(Service.class);
    if (serviceClass == null) {
        throw new NamingException("Could not load service type class " + serviceClassName);
    }
    // load the reference class which is the ultimate type of the port
    final Class<?> referenceClass = loadClass(referenceClassName);
    // if ref class is a subclass of Service, use it for the service class
    if (referenceClass != null && Service.class.isAssignableFrom(referenceClass)) {
        serviceClass = referenceClass.asSubclass(Service.class);
    }
    // Service QName
    final QName serviceQName = QName.valueOf(this.serviceQName);
    // WSDL URL
    final URL wsdlLocation = new URL(this.wsdlUrl);
    JaxWsProviderWrapper.beforeCreate(portRefs);
    Service instance;
    try {
        instance = null;
        if (Service.class.equals(serviceClass)) {
            instance = Service.create(wsdlLocation, serviceQName);
        } else {
            try {
                instance = serviceClass.getConstructor(URL.class, QName.class).newInstance(wsdlLocation, serviceQName);
            } catch (Throwable e) {
                throw (NamingException) new NamingException("Could not instantiate jax-ws service class " + serviceClass.getName()).initCause(e);
            }
        }
    } finally {
        JaxWsProviderWrapper.afterCreate();
    }
    if (!handlerChains.isEmpty()) {
        final InjectionMetaData injectionMetaData = ClientInstance.get().getComponent(InjectionMetaData.class);
        final List<Injection> injections = injectionMetaData.getInjections();
        final HandlerResolver handlerResolver = new ClientHandlerResolverImpl(handlerChains, injections, new InitialContext());
        instance.setHandlerResolver(handlerResolver);
    }
    final Object port;
    if (referenceClass != null && !Service.class.isAssignableFrom(referenceClass)) {
        // do port lookup
        port = instance.getPort(referenceClass);
    } else {
        // return service
        port = instance;
    }
    return port;
}
Also used : QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) URL(java.net.URL) InitialContext(javax.naming.InitialContext) HandlerResolver(javax.xml.ws.handler.HandlerResolver) NamingException(javax.naming.NamingException)

Aggregations

HandlerResolver (javax.xml.ws.handler.HandlerResolver)9 ArrayList (java.util.ArrayList)6 PortInfo (javax.xml.ws.handler.PortInfo)6 List (java.util.List)5 QName (javax.xml.namespace.QName)4 WebServiceException (javax.xml.ws.WebServiceException)4 Handler (javax.xml.ws.handler.Handler)4 ViteroSecurityHandler (de.vitero.ViteroSecurityHandler)2 GetModulesForCustomerRequest (de.vitero.schema.licence.GetModulesForCustomerRequest)2 Licence (de.vitero.schema.licence.Licence)2 LicenceService (de.vitero.schema.licence.LicenceService)2 Modulestype (de.vitero.schema.licence.Modulestype)2 ConnectException (java.net.ConnectException)2 URL (java.net.URL)2 DataHandler (javax.activation.DataHandler)2 InitialContext (javax.naming.InitialContext)2 NamingException (javax.naming.NamingException)2 Service (javax.xml.ws.Service)2 WebServiceFeature (javax.xml.ws.WebServiceFeature)2 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)2