1 /*
2 * Copyright 2012 The Kuali Foundation
3 *
4 * Licensed under the the Educational Community License, Version 1.0
5 * (the "License"); you may not use this file except in compliance
6 * with the License. You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl1.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.student.common.spring;
17
18 import java.util.Set;
19
20 import javax.jws.WebService;
21
22 import org.kuali.rice.ksb.api.bus.support.ServiceBusExporter;
23 import org.kuali.rice.ksb.api.bus.support.SoapServiceDefinition;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.springframework.beans.factory.BeanCreationException;
27 import org.springframework.beans.factory.InitializingBean;
28
29 /**
30 * Kuali Web Service interfaces have an @WebService annotation present.
31 *
32 * This class extends the Rice {@link ServiceBusExporter} class to let the @WebService details provide the {@link SoapServiceDefinition} automatically.
33 *
34 * The original class behavior still works and the annotation based functionality is only activated if no definition is provided in the xml.
35 *
36 *
37 * <pre>{@code
38 * <bean id="ks.AtpServiceExport" class="org.kuali.student.commone.spring.KualiWebServiceExporter">
39 * <property name="webService" ref="AtpService"/>
40 * <property name="busSecurity" value="true" />
41 *</bean>}
42 * </pre>
43 *
44 * versus the default:
45 *
46 * <pre>
47 * {@code
48 * <bean id="ks.AtpServiceExport" class="org.kuali.rice.ksb.api.bus.support.ServiceBusExporter">
49 <property name="serviceDefinition">
50 <bean class="org.kuali.rice.ksb.api.bus.support.SoapServiceDefinition">
51 <property name="jaxWsService" value="true" />
52 <property name="service" ref="atpEnrService" />
53 <property name="serviceInterface" value="org.kuali.student.r2.core.atp.service.AtpService" />
54 <property name="localServiceName" value="AtpService" />
55 <property name="serviceNameSpaceURI" value="http://student.kuali.org/wsdl/atp" />
56 <property name="busSecurity" value="true" />
57 </bean>
58 </property>
59 </bean>
60 }
61 * </pre>
62 *
63 *
64 * @author Kuali Student Team
65 *
66 */
67 public class KualiWebServiceExporter extends ServiceBusExporter implements
68 InitializingBean {
69
70 private static Logger log = LoggerFactory
71 .getLogger(KualiWebServiceExporter.class);
72
73 private Object webService;
74
75 private boolean busSecurity = true;
76
77
78 /**
79 */
80 public KualiWebServiceExporter() {
81 super();
82
83 }
84
85 /**
86 * @param webService
87 * the webService to set
88 */
89 public void setWebService(Object webService) {
90 this.webService = webService;
91 }
92
93 /*
94 * (non-Javadoc)
95 *
96 * @see
97 * org.kuali.rice.ksb.api.bus.support.ServiceBusExporter#afterPropertiesSet
98 * ()
99 */
100 @Override
101 public void afterPropertiesSet() {
102
103 if (getServiceDefinition() == null) {
104
105 if (webService == null)
106 throw new BeanCreationException("webService object must be set.");
107
108 // user did not set a definition via spring xml
109 // so try and read it from the @WebService annotation
110 SoapServiceDefinition def = new SoapServiceDefinition();
111
112 def.setJaxWsService(false);
113 def.setBusSecurity(busSecurity);
114
115 Set<Class<?>> webServiceInterfaceSet = AnnotationUtils
116 .extractInterfaceContainingAnnotation(webService,
117 WebService.class);
118
119 if (webServiceInterfaceSet.size() > 1)
120 throw new BeanCreationException(
121 "multiple interfaces exist with an @WebService annotation.");
122 else if (webServiceInterfaceSet.size() == 0)
123 throw new BeanCreationException(
124 "no interfaces exist with an @WebService annotation");
125
126 Class<?> webServiceInterfaceClass = webServiceInterfaceSet
127 .iterator().next();
128
129 WebService serviceAnnotation = webServiceInterfaceClass
130 .getAnnotation(WebService.class);
131
132 def.setService(webService);
133 def.setServiceInterface(webServiceInterfaceClass.getName());
134
135 String serviceName = serviceAnnotation.name();
136
137 if (serviceName == null)
138 throw new BeanCreationException("KualiWebServiceExporter: serviceName is not available for service: "
139 + webServiceInterfaceClass.getName());
140
141 String namespaceUri = serviceAnnotation.targetNamespace();
142
143 if (namespaceUri == null)
144 throw new BeanCreationException("KualiWebServiceExporter: namespaceUri is not availavble for service: "
145 + webServiceInterfaceClass.getName());
146
147 def.setLocalServiceName(serviceName);
148 def.setServiceNameSpaceURI(namespaceUri);
149
150 setServiceDefinition(def);
151
152 }
153
154 // intentionally call super after we build the ServiceDefinition from
155 // the @WebService annotation
156 super.afterPropertiesSet();
157 }
158
159 /**
160 * Set to false to disable security on the exported web service.
161 *
162 * Defaults to true.
163 *
164 * @param busSecurity the busSecurity to set
165 */
166 public void setBusSecurity(boolean busSecurity) {
167 this.busSecurity = busSecurity;
168 }
169
170
171
172 }