JaxWsPortProxyFactoryBean takes "wsdlDocumentUrl", "namespaceUri" etc defaults from @WebService (SPR-7412)
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3517 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
c7f1a2fd76
commit
fbc5081b0a
|
|
@ -18,8 +18,11 @@ package org.springframework.remoting.jaxws;
|
|||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.jws.WebService;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.ws.BindingProvider;
|
||||
import javax.xml.ws.ProtocolException;
|
||||
|
|
@ -41,6 +44,7 @@ import org.springframework.remoting.RemoteLookupFailureException;
|
|||
import org.springframework.remoting.RemoteProxyFailureException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* {@link org.aopalliance.intercept.MethodInterceptor} for accessing a specific
|
||||
|
|
@ -317,9 +321,14 @@ public class JaxWsPortClientInterceptor extends LocalJaxWsServiceFactory
|
|||
* Initialize the JAX-WS port for this interceptor.
|
||||
*/
|
||||
public void prepare() {
|
||||
if (getServiceInterface() == null) {
|
||||
Class<?> ifc = getServiceInterface();
|
||||
if (ifc == null) {
|
||||
throw new IllegalArgumentException("Property 'serviceInterface' is required");
|
||||
}
|
||||
WebService ann = ifc.getAnnotation(WebService.class);
|
||||
if (ann != null) {
|
||||
applyDefaultsFromAnnotation(ann);
|
||||
}
|
||||
Service serviceToUse = getJaxWsService();
|
||||
if (serviceToUse == null) {
|
||||
serviceToUse = createJaxWsService();
|
||||
|
|
@ -330,6 +339,52 @@ public class JaxWsPortClientInterceptor extends LocalJaxWsServiceFactory
|
|||
this.portStub = stub;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize this client interceptor's properties from the given WebService annotation,
|
||||
* if necessary and possible (i.e. if "wsdlDocumentUrl", "namespaceUri", "serviceName"
|
||||
* and "portName" haven't been set but corresponding values are declared at the
|
||||
* annotation level of the specified service interface).
|
||||
* @param ann the WebService annotation found on the specified service interface
|
||||
*/
|
||||
protected void applyDefaultsFromAnnotation(WebService ann) {
|
||||
if (getWsdlDocumentUrl() == null) {
|
||||
String wsdl = ann.wsdlLocation();
|
||||
if (StringUtils.hasText(wsdl)) {
|
||||
try {
|
||||
setWsdlDocumentUrl(new URL(wsdl));
|
||||
}
|
||||
catch (MalformedURLException ex) {
|
||||
throw new IllegalStateException(
|
||||
"Encountered invalid @Service wsdlLocation value [" + wsdl + "]", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getNamespaceUri() == null) {
|
||||
String ns = ann.targetNamespace();
|
||||
if (StringUtils.hasText(ns)) {
|
||||
setNamespaceUri(ns);
|
||||
}
|
||||
}
|
||||
if (getServiceName() == null) {
|
||||
String sn = ann.serviceName();
|
||||
if (StringUtils.hasText(sn)) {
|
||||
setServiceName(sn);
|
||||
}
|
||||
}
|
||||
if (getPortName() == null) {
|
||||
String pn = ann.portName();
|
||||
if (StringUtils.hasText(pn)) {
|
||||
setPortName(pn);
|
||||
}
|
||||
else {
|
||||
String nm = ann.name();
|
||||
if (StringUtils.hasText(nm)) {
|
||||
setPortName(nm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this client interceptor has already been prepared,
|
||||
* i.e. has already looked up the JAX-WS service and port.
|
||||
|
|
@ -478,7 +533,6 @@ public class JaxWsPortClientInterceptor extends LocalJaxWsServiceFactory
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class in order to avoid a hard-coded JAX-WS 2.1 dependency.
|
||||
* JAX-WS 2.0, as used in Java EE 5, didn't have WebServiceFeatures yet...
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -22,6 +22,8 @@ import javax.xml.namespace.QName;
|
|||
import javax.xml.ws.Service;
|
||||
import javax.xml.ws.handler.HandlerResolver;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Factory for locally defined JAX-WS {@link javax.xml.ws.Service} references.
|
||||
* Uses the JAX-WS {@link javax.xml.ws.Service#create} factory API underneath.
|
||||
|
|
@ -118,6 +120,7 @@ public class LocalJaxWsServiceFactory {
|
|||
* @see #setWsdlDocumentUrl
|
||||
*/
|
||||
public Service createJaxWsService() {
|
||||
Assert.notNull(this.serviceName, "No service name specified");
|
||||
Service service = (this.wsdlDocumentUrl != null ?
|
||||
Service.create(this.wsdlDocumentUrl, getQName(this.serviceName)) :
|
||||
Service.create(getQName(this.serviceName)));
|
||||
|
|
|
|||
Loading…
Reference in New Issue