Skip to content

Commit 9a0108a

Browse files
committed
added support for @WebServiceProvider annotation to Spring's JaxWsServiceExporters (SPR-5988)
1 parent 2cd7175 commit 9a0108a

File tree

3 files changed

+66
-10
lines changed

3 files changed

+66
-10
lines changed

org.springframework.web/src/main/java/org/springframework/remoting/jaxws/AbstractJaxWsServiceExporter.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.concurrent.Executor;
2323
import javax.jws.WebService;
2424
import javax.xml.ws.Endpoint;
25+
import javax.xml.ws.WebServiceProvider;
2526

2627
import org.springframework.beans.factory.BeanFactory;
2728
import org.springframework.beans.factory.BeanFactoryAware;
@@ -101,16 +102,22 @@ public void publishEndpoints() {
101102
String[] beanNames = this.beanFactory.getBeanNamesForType(Object.class, false, false);
102103
for (String beanName : beanNames) {
103104
Class<?> type = this.beanFactory.getType(beanName);
104-
WebService annotation = type.getAnnotation(WebService.class);
105-
if (annotation != null) {
105+
WebService wsAnnotation = type.getAnnotation(WebService.class);
106+
WebServiceProvider wsProviderAnnotation = type.getAnnotation(WebServiceProvider.class);
107+
if (wsAnnotation != null || wsProviderAnnotation != null) {
106108
Endpoint endpoint = Endpoint.create(this.beanFactory.getBean(beanName));
107109
if (this.endpointProperties != null) {
108110
endpoint.setProperties(this.endpointProperties);
109111
}
110112
if (this.executor != null) {
111113
endpoint.setExecutor(this.executor);
112114
}
113-
publishEndpoint(endpoint, annotation);
115+
if (wsAnnotation != null) {
116+
publishEndpoint(endpoint, wsAnnotation);
117+
}
118+
else {
119+
publishEndpoint(endpoint, wsProviderAnnotation);
120+
}
114121
this.publishedEndpoints.add(endpoint);
115122
}
116123
}
@@ -123,6 +130,13 @@ public void publishEndpoints() {
123130
*/
124131
protected abstract void publishEndpoint(Endpoint endpoint, WebService annotation);
125132

133+
/**
134+
* Actually publish the given provider endpoint. To be implemented by subclasses.
135+
* @param endpoint the JAX-WS Provider Endpoint object
136+
* @param annotation the service bean's WebServiceProvider annotation
137+
*/
138+
protected abstract void publishEndpoint(Endpoint endpoint, WebServiceProvider annotation);
139+
126140

127141
/**
128142
* Stops all published endpoints, taking the web services offline.

org.springframework.web/src/main/java/org/springframework/remoting/jaxws/SimpleHttpServerJaxWsServiceExporter.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2009 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,9 +18,9 @@
1818

1919
import java.net.InetSocketAddress;
2020
import java.util.List;
21-
2221
import javax.jws.WebService;
2322
import javax.xml.ws.Endpoint;
23+
import javax.xml.ws.WebServiceProvider;
2424

2525
import com.sun.net.httpserver.Authenticator;
2626
import com.sun.net.httpserver.Filter;
@@ -166,17 +166,43 @@ public void afterPropertiesSet() throws Exception {
166166

167167
@Override
168168
protected void publishEndpoint(Endpoint endpoint, WebService annotation) {
169-
String fullPath = this.basePath + annotation.serviceName();
169+
endpoint.publish(buildHttpContext(endpoint, annotation.serviceName()));
170+
}
171+
172+
@Override
173+
protected void publishEndpoint(Endpoint endpoint, WebServiceProvider annotation) {
174+
endpoint.publish(buildHttpContext(endpoint, annotation.serviceName()));
175+
}
176+
177+
/**
178+
* Build the HttpContext for the given endpoint.
179+
* @param endpoint the JAX-WS Provider Endpoint object
180+
* @param serviceName the given service name
181+
* @return the fully populated HttpContext
182+
*/
183+
protected HttpContext buildHttpContext(Endpoint endpoint, String serviceName) {
184+
String fullPath = calculateEndpointPath(endpoint, serviceName);
170185
HttpContext httpContext = this.server.createContext(fullPath);
171186
if (this.filters != null) {
172187
httpContext.getFilters().addAll(this.filters);
173188
}
174189
if (this.authenticator != null) {
175190
httpContext.setAuthenticator(this.authenticator);
176191
}
177-
endpoint.publish(httpContext);
192+
return httpContext;
193+
}
194+
195+
/**
196+
* Calculate the full endpoint path for the given endpoint.
197+
* @param endpoint the JAX-WS Provider Endpoint object
198+
* @param serviceName the given service name
199+
* @return the full endpoint path
200+
*/
201+
protected String calculateEndpointPath(Endpoint endpoint, String serviceName) {
202+
return this.basePath + serviceName;
178203
}
179204

205+
180206
@Override
181207
public void destroy() {
182208
super.destroy();

org.springframework.web/src/main/java/org/springframework/remoting/jaxws/SimpleJaxWsServiceExporter.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import javax.jws.WebService;
2020
import javax.xml.ws.Endpoint;
21+
import javax.xml.ws.WebServiceProvider;
2122

2223
/**
2324
* Simple exporter for JAX-WS services, autodetecting annotated service beans
@@ -64,12 +65,27 @@ public void setBaseAddress(String baseAddress) {
6465

6566
@Override
6667
protected void publishEndpoint(Endpoint endpoint, WebService annotation) {
67-
String fullAddress = this.baseAddress + annotation.serviceName();
68+
endpoint.publish(calculateEndpointAddress(endpoint, annotation.serviceName()));
69+
}
70+
71+
@Override
72+
protected void publishEndpoint(Endpoint endpoint, WebServiceProvider annotation) {
73+
endpoint.publish(calculateEndpointAddress(endpoint, annotation.serviceName()));
74+
}
75+
76+
/**
77+
* Calculate the full endpoint address for the given endpoint.
78+
* @param endpoint the JAX-WS Provider Endpoint object
79+
* @param serviceName the given service name
80+
* @return the full endpoint address
81+
*/
82+
protected String calculateEndpointAddress(Endpoint endpoint, String serviceName) {
83+
String fullAddress = this.baseAddress + serviceName;
6884
if (endpoint.getClass().getName().startsWith("weblogic.")) {
69-
// Workaround for WebLogic 10.3
85+
// Workaround for WebLogic 10.3
7086
fullAddress = fullAddress + "/";
7187
}
72-
endpoint.publish(fullAddress);
88+
return fullAddress;
7389
}
7490

7591
}

0 commit comments

Comments
 (0)