Debian Codegraph @

test/message/TestSOAPFault.java

raw
1 /*
2 * Copyright 2002-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package test.message;
17
18 import junit.framework.Test;
19 import junit.framework.TestCase;
20 import junit.framework.TestSuite;
21
22 import javax.xml.soap.MessageFactory;
23 import javax.xml.soap.SOAPFault;
24 import javax.xml.soap.SOAPMessage;
25 import java.io.ByteArrayInputStream;
26
27 /**
28 * @author [email protected] (Steve Johnson)
29 * @author Davanum Srinivas ([email protected])
30 * @version $Revision: 257456 $
31 */
32 public class TestSOAPFault extends TestCase {
33
34 /**
35 * Method suite
36 *
37 * @return
38 */
39 public static Test suite() {
40 return new TestSuite(TestSOAPFault.class);
41 }
42
43 /**
44 * Method main
45 *
46 * @param argv
47 */
48 public static void main(String[] argv) throws Exception {
49 TestSOAPFault tester = new TestSOAPFault("TestSOAPFault");
50 tester.testSoapFaultBUG();
51 }
52
53 /**
54 * Constructor TestSOAPFault
55 *
56 * @param name
57 */
58 public TestSOAPFault(String name) {
59 super(name);
60 }
61
62 String xmlString =
63 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
64 "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
65 "<soapenv:Body>" +
66 "<soapenv:Fault>" +
67 "<faultcode>soapenv:13001</faultcode>" +
68 "<faultstring>java.lang.Exception: File already exists</faultstring>" +
69 "<faultactor>urn:RiskMetricsDirect:1.0:object-service-service:CreateObject</faultactor>" +
70 "<detail/>" +
71 "</soapenv:Fault>" +
72 "</soapenv:Body>" +
73 "</soapenv:Envelope>";
74
75 /**
76 * Method testSoapFaultBUG
77 *
78 * @throws Exception
79 */
80 public void testSoapFaultBUG() throws Exception {
81 ByteArrayInputStream bis = new ByteArrayInputStream(xmlString.getBytes());
82 MessageFactory msgFactory = MessageFactory.newInstance();
83 SOAPMessage msg = msgFactory.createMessage(null, bis);
84
85 //now attempt to access the fault
86 if (msg.getSOAPPart().getEnvelope().getBody().hasFault()) {
87 SOAPFault fault =
88 msg.getSOAPPart().getEnvelope().getBody().getFault();
89 System.out.println("Fault: " + fault.getFaultString());
90 }
91 }
92 }