View Javadoc

1   /*
2    * $Id: DefaultMessageService.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  /*
12   * Copyright 2002-2004 The Apache Software Foundation.
13   *
14   * Licensed under the Apache License, Version 2.0 (the "License");
15   * you may not use this file except in compliance with the License.
16   * You may obtain a copy of the License at
17   *
18   *      http://www.apache.org/licenses/LICENSE-2.0
19   *
20   * Unless required by applicable law or agreed to in writing, software
21   * distributed under the License is distributed on an "AS IS" BASIS,
22   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or =mplied.
23   * See the License for the specific language governing permissions and
24   * limitations under the License.
25   */
26  
27  package org.mule.transport.soap.axis.style;
28  
29  import javax.xml.soap.Name;
30  import javax.xml.soap.SOAPBody;
31  import javax.xml.soap.SOAPElement;
32  import javax.xml.soap.SOAPEnvelope;
33  import javax.xml.soap.SOAPException;
34  
35  import org.apache.commons.logging.Log;
36  import org.apache.commons.logging.LogFactory;
37  import org.w3c.dom.Document;
38  import org.w3c.dom.Element;
39  
40  /**
41   * Simple message-style service sample.
42   */
43  public class DefaultMessageService implements MessageService
44  {
45  
46      private static Log logger = LogFactory.getLog(DefaultMessageService.class);
47  
48      /**
49       * Service method, which simply echoes back any XML it receives.
50       * 
51       * @param bodyElements an array of DOM Elements, one for each SOAP body =lement
52       * @return an array of DOM Elements to be sent in the response body
53       */
54      public org.apache.axis.message.SOAPBodyElement[] soapBodyElement(org.apache.axis.message.SOAPBodyElement[] bodyElements)
55      {
56          // Echo back
57          logger.debug("bodyElementTest Called");
58          return bodyElements;
59      }
60  
61      public Document document(Document body)
62      {
63          // Echo back
64          logger.debug("documentTest Called");
65          body.setNodeValue("TEST RESPONSE");
66          return body;
67      }
68  
69      public Element[] elementArray(Element[] elems)
70      {
71          // Echo back
72          logger.debug("echoElements Called");
73          return elems;
74      }
75  
76      public void soapRequestResponse(SOAPEnvelope req, SOAPEnvelope resp) throws SOAPException
77      {
78          // Echo back
79          logger.debug("envelopeTest Called");
80          SOAPBody body = resp.getBody();
81          Name ns0 = resp.createName("TestNS0", "ns0", "http://example.com");
82          Name ns1 = resp.createName("TestNS1", "ns1", "http://example.com");
83          SOAPElement bodyElmnt = body.addBodyElement(ns0);
84          SOAPElement el = bodyElmnt.addChildElement(ns1);
85          el.addTextNode("TEST RESPONSE");
86      }
87  }