1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.ws.security.common;
21  
22  import javax.xml.parsers.DocumentBuilder;
23  import javax.xml.parsers.DocumentBuilderFactory;
24  
25  import java.io.ByteArrayInputStream;
26  import java.io.InputStream;
27  
28  public class SOAPUtil {
29      
30      public static final String SAMPLE_SOAP_MSG = 
31          "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" 
32          + "<SOAP-ENV:Envelope "
33          +   "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" "
34          +   "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
35          +   "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" 
36          +   "<SOAP-ENV:Body>" 
37          +       "<add xmlns=\"http://ws.apache.org/counter/counter_port_type\">" 
38          +           "<value xmlns=\"\">15</value>" 
39          +       "</add>" 
40          +   "</SOAP-ENV:Body>" 
41          + "</SOAP-ENV:Envelope>";
42      
43      private static DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
44      
45      static {
46          factory.setNamespaceAware(true);
47      }
48      
49      /**
50       * Convert an SOAP Envelope as a String to a org.w3c.dom.Document.
51       */
52      public static org.w3c.dom.Document toSOAPPart(String xml) throws Exception {
53          InputStream in = new ByteArrayInputStream(xml.getBytes());
54          DocumentBuilder builder = factory.newDocumentBuilder();
55          return builder.parse(in);
56      }
57      
58  }