Package javax.xml.soap

Examples of javax.xml.soap.SOAPHeader


                bodyPart.setElement(this.saaj.getSOAPBody());
                result.add(bodyPart);
            }
        }
       
        final SOAPHeader header = saaj.getSOAPHeader();
       
        // Handle sign/enc parts
        for (WSEncryptionPart part : parts) {
            final List<Element> elements;
           
View Full Code Here


        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage msg = mf.createMessage();

        SOAPPart sp = msg.getSOAPPart();
        SOAPEnvelope envelope = sp.getEnvelope();
        SOAPHeader header = envelope.getHeader();
        SOAPBody body = envelope.getBody();

        SOAPElement el = header.addHeaderElement(envelope.createName("field4", NS_PREFIX, NS_URI));
        SOAPElement el2 = el.addChildElement("field4b", NS_PREFIX);
        SOAPElement el3 = el2.addTextNode("field4value");

        el = body.addBodyElement(envelope.createName("bodyfield3", NS_PREFIX, NS_URI));
        el2 = el.addChildElement("bodyfield3a", NS_PREFIX);
View Full Code Here

                     n2.getLocalName());
    }

    public void testHeader() throws Exception {
        SOAPEnvelope env = new org.apache.axis.message.SOAPEnvelope();
        SOAPHeader h1 = env.getHeader();
        assertTrue("null initial header", h1 != null);
        h1.detachNode();
        assertTrue("header not freed", env.getHeader() == null);
        SOAPHeader h2 = env.addHeader();
        assertTrue("null created header", h2 != null);
        assertEquals("wrong header retrieved", h2, env.getHeader());
        assertEquals("header parent incorrect", env,
                     (SOAPEnvelope)h2.getParentElement());
        try {
            env.addHeader();
            assertTrue("second header added", false);
        } catch (SOAPException e) {
        }
View Full Code Here

                    .getVersion().getSender());
        }
    }

    public static void replaceHeaders(SOAPMessage soapMessage, SoapMessage message) throws SOAPException {
        SOAPHeader header = soapMessage.getSOAPHeader();
        if (header == null) {
            return;
        }
        Element elem = DOMUtils.getFirstElement(header);
        while (elem != null) {
View Full Code Here

        super.doResults(msg, actor, doc, results);
    }
    private void assertHeadersExists(AssertionInfoMap aim, SoapMessage msg, SOAPMessage doc)
        throws SOAPException {
       
        SOAPHeader header = doc.getSOAPHeader();
        Collection<AssertionInfo> ais = aim.get(SP12Constants.REQUIRED_PARTS);
        if (ais != null) {
            for (AssertionInfo ai : ais) {
                RequiredParts rp = (RequiredParts)ai.getAssertion();
                ai.setAsserted(true);
                for (Header h : rp.getHeaders()) {
                    if (header == null || !header.getChildElements(h.getQName()).hasNext()) {
                        ai.setNotAsserted("No header element of name " + h.getQName() + " found.");
                    }
                }
            }
        }
View Full Code Here

        setupBindingOperationInfo(exch, sm);
        SOAPMessage msg = sm.getMessage();
        try {           
            List<SOAPElement> params = new ArrayList<SOAPElement>();
            message.put(MessageContext.REFERENCE_PARAMETERS, params);
            SOAPHeader head = msg.getSOAPHeader();
            if (head != null) {
                Iterator<Node> it = CastUtils.cast(head.getChildElements());
                while (it != null && it.hasNext()) {
                    Node nd = it.next();
                    if (nd instanceof SOAPElement) {
                        SOAPElement el = (SOAPElement)nd;
                        if (el.hasAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter")
View Full Code Here

                try {
                    Boolean outboundProperty = (Boolean)smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
                    if (!outboundProperty.booleanValue()) {
                        // change mustUnderstand to false
                        SOAPMessage message = smc.getMessage();
                        SOAPHeader soapHeader = message.getSOAPHeader();
                        Element headerElementNew = (Element)soapHeader.getChildNodes().item(0);

                        SoapVersion soapVersion = Soap11.getInstance();                       
                        Attr attr =
                            headerElementNew.getOwnerDocument().createAttributeNS(soapVersion.getNamespace(),
                                                                                  "SOAP-ENV:mustUnderstand");
View Full Code Here

                    Boolean outboundProperty = (Boolean)smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
                    if (outboundProperty.booleanValue()) {
                        // change mustUnderstand to false
                        SOAPMessage message = smc.getMessage();
                        
                        SOAPHeader soapHeader = message.getSOAPHeader();
                        Iterator it = soapHeader.getChildElements(new QName(
                            "http://apache.org/hello_world_rpclit/types", "header1"));
                        SOAPHeaderElement headerElementNew = (SOAPHeaderElement)it.next();

                        SoapVersion soapVersion = Soap11.getInstance();
                        Attr attr =
                            headerElementNew.getOwnerDocument().createAttributeNS(soapVersion.getNamespace(),
                                                                                  "SOAP-ENV:mustUnderstand");
                        attr.setValue("false");
                        headerElementNew.setAttributeNodeNS(attr);
                    }
                } catch (Exception e) {
                    throw new Fault(e);
                }
                return true;
            }

            public boolean handleFault(SOAPMessageContext smc) {
                return true;
            }

            public Set<QName> getHeaders() {
                return null;
            }

            public void close(MessageContext messageContext) {
            }
        });
        HandlerChainInvoker invoker = new HandlerChainInvoker(list);

        IMocksControl control = createNiceControl();
        Binding binding = control.createMock(Binding.class);
        Exchange exchange = control.createMock(Exchange.class);
        expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes();
        SoapMessage message = new SoapMessage(new MessageImpl());
        message.setExchange(exchange);
        // This is to set direction to outbound
        expect(exchange.getOutMessage()).andReturn(message).anyTimes();
        CachedStream originalEmptyOs = new CachedStream();
        message.setContent(OutputStream.class, originalEmptyOs);

        InterceptorChain chain = new PhaseInterceptorChain((new PhaseManagerImpl()).getOutPhases());
        //Interceptors after SOAPHandlerInterceptor DOMXMLStreamWriter to write
        chain.add(new AbstractProtocolHandlerInterceptor<SoapMessage>(binding, Phase.MARSHAL) {

            public void handleMessage(SoapMessage message) throws Fault {
                try {
                    XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
                    SoapVersion soapVersion = Soap11.getInstance();
                    writer.setPrefix(soapVersion.getPrefix(), soapVersion.getNamespace());
                    writer.writeStartElement(soapVersion.getPrefix(),
                                          soapVersion.getEnvelope().getLocalPart(),
                                          soapVersion.getNamespace());
                    writer.writeNamespace(soapVersion.getPrefix(), soapVersion.getNamespace());
                   
                    Object[] headerInfo = prepareSOAPHeader();
                    StaxUtils.writeElement((Element) headerInfo[1], writer, true, false);
                   
                    writer.writeEndElement();
                   
                    writer.flush();
                } catch (Exception e) {
                    // do nothing
                }
            }

        });
        chain.add(new SOAPHandlerInterceptor(binding));
        message.setInterceptorChain(chain);
        control.replay();

        chain.doIntercept(message);
       
        control.verify();

        // Verify SOAPMessage header
        SOAPMessage soapMessageNew = message.getContent(SOAPMessage.class);

        SOAPHeader soapHeader = soapMessageNew.getSOAPHeader();
        Iterator itNew = soapHeader.getChildElements(new QName("http://apache.org/hello_world_rpclit/types",
            "header1"));
        SOAPHeaderElement headerElementNew = (SOAPHeaderElement)itNew.next();
        SoapVersion soapVersion = Soap11.getInstance();
        assertEquals("false", headerElementNew.getAttributeNS(soapVersion.getNamespace(), "mustUnderstand"));
        originalEmptyOs.close();
View Full Code Here

    }

    public void testHeaderElements() throws Exception {
        SOAPEnvelope envelope = getSOAPEnvelope();
        SOAPBody body = envelope.getBody();
        SOAPHeader hdr = envelope.getHeader();

        SOAPHeaderElement she1 = hdr.addHeaderElement(envelope.createName("foo1", "f1", "foo1-URI"));
        she1.setActor("actor-URI");
        java.util.Iterator iterator = hdr.extractHeaderElements("actor-URI");
        int cnt = 0;
        while (iterator.hasNext()) {
            cnt++;
            SOAPHeaderElement she = (SOAPHeaderElement) iterator.next();
            assertTrue(she.equals(she1));
        }
        assertTrue(cnt == 1);
        iterator = hdr.extractHeaderElements("actor-URI");
        assertTrue(!iterator.hasNext());
    }
View Full Code Here

    }

    public void testSOAPEnvelope() throws Exception {
        // Create an example SOAP envelope
        SOAPEnvelope env = new org.apache.axis.message.SOAPEnvelope();
        SOAPHeader h = env.getHeader();
        SOAPBody b = env.getBody();
        Name heName = env.createName("localName", "prefix", "http://uri");
        SOAPHeaderElement he = h.addHeaderElement(heName);
        he.setActor("actor");

        // Serialize the SOAP envelope
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream os = new ObjectOutputStream(bos);
        os.writeObject(env);

        // Deserializet the SOAP envelope
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
        ObjectInputStream is = new ObjectInputStream(bis);
        SOAPEnvelope env2 = (SOAPEnvelope)is.readObject();

        // Check that the SOAP envelope survived the round trip
        SOAPHeader h2 = env2.getHeader();
        SOAPHeaderElement he2 = (SOAPHeaderElement)h2.
            examineHeaderElements("actor").next();
        Name heName2 = he2.getElementName();
        assertEquals("Local name did not survive java ser+deser",
                     heName.getLocalName(), heName2.getLocalName());
        assertEquals("Prefix did not survive java ser+deser",
View Full Code Here

TOP

Related Classes of javax.xml.soap.SOAPHeader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.