Search in sources :

Example 1 with HandlerResolverImpl

use of org.apache.openejb.core.webservices.HandlerResolverImpl 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<QName, PortRefData>();
    final List<PortRefData> ports = new ArrayList<PortRefData>(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 2 with HandlerResolverImpl

use of org.apache.openejb.core.webservices.HandlerResolverImpl in project tomee by apache.

the class CxfEndpoint method initHandlers.

/**
     * Set appropriate handlers for the port/service/bindings.
     */
protected void initHandlers() throws Exception {
    PortInfoImpl portInfo = new PortInfoImpl(implInfo.getBindingType(), serviceFactory.getEndpointName(), service.getName());
    handlerResolver = new HandlerResolverImpl(port.getHandlerChains(), port.getInjections(), context);
    List<Handler> chain = handlerResolver.getHandlerChain(portInfo);
    getBinding().setHandlerChain(chain);
}
Also used : HandlerResolverImpl(org.apache.openejb.core.webservices.HandlerResolverImpl) Handler(javax.xml.ws.handler.Handler) PortInfoImpl(org.apache.cxf.jaxws.handler.PortInfoImpl)

Aggregations

HandlerResolverImpl (org.apache.openejb.core.webservices.HandlerResolverImpl)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 QName (javax.xml.namespace.QName)1 Service (javax.xml.ws.Service)1 WebServiceFeature (javax.xml.ws.WebServiceFeature)1 Handler (javax.xml.ws.handler.Handler)1 HandlerResolver (javax.xml.ws.handler.HandlerResolver)1 PortInfoImpl (org.apache.cxf.jaxws.handler.PortInfoImpl)1 PortAddress (org.apache.openejb.core.webservices.PortAddress)1 PortRefData (org.apache.openejb.core.webservices.PortRefData)1 ServiceRefData (org.apache.openejb.core.webservices.ServiceRefData)1