private boolean isServerMessage(MessageContext context) { return context.containsKey(MessageContext.SERVLET_REQUEST) || context.containsKey(MessageContext.SERVLET_RESPONSE) || context.containsKey(MessageContext.SERVLET_CONTEXT); }
public static boolean isOutbound(MessageContext messageContext) { return (Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); }
private void setMessageOutboundProperty(MessageContext context) { context.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, this.outbound); if (logicalMessageContext != null) { logicalMessageContext.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, this.outbound); } if (protocolMessageContext != null) { protocolMessageContext.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, this.outbound); } }
protected void updateHeader(Exchange exchange, MessageContext ctx) { if (ctx.containsKey(Header.HEADER_LIST) && ctx.get(Header.HEADER_LIST) instanceof List<?>) { List<?> list = (List<?>) ctx.get(Header.HEADER_LIST); if (list != null && !list.isEmpty()) { SoapMessage sm = (SoapMessage) createResponseMessage(exchange); if (sm != null) { Iterator<?> iter = list.iterator(); while (iter.hasNext()) { Header header = (Header) iter.next(); if (header.getDirection() != Header.Direction.DIRECTION_IN && !header.getName().getNamespaceURI(). equals("http://docs.oasis-open.org/wss/2004/01/" + "oasis-200401-wss-wssecurity-secext-1.0.xsd") && !header.getName().getNamespaceURI(). equals("http://docs.oasis-open.org/" + "wss/oasis-wss-wssecurity-secext-1.1.xsd")) { //don't copy over security header, out interceptor chain will take care of it. sm.getHeaders().add(header); } } } } } }
String wssePassword = null; try { SOAPHeader header = context.getMessage().getSOAPHeader(); Iterator<?> headerElements = header.examineAllHeaderElements(); while (headerElements.hasNext()) { context.setScope("USERNAME", Scope.APPLICATION); context.setScope("PASSWORD", Scope.APPLICATION);
/** * Obtain handler chain from annotations. * * @param obj A endpoint implementation class or a SEI, or a generated * service class. */ private List<Handler> getHandlersFromAnnotation(Class<?> clazz, PortInfo portInfo) { AnnotationHandlerChainBuilder builder = new AnnotationHandlerChainBuilder(); return builder.buildHandlerChainFromClass(clazz, portInfo != null ? portInfo.getPortName() : null, portInfo != null ? portInfo.getServiceName() : null, portInfo != null ? portInfo.getBindingID() : null); }
public class MyHandlerResolver implements HandlerResolver { @Override public List<Handler> getHandlerChain(PortInfo portInfo) { List<Handler> handlerChain = Lists.newArrayList(); Handler soapHandler = new MySoapHandler(); String bindingID = portInfo.getBindingID(); if (bindingID.equals("http://schemas.xmlsoap.org/wsdl/soap/http")) { handlerChain.add(soapHandler); } else if (bindingID.equals("http://java.sun.com/xml/ns/jaxws/2003/05/soap/bindings/HTTP/")) { handlerChain.add(soapHandler); } return handlerChain; } }
@Override public boolean handleMessage(T context) { return delegate.handleMessage(context); }
List<Handler> hc = jaxwsEndpoint.getJaxwsBinding().getHandlerChain(); hc.addAll(handlerResolver.getHandlerChain(portInfos.get(portName))); jaxwsEndpoint.getJaxwsBinding().setHandlerChain(hc); LOG.log(Level.FINE, "created proxy", obj);
private void invokeReversedClose() { int index = invokedHandlers.size() - 1; while (index >= 0) { Handler<?> handler = invokedHandlers.get(index); if (handler instanceof LogicalHandler) { handler.close(logicalMessageContext); } else { handler.close(protocolMessageContext); } invokedHandlers.remove(index); index--; } closed = true; }
@SuppressWarnings("unchecked") private boolean invokeReversedHandleFault(MessageContext ctx) { boolean continueProcessing = true; try { int index = invokedHandlers.size() - 2; while (index >= 0 && continueProcessing) { Handler<? extends MessageContext> h = invokedHandlers.get(index); if (h instanceof LogicalHandler) { LogicalHandler<LogicalMessageContext> lh = (LogicalHandler<LogicalMessageContext>)h; continueProcessing = lh.handleFault(logicalMessageContext); } else { Handler<MessageContext> ph = (Handler<MessageContext>)h; continueProcessing = ph.handleFault(protocolMessageContext); } if (!continueProcessing) { invokeReversedClose(); break; } index--; } } catch (RuntimeException e) { LOG.log(Level.WARNING, "HANDLER_RAISED_RUNTIME_EXCEPTION", e); invokeReversedClose(); continueProcessing = false; closed = true; throw e; } invokeReversedClose(); return continueProcessing; }
@SuppressWarnings("unchecked") private boolean invokeHandleFault(List<? extends Handler<?>> handlerChain, MessageContext ctx) { boolean continueProcessing = true; try { for (Handler<?> h : handlerChain) { if (invokeThisHandler(h)) { closeHandlers.add(h); markHandlerInvoked(h); Handler<MessageContext> lh = (Handler<MessageContext>)h; continueProcessing = lh.handleFault(ctx); } if (!continueProcessing) { break; } } } catch (RuntimeException e) { LOG.log(Level.WARNING, "HANDLER_RAISED_RUNTIME_EXCEPTION", e); continueProcessing = false; throw e; } return continueProcessing; }
@WebService public class MyService { @Resource WebServiceContext wsContext; /** * Web service operation */ @WebMethod public String myMethod() { MessageContext mc = wsContext.getMessageContext(); HttpServletRequest req = (HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST); System.out.println("Client IP = " + req.getRemoteAddr()); } }
protected void updateWebServiceContext(Exchange exchange, MessageContext ctx) { // Guard against wrong type associated with header list. // Need to copy header only if the message is going out. if (ctx.containsKey(Header.HEADER_LIST) && ctx.get(Header.HEADER_LIST) instanceof List<?>) { List<?> list = (List<?>) ctx.get(Header.HEADER_LIST); if (list != null && !list.isEmpty()) { SoapMessage sm = (SoapMessage) createResponseMessage(exchange); if (sm != null) { Iterator<?> iter = list.iterator(); while (iter.hasNext()) { sm.getHeaders().add((Header) iter.next()); } } } } if (exchange.getOutMessage() != null) { Message out = exchange.getOutMessage(); if (out.containsKey(Message.PROTOCOL_HEADERS)) { Map<String, List<String>> heads = CastUtils .cast((Map<?, ?>)exchange.getOutMessage().get(Message.PROTOCOL_HEADERS)); if (heads.containsKey("Content-Type")) { List<String> ct = heads.get("Content-Type"); exchange.getOutMessage().put(Message.CONTENT_TYPE, ct.get(0)); heads.remove("Content-Type"); } } } }
private void setMessageOutboundProperty(MessageContext context) { context.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, this.outbound); if (logicalMessageContext != null) { logicalMessageContext.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, this.outbound); } if (protocolMessageContext != null) { protocolMessageContext.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, this.outbound); } }
@SuppressWarnings("rawtypes") public List<Handler> getHandlerChain(PortInfo portInfo) { bindingID = portInfo.getBindingID(); return chain; }
markHandlerInvoked(h); Handler<MessageContext> lh = (Handler<MessageContext>)h; continueProcessing = lh.handleMessage(ctx);
List<Handler> hc = clientFac.getHandlers(); hc.addAll(handlerResolver.getHandlerChain(portInfos.get(portName))); endpoint.getJaxwsBinding().setHandlerChain(hc);
public final boolean isUserInRole(final String role) { SecurityContext ctx = (SecurityContext)getMessageContext().get(SecurityContext.class.getName()); if (ctx == null) { return false; } return ctx.isUserInRole(role); }
public final Principal getUserPrincipal() { SecurityContext ctx = (SecurityContext)getMessageContext().get(SecurityContext.class.getName()); if (ctx == null) { return null; } return ctx.getUserPrincipal(); }