1 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 32 public class TestSOAPFault extends TestCase { 33 34 39 public static Test suite() { 40 return new TestSuite(TestSOAPFault.class); 41 } 42 43 48 public static void main(String [] argv) throws Exception { 49 TestSOAPFault tester = new TestSOAPFault("TestSOAPFault"); 50 tester.testSoapFaultBUG(); 51 } 52 53 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 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 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 } | Popular Tags |