Search in sources :

Example 1 with Handler

use of jakarta.xml.ws.handler.Handler in project metro-jax-ws by eclipse-ee4j.

the class DispatchHello method testDispatchPropertySoapUseAction.

public void testDispatchPropertySoapUseAction() {
    try {
        Dispatch dispatch = getDispatchSource();
        Source source = makeStreamSource(helloMsg);
        List<Handler> handlerchain = new ArrayList<Handler>();
        handlerchain.add(new MyHandler());
        dispatch.getBinding().setHandlerChain(handlerchain);
        dispatch.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
        dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, "urn:test:hello_mod");
        Object result = dispatch.invoke(source);
        assertTrue(result instanceof Source);
        String xmlResult = sourceToXMLString((Source) result);
        System.out.println("Got result : " + xmlResult);
    // tbd update assertion
    } catch (Exception ex) {
        fail("SOAPAction test fails");
    }
}
Also used : Dispatch(jakarta.xml.ws.Dispatch) Handler(jakarta.xml.ws.handler.Handler) SOAPHandler(jakarta.xml.ws.handler.soap.SOAPHandler) Source(javax.xml.transform.Source) MalformedURLException(java.net.MalformedURLException) WebServiceException(jakarta.xml.ws.WebServiceException) JAXBException(jakarta.xml.bind.JAXBException) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException)

Example 2 with Handler

use of jakarta.xml.ws.handler.Handler in project metro-jax-ws by eclipse-ee4j.

the class HandlerChainsModel method parseHandlerFile.

/**
 * <p>This method is called internally by HandlerAnnotationProcessor,
 * and by
 * {@link com.sun.xml.ws.transport.http.DeploymentDescriptorParser}
 * directly when it reaches the handler chains element in the
 * descriptor file it is parsing.
 * @param reader should be on &lt;handler-chains&gt; element
 * @return A HandlerAnnotationInfo object that stores the
 * handlers and roles.
 */
