1 package org.jbpm.bpel.service.soap; 2 3 import javax.wsdl.Definition; 4 import javax.wsdl.Port; 5 import javax.wsdl.Service; 6 import javax.wsdl.extensions.soap.SOAPAddress; 7 import javax.xml.namespace.QName ; 8 9 import junit.framework.TestCase; 10 11 import org.w3c.dom.Element ; 12 13 import org.jbpm.bpel.wsdl.util.WsdlUtil; 14 import org.jbpm.bpel.xml.util.NodeUtil; 15 16 import com.ibm.wsdl.extensions.soap.SOAPConstants; 17 18 22 public class SoapEndpointCallerTest extends TestCase { 23 24 public SoapEndpointCallerTest(String name) { 25 super(name); 26 System.setProperty("javax.xml.soap.MessageFactory", "org.jboss.axis.soap.MessageFactoryImpl"); 27 System.setProperty("javax.xml.soap.SOAPConnectionFactory", "org.jboss.webservice.soap.SOAPConnectionFactoryImpl"); 28 } 29 30 public void testCall_document() throws Exception { 31 String namespace = "http://www.27seconds.com/Holidays/US/Dates/"; 32 String inputText = 33 "<vendor:msg10 xmlns:vendor='http://jbpm.org/bpel'>" + 34 " <parameters>" + 35 " <tns:GetNewYear xmlns:tns='http://www.27seconds.com/Holidays/US/Dates/'>" + 36 " <tns:year>2005</tns:year>" + 37 " </tns:GetNewYear>" + 38 " </parameters>" + 39 "</vendor:msg10>"; 40 Element outputData = call( 41 "http://www.27seconds.com/Holidays/US/Dates/USHolidayDates.asmx?WSDL", 42 new QName (namespace, "USHolidayDates"), 43 "USHolidayDatesSoap", "GetNewYear", inputText); 44 45 Element parametersAccessor = NodeUtil.getElement(outputData, "parameters"); 46 Element responseElem = NodeUtil.getElement(parametersAccessor, namespace, "GetNewYearResponse"); 47 Element resultElem = NodeUtil.getElement(responseElem, "namespace", "GetNewYearResult"); 48 assertEquals("2005-01-01", NodeUtil.getValue(resultElem)); 49 } 50 51 public void testCall_rpc() throws Exception { 52 53 } 54 55 private Element call(String wsdlLocation, QName serviceName, String portName, 56 String operation, String inputText) throws Exception { 57 Definition def = WsdlUtil.getFactory().newWSDLReader().readWSDL(wsdlLocation); 59 Service service = def.getService(serviceName); 60 Port port = service.getPort(portName); 61 SoapEndpointCaller caller = new SoapEndpointCaller(); 63 caller.setBinding(port.getBinding()); 64 SOAPAddress soapAddress = (SOAPAddress) WsdlUtil.getExtension( 65 port.getExtensibilityElements(), SOAPConstants.Q_ELEM_SOAP_ADDRESS); 66 caller.setAddress(soapAddress.getLocationURI()); 67 Element inputData = NodeUtil.parseElement(inputText); 69 return caller.call(operation, inputData); 71 } 72 } 73 | Popular Tags |