Search in sources :

Example 16 with Handler

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

the class Helper method testCustomClientConfigurationOnDispatchFromFile.

public boolean testCustomClientConfigurationOnDispatchFromFile() throws Exception {
    final String reqString = "<ns1:echo xmlns:ns1=\"http://clientConfig.jaxws.ws.test.jboss.org/\"><arg0>Kermit</arg0></ns1:echo>";
    QName serviceName = new QName("http://clientConfig.jaxws.ws.test.jboss.org/", "EndpointImplService");
    QName portName = new QName("http://clientConfig.jaxws.ws.test.jboss.org/", "EndpointPort");
    URL wsdlURL = new URL(address + "?wsdl");
    Service service = Service.create(wsdlURL, serviceName);
    Dispatch<Source> dispatch = service.createDispatch(portName, Source.class, Mode.PAYLOAD);
    BindingProvider bp = (BindingProvider) dispatch;
    @SuppressWarnings("rawtypes") List<Handler> hc = bp.getBinding().getHandlerChain();
    hc.add(new UserHandler());
    bp.getBinding().setHandlerChain(hc);
    ClientConfigUtil.setConfigHandlers(bp, "META-INF/jaxws-client-config.xml", "Custom Client Config");
    Source resSource = dispatch.invoke(new DOMSource(DOMUtils.parse(reqString)));
    resSource = dispatch.invoke(new DOMSource(DOMUtils.parse(reqString)));
    resSource = dispatch.invoke(new DOMSource(DOMUtils.parse(reqString)));
    String resStr = DOMUtils.getTextContent(DOMUtils.sourceToElement(resSource).getElementsByTagName("return").item(0));
    return ("Kermit|RoutOut|CustomOut|UserOut|LogOut|endpoint|LogIn|UserIn|CustomIn|RoutIn".equals(resStr));
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) Handler(javax.xml.ws.handler.Handler) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source)

Example 17 with Handler

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

the class Helper method testCustomClientConfigurationOnDispatchUsingFeature.

public boolean testCustomClientConfigurationOnDispatchUsingFeature() throws Exception {
    final String reqString = "<ns1:echo xmlns:ns1=\"http://clientConfig.jaxws.ws.test.jboss.org/\"><arg0>Kermit</arg0></ns1:echo>";
    QName serviceName = new QName("http://clientConfig.jaxws.ws.test.jboss.org/", "EndpointImplService");
    QName portName = new QName("http://clientConfig.jaxws.ws.test.jboss.org/", "EndpointPort");
    URL wsdlURL = new URL(address + "?wsdl");
    final String testConfigName = "MyTestConfig";
    try {
        // -- add test client configuration
        TestUtils.addTestCaseClientConfiguration(testConfigName);
        // --
        Service service = Service.create(wsdlURL, serviceName);
        Dispatch<Source> dispatch = service.createDispatch(portName, Source.class, Mode.PAYLOAD, new ClientConfigFeature(null, testConfigName));
        BindingProvider bp = (BindingProvider) dispatch;
        @SuppressWarnings("rawtypes") List<Handler> hc = bp.getBinding().getHandlerChain();
        hc.add(new UserHandler());
        bp.getBinding().setHandlerChain(hc);
        Source resSource = dispatch.invoke(new DOMSource(DOMUtils.parse(reqString)));
        resSource = dispatch.invoke(new DOMSource(DOMUtils.parse(reqString)));
        resSource = dispatch.invoke(new DOMSource(DOMUtils.parse(reqString)));
        String resStr = DOMUtils.getTextContent(DOMUtils.sourceToElement(resSource).getElementsByTagName("return").item(0));
        return ("Kermit|RoutOut|UserOut|endpoint|UserIn|RoutIn".equals(resStr));
    } finally {
        // -- remove test client configuration --
        TestUtils.removeTestCaseClientConfiguration(testConfigName);
    // --
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) QName(javax.xml.namespace.QName) ClientConfigFeature(org.jboss.ws.api.configuration.ClientConfigFeature) Service(javax.xml.ws.Service) Handler(javax.xml.ws.handler.Handler) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source)