public static HandlerAnnotationInfo parseHandlerFile(XMLStreamReader reader, ClassLoader classLoader, QName serviceName, QName portName, WSBinding wsbinding) {
    ensureProperName(reader, QNAME_HANDLER_CHAINS);
    String bindingId = wsbinding.getBindingId().toString();
    HandlerAnnotationInfo info = new HandlerAnnotationInfo();
    XMLStreamReaderUtil.nextElementContent(reader);
    List<Handler> handlerChain = new ArrayList<>();
    Set<String> roles = new HashSet<>();
    while (reader.getName().equals(QNAME_HANDLER_CHAIN)) {
        XMLStreamReaderUtil.nextElementContent(reader);
        if (reader.getName().equals(QNAME_CHAIN_PORT_PATTERN)) {
            if (portName == null) {
                logger.warning("handler chain sepcified for port " + "but port QName passed to parser is null");
            }
            boolean parseChain = JAXWSUtils.matchQNames(portName, XMLStreamReaderUtil.getElementQName(reader));
            if (!parseChain) {
                skipChain(reader);
                continue;
            }
            XMLStreamReaderUtil.nextElementContent(reader);
        } else if (reader.getName().equals(QNAME_CHAIN_PROTOCOL_BINDING)) {
            if (bindingId == null) {
                logger.warning("handler chain sepcified for bindingId " + "but bindingId passed to parser is null");
            }
            String bindingConstraint = XMLStreamReaderUtil.getElementText(reader);
            boolean skipThisChain = true;
            StringTokenizer stk = new StringTokenizer(bindingConstraint);
            List<String> bindingList = new ArrayList<>();
            while (stk.hasMoreTokens()) {
                String tokenOrURI = stk.nextToken();
                /*
                    Convert short-form tokens to API's binding ids
                    Unknown token, Put it as it is
                    */
                tokenOrURI = DeploymentDescriptorParser.getBindingIdForToken(tokenOrURI);
                String binding = BindingID.parse(tokenOrURI).toString();
                bindingList.add(binding);
            }
            if (bindingList.contains(bindingId)) {
                skipThisChain = false;
            }
            if (skipThisChain) {
                skipChain(reader);
                continue;
            }
            XMLStreamReaderUtil.nextElementContent(reader);
        } else if (reader.getName().equals(QNAME_CHAIN_SERVICE_PATTERN)) {
            if (serviceName == null) {
                logger.warning("handler chain sepcified for service " + "but service QName passed to parser is null");
            }
            boolean parseChain = JAXWSUtils.matchQNames(serviceName, XMLStreamReaderUtil.getElementQName(reader));
            if (!parseChain) {
                skipChain(reader);
                continue;
            }
            XMLStreamReaderUtil.nextElementContent(reader);
        }
        // process all <handler> elements
        while (reader.getName().equals(QNAME_HANDLER)) {
            Handler handler;
            XMLStreamReaderUtil.nextContent(reader);
            if (reader.getName().equals(QNAME_HANDLER_NAME)) {
                skipTextElement(reader);
            }
            // handler class
            ensureProperName(reader, QNAME_HANDLER_CLASS);
            try {
                handler = (Handler) loadClass(classLoader, XMLStreamReaderUtil.getElementText(reader).trim()).newInstance();
            } catch (InstantiationException | IllegalAccessException ie) {
                throw new RuntimeException(ie);
            }
            XMLStreamReaderUtil.nextContent(reader);
            // init params (ignored)
            while (reader.getName().equals(QNAME_HANDLER_PARAM)) {
                skipInitParamElement(reader);
            }
            // headers (ignored)
            while (reader.getName().equals(QNAME_HANDLER_HEADER)) {
                skipTextElement(reader);
            }
            // roles (not stored per handler)
            while (reader.getName().equals(QNAME_HANDLER_ROLE)) {
                roles.add(XMLStreamReaderUtil.getElementText(reader));
                XMLStreamReaderUtil.nextContent(reader);
            }
            // call @PostConstruct method on handler if present
            for (Method method : handler.getClass().getMethods()) {
                if (method.getAnnotation(PostConstruct.class) == null) {
                    continue;
                }
                try {
                    method.invoke(handler);
                    break;
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
            handlerChain.add(handler);
            // move past </handler>
            ensureProperName(reader, QNAME_HANDLER);
            XMLStreamReaderUtil.nextContent(reader);
        }
        // move past </handler-chain>
        ensureProperName(reader, QNAME_HANDLER_CHAIN);
        XMLStreamReaderUtil.nextContent(reader);
    }
    info.setHandlers(handlerChain);
    info.setRoles(roles);
    return info;
}
Also used : ArrayList(java.util.ArrayList) Handler(jakarta.xml.ws.handler.Handler) Method(java.lang.reflect.Method) UtilException(com.sun.xml.ws.util.UtilException) HandlerAnnotationInfo(com.sun.xml.ws.util.HandlerAnnotationInfo) StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) List(java.util.List) PostConstruct(jakarta.annotation.PostConstruct) HashSet(java.util.HashSet)

Example 3 with Handler

use of jakarta.xml.ws.handler.Handler in project metro-jax-ws by eclipse-ee4j.

the class AddNumbersClient method testAddressingWithNoWSDLwithHandler.

public void testAddressingWithNoWSDLwithHandler() throws Exception {
    Service service = Service.create(SERVICE_QNAME);
    service.addPort(PORT_QNAME, SOAPBinding.SOAP11HTTP_BINDING, getAddress());
    Dispatch<SOAPMessage> dispatch = service.createDispatch(PORT_QNAME, SOAPMessage.class, Service.Mode.MESSAGE, new AddressingFeature());
    dispatch.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, true);
    dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, ADD_NUMBERS_ACTION);
    String message = "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"><S:Body>" + "<addNumbers xmlns=\"http://example.com/\">" + "<number1>10</number1>" + "<number2>10</number2>" + "</addNumbers>" + "</S:Body></S:Envelope>";
    List<Handler> handlerChain = dispatch.getBinding().getHandlerChain();
    handlerChain.add(new MyHandler());
    dispatch.getBinding().setHandlerChain(handlerChain);
    WsaUtils.invoke(dispatch, message);
}
Also used : AddressingFeature(jakarta.xml.ws.soap.AddressingFeature) Service(jakarta.xml.ws.Service) Handler(jakarta.xml.ws.handler.Handler) SOAPHandler(jakarta.xml.ws.handler.soap.SOAPHandler) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 4 with Handler

use of jakarta.xml.ws.handler.Handler in project metro-jax-ws by eclipse-ee4j.

the class HandlerClient method testLogicalGetSourceOnly.

