1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.messaging.serviceconnectors;
17
18 import org.apache.cxf.aegis.databinding.AegisDatabinding;
19 import org.apache.cxf.frontend.ClientProxyFactoryBean;
20 import org.apache.cxf.interceptor.LoggingInInterceptor;
21 import org.apache.cxf.interceptor.LoggingOutInterceptor;
22 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
23 import org.apache.log4j.Logger;
24 import org.kuali.rice.core.api.exception.RiceRuntimeException;
25 import org.kuali.rice.ksb.api.bus.support.SoapServiceConfiguration;
26 import org.kuali.rice.ksb.impl.cxf.interceptors.ImmutableCollectionsInInterceptor;
27 import org.kuali.rice.ksb.security.soap.CXFWSS4JInInterceptor;
28 import org.kuali.rice.ksb.security.soap.CXFWSS4JOutInterceptor;
29 import org.kuali.rice.ksb.security.soap.CredentialsOutHandler;
30 import org.kuali.rice.ksb.service.KSBServiceLocator;
31
32 import java.net.URL;
33
34
35
36
37
38
39
40 public class SOAPConnector extends AbstractServiceConnector {
41
42 private static final Logger LOG = Logger.getLogger(SOAPConnector.class);
43
44 public SOAPConnector(final SoapServiceConfiguration serviceConfiguration, final URL alternateEndpointUrl) {
45 super(serviceConfiguration, alternateEndpointUrl);
46 }
47
48 @Override
49 public SoapServiceConfiguration getServiceConfiguration() {
50 return (SoapServiceConfiguration) super.getServiceConfiguration();
51 }
52
53
54
55
56
57
58 public Object getService() {
59 ClientProxyFactoryBean clientFactory;
60
61
62 if (getServiceConfiguration().isJaxWsService()){
63 clientFactory = new JaxWsProxyFactoryBean();
64 } else {
65 clientFactory = new ClientProxyFactoryBean();
66 clientFactory.getServiceFactory().setDataBinding(new AegisDatabinding());
67 }
68
69 try {
70 clientFactory.setServiceClass(Class.forName(getServiceConfiguration().getServiceInterface()));
71 } catch (ClassNotFoundException e) {
72 throw new RiceRuntimeException("Failed to connect to soap service " + getServiceConfiguration().getServiceName() + " because failed to load interface class: " + getServiceConfiguration().getServiceInterface(), e);
73 }
74 clientFactory.setBus(KSBServiceLocator.getCXFBus());
75 clientFactory.setServiceName(getServiceConfiguration().getServiceName());
76 clientFactory.setAddress(getActualEndpointUrl().toExternalForm());
77
78
79 clientFactory.getOutInterceptors().add(new LoggingOutInterceptor());
80 clientFactory.getOutFaultInterceptors().add(new LoggingOutInterceptor());
81 CXFWSS4JOutInterceptor outSecurityInterceptor = new CXFWSS4JOutInterceptor(getServiceConfiguration().getBusSecurity());
82 clientFactory.getOutInterceptors().add(outSecurityInterceptor);
83 clientFactory.getOutFaultInterceptors().add(outSecurityInterceptor);
84 if (getCredentialsSource() != null) {
85 clientFactory.getOutInterceptors().add(new CredentialsOutHandler(getCredentialsSource(), getServiceConfiguration()));
86 }
87
88 clientFactory.getInInterceptors().add(new LoggingInInterceptor());
89 clientFactory.getInFaultInterceptors().add(new LoggingInInterceptor());
90 CXFWSS4JInInterceptor inSecurityInterceptor = new CXFWSS4JInInterceptor(getServiceConfiguration().getBusSecurity());
91 clientFactory.getInInterceptors().add(inSecurityInterceptor);
92 clientFactory.getInFaultInterceptors().add(inSecurityInterceptor);
93 clientFactory.getInInterceptors().add(new ImmutableCollectionsInInterceptor());
94
95
96 Object service = clientFactory.create();
97 return getServiceProxyWithFailureMode(service, getServiceConfiguration());
98 }
99 }