01: package org.bpmscript;
02:
03: import java.net.URL;
04: import java.util.ArrayList;
05: import java.util.List;
06:
07: import javax.jbi.messaging.InOut;
08: import javax.jbi.messaging.NormalizedMessage;
09: import javax.xml.namespace.QName;
10:
11: import junit.framework.TestCase;
12:
13: import org.apache.servicemix.client.DefaultServiceMixClient;
14: import org.apache.servicemix.jbi.container.ActivationSpec;
15: import org.apache.servicemix.jbi.container.SpringJBIContainer;
16: import org.apache.servicemix.jbi.jaxp.SourceTransformer;
17: import org.apache.servicemix.jbi.jaxp.StringSource;
18: import org.apache.servicemix.jbi.resolver.ServiceNameEndpointResolver;
19: import org.bpmscript.jbi.DynamicSaajBinding;
20:
21: public class GeoWsTest extends TestCase {
22:
23: // public void testGeoTime() throws Exception {
24: // SpringJBIContainer container = new SpringJBIContainer();
25: // ActivationSpec activationSpec = new ActivationSpec();
26: // QName serviceName = new QName("http://servicemix.org", "soapclient");
27: // activationSpec.setService(serviceName);
28: // HttpSoapInvoker httpSoapInvoker = new HttpSoapInvoker();
29: // httpSoapInvoker.setUrl("http://www.webservicex.com/geoipservice.asmx");
30: // activationSpec.setComponent(httpSoapInvoker);
31: // List<ActivationSpec> activationSpecs = new ArrayList<ActivationSpec>();
32: // activationSpecs.add(activationSpec);
33: // container.setActivationSpecs(activationSpecs.toArray(new ActivationSpec[activationSpecs.size()]));
34: // container.afterPropertiesSet();
35: // DefaultServiceMixClient client = new DefaultServiceMixClient(container);
36: // InOut inOut = client.createInOutExchange(new ServiceNameEndpointResolver(serviceName));
37: // inOut.setProperty("SOAPAction", "http://www.webservicex.net/GetGeoIP");
38: // NormalizedMessage message = inOut.getInMessage();
39: // message.setContent(new StringSource("<tns:GetGeoIP xmlns:tns=\"http://www.webservicex.net\">" +
40: // "<tns:IPAddress>192.168.0.1</tns:IPAddress>" +
41: // "</tns:GetGeoIP>"));
42: // boolean b = client.sendSync(inOut, 10000);
43: // assertTrue(b);
44: // if(inOut.getFault() != null) {
45: //
46: // } else if (inOut.getError() != null) {
47: // inOut.getError().printStackTrace();
48: // } else {
49: // SourceTransformer st = new SourceTransformer();
50: // System.out.println(st.contentToString(inOut.getOutMessage()));
51: // container.shutDown();
52: // }
53: // }
54:
55: public void testGeoTimeSaaj() throws Exception {
56: SpringJBIContainer container = new SpringJBIContainer();
57: ActivationSpec activationSpec = new ActivationSpec();
58: QName serviceName = new QName("http://servicemix.org",
59: "soapclient");
60: activationSpec.setService(serviceName);
61: DynamicSaajBinding saajBinding = new DynamicSaajBinding();
62: activationSpec.setComponent(saajBinding);
63: List<ActivationSpec> activationSpecs = new ArrayList<ActivationSpec>();
64: activationSpecs.add(activationSpec);
65: container.setActivationSpecs(activationSpecs
66: .toArray(new ActivationSpec[activationSpecs.size()]));
67: container.afterPropertiesSet();
68: DefaultServiceMixClient client = new DefaultServiceMixClient(
69: container);
70: InOut inOut = client
71: .createInOutExchange(new ServiceNameEndpointResolver(
72: serviceName));
73: NormalizedMessage message = inOut.getInMessage();
74:
75: message.setProperty("SOAPAction",
76: "http://www.webservicex.net/GetGeoIP");
77: message.setProperty("SOAPEndpoint", new URL(
78: "http://www.webservicex.com/geoipservice.asmx"));
79:
80: message.setContent(new StringSource(
81: "<tns:GetGeoIP xmlns:tns=\"http://www.webservicex.net\">"
82: + "<tns:IPAddress>192.168.0.1</tns:IPAddress>"
83: + "</tns:GetGeoIP>"));
84:
85: boolean b = client.sendSync(inOut, 10000);
86: assertTrue(b);
87: if (inOut.getFault() != null) {
88:
89: } else if (inOut.getError() != null) {
90: inOut.getError().printStackTrace();
91: } else {
92: SourceTransformer st = new SourceTransformer();
93: System.out.println(st
94: .contentToString(inOut.getOutMessage()));
95: container.shutDown();
96: }
97: }
98: }
|