Search in sources :

Example 26 with Handler

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

the class HandlerResolverImpl method sortHandlers.

/**
 * sorts the handlers into correct order. All of the logical handlers first
 * followed by the protocol handlers
 *
 * @param handlers
 * @return sorted list of handlers
 */
private List<Handler> sortHandlers(final List<Handler> handlers) {
    final List<LogicalHandler> logicalHandlers = new ArrayList<>();
    final List<Handler> protocolHandlers = new ArrayList<>();
    for (final Handler handler : handlers) {
        if (handler instanceof LogicalHandler) {
            logicalHandlers.add((LogicalHandler) handler);
        } else {
            protocolHandlers.add(handler);
        }
    }
    final List<Handler> sortedHandlers = new ArrayList<>();
    sortedHandlers.addAll(logicalHandlers);
    sortedHandlers.addAll(protocolHandlers);
    return sortedHandlers;
}
Also used : LogicalHandler(javax.xml.ws.handler.LogicalHandler) ArrayList(java.util.ArrayList) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Handler(javax.xml.ws.handler.Handler)

Example 27 with Handler

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

the class HandlerResolverImpl method buildHandlers.

private List<Handler> buildHandlers(final PortInfo portInfo, final HandlerChainData handlerChain) {
    if (!matchServiceName(portInfo, handlerChain.getServiceNamePattern()) || !matchPortName(portInfo, handlerChain.getPortNamePattern()) || !matchBinding(portInfo, handlerChain.getProtocolBindings())) {
        return Collections.emptyList();
    }
    final List<Handler> handlers = new ArrayList<>(handlerChain.getHandlers().size());
    for (final HandlerData handler : handlerChain.getHandlers()) {
        final WebBeansContext webBeansContext = AppFinder.findAppContextOrWeb(Thread.currentThread().getContextClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE);
        if (webBeansContext != null) {
            // cdi
            final BeanManagerImpl bm = webBeansContext.getBeanManagerImpl();
            if (bm.isInUse()) {
                try {
                    final Set<Bean<?>> beans = bm.getBeans(handler.getHandlerClass());
                    final Bean<?> bean = bm.resolve(beans);
                    if (bean != null) {
                        // proxy so faster to do it
                        final boolean normalScoped = bm.isNormalScope(bean.getScope());
                        final CreationalContextImpl<?> creationalContext = bm.createCreationalContext(bean);
                        final Handler instance = Handler.class.cast(bm.getReference(bean, bean.getBeanClass(), creationalContext));
                        // hack for destroyHandlers()
                        handlers.add(instance);
                        handlerInstances.add(new InjectionProcessor<Handler>(instance, Collections.<Injection>emptySet(), null) {

                            @Override
                            public void preDestroy() {
                                if (!normalScoped) {
                                    creationalContext.release();
                                }
                            }
                        });
                        continue;
                    }
                } catch (final InjectionException ie) {
                    LOGGER.info(ie.getMessage(), ie);
                }
            }
        }
        try {
            // old way
            final Class<? extends Handler> handlerClass = handler.getHandlerClass().asSubclass(Handler.class);
            final InjectionProcessor<Handler> processor = new InjectionProcessor<>(handlerClass, injections, handler.getPostConstruct(), handler.getPreDestroy(), unwrap(context));
            processor.createInstance();
            processor.postConstruct();
            final Handler handlerInstance = processor.getInstance();
            handlers.add(handlerInstance);
            handlerInstances.add(processor);
        } catch (final Exception e) {
            throw new WebServiceException("Failed to instantiate handler", e);
        }
    }
    return handlers;
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) ArrayList(java.util.ArrayList) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Handler(javax.xml.ws.handler.Handler) Injection(org.apache.openejb.Injection) InjectionProcessor(org.apache.openejb.InjectionProcessor) InjectionException(javax.enterprise.inject.InjectionException) WebServiceException(javax.xml.ws.WebServiceException) Bean(javax.enterprise.inject.spi.Bean) InjectionException(javax.enterprise.inject.InjectionException) WebBeansContext(org.apache.webbeans.config.WebBeansContext) BeanManagerImpl(org.apache.webbeans.container.BeanManagerImpl)

Example 28 with Handler

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

the class HandlerResolverImplTest method testBasic.

public void testBasic() throws Exception {
    final HandlerChains handlerChains = readHandlerChains("/handlers.xml");
    assertEquals(3, handlerChains.getHandlerChain().size());
    final List<HandlerChainInfo> handlerChainInfos = ConfigurationFactory.toHandlerChainInfo(handlerChains);
    final List<HandlerChainData> handlerChainDatas = WsBuilder.toHandlerChainData(handlerChainInfos, getClass().getClassLoader());
    final HandlerResolverImpl resolver = new HandlerResolverImpl(handlerChainDatas, null, new InitialContext());
    List<Handler> handlers = null;
    handlers = resolver.getHandlerChain(new TestPortInfo(null, null, null));
    assertEquals(3, handlers.size());
}
Also used : HandlerChainInfo(org.apache.openejb.assembler.classic.HandlerChainInfo) Handler(javax.xml.ws.handler.Handler) HandlerChains(org.apache.openejb.jee.HandlerChains) InitialContext(javax.naming.InitialContext)

