1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.messaging.serviceexporters;
17
18 import org.apache.cxf.Bus;
19 import org.apache.cxf.aegis.databinding.AegisDatabinding;
20 import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
21 import org.apache.cxf.frontend.ServerFactoryBean;
22 import org.apache.cxf.interceptor.LoggingInInterceptor;
23 import org.apache.cxf.interceptor.LoggingOutInterceptor;
24 import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
25 import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
26 import org.apache.log4j.Logger;
27 import org.apache.ws.security.WSConstants;
28 import org.apache.ws.security.handler.WSHandlerConstants;
29 import org.kuali.rice.core.api.exception.RiceRuntimeException;
30 import org.kuali.rice.ksb.api.bus.ServiceDefinition;
31 import org.kuali.rice.ksb.api.bus.support.SoapServiceDefinition;
32 import org.kuali.rice.ksb.impl.cxf.interceptors.ImmutableCollectionsInInterceptor;
33 import org.kuali.rice.ksb.messaging.servicehandlers.BasicAuthenticationHandler;
34 import org.kuali.rice.ksb.security.soap.CXFWSS4JInInterceptor;
35 import org.kuali.rice.ksb.security.soap.CXFWSS4JOutInterceptor;
36
37 import java.util.HashMap;
38 import java.util.Map;
39
40
41
42
43
44 public class SOAPServiceExporter extends AbstractWebServiceExporter implements ServiceExporter {
45
46 static final Logger LOG = Logger.getLogger(SOAPServiceExporter.class);
47
48 public SOAPServiceExporter(SoapServiceDefinition serviceDefinition, Bus cxfBus) {
49 super(serviceDefinition, cxfBus);
50 }
51
52
53
54
55
56
57
58 @Override
59 public void publishService(ServiceDefinition serviceDefinition, Object serviceImpl, String address) {
60 ServerFactoryBean svrFactory;
61
62 SoapServiceDefinition soapServiceDefinition = (SoapServiceDefinition)serviceDefinition;
63
64
65 if (soapServiceDefinition.isJaxWsService()){
66 LOG.info("Creating JaxWsService " + soapServiceDefinition.getServiceName());
67 svrFactory = new JaxWsServerFactoryBean();
68 } else {
69 svrFactory = new ServerFactoryBean();
70
71
72 svrFactory.getServiceFactory().setDataBinding(new AegisDatabinding());
73 }
74
75 svrFactory.setBus(getCXFBus());
76 svrFactory.setServiceName(soapServiceDefinition.getServiceName());
77 svrFactory.setAddress(address);
78 svrFactory.setPublishedEndpointUrl(soapServiceDefinition.getEndpointUrl().toExternalForm());
79 svrFactory.setServiceBean(serviceImpl);
80
81 try {
82 svrFactory.setServiceClass(Class.forName(soapServiceDefinition.getServiceInterface()));
83 } catch (ClassNotFoundException e) {
84 throw new RiceRuntimeException("Failed to publish service " + soapServiceDefinition.getServiceName() + " because service interface could not be loaded: " + soapServiceDefinition.getServiceInterface(), e);
85 }
86
87
88 if (soapServiceDefinition.isBasicAuthentication()) {
89 Map<String, Object> properties = new HashMap<String, Object>();
90 properties.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
91 properties.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
92 BasicAuthenticationHandler authenticationHandler = new BasicAuthenticationHandler(
93 soapServiceDefinition.getServiceNameSpaceURI(), serviceDefinition.getServiceName());
94 properties.put(WSHandlerConstants.PW_CALLBACK_REF, authenticationHandler);
95 svrFactory.getInInterceptors().add(new WSS4JInInterceptor(properties));
96 svrFactory.getInInterceptors().add(new SAAJInInterceptor());
97 } else {
98 svrFactory.getInInterceptors().add(new CXFWSS4JInInterceptor(soapServiceDefinition.getBusSecurity()));
99 svrFactory.getOutInterceptors().add(new CXFWSS4JOutInterceptor(soapServiceDefinition.getBusSecurity()));
100 svrFactory.getInFaultInterceptors().add(new CXFWSS4JInInterceptor(soapServiceDefinition.getBusSecurity()));
101 svrFactory.getOutFaultInterceptors().add(new CXFWSS4JOutInterceptor(soapServiceDefinition.getBusSecurity()));
102 }
103
104 svrFactory.getInInterceptors().add(new LoggingInInterceptor());
105 svrFactory.getInInterceptors().add(new ImmutableCollectionsInInterceptor());
106
107 svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
108
109 svrFactory.create();
110 }
111
112 }