View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.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.rice.ksb.api.bus.support;
17  
18  import org.kuali.rice.core.api.config.property.ConfigContext;
19  import org.kuali.rice.ksb.api.bus.ServiceBus;
20  import org.kuali.rice.ksb.api.bus.ServiceDefinition;
21  import org.springframework.beans.factory.InitializingBean;
22  
23  import javax.xml.namespace.QName;
24  import java.net.URL;
25  
26  /**
27   * A helper class which can be used to by a client application to export a callback service to the Kuali Service Bus
28   * service registry.  A callback service is a service published by a client application which is invoked by one of the
29   * Kuali Rice modules running as part of the standalone server.
30   *
31   * <p>While it's perfectly legal for an application to handle publishing of callback service implementations to the
32   * service registry manually using the {@link ServiceBus} api or the {@link ServiceBusExporter}, this class helps with
33   * publishing the services in such a way that they are compatible with the requirements of how the specific callback
34   * services are supposed to be published.  This includes ensuring that information about the version of the callback
35   * services is properly present in the service registry.  This additionally ensures the service is published using the
36   * correct type of {@link ServiceDefinition} and the proper security settings.  By default, callback services use SOAP
37   * and have bus security turned on.</p>
38   *
39   * <p>With the exception of the {@code callbackService}, most of the properties on this class are passed through to
40   * either a {@code ServiceBusExporter} or a {@code SoapServiceDefinition}.  As a result, many of them are optional (see
41   * the documentation on the aforementioned classes for details).  The callback service must be injected into this class
42   * or else an {@code IllegalStateException} will be thrown during startup of this bean.
43   *
44   * @see org.kuali.rice.ksb.api.bus.support.ServiceBusExporter
45   * @see org.kuali.rice.ksb.api.bus.support.SoapServiceDefinition
46   *
47   * @author Kuali Rice Team (rice.collab@kuali.org)
48   */
49  public class CallbackServiceExporter implements InitializingBean {
50  
51      private String localServiceName;
52  	private String serviceNameSpaceURI;
53  	private QName serviceName;
54      private String servicePath;
55      private URL endpointUrl;
56      private Boolean busSecurity;
57      private String serviceInterface;
58      private Object callbackService;
59  
60      private ServiceBus serviceBus;
61  
62      public CallbackServiceExporter() {
63          this.busSecurity = Boolean.TRUE;
64      }
65  
66      @Override
67      public final void afterPropertiesSet() throws Exception {
68          if (getCallbackService() == null) {
69              throw new IllegalStateException("No callback service was provided to this exporter.");
70          }
71          ServiceBusExporter serviceBusExporter = createServiceBusExporter();
72          serviceBusExporter.afterPropertiesSet();
73      }
74  
75      /**
76       * Creates a {@link org.kuali.rice.ksb.api.bus.support.ServiceBusExporter} based on the properties set on this
77       * exporter.  Subclasses may override this method in order to customize how the exporter or it's
78       * {@link org.kuali.rice.ksb.api.bus.ServiceDefinition} are created.
79       *
80       * @return a fully constructed ServiceBusExporter which is ready to be exported
81       */
82      protected ServiceBusExporter createServiceBusExporter() {
83          ServiceBusExporter serviceBusExporter = new ServiceBusExporter();
84          serviceBusExporter.setServiceDefinition(createSoapServiceDefinition());
85          return serviceBusExporter;
86      }
87  
88      /**
89       * Creates a {@link org.kuali.rice.ksb.api.bus.support.SoapServiceDefinition} based on the properties set on this
90       * exporter.  Subclasses may override this method in order to customize how the SOAP service definition is created.
91       *
92       * @return the SoapServiceDefinition to be exported
93       */
94      protected SoapServiceDefinition createSoapServiceDefinition() {
95          SoapServiceDefinition serviceDefinition = new SoapServiceDefinition();
96  
97          // configured setup
98          serviceDefinition.setLocalServiceName(getLocalServiceName());
99          serviceDefinition.setServiceNameSpaceURI(getServiceNameSpaceURI());
100         serviceDefinition.setServiceName(getServiceName());
101 
102         serviceDefinition.setService(getCallbackService());
103         serviceDefinition.setServicePath(getServicePath());
104         serviceDefinition.setEndpointUrl(getEndpointUrl());
105         serviceDefinition.setServiceInterface(getServiceInterface());
106 
107         // standard setup
108         serviceDefinition.setJaxWsService(true);
109         serviceDefinition.setBusSecurity(getBusSecurity());
110         serviceDefinition.setServiceVersion(ConfigContext.getCurrentContextConfig().getRiceVersion());
111 
112         return serviceDefinition;
113     }
114 
115     protected final String getLocalServiceName() {
116         return localServiceName;
117     }
118 
119     public final void setLocalServiceName(String localServiceName) {
120         this.localServiceName = localServiceName;
121     }
122 
123     public final String getServiceNameSpaceURI() {
124         return serviceNameSpaceURI;
125     }
126 
127     public final void setServiceNameSpaceURI(String serviceNameSpaceURI) {
128         this.serviceNameSpaceURI = serviceNameSpaceURI;
129     }
130 
131     public final QName getServiceName() {
132         return serviceName;
133     }
134 
135     public final void setServiceName(QName serviceName) {
136         this.serviceName = serviceName;
137     }
138 
139     public final String getServicePath() {
140         return servicePath;
141     }
142 
143     public final void setServicePath(String servicePath) {
144         this.servicePath = servicePath;
145     }
146 
147     public final URL getEndpointUrl() {
148         return endpointUrl;
149     }
150 
151     public final void setEndpointUrl(URL endpointUrl) {
152         this.endpointUrl = endpointUrl;
153     }
154 
155     public final Boolean getBusSecurity() {
156         return busSecurity;
157     }
158 
159     public final void setBusSecurity(Boolean busSecurity) {
160         this.busSecurity = busSecurity;
161     }
162 
163     public String getServiceInterface() {
164         return serviceInterface;
165     }
166 
167     public void setServiceInterface(String serviceInterface) {
168         this.serviceInterface = serviceInterface;
169     }
170 
171     public Object getCallbackService() {
172         return callbackService;
173     }
174 
175     public void setCallbackService(Object callbackService) {
176         this.callbackService = callbackService;
177     }
178 
179     public final ServiceBus getServiceBus() {
180         return serviceBus;
181     }
182 
183     public final void setServiceBus(ServiceBus serviceBus) {
184         this.serviceBus = serviceBus;
185     }
186 
187 }