Example 18 with Handler

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

the class SOAPBindingTestCase method testClientAccess.

@Test
@RunAsClient
public void testClientAccess() throws Exception {
    URL wsdlURL = new URL(baseURL + "?wsdl");
    QName qname = new QName("http://org.jboss.ws/jaxws/binding", "SOAPEndpointService");
    Service service = Service.create(wsdlURL, qname);
    SOAPEndpoint port = service.getPort(SOAPEndpoint.class);
    BindingProvider provider = (BindingProvider) port;
    @SuppressWarnings("rawtypes") List<Handler> handlerChain = new ArrayList<Handler>();
    handlerChain.addAll(provider.getBinding().getHandlerChain());
    handlerChain.add(new ClientHandler());
    handlerChain.add(new ClientHandler2());
    provider.getBinding().setHandlerChain(handlerChain);
    String nsURI = port.namespace();
    assertEquals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE + ":" + SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, nsURI);
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Service(javax.xml.ws.Service) Handler(javax.xml.ws.handler.Handler) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 19 with Handler

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

the class CXFHandlerResolverImpl method getHandlerChain.

@SuppressWarnings("rawtypes")
public List<Handler> getHandlerChain(PortInfo portInfo) {
    synchronized (handlerMap) {
        List<Handler> handlerChain = handlerMap.get(portInfo);
        if (handlerChain == null) {
            QName portQName = portInfo.getPortName();
            QName serviceQName = portInfo.getServiceName();
            String bindingId = portInfo.getBindingID();
            handlerChain = createHandlerChain(portInfo, portQName, serviceQName, bindingId);
            handlerMap.put(portInfo, handlerChain);
        }
        return handlerChain;
    }
}
Also used : QName(javax.xml.namespace.QName) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Handler(javax.xml.ws.handler.Handler)

Example 20 with Handler

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

the class CXFHandlerResolverImpl method createHandlerChain.

@SuppressWarnings("rawtypes")
protected List<Handler> createHandlerChain(PortInfo portInfo, QName portQName, QName serviceQName, String bindingID) {
    List<Handler> chain = new ArrayList<Handler>();
    InputStream is = getInputStream();
    try {
        if (is == null) {
            throw MESSAGES.handlerConfigFileNotFound(handlerFile);
        }
        Element el = DOMUtils.parse(is, Holder.builder);
        if (!ParserConstants.JAVAEE_NS.equals(el.getNamespaceURI()) || !ParserConstants.HANDLER_CHAINS.equals(el.getLocalName())) {
            throw MESSAGES.differentElementExpected(handlerFile, "{" + ParserConstants.JAVAEE_NS + "}" + ParserConstants.HANDLER_CHAINS, "{" + el.getNamespaceURI() + "}" + el.getLocalName());
        }
        Node node = el.getFirstChild();
        while (node != null) {
            if (node instanceof Element) {
                el = (Element) node;
                if (!el.getNamespaceURI().equals(ParserConstants.JAVAEE_NS) || !el.getLocalName().equals(ParserConstants.HANDLER_CHAIN)) {
                    throw MESSAGES.differentElementExpected(handlerFile, "{" + ParserConstants.JAVAEE_NS + "}" + ParserConstants.HANDLER_CHAIN, "{" + el.getNamespaceURI() + "}" + el.getLocalName());
                }
                processHandlerChainElement(el, chain, portQName, serviceQName, bindingID);
            }
            node = node.getNextSibling();
        }
    } catch (WebServiceException e) {
        throw e;
    } catch (Exception e) {
        throw MESSAGES.noHandlerChainFound(handlerFile, e);
    }
    assert chain != null;
    return sortHandlers(chain);
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Handler(javax.xml.ws.handler.Handler) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) WebServiceException(javax.xml.ws.WebServiceException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

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