Example 29 with Handler

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

the class HandlerResolverImplTest method testServiceMatching.

public void testServiceMatching() throws Exception {
    final HandlerChains handlerChains = readHandlerChains("/handlers_service.xml");
    assertEquals(3, handlerChains.getHandlerChain().size());
    final List<HandlerChainInfo> handlerChainInfos = ConfigurationFactory.toHandlerChainInfo(handlerChains);
    final List<HandlerChainData> handlerChainDatas = WsBuilder.toHandlerChainData(handlerChainInfos, getClass().getClassLoader());
    final HandlerResolverImpl resolver = new HandlerResolverImpl(handlerChainDatas, null, new InitialContext());
    List<Handler> handlers = null;
    handlers = resolver.getHandlerChain(new TestPortInfo(null, null, null));
    assertEquals(0, handlers.size());
    final QName serviceName1 = new QName("http://java.sun.com/xml/ns/javaee", "Bar");
    handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName1));
    assertEquals(1, handlers.size());
    final QName serviceName2 = new QName("http://java.sun.com/xml/ns/javaee", "Foo");
    handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName2));
    assertEquals(2, handlers.size());
    final QName serviceName3 = new QName("http://java.sun.com/xml/ns/javaee", "FooBar");
    handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName3));
    assertEquals(1, handlers.size());
    final QName serviceName4 = new QName("http://java.sun.com/xml/ns/javaee", "BarFoo");
    handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName4));
    assertEquals(0, handlers.size());
}
Also used : HandlerChainInfo(org.apache.openejb.assembler.classic.HandlerChainInfo) QName(javax.xml.namespace.QName) Handler(javax.xml.ws.handler.Handler) HandlerChains(org.apache.openejb.jee.HandlerChains) InitialContext(javax.naming.InitialContext)

Example 30 with Handler

use of javax.xml.ws.handler.Handler in project openolat by klemens.

the class ViteroManager method checkConnection.

public boolean checkConnection(final String url, final String login, final String password, final int customerId) throws VmsNotAvailableException {
    try {
        LicenceService ss = new LicenceService();
        ss.setHandlerResolver(new HandlerResolver() {

            @SuppressWarnings("rawtypes")
            @Override
            public List<Handler> getHandlerChain(PortInfo portInfo) {
                List<Handler> handlerList = new ArrayList<Handler>();
                handlerList.add(new ViteroSecurityHandler(login, password));
                return handlerList;
            }
        });
        Licence port = ss.getLicenceSoap11();
        String endPoint = UriBuilder.fromUri(url).path("services").path("LicenseService").build().toString();
        ((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPoint);
        GetModulesForCustomerRequest request = new GetModulesForCustomerRequest();
        request.setCustomerid(customerId);
        Modulestype modulesType = port.getModulesForCustomer(request);
        return modulesType != null;
    } catch (SOAPFaultException f) {
        ErrorCode code = handleAxisFault(f);
        switch(code) {
            case unsufficientRights:
                log.error("Unsufficient rights", f);
                break;
            default:
                logAxisError("Cannot check connection", f);
        }
        return false;
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        log.warn("Error checking connection", e);
        return false;
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Handler(javax.xml.ws.handler.Handler) ViteroSecurityHandler(de.vitero.ViteroSecurityHandler) DataHandler(javax.activation.DataHandler) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Modulestype(de.vitero.schema.licence.Modulestype) PortInfo(javax.xml.ws.handler.PortInfo) HandlerResolver(javax.xml.ws.handler.HandlerResolver) GetModulesForCustomerRequest(de.vitero.schema.licence.GetModulesForCustomerRequest) Licence(de.vitero.schema.licence.Licence) ArrayList(java.util.ArrayList) List(java.util.List) ErrorCode(org.olat.modules.vitero.model.ErrorCode) ViteroSecurityHandler(de.vitero.ViteroSecurityHandler) LicenceService(de.vitero.schema.licence.LicenceService) ConnectException(java.net.ConnectException)

Aggregations

Handler (javax.xml.ws.handler.Handler)100 QName (javax.xml.namespace.QName)47 ArrayList (java.util.ArrayList)46 BindingProvider (javax.xml.ws.BindingProvider)36 URL (java.net.URL)32 Service (javax.xml.ws.Service)29 Test (org.junit.Test)29 LogicalHandler (javax.xml.ws.handler.LogicalHandler)24 Binding (javax.xml.ws.Binding)11 WebServiceException (javax.xml.ws.WebServiceException)11 MessageContext (javax.xml.ws.handler.MessageContext)9 SOAPHandler (javax.xml.ws.handler.soap.SOAPHandler)9 Exchange (org.apache.cxf.message.Exchange)9 IOException (java.io.IOException)8 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)7 HandlerChainInvoker (org.apache.cxf.jaxws.handler.HandlerChainInvoker)7 DataHandler (javax.activation.DataHandler)6 InitialContext (javax.naming.InitialContext)6 Source (javax.xml.transform.Source)6 DOMSource (javax.xml.transform.dom.DOMSource)6