1 16 17 package test.functional; 18 19 import junit.framework.TestCase; 20 import org.apache.axis.AxisFault; 21 import org.apache.axis.components.logger.LogFactory; 22 import org.apache.commons.logging.Log; 23 import samples.jaxm.DelayedStockQuote; 24 25 import javax.xml.messaging.URLEndpoint; 26 import javax.xml.soap.MessageFactory ; 27 import javax.xml.soap.Name ; 28 import javax.xml.soap.SOAPBody ; 29 import javax.xml.soap.SOAPBodyElement ; 30 import javax.xml.soap.SOAPConnection ; 31 import javax.xml.soap.SOAPConnectionFactory ; 32 import javax.xml.soap.SOAPElement ; 33 import javax.xml.soap.SOAPEnvelope ; 34 import javax.xml.soap.SOAPMessage ; 35 import java.net.SocketException ; 36 37 38 41 public class TestJAXMSamples extends TestCase { 42 static Log log = LogFactory.getLog(TestJAXMSamples.class.getName()); 43 44 public TestJAXMSamples(String name) { 45 super(name); 46 } 48 78 public void testDelayedStockQuote() throws Exception { 79 try { 80 log.info("Testing JAXM DelayedStockQuote sample."); 81 DelayedStockQuote stockQuote = new DelayedStockQuote(); 82 System.out.print("The last price for SUNW is " + stockQuote.getStockQuote("SUNW")); 83 log.info("Test complete."); 84 } catch (javax.xml.soap.SOAPException e) { 85 Throwable t = e.getCause(); 86 if (t != null) { 87 t.printStackTrace(); 88 if (t instanceof AxisFault) { 89 if (((AxisFault) t).detail instanceof SocketException ) { 90 System.out.println("Connect failure caused JAXM DelayedStockQuote to be skipped."); 91 return; 92 } 93 } 94 throw new Exception ("Fault returned from test: " + t); 95 } else { 96 e.printStackTrace(); 97 throw new Exception ("Exception returned from test: " + e); 98 } 99 } catch (Throwable t) { 100 t.printStackTrace(); 101 throw new Exception ("Fault returned from test: " + t); 102 } 103 } 105 public void testJWSFault() throws Exception { 106 SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance(); 107 SOAPConnection con = scFactory.createConnection(); 108 109 MessageFactory factory = MessageFactory.newInstance(); 110 SOAPMessage message = factory.createMessage(); 111 112 SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); 113 SOAPBody body = envelope.getBody(); 114 115 Name bodyName = envelope.createName("echo"); 116 SOAPBodyElement bodyElement = body.addBodyElement(bodyName); 117 118 Name name = envelope.createName("arg0"); 119 SOAPElement symbol = bodyElement.addChildElement(name); 120 symbol.addTextNode("Hello"); 121 122 URLEndpoint endpoint = new URLEndpoint("http://localhost:8080/jws/FaultTest.jws"); 123 SOAPMessage response = con.call(message, endpoint); 124 SOAPBody respBody = response.getSOAPPart().getEnvelope().getBody(); 125 assertTrue(respBody.hasFault()); 126 } 127 128 public static void main(String args[]) throws Exception { 129 TestJAXMSamples tester = new TestJAXMSamples("tester"); 130 } } 133 134 135 | Popular Tags |