Search in sources :

Example 86 with Handler

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

the class HandlerChainBuilderTest method testBuilderCallsInit.

@Test
public void testBuilderCallsInit() {
    List<PortComponentHandlerType> hc = createHandlerChainType();
    hc.remove(3);
    hc.remove(2);
    hc.remove(1);
    PortComponentHandlerType h = hc.get(0);
    List<ParamValueType> params = h.getInitParam();
    ParamValueType p = new ParamValueType();
    CString pName = new CString();
    pName.setValue("foo");
    p.setParamName(pName);
    XsdStringType pValue = new XsdStringType();
    pValue.setValue("1");
    p.setParamValue(pValue);
    params.add(p);
    p = new ParamValueType();
    pName = new CString();
    pName.setValue("bar");
    p.setParamName(pName);
    pValue = new XsdStringType();
    pValue.setValue("2");
    p.setParamValue(pValue);
    params.add(p);
    List<Handler> chain = builder.buildHandlerChainFromConfiguration(hc);
    assertEquals(1, chain.size());
    TestLogicalHandler tlh = (TestLogicalHandler) chain.get(0);
    assertTrue(tlh.initCalled);
    Map cfg = tlh.config;
    assertNotNull(tlh.config);
    assertEquals(2, cfg.keySet().size());
    assertEquals("1", cfg.get("foo"));
    assertEquals("2", cfg.get("bar"));
}
Also used : ParamValueType(org.apache.cxf.jaxws.handler.types.ParamValueType) XsdStringType(org.apache.cxf.jaxws.handler.types.XsdStringType) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Handler(javax.xml.ws.handler.Handler) PortComponentHandlerType(org.apache.cxf.jaxws.handler.types.PortComponentHandlerType) Map(java.util.Map) CString(org.apache.cxf.jaxws.handler.types.CString) Test(org.junit.Test)

Example 87 with Handler

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

the class JavaxAnnotationHandlerChainBuilderTest method testFindHandlerChainAnnotationPerPortServiceBindingWildcard.

@Test
public void testFindHandlerChainAnnotationPerPortServiceBindingWildcard() {
    JavaxHandlerTestImpl handlerTestImpl = new JavaxHandlerTestImpl();
    AnnotationHandlerChainBuilder chainBuilder = new AnnotationHandlerChainBuilder();
    QName portQName = new QName("http://apache.org/handler_test", "SoapPortWildcard");
    QName serviceQName = new QName("http://apache.org/handler_test", "SoapServiceWildcard");
    String bindingID = "BindingUnknow";
    @SuppressWarnings("rawtypes") List<Handler> handlers = chainBuilder.buildHandlerChainFromClass(handlerTestImpl.getClass(), portQName, serviceQName, bindingID);
    assertNotNull(handlers);
    assertEquals(7, handlers.size());
}
Also used : QName(javax.xml.namespace.QName) Handler(javax.xml.ws.handler.Handler) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Test(org.junit.Test)

Example 88 with Handler

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

the class BaseHandlerChainBuilder method build.

