001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.ksb.api.bus.support;
017
018import org.kuali.rice.core.api.config.property.ConfigContext;
019import org.kuali.rice.ksb.api.bus.ServiceBus;
020import org.kuali.rice.ksb.api.bus.ServiceDefinition;
021import org.springframework.beans.factory.InitializingBean;
022
023import javax.xml.namespace.QName;
024import java.net.URL;
025
026/**
027 * A helper class which can be used to by a client application to export a callback service to the Kuali Service Bus
028 * service registry.  A callback service is a service published by a client application which is invoked by one of the
029 * Kuali Rice modules running as part of the standalone server.
030 *
031 * <p>While it's perfectly legal for an application to handle publishing of callback service implementations to the
032 * service registry manually using the {@link ServiceBus} api or the {@link ServiceBusExporter}, this class helps with
033 * publishing the services in such a way that they are compatible with the requirements of how the specific callback
034 * services are supposed to be published.  This includes ensuring that information about the version of the callback
035 * services is properly present in the service registry.  This additionally ensures the service is published using the
036 * correct type of {@link ServiceDefinition} and the proper security settings.  By default, callback services use SOAP
037 * and have bus security turned on.</p>
038 *
039 * <p>With the exception of the {@code callbackService}, most of the properties on this class are passed through to
040 * either a {@code ServiceBusExporter} or a {@code SoapServiceDefinition}.  As a result, many of them are optional (see
041 * the documentation on the aforementioned classes for details).  The callback service must be injected into this class
042 * or else an {@code IllegalStateException} will be thrown during startup of this bean.
043 *
044 * @see org.kuali.rice.ksb.api.bus.support.ServiceBusExporter
045 * @see org.kuali.rice.ksb.api.bus.support.SoapServiceDefinition
046 *
047 * @author Kuali Rice Team (rice.collab@kuali.org)
048 */
049public class CallbackServiceExporter implements InitializingBean {
050
051    private String localServiceName;
052        private String serviceNameSpaceURI;
053        private QName serviceName;
054    private String servicePath;
055    private URL endpointUrl;
056    private Boolean busSecurity;
057    private String serviceInterface;
058    private Object callbackService;
059
060    private ServiceBus serviceBus;
061
062    public CallbackServiceExporter() {
063        this.busSecurity = Boolean.TRUE;
064    }
065
066    @Override
067    public final void afterPropertiesSet() throws Exception {
068        if (getCallbackService() == null) {
069            throw new IllegalStateException("No callback service was provided to this exporter.");
070        }
071        ServiceBusExporter serviceBusExporter = createServiceBusExporter();
072        serviceBusExporter.afterPropertiesSet();
073    }
074
075    /**
076     * Creates a {@link org.kuali.rice.ksb.api.bus.support.ServiceBusExporter} based on the properties set on this
077     * exporter.  Subclasses may override this method in order to customize how the exporter or it's
078     * {@link org.kuali.rice.ksb.api.bus.ServiceDefinition} are created.
079     *
080     * @return a fully constructed ServiceBusExporter which is ready to be exported
081     */
082    protected ServiceBusExporter createServiceBusExporter() {
083        ServiceBusExporter serviceBusExporter = new ServiceBusExporter();
084        serviceBusExporter.setServiceDefinition(createSoapServiceDefinition());
085        return serviceBusExporter;
086    }
087
088    /**
089     * Creates a {@link org.kuali.rice.ksb.api.bus.support.SoapServiceDefinition} based on the properties set on this
090     * exporter.  Subclasses may override this method in order to customize how the SOAP service definition is created.
091     *
092     * @return the SoapServiceDefinition to be exported
093     */
094    protected SoapServiceDefinition createSoapServiceDefinition() {
095        SoapServiceDefinition serviceDefinition = new SoapServiceDefinition();
096
097        // configured setup
098        serviceDefinition.setLocalServiceName(getLocalServiceName());
099        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}