Hi All,
 Im using message style. Im able to get the request from the xml file which
im passing from client.
 Now I want to send the response back to client.
 Can some give some pointers on how to add response into the SOAP Body
so that I can pass the my own xml or modified xml back to the client.


Client source >> From this method im passing a xml doc to the server

  private static Source postDOM(String file, String endpoint) throws
Exception {
//    The Document code fails, looks like a bug in Axis XMLUtils...
//    DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
//    DocumentBuilder documentBuilder =
documentBuilderFactory.newDocumentBuilder();
//    Document document = documentBuilder.parse(file);
//    DOMSource source = new DOMSource(document);
    StreamSource source = new StreamSource(new File(file));
    source.setInputStream(new FileInputStream(file));

    SOAPConnectionFactory soapConnectionFactory =
SOAPConnectionFactory.newInstance();
    SOAPConnection connection = soapConnectionFactory.createConnection();
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage message = messageFactory.createMessage();
    SOAPPart soapPart = message.getSOAPPart();
    soapPart.setContent(source);
    SOAPMessage soapMessage = connection.call(message, endpoint);
    return soapMessage.getSOAPPart().getContent();
  }

 Follows the web service method that is receiving request from the client.

 public Document method(Document request) throws
ParserConfigurationException {
    System.out.println("Document Updated = "+request.toString());


        Document response = newDocument();

        Element elem = response.createElementNS(namespace, "response");
        response.appendChild(elem);


        System.out.println("Here comes  the
Request=="+getSOAPRequestText(request));
  }
  //    catch(Exception e)
          {
                System.out.println("Exception = = "+e);
          }
 */
    return response;
  }

  private Document newDocument() throws ParserConfigurationException {
    DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder =
documentBuilderFactory.newDocumentBuilder();
    return documentBuilder.newDocument();
  }

  public String getSOAPRequestText (Document doc) {
        StringBuffer XMLText = new StringBuffer();
        XMLText.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n");
        Element e = doc.getDocumentElement();
        XMLText.append(getElementAsText(e));
        return XMLText.toString();
    }


    private StringBuffer getElementAsText(Element element) {
        StringBuffer elementText = new StringBuffer();
        if (element == null)
            return elementText;

        //Author name of the element.
        elementText.append("<"+element.getTagName());

        //Author attributes.
        NamedNodeMap attributes = element.getAttributes();
        int attCount = attributes.getLength();
        for (int j = 0; j<attCount; j++) {
            elementText.append(" "+attributes.item(j).getNodeName()+"=\"");
            elementText.append(attributes.item(j).getNodeValue()+"\"");
        }//for

        // Author the namespace node.
        if (element.getNamespaceURI()!=null) {
            elementText.append(" ");
            elementText.append("xmlns");
            if (element.getPrefix()!=null) {
                elementText.append(":");
                elementText.append(element.getPrefix());
            }//if
            elementText.append("=\"");
            elementText.append(element.getNamespaceURI());
            elementText.append("\" ");
        }

        elementText.append(">");

        //Author child nodes.
        for (int i=0;i<element.getChildNodes().getLength();i++) {
            Node child = element.getChildNodes().item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE)
elementText.append(getElementAsText((Element)child));
            if (child.getNodeType() == Node.TEXT_NODE)
elementText.append(child.getNodeValue());
            // Process other types of child nodes if required.
        }//for

        elementText.append("</"+element.getTagName()+">");
        return elementText;
    }//getElementAsText



 Thanks in advance,
 Rajendra.


*********************************************************
Disclaimer:          

This message (including any attachments) contains 
confidential information intended for a specific 
individual and purpose, and is protected by law. 
If you are not the intended recipient, you should 
delete this message and are hereby notified that 
any disclosure, copying, or distribution of this
message, or the taking of any action based on it, 
is strictly prohibited.

*********************************************************
Visit us at http://www.mahindrabt.com



Reply via email to