1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.ksb.messaging;
18
19 import javax.xml.namespace.QName;
20
21 import org.apache.commons.httpclient.URI;
22 import org.apache.cxf.aegis.databinding.AegisDatabinding;
23 import org.apache.cxf.binding.soap.SoapFault;
24 import org.apache.cxf.endpoint.Client;
25 import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
26 import org.apache.cxf.frontend.ClientProxyFactoryBean;
27 import org.apache.cxf.interceptor.LoggingInInterceptor;
28 import org.apache.cxf.interceptor.LoggingOutInterceptor;
29 import org.junit.Test;
30 import org.kuali.rice.core.config.ConfigContext;
31 import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
32 import org.kuali.rice.ksb.messaging.remotedservices.EchoService;
33 import org.kuali.rice.ksb.messaging.remotedservices.JaxWsEchoService;
34 import org.kuali.rice.ksb.messaging.remotedservices.SOAPService;
35 import org.kuali.rice.ksb.service.KSBServiceLocator;
36 import org.kuali.rice.ksb.test.KSBTestCase;
37
38
39
40
41
42
43 public class SOAPServiceTest extends KSBTestCase {
44
45 public boolean startClient1() {
46 return true;
47 }
48
49 private String getEndpointUrl() {
50 return "http://localhost:" +
51 getClient1Port() +
52 "/TestClient1/remoting/secure/soap-echoServiceSecure";
53 }
54
55 private String getWsdlUrl() {
56 return "http://localhost:" +
57 getClient1Port() +
58 "/TestClient1/remoting/soap-echoService?wsdl";
59 }
60
61 private String getClient1Port() {
62 return ConfigContext.getCurrentContextConfig().getProperty("ksb.client1.port");
63 }
64
65
66 @Test public void testSimpleSOAPService() throws Exception{
67
68
69 EchoService echoService = (EchoService)GlobalResourceLoader.getService(new QName("TestCl1", "soap-echoService"));
70 String result = echoService.trueEcho("Yo yo yo");
71 assertNotNull(result);
72
73 QName serviceName = new QName("testNameSpace", "soap-repeatTopic");
74 SOAPService soapService = (SOAPService) GlobalResourceLoader.getService(serviceName);
75 soapService.doTheThing("hello");
76 }
77
78 @Test
79 public void testJaxWsSOAPService(){
80
81 JaxWsEchoService jaxwsEchoService = (JaxWsEchoService)GlobalResourceLoader.getService(new QName("TestCl1", "jaxwsEchoService"));
82 String result = jaxwsEchoService.doEcho("Fi Fi Fo Fum");
83 assertTrue(("Fi Fi Fo Fum").equals(result));
84 }
85
86 @Test
87 public void testBusSecureSoapService() throws Exception{
88
89 ClientProxyFactoryBean clientFactory;
90 clientFactory = new ClientProxyFactoryBean();
91
92 clientFactory.setBus(KSBServiceLocator.getCXFBus());
93 clientFactory.getServiceFactory().setDataBinding(new AegisDatabinding());
94 clientFactory.setServiceClass(EchoService.class);
95 clientFactory.setServiceName(new QName("urn:TestCl1", "soap-echoServiceSecure"));
96 clientFactory.setAddress(new URI(getEndpointUrl(), false).toString());
97 clientFactory.getInInterceptors().add(new LoggingInInterceptor());
98 clientFactory.getOutInterceptors().add(new LoggingOutInterceptor());
99 EchoService echoService = (EchoService)clientFactory.create();
100
101 try{
102 echoService.echo("I can't echo");
103 fail("Expected failure using non-secure client with secure service");
104 } catch (SoapFault sf){
105 sf.printStackTrace();
106 assertTrue("Non-secure client did not get expected exception.",
107 sf.getMessage().startsWith("An error was discovered processing the <wsse:Security> header"));
108 }
109
110
111 echoService = (EchoService)GlobalResourceLoader.getService(new QName("urn:TestCl1", "soap-echoServiceSecure"));
112 String result = echoService.echo("I can echo");
113 assertTrue("I can echo".equals(result));
114 }
115
116 @Test
117 public void testWsdlGeneration() throws Exception {
118
119
120 DynamicClientFactory dcf = DynamicClientFactory.newInstance(KSBServiceLocator.getCXFBus());
121
122 Client client = dcf.createClient(new URI(getWsdlUrl(), false).toString());
123 client.getInInterceptors().add(new LoggingInInterceptor());
124 client.getOutInterceptors().add(new LoggingOutInterceptor());
125 Object[] results = client.invoke("trueEcho", new Object[] { "testing" });
126 assertNotNull(results);
127 assertTrue(results.length > 0);
128
129 }
130
131 }