Package javax.xml.soap

Examples of javax.xml.soap.SOAPMessage


                   soapContext,
                   new JAXBDataBindingCallback(testHeader2,
                                               DataBindingCallback.Mode.PARTS,
                                               null));               

        SOAPMessage msg = soapContext.getMessage();
        assertNotNull(msg);

        //Test the Header Part Only
        assertNotNull(msg.getSOAPHeader());
        assertTrue(msg.getSOAPHeader().hasChildNodes());
        NodeList list = msg.getSOAPHeader().getChildNodes();
        assertEquals(1, list.getLength());
        Element headerElement = (Element)list.item(0);
        //Check for mustUndrstand Attribute
        assertEquals("true", headerElement
                     .getAttributeNS(SOAPConstants.HEADER_MUSTUNDERSTAND.getNamespaceURI(),
                                     SOAPConstants.HEADER_MUSTUNDERSTAND.getLocalPart()));
       
        //TestHeader3 has child elements.
        assertTrue(headerElement.hasChildNodes());
        list = headerElement.getChildNodes();
        assertEquals(1, list.getLength());
        assertEquals(arg1.getResponseType(), list.item(0).getFirstChild().getNodeValue());
       
        //TestHeader5 return Header
        Method testHeader5 = SOAPMessageUtil.getMethod(TestHeader.class, "testHeader5");
        assertNotNull(testHeader5);
        objContext.setMethod(testHeader5);
       
        TestHeader5 arg2 = new TestHeader5();
        arg2.setRequestType("HeaderVal5");
       
        objContext.setMessageObjects(new Object[0]);
        objContext.setReturn(arg2);
        //Write the SOAP Headers for testHeader5 operation - tests headers as return.       
        binding.marshal(
                                     objContext,
                                     soapContext,
                                     new JAXBDataBindingCallback(testHeader5,
                                                                 DataBindingCallback.Mode.PARTS,
                                                                 null));               

        msg = soapContext.getMessage();
        assertNotNull(msg);

        //Test the Header Part Only
        assertNotNull(msg.getSOAPHeader());
        assertTrue(msg.getSOAPHeader().hasChildNodes());
        list = msg.getSOAPHeader().getChildNodes();
        assertEquals(1, list.getLength());
        headerElement = (Element)list.item(0);
        //Check for mustUndrstand Attribute
        assertEquals("true", headerElement
                     .getAttributeNS(SOAPConstants.HEADER_MUSTUNDERSTAND.getNamespaceURI(),
View Full Code Here


        TestClientBinding clientBinding = new TestClientBinding(bus, epr);
        SOAPMessageContext soapCtx = new SOAPMessageContextImpl(new GenericMessageContext());

        InputStream is =  getClass().getResourceAsStream("resources/NoSuchCodeDocLiteral.xml");
        MessageFactory msgFactory = MessageFactory.newInstance();
        SOAPMessage faultMsg = msgFactory.createMessage(null,  is);
        soapCtx.setMessage(faultMsg);
        assertTrue(clientBinding.getBindingImpl().hasFault(soapCtx));
       
        is =  getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
        faultMsg = msgFactory.createMessage(null,  is);
View Full Code Here

        TestClientBinding clientBinding = new TestClientBinding(bus, epr);
       
        InputStream is =  getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
       
        MessageFactory msgFactory = MessageFactory.newInstance();
        SOAPMessage greetMeMsg = msgFactory.createMessage(null,  is);
        is.close();
       
        BufferedReader br =
            new BufferedReader(
                new InputStreamReader(
View Full Code Here

     */
    protected ResendCandidate cacheUnacknowledged(ObjectMessageContext ctx) {
        ResendCandidate candidate = null;
        RMProperties rmps = RMContextUtils.retrieveRMProperties(ctx, true);
        if (null == rmps) {
            SOAPMessage message = (SOAPMessage)ctx.get(SOAP_MSG_KEY);
            rmps = getRMSoapHandler().unmarshalRMProperties(message);
            RMContextUtils.storeRMProperties(ctx, rmps, true);           
        }
        AddressingProperties maps = ContextUtils.retrieveMAPs(ctx, false, true);
        if (null == maps) {
            SOAPMessage message = (SOAPMessage)ctx.get(SOAP_MSG_KEY);
            try {
                maps = getWsaSOAPHandler().unmarshalMAPs(message);
                ContextUtils.storeMAPs(maps, ctx, true);
            } catch (Exception ex) {
                ex.printStackTrace();
View Full Code Here

                    oos.writeObject(key);
                    oos.writeObject(value);
                }               
            }

            SOAPMessage msg = (SOAPMessage)ctx.get(SOAP_MSG_KEY);
            msg.writeTo(bos);
           
            bos.close();

        } catch (Exception ex) {
            throw new RMStoreException(ex);   
View Full Code Here

                ctx.put(key, value);
            }
           
            // construct SOAPMessage from input stream
           
            SOAPMessage msg = getMessageFactory().createMessage(null, is);
            ctx.put(SOAP_MSG_KEY, msg);
           
        } catch (Exception ex) {
            throw new RMStoreException(ex)
        }
View Full Code Here

    public AbstractBindingImpl getBindingImpl() {
        return soapBinding;
    }
    public QName getOperationName(MessageContext ctx) {
        SOAPMessageContext soapContext = SOAPMessageContext.class.cast(ctx);
        SOAPMessage msg = soapContext.getMessage();
        Map<QName, ? extends DataBindingCallback> ops = sbeCallback.getOperations();


       
        //attempt the simple case first....
        Node node = null;
        try {
            node = NodeUtils.getChildElementNode(msg.getSOAPBody());
        } catch (SOAPException e) {
            return null;
        }
        QName firstNodeName = null;
        if (node != null) {
            firstNodeName = new QName(node.getNamespaceURI(), node.getLocalName());
            if (ops.containsKey(firstNodeName)) {
                DataBindingCallback cb = ops.get(firstNodeName);
                if (cb.getSOAPStyle() == SOAPBinding.Style.RPC) {
                    return firstNodeName;
                }
            }
        }

        for (Map.Entry<QName, ? extends DataBindingCallback> entry : ops.entrySet()) {
            DataBindingCallback cb = entry.getValue();
            if (cb.getSOAPStyle() == SOAPBinding.Style.RPC) {
                //RPC ones should already have been found
                continue;
            }
            if (cb.getSOAPParameterStyle() == SOAPBinding.ParameterStyle.BARE) {
                //unwrapped
                try {
                    NodeList nl = msg.getSOAPBody().getChildNodes();
                    NodeList hl = null;
                    if (msg.getSOAPHeader() != null) {
                        hl = msg.getSOAPHeader().getChildNodes();
                    }
                    if (matchParamsForDocLitBare(cb, nl, hl)) {
                        return entry.getKey();
                    }
                } catch (SOAPException e) {
View Full Code Here

    public void marshal(ObjectMessageContext objContext, MessageContext mc, DataBindingCallback callback) {

        try {
            boolean isInputMsg = (Boolean)mc.get(ObjectMessageContext.MESSAGE_INPUT);
            SOAPMessage msg = initSOAPMessage();

            if (null != callback) {

                if (!"".equals(callback.getSOAPAction())) {
                    msg.getMimeHeaders().setHeader("SOAPAction", "\"" + callback.getSOAPAction() + "\"");
                }

                if (callback.getMode() == DataBindingCallback.Mode.PARTS) {
                    if (callback.getSOAPStyle() == Style.RPC) {
                        nsStack = new NSStack();
                        nsStack.push();
                    }

                    // add in, out and inout header params
                    addHeaderParts(msg.getSOAPPart().getEnvelope(), objContext, isInputMsg, callback);

                    SOAPElement soapElement = addOperationNode(msg.getSOAPBody(), callback, isInputMsg);
                    // add in, out and inout non-header params
                    addParts(soapElement, objContext, isInputMsg, callback);
                } else if (callback.getMode() == DataBindingCallback.Mode.MESSAGE) {

                    Object src = isInputMsg ? objContext.getReturn() : objContext.getMessageObjects()[0];
                    // contains the entire SOAP message
                    boolean found = false;
                    for (Class<?> cls : callback.getSupportedFormats()) {
                        if (cls == SOAPMessage.class) {
                            msg = (SOAPMessage)src;
                            found = true;
                            break;
                        } else if (cls == DOMSource.class || cls == SAXSource.class
                                   || cls == StreamSource.class) {
                            DataWriter<SOAPMessage> writer = callback.createWriter(SOAPMessage.class);
                            writer.write(src, msg);
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        throw new SOAPException("Could not figure out how to marshal data");
                    }
                } else if (callback.getMode() == DataBindingCallback.Mode.PAYLOAD) {
                    // contains the contents of the SOAP:Body
                    boolean found = false;
                    Object src = isInputMsg ? objContext.getReturn() : objContext.getMessageObjects()[0];

                    for (Class<?> cls : callback.getSupportedFormats()) {
                        if (cls == DOMSource.class || cls == SAXSource.class || cls == StreamSource.class
                            || cls == Object.class) {
                            DataWriter<SOAPBody> writer = callback.createWriter(SOAPBody.class);
                            writer.write(src, msg.getSOAPBody());
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
View Full Code Here

    }

    public void marshalFault(ObjectMessageContext objContext, MessageContext mc,
                             DataBindingCallback callback) {

        SOAPMessage msg = null;

        try {
            msg = SOAPMessageContext.class.isInstance(mc) && ((SOAPMessageContext)mc).getMessage() != null
                ? ((SOAPMessageContext)mc).getMessage() : initSOAPMessage();

            if (msg.getSOAPBody().hasChildNodes()) {
                msg.getSOAPBody().removeContents();
            }

            Throwable t = objContext.getException();
            if (t instanceof SOAPFaultException) {
                msg.getSOAPBody().addChildElement(((SOAPFaultException)t).getFault());
            } else {
                StringBuffer str = new StringBuffer(t.toString());
                if (!t.getClass().isAnnotationPresent(WebFault.class)) {
                    str.append("\n");
                    for (StackTraceElement s : t.getStackTrace()) {
                        str.append(s.toString());
                        str.append("\n");
                    }
                }

                SOAPFault fault = msg.getSOAPBody().addFault(faultCode, str.toString());

                DataWriter<Detail> writer = callback.createWriter(Detail.class);
                if (writer != null) {
                    writer.write(t, fault.addDetail());
                    if (!fault.getDetail().hasChildNodes()) {
View Full Code Here

            if (!SOAPMessageContext.class.isInstance(mc)) {
                throw new SOAPException("SOAPMessageContext not available");
            }

            SOAPMessageContext soapContext = SOAPMessageContext.class.cast(mc);
            SOAPMessage soapMessage = soapContext.getMessage();

            if (callback.getMode() == DataBindingCallback.Mode.PARTS) {
                // Assuming No Headers are inserted.
                Node soapEl = soapMessage.getSOAPBody();

                if (callback.getSOAPStyle() == Style.RPC) {
                    soapEl = NodeUtils.getChildElementNode(soapEl);
                }

                if (soapEl.hasChildNodes()) {
                    getParts(soapEl, callback, objContext, isOutputMsg);
                } else {
                    LOG.fine("Body of SOAP message is empty.");
                }

                getHeaderParts(soapMessage.getSOAPHeader(), callback, objContext, isOutputMsg);
            } else if (callback.getMode() == DataBindingCallback.Mode.MESSAGE) {
                boolean found = false;
                Object obj = null;
                for (Class<?> cls : callback.getSupportedFormats()) {
                    if (cls == SOAPMessage.class) {
                        obj = soapMessage;
                        found = true;
                        break;
                    } else if (cls == DOMSource.class
                        || cls == SAXSource.class
                        || cls == StreamSource.class) {
                        DataReader<SOAPMessage> reader = callback.createReader(SOAPMessage.class);
                        obj = reader.read(0, soapMessage);
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    throw new SOAPException("Cannot unmarshal data");
                }

                if (isOutputMsg) {
                    objContext.setReturn(obj);
                } else {
                    objContext.setMessageObjects(obj);
                }

            } else if (callback.getMode() == DataBindingCallback.Mode.PAYLOAD) {
                boolean found = false;
                Object obj = null;
                for (Class<?> cls : callback.getSupportedFormats()) {
                    if (cls == DOMSource.class
                        || cls == SAXSource.class
                        || cls == StreamSource.class
                        || cls == Object.class) {
                        DataReader<SOAPBody> reader = callback.createReader(SOAPBody.class);
                        obj = reader.read(0, soapMessage.getSOAPBody());
                        found = true;
                        break;
                    }
                }
               
View Full Code Here

TOP

Related Classes of javax.xml.soap.SOAPMessage

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.