Java Code Examples for javax.xml.ws.handler.MessageContext#containsKey()

The following examples show how to use javax.xml.ws.handler.MessageContext#containsKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractJAXWSMethodInvoker.java    From cxf with Apache License 2.0 6 votes vote down vote up
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);
                    }
                }
            }
        }
    }
}
 
Example 2
Source File: TestHandlerBase.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected List<String> getHandlerInfoList(MessageContext ctx) {
    List<String> handlerInfoList = null;
    if (ctx.containsKey("handler.info")) {
        handlerInfoList = CastUtils.cast((List<?>)ctx.get("handler.info"));
    } else {
        handlerInfoList = new ArrayList<>();
        ctx.put("handler.info", handlerInfoList);
        ctx.setScope("handler.info", MessageContext.Scope.APPLICATION);
    }
    return handlerInfoList;
}
 
Example 3
Source File: AbstractJAXWSMethodInvoker.java    From cxf with Apache License 2.0 5 votes vote down vote up
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");
            }
        }
    }
}
 
Example 4
Source File: LoggingHandler.java    From juddi with Apache License 2.0 4 votes vote down vote up
private boolean isFaultReceived(MessageContext context)
{
    return context.containsKey(XLT_FAULT);
}
 
Example 5
Source File: OOBHdrServiceImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
private boolean checkContext() {
    boolean success = false;
    MessageContext ctx = context == null ? null : context.getMessageContext();
    if (ctx.containsKey(Header.HEADER_LIST)) {
        List<?> oobHdr = (List<?>) ctx.get(Header.HEADER_LIST);
        Iterator<?> iter = oobHdr.iterator();
        while (iter.hasNext()) {
            Object hdr = iter.next();
            if (hdr instanceof Header && ((Header) hdr).getObject() instanceof Node) {
                Header hdr1 = (Header) hdr;
                //System.out.println("Node conains : " + hdr1.getObject().toString());
                try {
                    JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(ObjectFactory.class)
                        .createUnmarshaller()
                        .unmarshal((Node) hdr1.getObject());
                    OutofBandHeader ob = (OutofBandHeader) job.getValue();
                    if ("testOobHeader".equals(ob.getName())
                        && "testOobHeaderValue".equals(ob.getValue())) {
                        if ("testHdrAttribute".equals(ob.getHdrAttribute())) {
                            success = true;
                            iter.remove(); //mark it processed
                        } else if ("dontProcess".equals(ob.getHdrAttribute())) {
                            //we won't remove it so we won't let the runtime know
                            //it's processed.   It SHOULD throw an exception
                            //saying the mustunderstand wasn't processed
                            success = true;
                        }
                    } else {
                        throw new RuntimeException("test failed");
                    }
                } catch (JAXBException ex) {
                    //
                    ex.printStackTrace();
                }
            }
        }
    } else {
        throw new RuntimeException("MessageContext is null or doesnot contain OOBHeaders");
    }

    return success;
}