Search in sources :

Example 51 with Header

use of org.apache.cxf.headers.Header in project cxf by apache.

the class SAAJOutInterceptorTest method testHandleHeader.

@Test
public void testHandleHeader() throws Exception {
    soapMessage = TestUtil.createEmptySoapMessage(Soap11.getInstance(), chain);
    soapMessage.setContent(OutputStream.class, new ByteArrayOutputStream());
    SOAPMessage m = SAAJFactoryResolver.createMessageFactory(soapMessage.getVersion()).createMessage();
    InputStream ins = getClass().getResourceAsStream("../test-soap-header.xml");
    m.getSOAPPart().setContent(new StreamSource(ins));
    Element el = DOMUtils.getFirstElement(m.getSOAPPart().getEnvelope().getHeader());
    List<Header> h = soapMessage.getHeaders();
    while (el != null) {
        h.add(new SoapHeader(DOMUtils.getElementQName(el), el));
        el = DOMUtils.getNextElement(el);
    }
    soapMessage.setContent(SOAPMessage.class, m);
    W3CDOMStreamWriter writer = new SAAJStreamWriter(m.getSOAPPart());
    soapMessage.setContent(XMLStreamWriter.class, writer);
    soi.handleMessage(soapMessage);
}
Also used : W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) Header(org.apache.cxf.headers.Header) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Element(org.w3c.dom.Element) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPMessage(javax.xml.soap.SOAPMessage) Test(org.junit.Test)

Example 52 with Header

use of org.apache.cxf.headers.Header in project BIMserver by opensourceBIM.

the class SoapChannel method newToken.

@Override
public void newToken(String token) {
    if (useSoapHeaderSessions) {
        for (PublicInterface p : getServiceInterfaces().values()) {
            List<Header> headers = new ArrayList<Header>();
            try {
                Token tokenObject = new Token(token);
                Header sessionHeader = new Header(new QName("uri:org.bimserver.shared", "token"), tokenObject, new JAXBDataBinding(Token.class));
                headers.add(sessionHeader);
            } catch (JAXBException e) {
                LOGGER.error("", e);
            }
            ((BindingProvider) p).getRequestContext().put(Header.HEADER_LIST, headers);
        }
    }
}
Also used : PublicInterface(org.bimserver.shared.interfaces.PublicInterface) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) Token(org.bimserver.shared.Token) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding)

Example 53 with Header

use of org.apache.cxf.headers.Header in project BIMserver by opensourceBIM.

the class CustomInvoker method getServiceObject.

@Override
public Object getServiceObject(Exchange exchange) {
    Message inMessage = exchange.getInMessage();
    if (inMessage instanceof SoapMessage) {
        SoapMessage soapMessage = (SoapMessage) inMessage;
        Header header = soapMessage.getHeader(new QName("uri:org.bimserver.shared", "token"));
        String token = null;
        if (header != null) {
            token = ((Token) (header.getObject())).getToken();
        }
        if (token == null) {
            token = (String) exchange.getSession().get("token");
        }
        if (token != null) {
            try {
                return serviceFactory.get(token, AccessMethod.SOAP).get(interfaceClass);
            } catch (UserException e) {
                LOGGER.error("", e);
                return null;
            }
        } else {
            try {
                PublicInterface newService = serviceFactory.get(AccessMethod.SOAP).get(interfaceClass);
                exchange.getSession().put("token", token);
                return newService;
            } catch (UserException e) {
                LOGGER.error("", e);
            }
        }
    } else {
        try {
            return serviceFactory.get(AccessMethod.SOAP).get(interfaceClass);
        } catch (UserException e) {
            LOGGER.error("", e);
        }
    }
    return null;
}
Also used : Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) Header(org.apache.cxf.headers.Header) PublicInterface(org.bimserver.shared.interfaces.PublicInterface) QName(javax.xml.namespace.QName) UserException(org.bimserver.shared.exceptions.UserException) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 54 with Header

use of org.apache.cxf.headers.Header in project camel by apache.

the class HeaderTesterImpl method validateOutOfBandHander.

protected boolean validateOutOfBandHander() {
    MessageContext ctx = context == null ? null : context.getMessageContext();
    if (!relayHeaders) {
        if (ctx != null && !ctx.containsKey(Header.HEADER_LIST) || (ctx.containsKey(Header.HEADER_LIST) && ((List<?>) ctx.get(Header.HEADER_LIST)).size() == 0)) {
            return true;
        }
        return false;
    }
    boolean success = false;
    if (ctx != null && 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;
                try {
                    JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(org.apache.cxf.outofband.header.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;
                            //mark it processed
                            iter.remove();
                        } 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;
}
Also used : Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) JAXBElement(javax.xml.bind.JAXBElement) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) List(java.util.List) MessageContext(javax.xml.ws.handler.MessageContext)

Example 55 with Header

use of org.apache.cxf.headers.Header in project cxf by apache.

the class OOBHdrServiceImpl method sendReturnOOBHeader.

private void sendReturnOOBHeader() {
    if (context != null) {
        MessageContext ctx = context.getMessageContext();
        if (ctx != null) {
            try {
                // Create out-of-band header object.
                OutofBandHeader ob = new OutofBandHeader();
                ob.setName("testOobReturnHeaderName");
                ob.setValue("testOobReturnHeaderValue");
                ob.setHdrAttribute("testReturnHdrAttribute");
                // Add Out-of-band header object to HeaderHolder.
                JAXBElement<OutofBandHeader> job = new JAXBElement<OutofBandHeader>(new QName(OOBHeaderTest.TEST_HDR_NS, OOBHeaderTest.TEST_HDR_RESPONSE_ELEM), OutofBandHeader.class, null, ob);
                Header hdr = new Header(new QName(OOBHeaderTest.TEST_HDR_NS, OOBHeaderTest.TEST_HDR_RESPONSE_ELEM), job, new JAXBDataBinding(ob.getClass()));
                List<Header> hdrList = CastUtils.cast((List<?>) ctx.get(Header.HEADER_LIST));
                hdrList.add(hdr);
            // Add headerHolder to requestContext.
            // ctx.put(Header.HEADER_LIST, hdrList);
            // System.out.println("Completed adding list to context");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
}
Also used : OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) MessageContext(javax.xml.ws.handler.MessageContext) JAXBElement(javax.xml.bind.JAXBElement) JAXBException(javax.xml.bind.JAXBException)

Aggregations

Header (org.apache.cxf.headers.Header)78 QName (javax.xml.namespace.QName)29 Element (org.w3c.dom.Element)27 ArrayList (java.util.ArrayList)25 JAXBException (javax.xml.bind.JAXBException)24 SoapHeader (org.apache.cxf.binding.soap.SoapHeader)18 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)17 Node (org.w3c.dom.Node)16 JAXBDataBinding (org.apache.cxf.jaxb.JAXBDataBinding)15 JAXBElement (javax.xml.bind.JAXBElement)14 List (java.util.List)13 OutofBandHeader (org.apache.cxf.outofband.header.OutofBandHeader)13 MessageContext (javax.xml.ws.handler.MessageContext)9 Test (org.junit.Test)9 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)8 SoapVersion (org.apache.cxf.binding.soap.SoapVersion)7 Message (org.apache.cxf.message.Message)7 HashMap (java.util.HashMap)6 Fault (org.apache.cxf.interceptor.Fault)6 Exchange (org.apache.cxf.message.Exchange)6