1 22 package org.jboss.test.webservice.jbws425; 23 24 import java.io.ByteArrayInputStream ; 25 import java.net.URL ; 26 27 import javax.naming.InitialContext ; 28 import javax.xml.namespace.QName ; 29 import javax.xml.rpc.Call ; 30 import javax.xml.rpc.Service ; 31 import javax.xml.rpc.ServiceFactory ; 32 import javax.xml.soap.MessageFactory ; 33 import javax.xml.soap.MimeHeaders ; 34 import javax.xml.soap.SOAPConnection ; 35 import javax.xml.soap.SOAPConnectionFactory ; 36 import javax.xml.soap.SOAPElement ; 37 import javax.xml.soap.SOAPMessage ; 38 39 import junit.framework.Test; 40 41 import org.jboss.test.webservice.WebserviceTestBase; 42 43 51 public class JBWS425TestCase extends WebserviceTestBase 52 { 53 private static final String SOAP_ACTION = "\"urn:some-soap-action\""; 54 55 private static Hello endpoint; 56 57 public JBWS425TestCase(String name) 58 { 59 super(name); 60 } 61 62 public static Test suite() throws Exception  63 { 64 return getDeploySetup(JBWS425TestCase.class, "ws4ee-jbws425.war, ws4ee-jbws425-client.jar"); 65 } 66 67 public void setUp() throws Exception  68 { 69 super.setUp(); 70 if (endpoint == null) 71 { 72 InitialContext iniCtx = getClientContext(); 73 Service service = (Service )iniCtx.lookup("java:comp/env/service/HelloService"); 74 endpoint = (Hello)service.getPort(Hello.class); 75 } 76 } 77 78 public void testClientActionFromWSDL() throws Exception  79 { 80 String soapAction = endpoint.hello("Hello Server"); 81 assertEquals(SOAP_ACTION, soapAction); 82 } 83 84 public void testCallActionFromProperty() throws Exception  86 { 87 ServiceFactory factory = ServiceFactory.newInstance(); 88 URL wsdlUrl = new URL ("http://" + getServerHost() + ":8080/ws4ee-jbws425?wsdl"); 89 QName serviceName = new QName ("http://org.jboss.test.webservice/jbws425", "HelloService"); 90 QName portName = new QName ("http://org.jboss.test.webservice/jbws425", "HelloPort"); 91 Service service = factory.createService(wsdlUrl, serviceName); 92 Call call = service.createCall(portName, "hello"); 93 call.setProperty(Call.SOAPACTION_URI_PROPERTY, "uri:property-action"); 94 String soapAction = (String )call.invoke(new Object [] {"Hello Server"}); 95 assertEquals("\"uri:property-action\"", soapAction); 96 } 97 98 public void testMessageAccess() throws Exception  99 { 100 String reqEnv = 101 "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>" + 102 " <soapenv:Body>" + 103 " <ns1:hello xmlns:ns1='http://org.jboss.test.webservice/jbws425'>" + 104 " <String_1>Hello Server</String_1>" + 105 " </ns1:hello>" + 106 " </soapenv:Body>" + 107 "</soapenv:Envelope>"; 108 109 MessageFactory msgFactory = MessageFactory.newInstance(); 110 SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection(); 111 112 MimeHeaders mimeHeaders = new MimeHeaders (); 113 mimeHeaders.addHeader("SOAPAction", SOAP_ACTION); 114 115 SOAPMessage reqMsg = msgFactory.createMessage(mimeHeaders, new ByteArrayInputStream (reqEnv.getBytes())); 116 117 URL epURL = new URL ("http://" + getServerHost() + ":8080/ws4ee-jbws425"); 118 SOAPMessage resMsg = con.call(reqMsg, epURL); 119 120 SOAPElement soapElement = (SOAPElement )resMsg.getSOAPBody().getChildElements().next(); 121 soapElement = (SOAPElement )soapElement.getChildElements().next(); 122 String soapAction = soapElement.getValue(); 123 assertEquals(SOAP_ACTION, soapAction); 124 } 125 126 } 127 | Popular Tags |