001/* 002 * Copyright 2002-2016 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. This is the case with the JAX-WS runtime 034 * that's included in Sun's JDK 6 but not with the standalone JAX-WS 2.1 RI. 035 * 036 * <p>For explicit configuration of JAX-WS endpoints with Sun's JDK 6 037 * HTTP server, consider using {@link SimpleHttpServerJaxWsServiceExporter}! 038 * 039 * @author Juergen Hoeller 040 * @since 2.5 041 * @see javax.jws.WebService 042 * @see javax.xml.ws.Endpoint#publish(String) 043 * @see SimpleHttpServerJaxWsServiceExporter 044 */ 045public class SimpleJaxWsServiceExporter extends AbstractJaxWsServiceExporter { 046 047 public static final String DEFAULT_BASE_ADDRESS = "http://localhost:8080/"; 048 049 private String baseAddress = DEFAULT_BASE_ADDRESS; 050 051 052 /** 053 * Set the base address for exported services. 054 * Default is "http://localhost:8080/". 055 * <p>For each actual publication address, the service name will be 056 * appended to this base address. E.g. service name "OrderService" 057 * -> "http://localhost:8080/OrderService". 058 * @see javax.xml.ws.Endpoint#publish(String) 059 * @see javax.jws.WebService#serviceName() 060 */ 061 public void setBaseAddress(String baseAddress) { 062 this.baseAddress = baseAddress; 063 } 064 065 066 @Override 067 protected void publishEndpoint(Endpoint endpoint, WebService annotation) { 068 endpoint.publish(calculateEndpointAddress(endpoint, annotation.serviceName())); 069 } 070 071 @Override 072 protected void publishEndpoint(Endpoint endpoint, WebServiceProvider annotation) { 073 endpoint.publish(calculateEndpointAddress(endpoint, annotation.serviceName())); 074 } 075 076 /** 077 * Calculate the full endpoint address for the given endpoint. 078 * @param endpoint the JAX-WS Provider Endpoint object 079 * @param serviceName the given service name 080 * @return the full endpoint address 081 */ 082 protected String calculateEndpointAddress(Endpoint endpoint, String serviceName) { 083 String fullAddress = this.baseAddress + serviceName; 084 if (endpoint.getClass().getName().startsWith("weblogic.")) { 085 // Workaround for WebLogic 10.3 086 fullAddress = fullAddress + "/"; 087 } 088 return fullAddress; 089 } 090 091}