Search in sources :

Example 1 with LogicalHandler

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

the class CXFHandlerResolverImpl method sortHandlers.

@SuppressWarnings("rawtypes")
public List<Handler> sortHandlers(List<Handler> handlers) {
    final int size = handlers.size();
    List<Handler> logicalHandlers = new ArrayList<Handler>(size);
    List<Handler> protocolHandlers = new ArrayList<Handler>(Math.min(10, size));
    for (Handler handler : handlers) {
        if (handler instanceof LogicalHandler) {
            logicalHandlers.add(handler);
        } else {
            protocolHandlers.add(handler);
        }
    }
    if (!protocolHandlers.isEmpty()) {
        logicalHandlers.addAll(protocolHandlers);
    }
    return logicalHandlers;
}
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 2 with LogicalHandler

use of javax.xml.ws.handler.LogicalHandler 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 3 with LogicalHandler

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

the class JaxWsClientTest method testLogicalHandler.

@Test
public void testLogicalHandler() {
    URL url = getClass().getResource("/wsdl/hello_world.wsdl");
    javax.xml.ws.Service s = javax.xml.ws.Service.create(url, SERVICE_NAME);
    Greeter greeter = s.getPort(PORT_NAME, Greeter.class);
    d.setMessageObserver(new MessageReplayObserver("sayHiResponse.xml"));
    // JAX-WS api doesn't specify this as List<Handler<? extends MessageContext>>
    @SuppressWarnings("rawtypes") List<Handler> chain = ((BindingProvider) greeter).getBinding().getHandlerChain();
    chain.add(new LogicalHandler<LogicalMessageContext>() {

        public void close(MessageContext arg0) {
        }

        public boolean handleFault(LogicalMessageContext arg0) {
            return true;
        }

        public boolean handleMessage(LogicalMessageContext context) {
            Boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
            if (outbound) {
                headers = CastUtils.cast((Map<?, ?>) context.get(MessageContext.HTTP_REQUEST_HEADERS));
                if (headers == null) {
                    headers = new HashMap<>();
                    context.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
                }
                headers.put("My-Custom-Header", Collections.singletonList("value"));
            }
            return true;
        }
    });
    ((BindingProvider) greeter).getBinding().setHandlerChain(chain);
    String response = greeter.sayHi();
    assertNotNull(response);
    assertTrue("custom header should be present", headers.containsKey("My-Custom-Header"));
    assertTrue("existing SOAPAction header should not be removed", headers.containsKey("SOAPAction"));
}
Also used : LogicalMessageContext(javax.xml.ws.handler.LogicalMessageContext) HashMap(java.util.HashMap) SOAPHandler(javax.xml.ws.handler.soap.SOAPHandler) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Handler(javax.xml.ws.handler.Handler) InvocationHandler(java.lang.reflect.InvocationHandler) URL(java.net.URL) Greeter(org.apache.hello_world_soap_http.Greeter) MessageContext(javax.xml.ws.handler.MessageContext) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) LogicalMessageContext(javax.xml.ws.handler.LogicalMessageContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 4 with LogicalHandler

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

the class ClientHandlerResolverImpl method sortHandlers.

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

Example 5 with LogicalHandler

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

the class LogicalHandlerInterceptorTest method testInterceptSuccess.

@Test
public void testInterceptSuccess() {
    List<LogicalHandler<?>> list = new ArrayList<>();
    list.add(new LogicalHandler<LogicalMessageContext>() {

        public void close(MessageContext arg0) {
        }

        public boolean handleFault(LogicalMessageContext arg0) {
            return true;
        }

        public boolean handleMessage(LogicalMessageContext arg0) {
            return true;
        }
    });
    @SuppressWarnings("rawtypes") List<Handler> hList = CastUtils.cast(list);
    expect(binding.getHandlerChain()).andReturn(hList).anyTimes();
    expect(invoker.getLogicalHandlers()).andReturn(list);
    expect(message.getExchange()).andReturn(exchange).anyTimes();
    expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes();
    expect(message.keySet()).andReturn(new TreeSet<String>()).anyTimes();
    expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker);
    expect(exchange.getOutMessage()).andReturn(message);
    expect(invoker.invokeLogicalHandlers(eq(true), isA(LogicalMessageContext.class))).andReturn(true);
    control.replay();
    LogicalHandlerInInterceptor li = new LogicalHandlerInInterceptor(binding);
    assertEquals("unexpected phase", "pre-protocol-frontend", li.getPhase());
    li.handleMessage(message);
    control.verify();
}
Also used : LogicalMessageContext(javax.xml.ws.handler.LogicalMessageContext) TreeSet(java.util.TreeSet) LogicalHandler(javax.xml.ws.handler.LogicalHandler) ArrayList(java.util.ArrayList) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Handler(javax.xml.ws.handler.Handler) LogicalHandlerInInterceptor(org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor) LogicalMessageContext(javax.xml.ws.handler.LogicalMessageContext) MessageContext(javax.xml.ws.handler.MessageContext) Test(org.junit.Test)

Aggregations

Handler (javax.xml.ws.handler.Handler)6 LogicalHandler (javax.xml.ws.handler.LogicalHandler)6 ArrayList (java.util.ArrayList)5 LogicalMessageContext (javax.xml.ws.handler.LogicalMessageContext)3 MessageContext (javax.xml.ws.handler.MessageContext)3 Test (org.junit.Test)3 LogicalHandlerInInterceptor (org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor)2 InvocationHandler (java.lang.reflect.InvocationHandler)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Binding (javax.xml.ws.Binding)1 LogicalMessage (javax.xml.ws.LogicalMessage)1 SOAPHandler (javax.xml.ws.handler.soap.SOAPHandler)1 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)1 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)1 Exchange (org.apache.cxf.message.Exchange)1 Message (org.apache.cxf.message.Message)1 MessageImpl (org.apache.cxf.message.MessageImpl)1