protected List<Handler> build(String namespace, Element el, QName portQName, QName serviceQName, String bindingID) {
    if (!HANDLER_CHAINS_E.equals(el.getLocalName())) {
        String xml = StaxUtils.toString(el);
        throw new WebServiceException(BundleUtils.getFormattedString(bundle, "NOT_VALID_ROOT_ELEMENT", namespace.equals(el.getNamespaceURI()), HANDLER_CHAINS_E.equals(el.getLocalName()), xml, handlerFileURL));
    }
    List<Handler> chain = new ArrayList<>();
    Node node = el.getFirstChild();
    while (node != null) {
        if (node instanceof Element) {
            el = (Element) node;
            if (!namespace.equals(el.getNamespaceURI())) {
                throw new WebServiceException(BundleUtils.getFormattedString(bundle, "NOT_VALID_NAMESPACE", el.getNamespaceURI()));
            }
            if (!HANDLER_CHAIN_E.equals(el.getLocalName())) {
                String xml = StaxUtils.toString(el);
                throw new WebServiceException(BundleUtils.getFormattedString(bundle, "NOT_VALID_ELEMENT_IN_HANDLER", xml));
            }
            processHandlerChainElement(namespace, el, chain, portQName, serviceQName, bindingID);
        }
        node = node.getNextSibling();
    }
    return chain;
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Handler(javax.xml.ws.handler.Handler)

Example 89 with Handler

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

the class HandlerChainBuilder method buildHandlerChain.

protected List<Handler> buildHandlerChain(PortComponentHandlerType ht, ClassLoader classLoader) {
    List<Handler> handlerChain = new ArrayList<>();
    try {
        final boolean fineLog = LOG.isLoggable(Level.FINE);
        if (fineLog) {
            LOG.log(Level.FINE, "loading handler", trimString(ht.getHandlerName().getValue()));
        }
        Class<? extends Handler> handlerClass = Class.forName(trimString(ht.getHandlerClass().getValue()), true, classLoader).asSubclass(Handler.class);
        Handler<?> handler = handlerClass.newInstance();
        if (fineLog) {
            LOG.fine("adding handler to chain: " + handler);
        }
        configureHandler(handler, ht);
        handlerChain.add(handler);
    } catch (Exception e) {
        throw new WebServiceException(BUNDLE.getString("HANDLER_INSTANTIATION_EXC"), e);
    }
    return handlerChain;
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) ArrayList(java.util.ArrayList) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Handler(javax.xml.ws.handler.Handler) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebServiceException(javax.xml.ws.WebServiceException)

Example 90 with Handler

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

the class JaxWsProxyFactoryBean method buildHandlerChain.

private void buildHandlerChain(JaxWsClientProxy cp) {
    AnnotationHandlerChainBuilder builder = new AnnotationHandlerChainBuilder();
    JaxWsServiceFactoryBean sf = (JaxWsServiceFactoryBean) getServiceFactory();
    @SuppressWarnings("rawtypes") List<Handler> chain = new ArrayList<>(handlers);
    if (loadHandlers) {
        chain.addAll(builder.buildHandlerChainFromClass(sf.getServiceClass(), sf.getEndpointInfo().getName(), sf.getServiceQName(), this.getBindingId()));
    }
    if (!chain.isEmpty()) {
        ResourceManager resourceManager = getBus().getExtension(ResourceManager.class);
        List<ResourceResolver> resolvers = resourceManager.getResourceResolvers();
        resourceManager = new DefaultResourceManager(resolvers);
        resourceManager.addResourceResolver(new WebServiceContextResourceResolver());
        ResourceInjector injector = new ResourceInjector(resourceManager);
        for (Handler<?> h : chain) {
            if (Proxy.isProxyClass(h.getClass()) && getServiceClass() != null) {
                injector.inject(h, getServiceClass());
                injector.construct(h, getServiceClass());
            } else {
                injector.inject(h);
                injector.construct(h);
            }
        }
    }
    cp.getBinding().setHandlerChain(chain);
}
Also used : JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) AnnotationHandlerChainBuilder(org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilder) ArrayList(java.util.ArrayList) Handler(javax.xml.ws.handler.Handler) DefaultResourceManager(org.apache.cxf.resource.DefaultResourceManager) ResourceManager(org.apache.cxf.resource.ResourceManager) ResourceInjector(org.apache.cxf.common.injection.ResourceInjector) DefaultResourceManager(org.apache.cxf.resource.DefaultResourceManager) ResourceResolver(org.apache.cxf.resource.ResourceResolver) WebServiceContextResourceResolver(org.apache.cxf.jaxws.context.WebServiceContextResourceResolver) WebServiceContextResourceResolver(org.apache.cxf.jaxws.context.WebServiceContextResourceResolver)

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