View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.soap.axis.style;
8   
9   import javax.xml.soap.Name;
10  import javax.xml.soap.SOAPBody;
11  import javax.xml.soap.SOAPElement;
12  import javax.xml.soap.SOAPEnvelope;
13  import javax.xml.soap.SOAPException;
14  
15  import org.apache.commons.logging.Log;
16  import org.apache.commons.logging.LogFactory;
17  import org.w3c.dom.Document;
18  import org.w3c.dom.Element;
19  
20  /**
21   * Simple message-style service sample.
22   */
23  public class DefaultMessageService implements MessageService
24  {
25  
26      private static Log logger = LogFactory.getLog(DefaultMessageService.class);
27  
28      /**
29       * Service method, which simply echoes back any XML it receives.
30       * 
31       * @param bodyElements an array of DOM Elements, one for each SOAP body =lement
32       * @return an array of DOM Elements to be sent in the response body
33       */
34      public org.apache.axis.message.SOAPBodyElement[] soapBodyElement(org.apache.axis.message.SOAPBodyElement[] bodyElements)
35      {
36          // Echo back
37          logger.debug("bodyElementTest Called");
38          return bodyElements;
39      }
40  
41      public Document document(Document body)
42      {
43          // Echo back
44          logger.debug("documentTest Called");
45          body.setNodeValue("TEST RESPONSE");
46          return body;
47      }
48  
49      public Element[] elementArray(Element[] elems)
50      {
51          // Echo back
52          logger.debug("echoElements Called");
53          return elems;
54      }
55  
56      public void soapRequestResponse(SOAPEnvelope req, SOAPEnvelope resp) throws SOAPException
57      {
58          // Echo back
59          logger.debug("envelopeTest Called");
60          SOAPBody body = resp.getBody();
61          Name ns0 = resp.createName("TestNS0", "ns0", "http://example.com");
62          Name ns1 = resp.createName("TestNS1", "ns1", "http://example.com");
63          SOAPElement bodyElmnt = body.addBodyElement(ns0);
64          SOAPElement el = bodyElmnt.addChildElement(ns1);
65          el.addTextNode("TEST RESPONSE");
66      }
67  }