Constructing SOAP Message

Discussion in 'Java' started by gabsaga_tata@hotmail.com, Aug 26, 2005.

  1. Guest

    ************** INPUT 1 ************************

    <?xml version='1.0'?>
    <SOAP-ENV:Envelope
    xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
    <SOAP-ENV:Body>
    <calculateFibonacci
    xmlns='http://namespaces.cafeconleche.org/xmljava/ch3/'
    type='xsi:positiveInteger'>10
    </calculateFibonacci>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

    ************** INPUT 2 ********************************


    <SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
    <calculateFibonacci
    xmlns="http://namespaces.cafeconleche.org/xml/ch3/">10
    </calculateFibonacci>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>


    *****************************************************************

    The code below produces the results as shown in INPUT 2. What do I need
    to add/change to get it to produce the results as shown in INPUT 1?
    Please forgive my ignorance 'cause I'm new to webservices.

    Thanks.

    *************************************************************8

    package com.simpaq.soap;

    // imports to make a SOAP connection
    import javax.xml.soap.SOAPConnectionFactory;
    import javax.xml.soap.SOAPConnection;

    // imports for SOAP message
    import javax.xml.soap.MessageFactory;
    import javax.xml.soap.Name;
    import javax.xml.soap.SOAPMessage;
    import javax.xml.soap.SOAPPart;
    import javax.xml.soap.SOAPEnvelope;
    import javax.xml.soap.SOAPBody;
    import javax.xml.soap.SOAPElement;

    // imports to read response
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.Source;

    import javax.xml.transform.stream.StreamResult;

    public class SOAPRequest
    {

    public static void main(String args[])
    {
    try
    {
    //First create the connection
    SOAPConnectionFactory soapConnFactory =
    SOAPConnectionFactory.newInstance();
    SOAPConnection connection = soapConnFactory.createConnection();

    //Next, create the actual message
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage message = messageFactory.createMessage();

    //Create objects for the message parts
    SOAPPart soapPart = message.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();
    SOAPBody body = envelope.getBody();

    //Populate the body
    //Create the main element and namespace
    Name name = envelope.createName("calculateFibonacci", "",
    "http://namespaces.cafeconleche.org/xml/ch3/");
    SOAPElement bodyElement = body.addChildElement(name);

    //Add content
    bodyElement.addTextNode("10");

    //Save the message
    message.saveChanges();

    //Check the input
    System.out.println("\nREQUEST:\n");
    message.writeTo(System.out);
    System.out.println();

    }
    catch(Exception e)
    {
    System.out.println(e.getMessage());
    }
    }


    // JAR files in classpath

    /*

    /Sun/AppServer/lib/activation.jar
    /Sun/AppServer/lib/mail.jar
    /Sun/AppServer/lib/saaj-api.jar
    /Sun/AppServer/lib/saaj-impl.jar
    /Sun/AppServer/lib/commons-logging.jar
    /Sun/AppServer/lib/endorsed/xalan.jar
    /Sun/AppServer/lib/endorsed/dom.jar
    /Tomcat_4_1/common/endorsed/xercesImpl.jar

    */
     
    , Aug 26, 2005
    #1
    1. Advertising

  2. isitmeorthey Guest

    isitmeorthey, Aug 26, 2005
    #2
    1. Advertising

  3. Guest

    isitmeorthey, I actually got that from that example and I'm just trying
    to make some enhancements to it so it really doesn't answer my question.
     
    , Aug 29, 2005
    #3
  4. isitmeorthey Guest

    sorry
     
    isitmeorthey, Aug 29, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rabbits77
    Replies:
    0
    Views:
    901
    rabbits77
    Feb 26, 2004
  2. Narendra

    Constructing RFC2822 Message

    Narendra, Dec 5, 2005, in forum: Python
    Replies:
    4
    Views:
    340
    Narendra
    Dec 19, 2005
  3. Kris Kennaway
    Replies:
    2
    Views:
    376
    Kris Kennaway
    Aug 11, 2008
  4. Peter van der veen

    How to add SOAP header to a SOAP message?

    Peter van der veen, Nov 8, 2006, in forum: ASP .Net Web Services
    Replies:
    6
    Views:
    645
    J. Dudgeon
    Nov 14, 2006
  5. Replies:
    0
    Views:
    125
Loading...

Share This Page