001/*
002 * Copyright 2002-2018 the original author or authors.
003 *
004 * Licensed under the Apache 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 *      https://www.apache.org/licenses/LICENSE-2.0
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 */
016
017package org.springframework.remoting.jaxws;
018
019import javax.jws.WebService;
020import javax.xml.ws.Endpoint;
021import javax.xml.ws.WebServiceProvider;
022
023/**
024 * Simple exporter for JAX-WS services, autodetecting annotated service beans
025 * (through the JAX-WS {@link javax.jws.WebService} annotation) and exporting
026 * them with a configured base address (by default "http://localhost:8080/")
027 * using the JAX-WS provider's built-in publication support. The full address
028 * for each service will consist of the base address with the service name
029 * appended (e.g. "http://localhost:8080/OrderService").
030 *
031 * <p>Note that this exporter will only work if the JAX-WS runtime actually
032 * supports publishing with an address argument, i.e. if the JAX-WS runtime
033 * ships an internal HTTP server.
034 *
035 * @author Juergen Hoeller
036 * @since 2.5
037 * @see javax.jws.WebService
038 * @see javax.xml.ws.Endpoint#publish(String)
039 */
040public class SimpleJaxWsServiceExporter extends AbstractJaxWsServiceExporter {
041
042        /**
043         * The default base address.
044         */
045        public static final String DEFAULT_BASE_ADDRESS = "http://localhost:8080/";
046
047        private String baseAddress = DEFAULT_BASE_ADDRESS;
048
049
050        /**
051         * Set the base address for exported services.
052         * Default is "http://localhost:8080/".
053         * <p>For each actual publication address, the service name will be
054         * appended to this base address. E.g. service name "OrderService"
055         * -> "http://localhost:8080/OrderService".
056         * @see javax.xml.ws.Endpoint#publish(String)
057         * @see javax.jws.WebService#serviceName()
058         */
059        public void setBaseAddress(String baseAddress) {
060                this.baseAddress = baseAddress;
061        }
062
063
064        @Override
065        protected void publishEndpoint(Endpoint endpoint, WebService annotation) {
066                endpoint.publish(calculateEndpointAddress(endpoint, annotation.serviceName()));
067        }
068
069        @Override
070        protected void publishEndpoint(Endpoint endpoint, WebServiceProvider annotation) {
071                endpoint.publish(calculateEndpointAddress(endpoint, annotation.serviceName()));
072        }
073
074        /**
075         * Calculate the full endpoint address for the given endpoint.
076         * @param endpoint the JAX-WS Provider Endpoint object
077         * @param serviceName the given service name
078         * @return the full endpoint address
079         */
080        protected String calculateEndpointAddress(Endpoint endpoint, String serviceName) {
081                String fullAddress = this.baseAddress + serviceName;
082                if (endpoint.getClass().getName().startsWith("weblogic.")) {
083                        // Workaround for WebLogic 10.3
084                        fullAddress = fullAddress + "/";
085                }
086                return fullAddress;
087        }
088
089}