KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > service > soap > SoapEndpointCallerTest


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 JavaDoc;
8
9 import junit.framework.TestCase;
10
11 import org.w3c.dom.Element JavaDoc;
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 /**
19  * @author Alejandro Guízar
20  * @version $Revision: 1.2 $ $Date: 2005/06/23 20:27:18 $
21  */

22 public class SoapEndpointCallerTest extends TestCase {
23
24   public SoapEndpointCallerTest(String JavaDoc 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 JavaDoc {
31     String JavaDoc namespace = "http://www.27seconds.com/Holidays/US/Dates/";
32     String JavaDoc 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 JavaDoc outputData = call(
41         "http://www.27seconds.com/Holidays/US/Dates/USHolidayDates.asmx?WSDL",
42         new QName JavaDoc(namespace, "USHolidayDates"),
43         "USHolidayDatesSoap", "GetNewYear", inputText);
44     
45     Element JavaDoc parametersAccessor = NodeUtil.getElement(outputData, "parameters");
46     Element JavaDoc responseElem = NodeUtil.getElement(parametersAccessor, namespace, "GetNewYearResponse");
47     Element JavaDoc resultElem = NodeUtil.getElement(responseElem, "namespace", "GetNewYearResult");
48     assertEquals("2005-01-01", NodeUtil.getValue(resultElem));
49   }
50   
51   public void testCall_rpc() throws Exception JavaDoc {
52     
53   }
54
55   private Element JavaDoc call(String JavaDoc wsdlLocation, QName JavaDoc serviceName, String JavaDoc portName,
56       String JavaDoc operation, String JavaDoc inputText) throws Exception JavaDoc {
57     // read wsdl
58
Definition def = WsdlUtil.getFactory().newWSDLReader().readWSDL(wsdlLocation);
59     Service service = def.getService(serviceName);
60     Port port = service.getPort(portName);
61     // configure caller
62
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     // parse input text
68
Element JavaDoc inputData = NodeUtil.parseElement(inputText);
69     // execute the call
70
return caller.call(operation, inputData);
71   }
72 }
73
Popular Tags