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;
}
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;
}
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"));
}
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;
}
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();
}
Aggregations