/*
     * Test removes the static handler and adds a logical
     * handler that uses JAXB to change the message.
     */
// public void testLogicalJAXB() throws Exception {
// Hello stub = createStub();
// Binding binding = ((BindingProvider) stub).getBinding();
// 
// LogicalTestHandler handler = new LogicalTestHandler();
// handler.setHandleMode(LogicalTestHandler.HandleMode.JAXB);
// List<Handler> handlerChain = new ArrayList<Handler>();
// handlerChain.add(handler);
// binding.setHandlerChain(handlerChain);
// 
// 
// int x = 1;
// int diff = 4; // 2 per handler invoked
// 
// int y = stub.hello(x);
// assertEquals(x+diff, y); // x+4 with all handlers
// }
/*
     * Test removes the static handler and adds a logical
     * handler that gets the source but does not change it.
     */
public void testLogicalGetSourceOnly() throws Exception {
    Hello stub = createStub();
    Binding binding = ((BindingProvider) stub).getBinding();
    LogicalTestHandler handler = new LogicalTestHandler();
    handler.setHandleMode(LogicalTestHandler.HandleMode.SOURCE_NO_CHANGE);
    List<Handler> handlerChain = new ArrayList<Handler>();
    handlerChain.add(handler);
    binding.setHandlerChain(handlerChain);
    int x = 1;
    // 2 per handler invoked
    int diff = 2;
    int y = stub.hello(x);
    assertEquals(x + diff, y);
}
Also used : Binding(jakarta.xml.ws.Binding) ArrayList(java.util.ArrayList) Handler(jakarta.xml.ws.handler.Handler) SOAPTestHandler(fromwsdl.handler_simple_rpclit.common.SOAPTestHandler) BindingProvider(jakarta.xml.ws.BindingProvider)

Example 5 with Handler

use of jakarta.xml.ws.handler.Handler in project metro-jax-ws by eclipse-ee4j.

the class HandlerClient method testLogicalSource.

/*
     * Test removes the static handler and adds a logical
     * handler that uses a Source to change the message.
     */
public void testLogicalSource() throws Exception {
    Hello stub = createStub();
    Binding binding = ((BindingProvider) stub).getBinding();
    LogicalTestHandler handler = new LogicalTestHandler();
    handler.setHandleMode(LogicalTestHandler.HandleMode.SOURCE);
    List<Handler> handlerChain = new ArrayList<Handler>();
    handlerChain.add(handler);
    binding.setHandlerChain(handlerChain);
    int x = 1;
    // 2 per handler invoked
    int diff = 4;
    int y = stub.hello(x);
    // x+4 with all handlers
    assertEquals(x + diff, y);
}
Also used : Binding(jakarta.xml.ws.Binding) ArrayList(java.util.ArrayList) Handler(jakarta.xml.ws.handler.Handler) SOAPTestHandler(fromwsdl.handler_simple_rpclit.common.SOAPTestHandler) BindingProvider(jakarta.xml.ws.BindingProvider)

Aggregations

Handler (jakarta.xml.ws.handler.Handler)43 Binding (jakarta.xml.ws.Binding)30 BindingProvider (jakarta.xml.ws.BindingProvider)28 ArrayList (java.util.ArrayList)18 SOAPBinding (jakarta.xml.ws.soap.SOAPBinding)15 SOAPTestHandler (fromwsdl.handler_simple.common.SOAPTestHandler)7 Service (jakarta.xml.ws.Service)7 List (java.util.List)7 HandlerResolver (jakarta.xml.ws.handler.HandlerResolver)6 PortInfo (jakarta.xml.ws.handler.PortInfo)6 SOAPTestHandler (fromwsdl.handler_simple_rpclit.common.SOAPTestHandler)5 BaseSOAPHandler (fromwsdl.handler.common.BaseSOAPHandler)4 WebServiceException (jakarta.xml.ws.WebServiceException)4 Source (javax.xml.transform.Source)4 HandlerTracker (fromwsdl.handler.common.HandlerTracker)3 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)3 HandlerAnnotationInfo (com.sun.xml.ws.util.HandlerAnnotationInfo)2 BaseSOAPHandler (handler.handler_processing.common.BaseSOAPHandler)2 SOAPMessage (jakarta.xml.soap.SOAPMessage)2 AsyncHandler (jakarta.xml.ws.AsyncHandler)2