1 package org.kuali.rice.test.remote;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.apache.cxf.endpoint.Client;
6 import org.apache.cxf.frontend.ClientProxy;
7 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
8 import org.kuali.rice.core.cxf.interceptors.ImmutableCollectionsInInterceptor;
9
10 import javax.jws.WebService;
11 import javax.xml.ws.Endpoint;
12
13
14
15
16
17
18
19
20
21 public class RemoteTestHarness {
22
23 private static final Log LOG = LogFactory.getLog(RemoteTestHarness.class);
24
25 private static String ENDPOINT_ROOT = "http://localhost"; //Default URL
26 private static String ENDPOINT_PATH = "/service";
27
28 private Endpoint endpoint;
29
30 @SuppressWarnings("unchecked")
31
32
33
34
35 public <T> T publishEndpointAndReturnProxy(Class<T> jaxWsAnnotatedInterface, T serviceImplementation) {
36 if (jaxWsAnnotatedInterface.isInterface() &&
37 jaxWsAnnotatedInterface.getAnnotation(WebService.class) != null &&
38 jaxWsAnnotatedInterface.isInstance(serviceImplementation)) {
39
40 String endpointUrl = getAvailableEndpointUrl();
41 endpoint = Endpoint.publish(endpointUrl, serviceImplementation);
42
43 JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
44 factory.setServiceClass(jaxWsAnnotatedInterface);
45 factory.setAddress(endpointUrl);
46
47 T serviceProxy = (T) factory.create();
48 Client cxfClient = ClientProxy.getClient(serviceProxy);
49 cxfClient.getInInterceptors().add(new ImmutableCollectionsInInterceptor());
50
51
52
53 return serviceProxy;
54 } else {
55 throw new IllegalArgumentException("Passed in interface class type must be annotated with @WebService " +
56 "and object reference must be an implementing class of that interface.");
57
58 }
59 }
60
61
62
63
64
65 public void stopEndpoint() {
66 if (endpoint != null) {
67 endpoint.stop();
68
69 }
70 }
71
72 private String getAvailableEndpointUrl() {
73 String port = Integer.toString(AvailablePortFinder.getNextAvailable());
74 return ENDPOINT_ROOT + ":" + port + ENDPOINT_PATH;
75 }
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 }