Author: thomas.diesler(a)jboss.com
Date: 2007-01-16 02:52:19 -0500 (Tue, 16 Jan 2007)
New Revision: 1978
Added:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSServerMetaDataBuilder.java
Removed:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSClientEndpointMetaDataBuilder.java
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSEndpointMetaDataBuilder.java
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSServerMetaDataBuilder.java
Modified:
trunk/integration-jboss42/.classpath
trunk/integration-jboss50/.classpath
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/spi/EndpointImpl.java
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/spi/ServiceDelegateImpl.java
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSClientMetaDataBuilder.java
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilderEJB21.java
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilderEJB3.java
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilderJSE.java
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSProviderMetaDataBuilder.java
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java
trunk/jbossws-tests/src/main/java/org/jboss/test/ws/tools/java2xsd/SchemaModelTestCase.java
Log:
Restructure JAXWS meta data builder
Modified: trunk/integration-jboss42/.classpath
===================================================================
--- trunk/integration-jboss42/.classpath 2007-01-16 04:10:04 UTC (rev 1977)
+++ trunk/integration-jboss42/.classpath 2007-01-16 07:52:19 UTC (rev 1978)
@@ -28,9 +28,6 @@
<classpathentry kind="lib"
path="/build/thirdparty/xalan.jar"/>
<classpathentry kind="lib"
path="/build/thirdparty/xercesImpl.jar"/>
<classpathentry kind="lib"
path="/build/thirdparty/mail.jar"/>
- <classpathentry kind="lib"
path="/home/tdiesler/svn/jbossas/branches/Branch_4_2/build/output/jboss-4.2.0.CR1-ejb3/server/default/deploy/ejb3.deployer/jboss-annotations-ejb3.jar"/>
- <classpathentry kind="lib"
path="/home/tdiesler/svn/jbossas/branches/Branch_4_2/build/output/jboss-4.2.0.CR1-ejb3/server/default/deploy/ejb3.deployer/jboss-ejb3.jar"/>
- <classpathentry kind="lib"
path="/home/tdiesler/svn/jbossas/branches/Branch_4_2/build/output/jboss-4.2.0.CR1-ejb3/server/default/deploy/ejb3.deployer/jboss-ejb3x.jar"/>
<classpathentry kind="lib"
path="/build/thirdparty/jbosssx-client.jar"
sourcepath="/build/thirdparty/jbosssx-src.zip"/>
<classpathentry kind="output" path="output-eclipse"/>
</classpath>
Modified: trunk/integration-jboss50/.classpath
===================================================================
--- trunk/integration-jboss50/.classpath 2007-01-16 04:10:04 UTC (rev 1977)
+++ trunk/integration-jboss50/.classpath 2007-01-16 07:52:19 UTC (rev 1978)
@@ -30,10 +30,6 @@
<classpathentry kind="lib"
path="/build/thirdparty/xercesImpl.jar"/>
<classpathentry kind="lib"
path="/build/thirdparty/mail.jar"/>
<classpathentry kind="con"
path="org.eclipse.jdt.USER_LIBRARY/jboss-5.0.x"/>
- <classpathentry kind="lib"
path="/home/tdiesler/svn/jbossas/trunk/build/output/jboss-5.0.0.Beta2/server/default/deployers/ejb3.deployer/jboss-annotations-ejb3.jar"/>
- <classpathentry kind="lib"
path="/home/tdiesler/svn/jbossas/trunk/build/output/jboss-5.0.0.Beta2/server/default/deployers/ejb3.deployer/jboss-ejb3.jar"
sourcepath="/home/tdiesler/svn/jbossas/trunk/ejb3/src/main"/>
- <classpathentry kind="lib"
path="/home/tdiesler/svn/jbossas/trunk/build/output/jboss-5.0.0.Beta2/server/default/deployers/ejb3.deployer/jboss-ejb3x.jar"/>
- <classpathentry kind="lib"
path="/home/tdiesler/svn/jbossas/trunk/build/output/jboss-5.0.0.Beta2/server/default/deployers/jboss-aop-jboss5.deployer/jboss-aspect-library-jdk50.jar"/>
<classpathentry kind="lib"
path="/build/thirdparty/jbosssx-client.jar"
sourcepath="/build/thirdparty/jbosssx-src.zip"/>
<classpathentry kind="output" path="output-eclipse"/>
</classpath>
Modified: trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/spi/EndpointImpl.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/spi/EndpointImpl.java 2007-01-16
04:10:04 UTC (rev 1977)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/spi/EndpointImpl.java 2007-01-16
07:52:19 UTC (rev 1978)
@@ -36,7 +36,6 @@
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Endpoint;
import javax.xml.ws.EndpointReference;
-import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServicePermission;
import org.jboss.logging.Logger;
@@ -44,6 +43,8 @@
import org.jboss.ws.core.jaxws.binding.BindingProviderImpl;
import org.jboss.ws.core.server.HttpContext;
import org.jboss.ws.core.server.HttpServer;
+import org.jboss.ws.core.server.ServiceEndpointManager;
+import org.jboss.ws.core.server.ServiceEndpointManagerFactory;
import org.w3c.dom.Element;
/**
@@ -61,6 +62,8 @@
private static final WebServicePermission ENDPOINT_PUBLISH_PERMISSION = new
WebServicePermission("publishEndpoint");
private Object implementor;
+ private Executor executor;
+ private List<Source> metadata;
private BindingProvider bindingProvider;
private Map<String, Object> properties = new HashMap<String, Object>();
private HttpContext serverContext;
@@ -145,6 +148,23 @@
// Check with the security manger
checkPublishEndpointPermission();
+ // Check if we are standalone
+ boolean isStandalone;
+ try
+ {
+ ServiceEndpointManagerFactory factory =
ServiceEndpointManagerFactory.getInstance();
+ factory.getServiceEndpointManager();
+ isStandalone = false;
+ }
+ catch (Exception ex)
+ {
+ // ignore, there should be no ServiceEndpointManager in VM
+ isStandalone = true;
+ }
+
+ if (isStandalone == false)
+ throw new IllegalStateException("Cannot publish endpoint from within
server");
+
if (context instanceof HttpContext)
{
serverContext = (HttpContext)context;
@@ -188,25 +208,27 @@
@Override
public List<Source> getMetadata()
{
- throw new NotImplementedException();
+ return metadata;
}
@Override
public void setMetadata(List<Source> list)
{
- throw new NotImplementedException();
+ log.info("Ignore metadata, not implemented");
+ this.metadata = list;
}
@Override
public Executor getExecutor()
{
- throw new NotImplementedException();
+ return executor;
}
@Override
public void setExecutor(Executor executor)
{
- throw new NotImplementedException();
+ log.info("Ignore executor, not implemented");
+ this.executor = executor;
}
@Override
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/spi/ServiceDelegateImpl.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/spi/ServiceDelegateImpl.java 2007-01-16
04:10:04 UTC (rev 1977)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/spi/ServiceDelegateImpl.java 2007-01-16
07:52:19 UTC (rev 1978)
@@ -23,39 +23,43 @@
// $Id$
+import java.lang.reflect.Proxy;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import javax.jws.WebService;
+import javax.xml.bind.JAXBContext;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.EndpointReference;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.WebServiceFeature;
+import javax.xml.ws.Service.Mode;
+import javax.xml.ws.handler.HandlerResolver;
+import javax.xml.ws.spi.ServiceDelegate;
+
import org.jboss.logging.Logger;
import org.jboss.util.NotImplementedException;
import org.jboss.ws.Constants;
+import org.jboss.ws.core.jaxws.StubExt;
import org.jboss.ws.core.jaxws.client.ClientImpl;
import org.jboss.ws.core.jaxws.client.ClientProxy;
import org.jboss.ws.core.jaxws.client.DispatchImpl;
import org.jboss.ws.core.jaxws.handler.HandlerResolverImpl;
-import org.jboss.ws.core.jaxws.StubExt;
-import org.jboss.ws.metadata.builder.jaxws.JAXWSClientEndpointMetaDataBuilder;
import org.jboss.ws.metadata.builder.jaxws.JAXWSClientMetaDataBuilder;
import org.jboss.ws.metadata.umdm.ClientEndpointMetaData;
import org.jboss.ws.metadata.umdm.EndpointMetaData;
+import org.jboss.ws.metadata.umdm.ServiceMetaData;
import org.jboss.ws.metadata.umdm.EndpointMetaData.Type;
import org.jboss.ws.metadata.umdm.HandlerMetaData.HandlerType;
-import org.jboss.ws.metadata.umdm.ServiceMetaData;
-import javax.jws.WebService;
-import javax.xml.bind.JAXBContext;
-import javax.xml.namespace.QName;
-import javax.xml.ws.*;
-import javax.xml.ws.Service.Mode;
-import javax.xml.ws.handler.HandlerResolver;
-import javax.xml.ws.spi.ServiceDelegate;
-import java.lang.reflect.Proxy;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.concurrent.Executor;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
/**
* Service delegates are used internally by Service objects to allow pluggability of
JAX-WS implementations.
*
@@ -89,8 +93,7 @@
{
JAXWSClientMetaDataBuilder builder = new JAXWSClientMetaDataBuilder();
- ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
- serviceMetaData = builder.buildMetaData(serviceName, wsdlURL, ctxClassLoader);
+ serviceMetaData = builder.buildMetaData(serviceName, wsdlURL);
for (EndpointMetaData epMetaData : serviceMetaData.getEndpoints())
{
@@ -179,7 +182,7 @@
// Adjust the endpoint meta data according to the annotations
if (annotatedPorts.contains(portName) == false)
{
- JAXWSClientEndpointMetaDataBuilder metaDataBuilder = new
JAXWSClientEndpointMetaDataBuilder();
+ JAXWSClientMetaDataBuilder metaDataBuilder = new JAXWSClientMetaDataBuilder();
metaDataBuilder.rebuildEndpointMetaData(epMetaData, seiClass);
}
Deleted:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSClientEndpointMetaDataBuilder.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSClientEndpointMetaDataBuilder.java 2007-01-16
04:10:04 UTC (rev 1977)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSClientEndpointMetaDataBuilder.java 2007-01-16
07:52:19 UTC (rev 1978)
@@ -1,82 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-// $Id$
-package org.jboss.ws.metadata.builder.jaxws;
-
-import javax.jws.HandlerChain;
-import javax.jws.soap.SOAPBinding;
-import javax.xml.ws.BindingType;
-
-import org.jboss.logging.Logger;
-import org.jboss.ws.metadata.config.jaxws.ClientConfigJAXWS;
-import org.jboss.ws.metadata.umdm.EndpointMetaData;
-import org.jboss.ws.metadata.umdm.HandlerMetaData.HandlerType;
-
-/**
- * A client side meta data builder that is based on JSR-181 annotations
- *
- * @author Thomas.Diesler(a)jboss.org
- * @since 9-Aug-2006
- */
-public class JAXWSClientEndpointMetaDataBuilder extends JAXWSWebServiceMetaDataBuilder
-{
- // provide logging
- private final Logger log =
Logger.getLogger(JAXWSClientEndpointMetaDataBuilder.class);
-
- public void rebuildEndpointMetaData(EndpointMetaData epMetaData, Class<?>
wsClass)
- {
- log.debug("START: rebuildMetaData");
-
- // Clear the java types, etc.
- resetMetaDataBuilder(epMetaData.getClassLoader());
-
- // Nuke parameterStyle
- epMetaData.setParameterStyle(null);
-
- // Process an optional @BindingType annotation
- if (wsClass.isAnnotationPresent(BindingType.class))
- processBindingType(epMetaData, wsClass);
-
- // Process @SOAPBinding
- if (wsClass.isAnnotationPresent(SOAPBinding.class))
- processSOAPBinding(epMetaData, wsClass);
-
- // process config, this will as well setup the handler
- epMetaData.configure(epMetaData);
-
- // Process an optional @HandlerChain annotation
- if (wsClass.isAnnotationPresent(HandlerChain.class))
- processHandlerChain(epMetaData, wsClass);
-
- // Process @WebMethod
- processWebMethods(epMetaData, wsClass);
-
- // Initialize types
- createJAXBContext(epMetaData);
- populateXmlTypes(epMetaData);
-
- // Eager initialization
- epMetaData.eagerInitialize();
-
- log.debug("END: rebuildMetaData\n" + epMetaData.getServiceMetaData());
- }
-}
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSClientMetaDataBuilder.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSClientMetaDataBuilder.java 2007-01-16
04:10:04 UTC (rev 1977)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSClientMetaDataBuilder.java 2007-01-16
07:52:19 UTC (rev 1978)
@@ -26,9 +26,11 @@
import java.io.IOException;
import java.net.URL;
+import javax.jws.HandlerChain;
+import javax.jws.soap.SOAPBinding;
import javax.xml.namespace.QName;
+import javax.xml.ws.BindingType;
-import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
import org.jboss.ws.WSException;
import org.jboss.ws.core.jaxrpc.Style;
@@ -57,12 +59,9 @@
*/
public class JAXWSClientMetaDataBuilder extends JAXWSMetaDataBuilder
{
- // provide logging
- private final Logger log = Logger.getLogger(JAXWSClientMetaDataBuilder.class);
-
/** Build from WSDL and jaxrpc-mapping.xml
*/
- public ServiceMetaData buildMetaData(QName serviceName, URL wsdlURL, ClassLoader
loader)
+ public ServiceMetaData buildMetaData(QName serviceName, URL wsdlURL)
{
if (wsdlURL == null)
throw new IllegalArgumentException("Invalid wsdlURL: " + wsdlURL);
@@ -170,4 +169,42 @@
opMetaData.setSOAPAction(wsdlBindingOperation.getSOAPAction());
}
}
+
+ public void rebuildEndpointMetaData(EndpointMetaData epMetaData, Class<?>
wsClass)
+ {
+ log.debug("START: rebuildMetaData");
+
+ // Clear the java types, etc.
+ resetMetaDataBuilder(epMetaData.getClassLoader());
+
+ // Nuke parameterStyle
+ epMetaData.setParameterStyle(null);
+
+ // Process an optional @BindingType annotation
+ if (wsClass.isAnnotationPresent(BindingType.class))
+ processBindingType(epMetaData, wsClass);
+
+ // Process @SOAPBinding
+ if (wsClass.isAnnotationPresent(SOAPBinding.class))
+ processSOAPBinding(epMetaData, wsClass);
+
+ // process config, this will as well setup the handler
+ epMetaData.configure(epMetaData);
+
+ // Process an optional @HandlerChain annotation
+ if (wsClass.isAnnotationPresent(HandlerChain.class))
+ processHandlerChain(epMetaData, wsClass);
+
+ // Process @WebMethod
+ processWebMethods(epMetaData, wsClass);
+
+ // Initialize types
+ createJAXBContext(epMetaData);
+ populateXmlTypes(epMetaData);
+
+ // Eager initialization
+ epMetaData.eagerInitialize();
+
+ log.debug("END: rebuildMetaData\n" + epMetaData.getServiceMetaData());
+ }
}
Deleted:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSEndpointMetaDataBuilder.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSEndpointMetaDataBuilder.java 2007-01-16
04:10:04 UTC (rev 1977)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSEndpointMetaDataBuilder.java 2007-01-16
07:52:19 UTC (rev 1978)
@@ -1,150 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-package org.jboss.ws.metadata.builder.jaxws;
-
-import java.io.IOException;
-
-import javax.xml.ws.BindingType;
-
-import org.jboss.logging.Logger;
-import org.jboss.ws.annotation.PortComponent;
-import org.jboss.ws.core.server.UnifiedDeploymentInfo;
-import org.jboss.ws.core.server.UnifiedDeploymentInfo.DeploymentType;
-import org.jboss.ws.metadata.umdm.EndpointMetaData;
-import org.jboss.ws.metadata.umdm.ServerEndpointMetaData;
-import org.jboss.ws.metadata.umdm.UnifiedMetaData;
-
-/**
- * Builds ServiceEndpointMetaData for a JAX-WS endpoint.
- *
- * @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
- * @version $Revision$
- */
-public abstract class JAXWSEndpointMetaDataBuilder extends JAXWSMetaDataBuilder
-{
- // provide logging
- private final Logger log = Logger.getLogger(JAXWSEndpointMetaDataBuilder.class);
-
- public abstract ServerEndpointMetaData buildEndpointMetaData(UnifiedMetaData
wsMetaData, UnifiedDeploymentInfo udi, Class<?> sepClass, String linkName) throws
IOException;
-
- protected void processBindingType(EndpointMetaData epMetaData, Class<?>
wsClass)
- {
- if (! wsClass.isAnnotationPresent(BindingType.class))
- return;
-
- BindingType anBindingType = (BindingType)wsClass.getAnnotation(BindingType.class);
- String uri = anBindingType.value();
- if (uri.length() > 0)
- {
- epMetaData.setBindingId(uri);
- }
- }
-
- protected void processPortComponent(UnifiedDeploymentInfo udi, Class<?> wsClass,
String linkName, ServerEndpointMetaData sepMetaData)
- {
- PortComponent anPortComponent = wsClass.getAnnotation(PortComponent.class);
- if (anPortComponent == null)
- return;
-
- // setup config name
- if (anPortComponent.configName().length() > 0)
- {
- String configName = anPortComponent.configName();
- sepMetaData.setConfigName(configName);
- }
-
- // setup config file
- if (anPortComponent.configFile().length() > 0)
- {
- String configFile = anPortComponent.configFile();
- sepMetaData.setConfigFile(configFile);
- }
-
- boolean isJSEEndpoint = (udi.type == DeploymentType.JAXWS_JSE);
-
- // context-root
- if (anPortComponent.contextRoot().length() > 0)
- {
- if (isJSEEndpoint)
- log.warn("(a)PortComponent.contextRoot is only valid on EJB
endpoints");
-
- if (isJSEEndpoint == false)
- {
- String contextRoot = anPortComponent.contextRoot();
- if (contextRoot.startsWith("/") == false)
- contextRoot = "/" + contextRoot;
-
- sepMetaData.setContextRoot(contextRoot);
- }
- }
-
- // url-pattern
- if (anPortComponent.urlPattern().length() > 0)
- {
- if (isJSEEndpoint)
- log.warn("(a)PortComponent.urlPattern is only valid on EJB
endpoints");
-
- if (isJSEEndpoint == false)
- {
- String urlPattern = anPortComponent.urlPattern();
- sepMetaData.setURLPattern(urlPattern);
- }
- }
-
- // auth-method
- if (anPortComponent.authMethod().length() > 0)
- {
- if (isJSEEndpoint)
- log.warn("(a)PortComponent.authMethod is only valid on EJB
endpoints");
-
- if (isJSEEndpoint == false)
- {
- String authMethod = anPortComponent.authMethod();
- sepMetaData.setAuthMethod(authMethod);
- }
- }
-
- // transport-guarantee
- if (anPortComponent.transportGuarantee().length() > 0)
- {
- if (isJSEEndpoint)
- log.warn("(a)PortComponent.transportGuarantee is only valid on EJB
endpoints");
-
- if (isJSEEndpoint == false)
- {
- String transportGuarantee = anPortComponent.transportGuarantee();
- sepMetaData.setTransportGuarantee(transportGuarantee);
- }
- }
-
- // secure wsdl access
- sepMetaData.setSecureWSDLAccess(anPortComponent.secureWSDLAccess());
-
- // virtual hosts
- String[] virtualHosts = anPortComponent.virtualHosts();
- if (virtualHosts != null & virtualHosts.length > 0)
- {
- sepMetaData.setVirtualHosts(virtualHosts);
- }
-
- }
-}
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java 2007-01-16
04:10:04 UTC (rev 1977)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java 2007-01-16
07:52:19 UTC (rev 1978)
@@ -21,14 +21,838 @@
*/
package org.jboss.ws.metadata.builder.jaxws;
+// $Id$
+
+import java.io.File;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import javax.jws.HandlerChain;
+import javax.jws.Oneway;
+import javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebResult;
+import javax.jws.soap.SOAPBinding;
+import javax.jws.soap.SOAPMessageHandlers;
+import javax.jws.soap.SOAPBinding.ParameterStyle;
+import javax.xml.bind.JAXBException;
+import javax.xml.namespace.QName;
+import javax.xml.rpc.ParameterMode;
+import javax.xml.ws.BindingType;
+import javax.xml.ws.RequestWrapper;
+import javax.xml.ws.ResponseWrapper;
+import javax.xml.ws.WebFault;
+import javax.xml.ws.addressing.AddressingProperties;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.Constants;
+import org.jboss.ws.WSException;
+import org.jboss.ws.core.jaxrpc.Style;
+import org.jboss.ws.core.jaxrpc.Use;
+import org.jboss.ws.core.jaxws.DynamicWrapperGenerator;
+import org.jboss.ws.core.jaxws.WrapperGenerator;
+import org.jboss.ws.core.utils.HolderUtils;
+import org.jboss.ws.core.utils.JBossWSEntityResolver;
+import org.jboss.ws.core.utils.JavaUtils;
+import org.jboss.ws.extensions.addressing.AddressingPropertiesImpl;
+import org.jboss.ws.extensions.addressing.metadata.AddressingOpMetaExt;
+import org.jboss.ws.metadata.acessor.JAXBAccessor;
import org.jboss.ws.metadata.builder.MetaDataBuilder;
+import org.jboss.ws.metadata.j2ee.UnifiedHandlerMetaData;
+import org.jboss.ws.metadata.jsr181.HandlerChainFactory;
+import org.jboss.ws.metadata.jsr181.HandlerChainMetaData;
+import org.jboss.ws.metadata.jsr181.HandlerChainsMetaData;
+import org.jboss.ws.metadata.umdm.EndpointMetaData;
+import org.jboss.ws.metadata.umdm.FaultMetaData;
+import org.jboss.ws.metadata.umdm.OperationMetaData;
+import org.jboss.ws.metadata.umdm.ParameterMetaData;
+import org.jboss.ws.metadata.umdm.TypeMappingMetaData;
+import org.jboss.ws.metadata.umdm.TypesMetaData;
+import org.jboss.ws.metadata.umdm.WrappedParameter;
+import org.jboss.ws.metadata.umdm.HandlerMetaData.HandlerType;
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import com.sun.xml.bind.api.JAXBRIContext;
+import com.sun.xml.bind.api.TypeReference;
+
/**
* Abstract class that represents a JAX-WS metadata builder.
*
* @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
- * @version $Revision$
+ * @author Thomas.Diesler(a)jboss.com
*/
+@SuppressWarnings("deprecation")
public class JAXWSMetaDataBuilder extends MetaDataBuilder
{
+
+ protected static final Logger log =
Logger.getLogger(JAXWSWebServiceMetaDataBuilder.class);
+ protected List<Class> javaTypes = new ArrayList<Class>();
+ protected JAXBRIContext jaxbCtx;
+ protected List<TypeReference> typeRefs = new ArrayList<TypeReference>();
+ protected WrapperGenerator wrapperGenerator;
+
+ protected void processBindingType(EndpointMetaData epMetaData, Class<?>
wsClass)
+ {
+ if (! wsClass.isAnnotationPresent(BindingType.class))
+ return;
+
+ BindingType anBindingType = (BindingType)wsClass.getAnnotation(BindingType.class);
+ String uri = anBindingType.value();
+ if (uri.length() > 0)
+ {
+ epMetaData.setBindingId(uri);
+ }
+ }
+
+ protected void processSOAPBinding(EndpointMetaData epMetaData, Class<?>
wsClass)
+ {
+
+ if (!wsClass.isAnnotationPresent(SOAPBinding.class))
+ return;
+
+ SOAPBinding anSoapBinding = wsClass.getAnnotation(SOAPBinding.class);
+
+ SOAPBinding.Style attrStyle = anSoapBinding.style();
+ Style style = (attrStyle == SOAPBinding.Style.RPC ? Style.RPC : Style.DOCUMENT);
+ epMetaData.setStyle(style);
+
+ SOAPBinding.Use attrUse = anSoapBinding.use();
+ if (attrUse == SOAPBinding.Use.ENCODED)
+ throw new WSException("SOAP encoding is not supported for JSR-181
deployments");
+
+ epMetaData.setEncodingStyle(Use.LITERAL);
+
+ ParameterStyle paramStyle = anSoapBinding.parameterStyle();
+ epMetaData.setParameterStyle(paramStyle);
+ }
+
+ /**
+ * Process an optional @HandlerChain annotation
+ *
+ * Location of the handler chain file. The location supports 2 formats.
+ *
+ * 1. An absolute java.net.URL in externalForm.
+ * (ex:
http://myhandlers.foo.com/handlerfile1.xml)
+ *
+ * 2. A relative path from the source file or class file.
+ * (ex: bar/handlerfile1.xml)
+ */
+ protected void processHandlerChain(EndpointMetaData epMetaData, Class<?>
wsClass)
+ {
+ if (wsClass.isAnnotationPresent(SOAPMessageHandlers.class))
+ throw new WSException("Cannot combine @HandlerChain with
@SOAPMessageHandlers");
+
+ HandlerChain anHandlerChain = wsClass.getAnnotation(HandlerChain.class);
+
+ URL fileURL = null;
+ String filename = anHandlerChain.file();
+
+ // Try the filename as URL
+ try
+ {
+ fileURL = new URL(filename);
+ }
+ catch (MalformedURLException ex)
+ {
+ // ignore
+ }
+
+ // Try the filename as File
+ if (fileURL == null)
+ {
+ try
+ {
+ File file = new File(filename);
+ if (file.exists())
+ fileURL = file.toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ // ignore
+ }
+ }
+
+ // Try the filename as Resource
+ if (fileURL == null)
+ {
+ fileURL = epMetaData.getClassLoader().getResource(filename);
+ }
+
+ // Try the filename relative to class
+ if (fileURL == null)
+ {
+ String packagePath = wsClass.getPackage().getName().replace('.',
'/');
+ fileURL = epMetaData.getClassLoader().getResource(packagePath + "/" +
filename);
+ }
+
+ if (fileURL == null)
+ throw new WSException("Cannot resolve handler file '" + filename +
"' on " + wsClass.getName());
+
+ try
+ {
+ HandlerChainsMetaData handlerChainsMetaData = null;
+ InputStream is = fileURL.openStream();
+ try
+ {
+ Unmarshaller unmarshaller =
UnmarshallerFactory.newInstance().newUnmarshaller();
+ unmarshaller.setValidation(true);
+ unmarshaller.setSchemaValidation(true);
+ unmarshaller.setEntityResolver(new JBossWSEntityResolver());
+ ObjectModelFactory factory = new HandlerChainFactory();
+ handlerChainsMetaData = (HandlerChainsMetaData)unmarshaller.unmarshal(is,
factory, null);
+ }
+ finally
+ {
+ is.close();
+ }
+
+ // Setup the endpoint handlers
+ for (HandlerChainMetaData handlerChainMetaData :
handlerChainsMetaData.getHandlerChains())
+ {
+ for (UnifiedHandlerMetaData uhmd : handlerChainMetaData.getHandlers())
+ {
+ epMetaData.addHandler(uhmd.getHandlerMetaDataJAXWS(epMetaData,
HandlerType.ENDPOINT));
+ }
+ }
+ }
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (Exception ex)
+ {
+ throw new WSException("Cannot process handler chain: " + filename,
ex);
+ }
+ }
+
+ private void addFault(OperationMetaData omd, Class<?> exception)
+ {
+ if (omd.isOneWay())
+ throw new IllegalStateException("JSR-181 4.3.1 - A JSR-181 processor is
REQUIRED to report an error if an operation marked "
+ + "@Oneway has a return value, declares any checked exceptions or has
any INOUT or OUT parameters.");
+
+ WebFault annotation = exception.getAnnotation(WebFault.class);
+
+ String name;
+ String namespace;
+ String faultBeanName = null;
+
+ // Only the element name is effected by @WebFault, the type uses the same
convention
+ QName xmlType = new QName(omd.getQName().getNamespaceURI(),
exception.getSimpleName());
+
+ /*
+ * If @WebFault is present, and the exception contains getFaultInfo, the
+ * return value should be used. Otherwise we need to generate the bean.
+ */
+ boolean generate = true;
+ if (annotation != null)
+ {
+ name = annotation.name();
+ namespace = annotation.targetNamespace();
+ if (namespace.length() == 0)
+ namespace = omd.getQName().getNamespaceURI();
+
+ Class<?> faultBean = getFaultInfo(exception);
+ if (faultBean != null)
+ {
+ generate = false;
+ faultBeanName = faultBean.getName();
+ }
+ }
+ else
+ {
+ name = xmlType.getLocalPart();
+ namespace = xmlType.getNamespaceURI();
+ }
+
+ if (faultBeanName == null)
+ faultBeanName =
JavaUtils.getPackageName(omd.getEndpointMetaData().getServiceEndpointInterface()) +
".jaxws." + exception.getSimpleName() + "Bean";
+
+ QName xmlName = new QName(namespace, name);
+
+ FaultMetaData fmd = new FaultMetaData(omd, xmlName, xmlType, exception.getName());
+ fmd.setFaultBeanName(faultBeanName);
+
+ if (generate)
+ wrapperGenerator.generate(fmd);
+
+ javaTypes.add(fmd.getFaultBean());
+ typeRefs.add(new TypeReference(fmd.getXmlName(), fmd.getFaultBean()));
+
+ omd.addFault(fmd);
+ }
+
+ private String convertToVariable(String localName)
+ {
+ return JAXBRIContext.mangleNameToVariableName(localName);
+ }
+
+ private String[] convertTypeArguments(Class rawType, Type type)
+ {
+ if (!Collection.class.isAssignableFrom(rawType) &&
!Map.class.isAssignableFrom(rawType))
+ return null;
+
+ if (!(type instanceof ParameterizedType))
+ return null;
+
+ ParameterizedType paramType = (ParameterizedType)type;
+ Type[] arguments = paramType.getActualTypeArguments();
+ String[] ret = new String[arguments.length];
+ for (int i = 0; i < arguments.length; i++)
+ ret[i] = JavaUtils.erasure(arguments[i]).getName();
+
+ return ret;
+ }
+
+ private ParameterMetaData createRequestWrapper(OperationMetaData operation, Method
method)
+ {
+ String requestWrapperType = null;
+ QName xmlName = operation.getQName();
+ QName xmlType = xmlName;
+ if (method.isAnnotationPresent(RequestWrapper.class))
+ {
+ RequestWrapper anReqWrapper = method.getAnnotation(RequestWrapper.class);
+
+ String localName = anReqWrapper.localName().length() > 0 ?
anReqWrapper.localName() : xmlName.getLocalPart();
+ String targetNamespace = anReqWrapper.targetNamespace().length() > 0 ?
anReqWrapper.targetNamespace() : xmlName.getNamespaceURI();
+ xmlName = new QName(targetNamespace, localName);
+
+ if (anReqWrapper.className().length() > 0)
+ requestWrapperType = anReqWrapper.className();
+ }
+
+ // Conformance 3.18, the default value must be the same as the method name
+ if (requestWrapperType == null)
+ {
+ String packageName = JavaUtils.getPackageName(method.getDeclaringClass()) +
".jaxws";
+ requestWrapperType = packageName + "." +
JavaUtils.capitalize(method.getName());
+ }
+
+ // JAX-WS p.37 pg.1, the annotation only affects the element name, not the type
name
+ ParameterMetaData wrapperParameter = new ParameterMetaData(operation, xmlName,
xmlType, requestWrapperType);
+ wrapperParameter.setAccessorFactoryCreator(JAXBAccessor.FACTORY_CREATOR);
+ operation.addParameter(wrapperParameter);
+
+ return wrapperParameter;
+ }
+
+ private ParameterMetaData createResponseWrapper(OperationMetaData operation, Method
method)
+ {
+ QName operationQName = operation.getQName();
+ QName xmlName = new QName(operationQName.getNamespaceURI(),
operationQName.getLocalPart() + "Response");
+ QName xmlType = xmlName;
+
+ String responseWrapperType = null;
+ if (method.isAnnotationPresent(ResponseWrapper.class))
+ {
+ ResponseWrapper anResWrapper = method.getAnnotation(ResponseWrapper.class);
+
+ String localName = anResWrapper.localName().length() > 0 ?
anResWrapper.localName() : xmlName.getLocalPart();
+ String targetNamespace = anResWrapper.targetNamespace().length() > 0 ?
anResWrapper.targetNamespace() : xmlName.getNamespaceURI();
+ xmlName = new QName(targetNamespace, localName);
+
+ if (anResWrapper.className().length() > 0)
+ responseWrapperType = anResWrapper.className();
+ }
+
+ if (responseWrapperType == null)
+ {
+ String packageName = JavaUtils.getPackageName(method.getDeclaringClass()) +
".jaxws";
+ responseWrapperType = packageName + "." +
JavaUtils.capitalize(method.getName()) + "Response";
+ }
+
+ ParameterMetaData retMetaData = new ParameterMetaData(operation, xmlName, xmlType,
responseWrapperType);
+ retMetaData.setAccessorFactoryCreator(JAXBAccessor.FACTORY_CREATOR);
+ operation.setReturnParameter(retMetaData);
+
+ return retMetaData;
+ }
+
+ private Class<?> getFaultInfo(Class<?> exception)
+ {
+ try
+ {
+ Method method = exception.getMethod("getFaultInfo");
+ Class<?> returnType = method.getReturnType();
+ if (returnType == void.class)
+ return null;
+
+ return returnType;
+ }
+ catch (SecurityException e)
+ {
+ throw new WSException("Unexpected security exception: " +
e.getMessage(), e);
+ }
+ catch (NoSuchMethodException e)
+ {
+ return null;
+ }
+ }
+
+ private ParameterMode getParameterMode(WebParam anWebParam, Class javaType)
+ {
+ if (anWebParam != null)
+ {
+ if (anWebParam.mode() == WebParam.Mode.INOUT)
+ return ParameterMode.INOUT;
+ if (anWebParam.mode() == WebParam.Mode.OUT)
+ return ParameterMode.OUT;
+ }
+
+ return HolderUtils.isHolderType(javaType) ? ParameterMode.INOUT :
ParameterMode.IN;
+ }
+
+ private WebParam getWebParamAnnotation(Method method, int pos)
+ {
+ for (Annotation annotation : method.getParameterAnnotations()[pos])
+ if (annotation instanceof WebParam)
+ return (WebParam)annotation;
+
+ return null;
+ }
+
+ private QName getWebParamName(OperationMetaData opMetaData, int index, WebParam
webParam)
+ {
+ String namespace = null;
+ String name = null;
+ boolean header = false;
+
+ if (webParam != null)
+ {
+ if (webParam.targetNamespace().length() > 0)
+ namespace = webParam.targetNamespace();
+
+ // RPC types use the partName for their XML name
+ if (webParam.partName().length() > 0 && opMetaData.isRPCLiteral())
+ name = webParam.partName();
+ else if (webParam.name().length() > 0)
+ name = webParam.name();
+
+ header = webParam.header();
+ }
+
+ // Bare and headers must be qualified
+ if (namespace == null && (opMetaData.isDocumentBare() || header))
+ namespace = opMetaData.getQName().getNamespaceURI();
+
+ // RPC body parts must have no namespace
+ else if (opMetaData.isRPCLiteral() && !header)
+ namespace = null;
+
+ // Bare uses the operation name as the default, everything else is generated
+ if (name == null)
+ name = opMetaData.isDocumentBare() && !header ?
opMetaData.getQName().getLocalPart() : "arg" + index;
+
+ return (namespace != null) ? new QName(namespace, name) : new QName(name);
+ }
+
+ private QName getWebResultName(OperationMetaData opMetaData, WebResult anWebResult)
+ {
+ String name = null;
+ String namespace = null;
+ boolean header = false;
+
+ if (anWebResult != null)
+ {
+ if (anWebResult.targetNamespace().length() > 0)
+ namespace = anWebResult.targetNamespace();
+
+ // RPC types use the partName for their XML name
+ if (anWebResult.partName().length() > 0 &&
opMetaData.isRPCLiteral())
+ name = anWebResult.partName();
+ else if (anWebResult.name().length() > 0)
+ name = anWebResult.name();
+
+ header = anWebResult.header();
+ }
+
+ // Bare and headers must be qualified
+ if (namespace == null && (opMetaData.isDocumentBare() || header))
+ namespace = opMetaData.getQName().getNamespaceURI();
+
+ // RPC body parts must have no namespace
+ else if (opMetaData.isRPCLiteral() && !header)
+ namespace = null;
+
+ // Bare uses the operation name as the default, everything else is generated
+ if (name == null)
+ name = opMetaData.isDocumentBare() && !header ?
opMetaData.getResponseName().getLocalPart() : "return";
+
+ return (namespace != null) ? new QName(namespace, name) : new QName(name);
+ }
+
+ /**
+ * Process operation meta data extensions.
+ */
+ private void processMetaExtensions(EndpointMetaData epMetaData, OperationMetaData
opMetaData)
+ {
+ // Until there is a addressing annotion we fallback to implicit action association
+ // TODO: figure out a way to assign message name instead of IN and OUT
+ String tns = epMetaData.getQName().getNamespaceURI();
+ String portTypeName = epMetaData.getQName().getLocalPart();
+
+ AddressingProperties ADDR = new AddressingPropertiesImpl();
+ AddressingOpMetaExt addrExt = new AddressingOpMetaExt(ADDR.getNamespaceURI());
+ addrExt.setInboundAction(tns + "/" + portTypeName + "/IN");
+
+ if (!opMetaData.isOneWay())
+ addrExt.setOutboundAction(tns + "/" + portTypeName +
"/OUT");
+
+ opMetaData.addExtension(addrExt);
+ }
+
+ private void processWebMethod(EndpointMetaData epMetaData, Method method)
+ {
+ String javaName = method.getName();
+
+ // skip asnyc methods, they dont need meta data representation
+ if (method.getName().endsWith(Constants.ASYNC_METHOD_SUFFIX))
+ return;
+
+ // reflection defaults
+ String soapAction = "";
+ String operationName = method.getName();
+
+ // annotation values that override defaults
+ if (method.isAnnotationPresent(WebMethod.class))
+ {
+ WebMethod anWebMethod = method.getAnnotation(WebMethod.class);
+ soapAction = anWebMethod.action();
+ if (anWebMethod.operationName().length() > 0)
+ {
+ operationName = anWebMethod.operationName();
+ }
+ }
+
+ String targetNS = epMetaData.getInterfaceQName().getNamespaceURI();
+ OperationMetaData opMetaData = new OperationMetaData(epMetaData, new
QName(targetNS, operationName), javaName);
+ opMetaData.setOneWay(method.isAnnotationPresent(Oneway.class));
+ opMetaData.setSOAPAction(soapAction);
+
+ if (method.isAnnotationPresent(SOAPBinding.class))
+ {
+ SOAPBinding anBinding = method.getAnnotation(SOAPBinding.class);
+ if (anBinding.style() != SOAPBinding.Style.DOCUMENT || epMetaData.getStyle() !=
Style.DOCUMENT)
+ throw new IllegalArgumentException("@SOAPBinding must be specified using
DOCUMENT style when placed on a method");
+ opMetaData.setParameterStyle(anBinding.parameterStyle());
+ }
+
+ epMetaData.addOperation(opMetaData);
+
+ // Build parameter meta data
+ Class[] parameterTypes = method.getParameterTypes();
+ Type[] genericTypes = method.getGenericParameterTypes();
+ Annotation[][] parameterAnnotations = method.getParameterAnnotations();
+ ParameterMetaData wrapperParameter = null, wrapperOutputParameter = null;
+ List<WrappedParameter> wrappedParameters = null, wrappedOutputParameters =
null;
+
+ // Force paramter style to wrapped
+ if (method.isAnnotationPresent(RequestWrapper.class) ||
method.isAnnotationPresent(ResponseWrapper.class))
+ {
+ epMetaData.setParameterStyle(ParameterStyle.WRAPPED);
+ }
+
+ if (opMetaData.isDocumentWrapped())
+ {
+ wrapperParameter = createRequestWrapper(opMetaData, method);
+ wrappedParameters = new
ArrayList<WrappedParameter>(parameterTypes.length);
+ wrapperParameter.setWrappedParameters(wrappedParameters);
+
+ if (!opMetaData.isOneWay())
+ {
+ wrapperOutputParameter = createResponseWrapper(opMetaData, method);
+ wrappedOutputParameters = new
ArrayList<WrappedParameter>(parameterTypes.length + 1);
+ wrapperOutputParameter.setWrappedParameters(wrappedOutputParameters);
+ }
+ }
+
+ for (int i = 0; i < parameterTypes.length; i++)
+ {
+ Class javaType = parameterTypes[i];
+ Type genericType = genericTypes[i];
+ String javaTypeName = javaType.getName();
+ WebParam anWebParam = getWebParamAnnotation(method, i);
+ boolean isHeader = anWebParam != null && anWebParam.header();
+ boolean isWrapped = opMetaData.isDocumentWrapped() && !isHeader;
+ ParameterMode mode = getParameterMode(anWebParam, javaType);
+
+ // Assert one-way
+ if (opMetaData.isOneWay() && mode != ParameterMode.IN)
+ throw new IllegalArgumentException("A one-way operation can not have
output parameters [" + "method = " + method.getName() + ", parameter =
" + i + "]");
+
+ if (HolderUtils.isHolderType(javaType))
+ {
+ genericType = HolderUtils.getGenericValueType(genericType);
+ javaType = JavaUtils.erasure(genericType);
+ javaTypeName = javaType.getName();
+ }
+
+ if (isWrapped)
+ {
+ QName wrappedElementName = getWebParamName(opMetaData, i, anWebParam);
+ String variable = convertToVariable(wrappedElementName.getLocalPart());
+
+ WrappedParameter wrappedParameter = new WrappedParameter(wrappedElementName,
javaTypeName, variable, i);
+ wrappedParameter.setTypeArguments(convertTypeArguments(javaType,
genericType));
+
+ if (mode != ParameterMode.OUT)
+ wrappedParameters.add(wrappedParameter);
+ if (mode != ParameterMode.IN)
+ {
+ wrappedOutputParameters.add(wrappedParameter);
+ wrappedParameter.setHolder(true);
+ }
+ }
+ else
+ {
+ QName xmlName = getWebParamName(opMetaData, i, anWebParam);
+
+ ParameterMetaData paramMetaData = new ParameterMetaData(opMetaData, xmlName,
javaTypeName);
+ paramMetaData.setInHeader(isHeader);
+ paramMetaData.setIndex(i);
+ paramMetaData.setMode(mode);
+
+ /*
+ * Note: The TCK enforces the following rule in the spec regarding
+ * partName: "This is only used if the operation is rpc style or if
+ * the operation is document style and the parameter style is BARE."
+ *
+ * This seems to be a flaw in the spec, because the intention is
+ * obviously to prevent the ambiguity of wrapped parameters that
+ * specify different partName values. There is, however, no reason
+ * that this limitation should apply to header parameters since they
+ * are never wrapped. In order to comply we adhere to this confusing
+ * rule, although I will ask for clarification.
+ */
+ if (anWebParam != null && !opMetaData.isDocumentWrapped() &&
anWebParam.partName().length() > 0)
+ paramMetaData.setPartName(anWebParam.partName());
+
+ opMetaData.addParameter(paramMetaData);
+ javaTypes.add(javaType);
+ typeRefs.add(new TypeReference(xmlName, genericType,
parameterAnnotations[i]));
+ }
+ }
+
+ // Build result meta data
+ Class returnType = method.getReturnType();
+ Type genericReturnType = method.getGenericReturnType();
+ String returnTypeName = returnType.getName();
+ if (!(returnType == void.class))
+ {
+ if (opMetaData.isOneWay())
+ throw new IllegalArgumentException("[JSR-181 2.5.1] The method
'" + method.getName() + "' can not have a return value if it is marked
OneWay");
+
+ WebResult anWebResult = method.getAnnotation(WebResult.class);
+ boolean isHeader = anWebResult != null && anWebResult.header();
+ boolean isWrappedBody = opMetaData.isDocumentWrapped() && !isHeader;
+ QName xmlName = getWebResultName(opMetaData, anWebResult);
+
+ if (isWrappedBody)
+ {
+ WrappedParameter wrapped = new WrappedParameter(xmlName, returnTypeName,
convertToVariable(xmlName.getLocalPart()), -1);
+ wrapped.setTypeArguments(convertTypeArguments(returnType,
genericReturnType));
+
+ // insert at the beginning just for prettiness
+ wrappedOutputParameters.add(0, wrapped);
+ }
+ else
+ {
+ ParameterMetaData retMetaData = new ParameterMetaData(opMetaData, xmlName,
returnTypeName);
+ retMetaData.setInHeader(isHeader);
+ retMetaData.setIndex(-1);
+ retMetaData.setMode(ParameterMode.OUT);
+
+ // Special case: If we have a document/literal wrapped message, then
+ // the return metadata must be the wrapper type that is sent in the
+ // body. So, in order to handle headers that are mapped to the java
+ // return value, we have to add them to a parameter with an index of
+ // -1 to signify the return value. All other binding styles use the
+ // expected return value mechanism.
+ if (opMetaData.isDocumentWrapped())
+ {
+ opMetaData.addParameter(retMetaData);
+ }
+ else
+ {
+ // See above comment in the parameter for loop section as to why
+ // we prevent customization of part names on document wrapped
+ // header parameters.
+ if (anWebResult != null && anWebResult.partName().length() >
0)
+ retMetaData.setPartName(anWebResult.partName());
+
+ opMetaData.setReturnParameter(retMetaData);
+ }
+
+ javaTypes.add(returnType);
+ typeRefs.add(new TypeReference(xmlName, genericReturnType,
method.getAnnotations()));
+ }
+ }
+
+ // Generate wrapper beans
+ if (opMetaData.isDocumentWrapped())
+ {
+ wrapperGenerator.generate(wrapperParameter);
+ Class wrapperClass = wrapperParameter.getJavaType();
+ javaTypes.add(wrapperClass);
+ // In case there is no @XmlRootElement
+ typeRefs.add(new TypeReference(wrapperParameter.getXmlName(), wrapperClass));
+ if (!opMetaData.isOneWay())
+ {
+ wrapperGenerator.generate(wrapperOutputParameter);
+ wrapperClass = wrapperOutputParameter.getJavaType();
+ javaTypes.add(wrapperClass);
+ // In case there is no @XmlRootElement
+ typeRefs.add(new TypeReference(wrapperOutputParameter.getXmlName(),
wrapperClass));
+ }
+ }
+
+ // Add faults
+ for (Class exClass : method.getExceptionTypes())
+ if (!RemoteException.class.isAssignableFrom(exClass))
+ addFault(opMetaData, exClass);
+
+ // process op meta data extension
+ processMetaExtensions(epMetaData, opMetaData);
+ }
+
+ protected void processWebMethods(EndpointMetaData epMetaData, Class wsClass)
+ {
+ epMetaData.clearOperations();
+
+ // Process @WebMethod annotations
+ int webMethodCount = 0;
+ for (Method method : wsClass.getMethods())
+ {
+ WebMethod annotation = method.getAnnotation(WebMethod.class);
+ boolean exclude = annotation != null && annotation.exclude();
+ if (!exclude && (annotation != null || wsClass.isInterface()))
+ {
+ processWebMethod(epMetaData, method);
+ webMethodCount++;
+ }
+ }
+
+ // @WebService should expose all inherited methods if @WebMethod is never
specified
+ if (webMethodCount == 0 && !wsClass.isInterface())
+ {
+ for (Method method : wsClass.getMethods())
+ {
+ WebMethod annotation = method.getAnnotation(WebMethod.class);
+ boolean exclude = annotation != null && annotation.exclude();
+ if (!exclude && method.getDeclaringClass() != Object.class)
+ {
+ processWebMethod(epMetaData, method);
+ webMethodCount++;
+ }
+ }
+ }
+
+ if (webMethodCount == 0)
+ throw new WSException("No exposable methods found");
+ }
+
+ protected void resetMetaDataBuilder(ClassLoader loader)
+ {
+ wrapperGenerator = new DynamicWrapperGenerator(loader);
+ javaTypes.clear();
+ typeRefs.clear();
+ jaxbCtx = null;
+ }
+
+ protected void createJAXBContext(EndpointMetaData epMetaData)
+ {
+ try
+ {
+ String targetNS = epMetaData.getInterfaceQName().getNamespaceURI();
+ log.debug("JAXBContext [types=" + javaTypes + ",tns=" +
targetNS + "]");
+ jaxbCtx = JAXBRIContext.newInstance(javaTypes.toArray(new Class[0]), typeRefs,
targetNS, false);
+ }
+ catch (JAXBException ex)
+ {
+ throw new IllegalStateException("Cannot build JAXB context", ex);
+ }
+ }
+
+ private void populateXmlType(FaultMetaData faultMetaData)
+ {
+ EndpointMetaData epMetaData =
faultMetaData.getOperationMetaData().getEndpointMetaData();
+ TypesMetaData types = epMetaData.getServiceMetaData().getTypesMetaData();
+
+ QName xmlType = faultMetaData.getXmlType();
+ String faultBeanName = faultMetaData.getFaultBeanName();
+
+ types.addTypeMapping(new TypeMappingMetaData(types, xmlType, faultBeanName));
+ }
+
+ private void populateXmlType(ParameterMetaData paramMetaData)
+ {
+ EndpointMetaData epMetaData =
paramMetaData.getOperationMetaData().getEndpointMetaData();
+ TypesMetaData types = epMetaData.getServiceMetaData().getTypesMetaData();
+
+ QName xmlName = paramMetaData.getXmlName();
+ QName xmlType = paramMetaData.getXmlType();
+ Class javaType = paramMetaData.getJavaType();
+ String javaName = paramMetaData.getJavaTypeName();
+
+ if (xmlType == null)
+ {
+ try
+ {
+ xmlType = jaxbCtx.getTypeName(new TypeReference(xmlName, javaType));
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new IllegalStateException("Cannot obtain xml type for:
[xmlName=" + xmlName + ",javaName=" + javaName + "]");
+ }
+
+ /* Anonymous type.
+ *
+ * Currently the design of our stack is based on the
+ * notion of their always being a unique type. In order to lookup the
+ * appropriate (de)serializer you must have a type. So we use a fake
+ * name. This is an illegal NCName, so it shouldn't collide.
+ */
+ if (xmlType == null)
+ xmlType = new QName(xmlName.getNamespaceURI(), ">" +
xmlName.getLocalPart());
+
+ paramMetaData.setXmlType(xmlType);
+ }
+
+ types.addTypeMapping(new TypeMappingMetaData(types, xmlType, javaName));
+ }
+
+ protected void populateXmlTypes(EndpointMetaData epMetaData)
+ {
+ for (OperationMetaData operation : epMetaData.getOperations())
+ {
+ // parameters
+ for (ParameterMetaData paramMetaData : operation.getParameters())
+ {
+ populateXmlType(paramMetaData);
+ }
+
+ // return value
+ ParameterMetaData returnParameter = operation.getReturnParameter();
+ if (returnParameter != null)
+ populateXmlType(returnParameter);
+
+ // faults
+ for (FaultMetaData faultMetaData : operation.getFaults())
+ {
+ populateXmlType(faultMetaData);
+ }
+ }
+ }
}
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilderEJB21.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilderEJB21.java 2007-01-16
04:10:04 UTC (rev 1977)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilderEJB21.java 2007-01-16
07:52:19 UTC (rev 1978)
@@ -42,7 +42,7 @@
* @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
* @since 19-May-2005
*/
-public class JAXWSMetaDataBuilderEJB21 extends JAXWSServerMetaDataBuilder
+public class JAXWSMetaDataBuilderEJB21
{
// provide logging
private final Logger log = Logger.getLogger(JAXWSMetaDataBuilderEJB21.class);
@@ -73,7 +73,7 @@
if (beanClass.isAnnotationPresent(WebService.class) ||
beanClass.isAnnotationPresent(WebServiceProvider.class))
{
String ejbLink = beanMetaData.getEjbName();
- setupEndpoint(wsMetaData, udi, beanClass, ejbLink);
+ JAXWSServerMetaDataBuilder.setupProviderOrWebService(wsMetaData, udi,
beanClass, ejbLink);
// setup the security domain
if (beanClass.isAnnotationPresent(SecurityDomain.class))
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilderEJB3.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilderEJB3.java 2007-01-16
04:10:04 UTC (rev 1977)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilderEJB3.java 2007-01-16
07:52:19 UTC (rev 1978)
@@ -42,7 +42,7 @@
* @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
* @since 19-May-2005
*/
-public class JAXWSMetaDataBuilderEJB3 extends JAXWSServerMetaDataBuilder
+public class JAXWSMetaDataBuilderEJB3
{
// provide logging
private final Logger log = Logger.getLogger(JAXWSMetaDataBuilderEJB3.class);
@@ -74,7 +74,7 @@
if (beanClass.isAnnotationPresent(WebService.class) ||
beanClass.isAnnotationPresent(WebServiceProvider.class))
{
String ejbLink = beanMetaData.getEjbName();
- setupEndpoint(wsMetaData, udi, beanClass, ejbLink);
+ JAXWSServerMetaDataBuilder.setupProviderOrWebService(wsMetaData, udi,
beanClass, ejbLink);
// setup the security domain
if (beanClass.isAnnotationPresent(SecurityDomain.class))
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilderJSE.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilderJSE.java 2007-01-16
04:10:04 UTC (rev 1977)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilderJSE.java 2007-01-16
07:52:19 UTC (rev 1978)
@@ -37,7 +37,7 @@
* @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
* @since 23-Jul-2005
*/
-public class JAXWSMetaDataBuilderJSE extends JAXWSServerMetaDataBuilder
+public class JAXWSMetaDataBuilderJSE
{
// provide logging
private final Logger log = Logger.getLogger(JAXWSMetaDataBuilderJSE.class);
@@ -65,7 +65,7 @@
try
{
Class beanClass = udi.classLoader.loadClass(servletClassName);
- setupEndpoint(wsMetaData, udi, beanClass, servletName);
+ JAXWSServerMetaDataBuilder.setupProviderOrWebService(wsMetaData, udi,
beanClass, servletName);
}
catch (ClassNotFoundException ex)
{
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSProviderMetaDataBuilder.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSProviderMetaDataBuilder.java 2007-01-16
04:10:04 UTC (rev 1977)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSProviderMetaDataBuilder.java 2007-01-16
07:52:19 UTC (rev 1978)
@@ -37,7 +37,6 @@
import javax.xml.ws.WebServiceProvider;
import javax.xml.ws.Service.Mode;
-import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
import org.jboss.ws.core.jaxrpc.Style;
import org.jboss.ws.core.server.UnifiedDeploymentInfo;
@@ -58,16 +57,9 @@
* @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
* @since 23-Jul-2005
*/
-public class JAXWSProviderMetaDataBuilder extends JAXWSEndpointMetaDataBuilder
+public class JAXWSProviderMetaDataBuilder extends JAXWSServerMetaDataBuilder
{
- // provide logging
- private final Logger log = Logger.getLogger(JAXWSProviderMetaDataBuilder.class);
-
- /** Build from annotations
- */
-
- @Override
- public ServerEndpointMetaData buildEndpointMetaData(UnifiedMetaData wsMetaData,
UnifiedDeploymentInfo udi, Class<?> sepClass, String linkName) throws IOException
+ public ServerEndpointMetaData buildProviderMetaData(UnifiedMetaData wsMetaData,
UnifiedDeploymentInfo udi, Class<?> sepClass, String linkName) throws IOException
{
// 5.3 Conformance (Provider implementation): A Provider based service endpoint
implementation MUST
// implement a typed Provider interface.
Deleted:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSServerMetaDataBuilder.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSServerMetaDataBuilder.java 2007-01-16
04:10:04 UTC (rev 1977)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSServerMetaDataBuilder.java 2007-01-16
07:52:19 UTC (rev 1978)
@@ -1,52 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.ws.metadata.builder.jaxws;
-
-// $Id$
-
-import javax.jws.WebService;
-import javax.xml.ws.WebServiceProvider;
-
-import org.jboss.ws.core.server.UnifiedDeploymentInfo;
-import org.jboss.ws.metadata.umdm.UnifiedMetaData;
-
-/** An abstract annotation meta data builder.
- *
- * @author Thomas.Diesler(a)jboss.org
- * @since 27-Jun-2006
- */
-public abstract class JAXWSServerMetaDataBuilder extends JAXWSMetaDataBuilder
-{
- protected void setupEndpoint(UnifiedMetaData umd, UnifiedDeploymentInfo udi,
Class<?> beanClass, String beanName) throws Exception
- {
- if (beanClass.isAnnotationPresent(WebService.class))
- {
- JAXWSEndpointMetaDataBuilder builder = new JAXWSWebServiceMetaDataBuilder();
- builder.buildEndpointMetaData(umd, udi, beanClass, beanName);
- }
- else if (beanClass.isAnnotationPresent(WebServiceProvider.class))
- {
- JAXWSEndpointMetaDataBuilder builder = new JAXWSProviderMetaDataBuilder();
- builder.buildEndpointMetaData(umd, udi, beanClass, beanName);
- }
- }
-}
Copied:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSServerMetaDataBuilder.java
(from rev 1975,
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSEndpointMetaDataBuilder.java)
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSEndpointMetaDataBuilder.java 2007-01-15
20:34:13 UTC (rev 1975)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSServerMetaDataBuilder.java 2007-01-16
07:52:19 UTC (rev 1978)
@@ -0,0 +1,145 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.jboss.ws.metadata.builder.jaxws;
+
+// $Id$
+
+import javax.jws.WebService;
+import javax.xml.ws.WebServiceProvider;
+
+import org.jboss.ws.annotation.PortComponent;
+import org.jboss.ws.core.server.UnifiedDeploymentInfo;
+import org.jboss.ws.core.server.UnifiedDeploymentInfo.DeploymentType;
+import org.jboss.ws.metadata.umdm.ServerEndpointMetaData;
+import org.jboss.ws.metadata.umdm.UnifiedMetaData;
+
+/**
+ * Builds ServiceEndpointMetaData for a JAX-WS endpoint.
+ *
+ * @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
+ * @author Thomas.Diesler(a)jboss.com
+ */
+public abstract class JAXWSServerMetaDataBuilder extends JAXWSMetaDataBuilder
+{
+ static void setupProviderOrWebService(UnifiedMetaData umd, UnifiedDeploymentInfo udi,
Class<?> beanClass, String beanName) throws Exception
+ {
+ if (beanClass.isAnnotationPresent(WebService.class))
+ {
+ JAXWSWebServiceMetaDataBuilder builder = new JAXWSWebServiceMetaDataBuilder();
+ builder.buildWebServiceMetaData(umd, udi, beanClass, beanName);
+ }
+ else if (beanClass.isAnnotationPresent(WebServiceProvider.class))
+ {
+ JAXWSProviderMetaDataBuilder builder = new JAXWSProviderMetaDataBuilder();
+ builder.buildProviderMetaData(umd, udi, beanClass, beanName);
+ }
+ }
+
+ protected void processPortComponent(UnifiedDeploymentInfo udi, Class<?> wsClass,
String linkName, ServerEndpointMetaData sepMetaData)
+ {
+ PortComponent anPortComponent = wsClass.getAnnotation(PortComponent.class);
+ if (anPortComponent == null)
+ return;
+
+ // setup config name
+ if (anPortComponent.configName().length() > 0)
+ {
+ String configName = anPortComponent.configName();
+ sepMetaData.setConfigName(configName);
+ }
+
+ // setup config file
+ if (anPortComponent.configFile().length() > 0)
+ {
+ String configFile = anPortComponent.configFile();
+ sepMetaData.setConfigFile(configFile);
+ }
+
+ boolean isJSEEndpoint = (udi.type == DeploymentType.JAXWS_JSE);
+
+ // context-root
+ if (anPortComponent.contextRoot().length() > 0)
+ {
+ if (isJSEEndpoint)
+ log.warn("(a)PortComponent.contextRoot is only valid on EJB
endpoints");
+
+ if (isJSEEndpoint == false)
+ {
+ String contextRoot = anPortComponent.contextRoot();
+ if (contextRoot.startsWith("/") == false)
+ contextRoot = "/" + contextRoot;
+
+ sepMetaData.setContextRoot(contextRoot);
+ }
+ }
+
+ // url-pattern
+ if (anPortComponent.urlPattern().length() > 0)
+ {
+ if (isJSEEndpoint)
+ log.warn("(a)PortComponent.urlPattern is only valid on EJB
endpoints");
+
+ if (isJSEEndpoint == false)
+ {
+ String urlPattern = anPortComponent.urlPattern();
+ sepMetaData.setURLPattern(urlPattern);
+ }
+ }
+
+ // auth-method
+ if (anPortComponent.authMethod().length() > 0)
+ {
+ if (isJSEEndpoint)
+ log.warn("(a)PortComponent.authMethod is only valid on EJB
endpoints");
+
+ if (isJSEEndpoint == false)
+ {
+ String authMethod = anPortComponent.authMethod();
+ sepMetaData.setAuthMethod(authMethod);
+ }
+ }
+
+ // transport-guarantee
+ if (anPortComponent.transportGuarantee().length() > 0)
+ {
+ if (isJSEEndpoint)
+ log.warn("(a)PortComponent.transportGuarantee is only valid on EJB
endpoints");
+
+ if (isJSEEndpoint == false)
+ {
+ String transportGuarantee = anPortComponent.transportGuarantee();
+ sepMetaData.setTransportGuarantee(transportGuarantee);
+ }
+ }
+
+ // secure wsdl access
+ sepMetaData.setSecureWSDLAccess(anPortComponent.secureWSDLAccess());
+
+ // virtual hosts
+ String[] virtualHosts = anPortComponent.virtualHosts();
+ if (virtualHosts != null & virtualHosts.length > 0)
+ {
+ sepMetaData.setVirtualHosts(virtualHosts);
+ }
+
+ }
+}
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java 2007-01-16
04:10:04 UTC (rev 1977)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java 2007-01-16
07:52:19 UTC (rev 1978)
@@ -23,30 +23,12 @@
// $Id$
-import com.sun.xml.bind.api.JAXBRIContext;
-import com.sun.xml.bind.api.TypeReference;
-import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
import org.jboss.ws.WSException;
-import org.jboss.ws.core.jaxrpc.Style;
-import org.jboss.ws.core.jaxrpc.Use;
-import org.jboss.ws.core.jaxws.DynamicWrapperGenerator;
-import org.jboss.ws.core.jaxws.WrapperGenerator;
import org.jboss.ws.core.server.UnifiedDeploymentInfo;
-import org.jboss.ws.core.utils.HolderUtils;
import org.jboss.ws.core.utils.IOUtils;
-import org.jboss.ws.core.utils.JBossWSEntityResolver;
-import org.jboss.ws.core.utils.JavaUtils;
-import org.jboss.ws.extensions.addressing.AddressingPropertiesImpl;
-import org.jboss.ws.extensions.addressing.metadata.AddressingOpMetaExt;
-import org.jboss.ws.metadata.acessor.JAXBAccessor;
import org.jboss.ws.metadata.builder.MetaDataBuilder;
-import org.jboss.ws.metadata.j2ee.UnifiedHandlerMetaData;
-import org.jboss.ws.metadata.jsr181.HandlerChainFactory;
-import org.jboss.ws.metadata.jsr181.HandlerChainMetaData;
-import org.jboss.ws.metadata.jsr181.HandlerChainsMetaData;
import org.jboss.ws.metadata.umdm.*;
-import org.jboss.ws.metadata.umdm.HandlerMetaData.HandlerType;
import org.jboss.ws.metadata.wsdl.WSDLDefinitions;
import org.jboss.ws.metadata.wsdl.WSDLUtils;
import org.jboss.ws.metadata.wsdl.xmlschema.JBossXSModel;
@@ -56,37 +38,15 @@
import org.jboss.ws.tools.jaxws.WSDLGenerator;
import org.jboss.ws.tools.wsdl.WSDLWriter;
import org.jboss.ws.tools.wsdl.WSDLWriterResolver;
-import org.jboss.xb.binding.ObjectModelFactory;
-import org.jboss.xb.binding.Unmarshaller;
-import org.jboss.xb.binding.UnmarshallerFactory;
import javax.jws.*;
-import javax.jws.soap.SOAPBinding;
-import javax.jws.soap.SOAPBinding.ParameterStyle;
import javax.jws.soap.SOAPMessageHandlers;
import javax.management.ObjectName;
-import javax.xml.bind.JAXBException;
import javax.xml.namespace.QName;
-import javax.xml.rpc.ParameterMode;
-import javax.xml.ws.RequestWrapper;
-import javax.xml.ws.ResponseWrapper;
-import javax.xml.ws.WebFault;
-import javax.xml.ws.addressing.AddressingProperties;
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
import java.io.Writer;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.net.MalformedURLException;
import java.net.URL;
-import java.rmi.RemoteException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
/**
* An abstract annotation meta data builder.
@@ -98,7 +58,7 @@
* @since 15-Oct-2005
*/
@SuppressWarnings("deprecation")
-public class JAXWSWebServiceMetaDataBuilder extends JAXWSEndpointMetaDataBuilder
+public class JAXWSWebServiceMetaDataBuilder extends JAXWSServerMetaDataBuilder
{
private static class EndpointResult
{
@@ -108,556 +68,96 @@
private URL wsdlLocation;
}
- // provide logging
- private static final Logger log =
Logger.getLogger(JAXWSWebServiceMetaDataBuilder.class);
- private List<Class> javaTypes = new ArrayList<Class>();
- private JAXBRIContext jaxbCtx;
- private List<TypeReference> typeRefs = new ArrayList<TypeReference>();
- private WrapperGenerator wrapperGenerator;
-
- public JAXWSWebServiceMetaDataBuilder()
+ public ServerEndpointMetaData buildWebServiceMetaData(UnifiedMetaData wsMetaData,
UnifiedDeploymentInfo udi, Class<?> sepClass, String linkName)
{
- }
-
- private void addFault(OperationMetaData omd, Class<?> exception)
- {
- if (omd.isOneWay())
- throw new IllegalStateException("JSR-181 4.3.1 - A JSR-181 processor is
REQUIRED to report an error if an operation marked "
- + "@Oneway has a return value, declares any checked exceptions or has
any INOUT or OUT parameters.");
-
- WebFault annotation = exception.getAnnotation(WebFault.class);
-
- String name;
- String namespace;
- String faultBeanName = null;
-
- // Only the element name is effected by @WebFault, the type uses the same
convention
- QName xmlType = new QName(omd.getQName().getNamespaceURI(),
exception.getSimpleName());
-
- /*
- * If @WebFault is present, and the exception contains getFaultInfo, the
- * return value should be used. Otherwise we need to generate the bean.
- */
- boolean generate = true;
- if (annotation != null)
- {
- name = annotation.name();
- namespace = annotation.targetNamespace();
- if (namespace.length() == 0)
- namespace = omd.getQName().getNamespaceURI();
-
- Class<?> faultBean = getFaultInfo(exception);
- if (faultBean != null)
- {
- generate = false;
- faultBeanName = faultBean.getName();
- }
- }
- else
- {
- name = xmlType.getLocalPart();
- namespace = xmlType.getNamespaceURI();
- }
-
- if (faultBeanName == null)
- faultBeanName =
JavaUtils.getPackageName(omd.getEndpointMetaData().getServiceEndpointInterface()) +
".jaxws." + exception.getSimpleName() + "Bean";
-
- QName xmlName = new QName(namespace, name);
-
- FaultMetaData fmd = new FaultMetaData(omd, xmlName, xmlType, exception.getName());
- fmd.setFaultBeanName(faultBeanName);
-
- if (generate)
- wrapperGenerator.generate(fmd);
-
- javaTypes.add(fmd.getFaultBean());
- typeRefs.add(new TypeReference(fmd.getXmlName(), fmd.getFaultBean()));
-
- omd.addFault(fmd);
- }
-
- private String convertToVariable(String localName)
- {
- return JAXBRIContext.mangleNameToVariableName(localName);
- }
-
- private String[] convertTypeArguments(Class rawType, Type type)
- {
- if (!Collection.class.isAssignableFrom(rawType) &&
!Map.class.isAssignableFrom(rawType))
- return null;
-
- if (!(type instanceof ParameterizedType))
- return null;
-
- ParameterizedType paramType = (ParameterizedType)type;
- Type[] arguments = paramType.getActualTypeArguments();
- String[] ret = new String[arguments.length];
- for (int i = 0; i < arguments.length; i++)
- ret[i] = JavaUtils.erasure(arguments[i]).getName();
-
- return ret;
- }
-
- private ParameterMetaData createRequestWrapper(OperationMetaData operation, Method
method)
- {
- String requestWrapperType = null;
- QName xmlName = operation.getQName();
- QName xmlType = xmlName;
- if (method.isAnnotationPresent(RequestWrapper.class))
- {
- RequestWrapper anReqWrapper = method.getAnnotation(RequestWrapper.class);
-
- String localName = anReqWrapper.localName().length() > 0 ?
anReqWrapper.localName() : xmlName.getLocalPart();
- String targetNamespace = anReqWrapper.targetNamespace().length() > 0 ?
anReqWrapper.targetNamespace() : xmlName.getNamespaceURI();
- xmlName = new QName(targetNamespace, localName);
-
- if (anReqWrapper.className().length() > 0)
- requestWrapperType = anReqWrapper.className();
- }
-
- // Conformance 3.18, the default value must be the same as the method name
- if (requestWrapperType == null)
- {
- String packageName = JavaUtils.getPackageName(method.getDeclaringClass()) +
".jaxws";
- requestWrapperType = packageName + "." +
JavaUtils.capitalize(method.getName());
- }
-
- // JAX-WS p.37 pg.1, the annotation only affects the element name, not the type
name
- ParameterMetaData wrapperParameter = new ParameterMetaData(operation, xmlName,
xmlType, requestWrapperType);
- wrapperParameter.setAccessorFactoryCreator(JAXBAccessor.FACTORY_CREATOR);
- operation.addParameter(wrapperParameter);
-
- return wrapperParameter;
- }
-
- private ParameterMetaData createResponseWrapper(OperationMetaData operation, Method
method)
- {
- QName operationQName = operation.getQName();
- QName xmlName = new QName(operationQName.getNamespaceURI(),
operationQName.getLocalPart() + "Response");
- QName xmlType = xmlName;
-
- String responseWrapperType = null;
- if (method.isAnnotationPresent(ResponseWrapper.class))
- {
- ResponseWrapper anResWrapper = method.getAnnotation(ResponseWrapper.class);
-
- String localName = anResWrapper.localName().length() > 0 ?
anResWrapper.localName() : xmlName.getLocalPart();
- String targetNamespace = anResWrapper.targetNamespace().length() > 0 ?
anResWrapper.targetNamespace() : xmlName.getNamespaceURI();
- xmlName = new QName(targetNamespace, localName);
-
- if (anResWrapper.className().length() > 0)
- responseWrapperType = anResWrapper.className();
- }
-
- if (responseWrapperType == null)
- {
- String packageName = JavaUtils.getPackageName(method.getDeclaringClass()) +
".jaxws";
- responseWrapperType = packageName + "." +
JavaUtils.capitalize(method.getName()) + "Response";
- }
-
- ParameterMetaData retMetaData = new ParameterMetaData(operation, xmlName, xmlType,
responseWrapperType);
- retMetaData.setAccessorFactoryCreator(JAXBAccessor.FACTORY_CREATOR);
- operation.setReturnParameter(retMetaData);
-
- return retMetaData;
- }
-
- private Class<?> getFaultInfo(Class<?> exception)
- {
try
{
- Method method = exception.getMethod("getFaultInfo");
- Class<?> returnType = method.getReturnType();
- if (returnType == void.class)
- return null;
+ EndpointResult result = processWebService(wsMetaData, sepClass, udi);
- return returnType;
- }
- catch (SecurityException e)
- {
- throw new WSException("Unexpected security exception: " +
e.getMessage(), e);
- }
- catch (NoSuchMethodException e)
- {
- return null;
- }
- }
+ // Clear the java types, etc.
+ resetMetaDataBuilder(udi.classLoader);
- private ParameterMode getParameterMode(WebParam anWebParam, Class javaType)
- {
- if (anWebParam != null)
- {
- if (anWebParam.mode() == WebParam.Mode.INOUT)
- return ParameterMode.INOUT;
- if (anWebParam.mode() == WebParam.Mode.OUT)
- return ParameterMode.OUT;
- }
+ ServerEndpointMetaData sepMetaData = result.sepMetaData;
+ ServiceMetaData serviceMetaData = result.serviceMetaData;
+ Class<?> seiClass = result.epClass;
- return HolderUtils.isHolderType(javaType) ? ParameterMode.INOUT :
ParameterMode.IN;
- }
+ sepMetaData.setLinkName(linkName);
+ sepMetaData.setServiceEndpointImplName(sepClass.getName());
+ sepMetaData.setServiceEndpointInterfaceName(seiClass.getName());
- private WebParam getWebParamAnnotation(Method method, int pos)
- {
- for (Annotation annotation : method.getParameterAnnotations()[pos])
- if (annotation instanceof WebParam)
- return (WebParam)annotation;
+ // Assign the WS-Security configuration,
+ WSSecurityConfigFactory wsseConfFactory =
WSSecurityConfigFactory.newInstance();
+ WSSecurityConfiguration securityConfiguration =
wsseConfFactory.createConfiguration(udi);
+ serviceMetaData.setSecurityConfiguration(securityConfiguration);
- return null;
- }
+ // Process an optional @SOAPBinding annotation
+ processSOAPBinding(sepMetaData, seiClass);
- private QName getWebParamName(OperationMetaData opMetaData, int index, WebParam
webParam)
- {
- String namespace = null;
- String name = null;
- boolean header = false;
+ // Process an optional @BindingType annotation
+ processBindingType(sepMetaData, seiClass);
- if (webParam != null)
- {
- if (webParam.targetNamespace().length() > 0)
- namespace = webParam.targetNamespace();
+ // Process web methods
+ processWebMethods(sepMetaData, seiClass);
- // RPC types use the partName for their XML name
- if (webParam.partName().length() > 0 && opMetaData.isRPCLiteral())
- name = webParam.partName();
- else if (webParam.name().length() > 0)
- name = webParam.name();
+ // Init the transport guarantee
+ initTransportGuaranteeJSE(udi, sepMetaData, linkName);
- header = webParam.header();
- }
+ // Initialize types
+ createJAXBContext(sepMetaData);
+ populateXmlTypes(sepMetaData);
- // Bare and headers must be qualified
- if (namespace == null && (opMetaData.isDocumentBare() || header))
- namespace = opMetaData.getQName().getNamespaceURI();
+ // Process or generate WSDL
+ processOrGenerateWSDL(seiClass, serviceMetaData, result.wsdlLocation,
sepMetaData);
- // RPC body parts must have no namespace
- else if (opMetaData.isRPCLiteral() && !header)
- namespace = null;
+ // process config name and config file amongst others
+ // Note, that @PortComponent needs to be defined on the endpoint not the SEI
+ processPortComponent(udi, sepClass, linkName, sepMetaData);
- // Bare uses the operation name as the default, everything else is generated
- if (name == null)
- name = opMetaData.isDocumentBare() && !header ?
opMetaData.getQName().getLocalPart() : "arg" + index;
+ // setup handler chain from config
+ sepMetaData.configure(sepMetaData);
- return (namespace != null) ? new QName(namespace, name) : new QName(name);
- }
-
- private QName getWebResultName(OperationMetaData opMetaData, WebResult anWebResult)
- {
- String name = null;
- String namespace = null;
- boolean header = false;
-
- if (anWebResult != null)
- {
- if (anWebResult.targetNamespace().length() > 0)
- namespace = anWebResult.targetNamespace();
-
- // RPC types use the partName for their XML name
- if (anWebResult.partName().length() > 0 &&
opMetaData.isRPCLiteral())
- name = anWebResult.partName();
- else if (anWebResult.name().length() > 0)
- name = anWebResult.name();
-
- header = anWebResult.header();
- }
-
- // Bare and headers must be qualified
- if (namespace == null && (opMetaData.isDocumentBare() || header))
- namespace = opMetaData.getQName().getNamespaceURI();
-
- // RPC body parts must have no namespace
- else if (opMetaData.isRPCLiteral() && !header)
- namespace = null;
-
- // Bare uses the operation name as the default, everything else is generated
- if (name == null)
- name = opMetaData.isDocumentBare() && !header ?
opMetaData.getResponseName().getLocalPart() : "return";
-
- return (namespace != null) ? new QName(namespace, name) : new QName(name);
- }
-
- private void populateXmlType(FaultMetaData faultMetaData)
- {
- EndpointMetaData epMetaData =
faultMetaData.getOperationMetaData().getEndpointMetaData();
- TypesMetaData types = epMetaData.getServiceMetaData().getTypesMetaData();
-
- QName xmlType = faultMetaData.getXmlType();
- String faultBeanName = faultMetaData.getFaultBeanName();
-
- types.addTypeMapping(new TypeMappingMetaData(types, xmlType, faultBeanName));
- }
-
- private void populateXmlType(ParameterMetaData paramMetaData)
- {
- EndpointMetaData epMetaData =
paramMetaData.getOperationMetaData().getEndpointMetaData();
- TypesMetaData types = epMetaData.getServiceMetaData().getTypesMetaData();
-
- QName xmlName = paramMetaData.getXmlName();
- QName xmlType = paramMetaData.getXmlType();
- Class javaType = paramMetaData.getJavaType();
- String javaName = paramMetaData.getJavaTypeName();
-
- if (xmlType == null)
- {
- try
+ // Process an optional @HandlerChain annotation
+ if (sepClass.isAnnotationPresent(HandlerChain.class))
{
- xmlType = jaxbCtx.getTypeName(new TypeReference(xmlName, javaType));
+ processHandlerChain(sepMetaData, sepClass);
}
- catch (IllegalArgumentException e)
+ else if (seiClass.isAnnotationPresent(HandlerChain.class))
{
- throw new IllegalStateException("Cannot obtain xml type for:
[xmlName=" + xmlName + ",javaName=" + javaName + "]");
+ processHandlerChain(sepMetaData, seiClass);
}
- /* Anonymous type.
- *
- * Currently the design of our stack is based on the
- * notion of their always being a unique type. In order to lookup the
- * appropriate (de)serializer you must have a type. So we use a fake
- * name. This is an illegal NCName, so it shouldn't collide.
- */
- if (xmlType == null)
- xmlType = new QName(xmlName.getNamespaceURI(), ">" +
xmlName.getLocalPart());
+ // Sanity check: read the generated WSDL and initialize the schema model
+ WSDLDefinitions wsdlDefinitions = serviceMetaData.getWsdlDefinitions();
+ JBossXSModel schemaModel =
WSDLUtils.getSchemaModel(wsdlDefinitions.getWsdlTypes());
+ serviceMetaData.getTypesMetaData().setSchemaModel(schemaModel);
- paramMetaData.setXmlType(xmlType);
- }
+ // Init the endpoint address
+ MetaDataBuilder.initEndpointAddress(udi, sepMetaData, linkName);
- types.addTypeMapping(new TypeMappingMetaData(types, xmlType, javaName));
- }
+ // replace the SOAP address
+ MetaDataBuilder.replaceAddressLocation(sepMetaData);
- /**
- * Process operation meta data extensions.
- */
- private void processMetaExtensions(EndpointMetaData epMetaData, OperationMetaData
opMetaData)
- {
- // Until there is a addressing annotion we fallback to implicit action association
- // TODO: figure out a way to assign message name instead of IN and OUT
- String tns = epMetaData.getQName().getNamespaceURI();
- String portTypeName = epMetaData.getQName().getLocalPart();
+ // Process an optional @SOAPMessageHandlers annotation
+ if (sepClass.isAnnotationPresent(SOAPMessageHandlers.class) ||
seiClass.isAnnotationPresent(SOAPMessageHandlers.class))
+ log.warn("@SOAPMessageHandlers is deprecated as of JAX-WS 2.0 with no
replacement.");
- AddressingProperties ADDR = new AddressingPropertiesImpl();
- AddressingOpMetaExt addrExt = new AddressingOpMetaExt(ADDR.getNamespaceURI());
- addrExt.setInboundAction(tns + "/" + portTypeName + "/IN");
+ // init service endpoint id
+ ObjectName sepID = MetaDataBuilder.createServiceEndpointID(udi, sepMetaData);
+ sepMetaData.setServiceEndpointID(sepID);
- if (!opMetaData.isOneWay())
- addrExt.setOutboundAction(tns + "/" + portTypeName +
"/OUT");
-
- opMetaData.addExtension(addrExt);
- }
-
- private void processWebMethod(EndpointMetaData epMetaData, Method method)
- {
- String javaName = method.getName();
-
- // skip asnyc methods, they dont need meta data representation
- if (method.getName().endsWith(Constants.ASYNC_METHOD_SUFFIX))
- return;
-
- // reflection defaults
- String soapAction = "";
- String operationName = method.getName();
-
- // annotation values that override defaults
- if (method.isAnnotationPresent(WebMethod.class))
- {
- WebMethod anWebMethod = method.getAnnotation(WebMethod.class);
- soapAction = anWebMethod.action();
- if (anWebMethod.operationName().length() > 0)
- {
- operationName = anWebMethod.operationName();
- }
+ return sepMetaData;
}
-
- String targetNS = epMetaData.getInterfaceQName().getNamespaceURI();
- OperationMetaData opMetaData = new OperationMetaData(epMetaData, new
QName(targetNS, operationName), javaName);
- opMetaData.setOneWay(method.isAnnotationPresent(Oneway.class));
- opMetaData.setSOAPAction(soapAction);
-
- if (method.isAnnotationPresent(SOAPBinding.class))
+ catch (RuntimeException rte)
{
- SOAPBinding anBinding = method.getAnnotation(SOAPBinding.class);
- if (anBinding.style() != SOAPBinding.Style.DOCUMENT || epMetaData.getStyle() !=
Style.DOCUMENT)
- throw new IllegalArgumentException("@SOAPBinding must be specified using
DOCUMENT style when placed on a method");
- opMetaData.setParameterStyle(anBinding.parameterStyle());
+ throw rte;
}
-
- epMetaData.addOperation(opMetaData);
-
- // Build parameter meta data
- Class[] parameterTypes = method.getParameterTypes();
- Type[] genericTypes = method.getGenericParameterTypes();
- Annotation[][] parameterAnnotations = method.getParameterAnnotations();
- ParameterMetaData wrapperParameter = null, wrapperOutputParameter = null;
- List<WrappedParameter> wrappedParameters = null, wrappedOutputParameters =
null;
-
- // Force paramter style to wrapped
- if (method.isAnnotationPresent(RequestWrapper.class) ||
method.isAnnotationPresent(ResponseWrapper.class))
+ catch (Exception ex)
{
- epMetaData.setParameterStyle(ParameterStyle.WRAPPED);
+ throw new WSException("Cannot build meta data: " + ex.getMessage(),
ex);
}
-
- if (opMetaData.isDocumentWrapped())
- {
- wrapperParameter = createRequestWrapper(opMetaData, method);
- wrappedParameters = new
ArrayList<WrappedParameter>(parameterTypes.length);
- wrapperParameter.setWrappedParameters(wrappedParameters);
-
- if (!opMetaData.isOneWay())
- {
- wrapperOutputParameter = createResponseWrapper(opMetaData, method);
- wrappedOutputParameters = new
ArrayList<WrappedParameter>(parameterTypes.length + 1);
- wrapperOutputParameter.setWrappedParameters(wrappedOutputParameters);
- }
- }
-
- for (int i = 0; i < parameterTypes.length; i++)
- {
- Class javaType = parameterTypes[i];
- Type genericType = genericTypes[i];
- String javaTypeName = javaType.getName();
- WebParam anWebParam = getWebParamAnnotation(method, i);
- boolean isHeader = anWebParam != null && anWebParam.header();
- boolean isWrapped = opMetaData.isDocumentWrapped() && !isHeader;
- ParameterMode mode = getParameterMode(anWebParam, javaType);
-
- // Assert one-way
- if (opMetaData.isOneWay() && mode != ParameterMode.IN)
- throw new IllegalArgumentException("A one-way operation can not have
output parameters [" + "method = " + method.getName() + ", parameter =
" + i + "]");
-
- if (HolderUtils.isHolderType(javaType))
- {
- genericType = HolderUtils.getGenericValueType(genericType);
- javaType = JavaUtils.erasure(genericType);
- javaTypeName = javaType.getName();
- }
-
- if (isWrapped)
- {
- QName wrappedElementName = getWebParamName(opMetaData, i, anWebParam);
- String variable = convertToVariable(wrappedElementName.getLocalPart());
-
- WrappedParameter wrappedParameter = new WrappedParameter(wrappedElementName,
javaTypeName, variable, i);
- wrappedParameter.setTypeArguments(convertTypeArguments(javaType,
genericType));
-
- if (mode != ParameterMode.OUT)
- wrappedParameters.add(wrappedParameter);
- if (mode != ParameterMode.IN)
- {
- wrappedOutputParameters.add(wrappedParameter);
- wrappedParameter.setHolder(true);
- }
- }
- else
- {
- QName xmlName = getWebParamName(opMetaData, i, anWebParam);
-
- ParameterMetaData paramMetaData = new ParameterMetaData(opMetaData, xmlName,
javaTypeName);
- paramMetaData.setInHeader(isHeader);
- paramMetaData.setIndex(i);
- paramMetaData.setMode(mode);
-
- /*
- * Note: The TCK enforces the following rule in the spec regarding
- * partName: "This is only used if the operation is rpc style or if
- * the operation is document style and the parameter style is BARE."
- *
- * This seems to be a flaw in the spec, because the intention is
- * obviously to prevent the ambiguity of wrapped parameters that
- * specify different partName values. There is, however, no reason
- * that this limitation should apply to header parameters since they
- * are never wrapped. In order to comply we adhere to this confusing
- * rule, although I will ask for clarification.
- */
- if (anWebParam != null && !opMetaData.isDocumentWrapped() &&
anWebParam.partName().length() > 0)
- paramMetaData.setPartName(anWebParam.partName());
-
- opMetaData.addParameter(paramMetaData);
- javaTypes.add(javaType);
- typeRefs.add(new TypeReference(xmlName, genericType,
parameterAnnotations[i]));
- }
- }
-
- // Build result meta data
- Class returnType = method.getReturnType();
- Type genericReturnType = method.getGenericReturnType();
- String returnTypeName = returnType.getName();
- if (!(returnType == void.class))
- {
- if (opMetaData.isOneWay())
- throw new IllegalArgumentException("[JSR-181 2.5.1] The method
'" + method.getName() + "' can not have a return value if it is marked
OneWay");
-
- WebResult anWebResult = method.getAnnotation(WebResult.class);
- boolean isHeader = anWebResult != null && anWebResult.header();
- boolean isWrappedBody = opMetaData.isDocumentWrapped() && !isHeader;
- QName xmlName = getWebResultName(opMetaData, anWebResult);
-
- if (isWrappedBody)
- {
- WrappedParameter wrapped = new WrappedParameter(xmlName, returnTypeName,
convertToVariable(xmlName.getLocalPart()), -1);
- wrapped.setTypeArguments(convertTypeArguments(returnType,
genericReturnType));
-
- // insert at the beginning just for prettiness
- wrappedOutputParameters.add(0, wrapped);
- }
- else
- {
- ParameterMetaData retMetaData = new ParameterMetaData(opMetaData, xmlName,
returnTypeName);
- retMetaData.setInHeader(isHeader);
- retMetaData.setIndex(-1);
- retMetaData.setMode(ParameterMode.OUT);
-
- // Special case: If we have a document/literal wrapped message, then
- // the return metadata must be the wrapper type that is sent in the
- // body. So, in order to handle headers that are mapped to the java
- // return value, we have to add them to a parameter with an index of
- // -1 to signify the return value. All other binding styles use the
- // expected return value mechanism.
- if (opMetaData.isDocumentWrapped())
- {
- opMetaData.addParameter(retMetaData);
- }
- else
- {
- // See above comment in the parameter for loop section as to why
- // we prevent customization of part names on document wrapped
- // header parameters.
- if (anWebResult != null && anWebResult.partName().length() >
0)
- retMetaData.setPartName(anWebResult.partName());
-
- opMetaData.setReturnParameter(retMetaData);
- }
-
- javaTypes.add(returnType);
- typeRefs.add(new TypeReference(xmlName, genericReturnType,
method.getAnnotations()));
- }
- }
-
- // Generate wrapper beans
- if (opMetaData.isDocumentWrapped())
- {
- wrapperGenerator.generate(wrapperParameter);
- Class wrapperClass = wrapperParameter.getJavaType();
- javaTypes.add(wrapperClass);
- // In case there is no @XmlRootElement
- typeRefs.add(new TypeReference(wrapperParameter.getXmlName(), wrapperClass));
- if (!opMetaData.isOneWay())
- {
- wrapperGenerator.generate(wrapperOutputParameter);
- wrapperClass = wrapperOutputParameter.getJavaType();
- javaTypes.add(wrapperClass);
- // In case there is no @XmlRootElement
- typeRefs.add(new TypeReference(wrapperOutputParameter.getXmlName(),
wrapperClass));
- }
- }
-
- // Add faults
- for (Class exClass : method.getExceptionTypes())
- if (!RemoteException.class.isAssignableFrom(exClass))
- addFault(opMetaData, exClass);
-
- // process op meta data extension
- processMetaExtensions(epMetaData, opMetaData);
}
-
+
private EndpointResult processWebService(UnifiedMetaData wsMetaData, Class<?>
sepClass, UnifiedDeploymentInfo udi) throws ClassNotFoundException, IOException
{
WebService anWebService = sepClass.getAnnotation(WebService.class);
@@ -731,144 +231,8 @@
return result;
}
- protected void createJAXBContext(EndpointMetaData epMetaData)
+ private void processOrGenerateWSDL(Class wsClass, ServiceMetaData serviceMetaData, URL
wsdlLocation, EndpointMetaData epMetaData)
{
- try
- {
- String targetNS = epMetaData.getInterfaceQName().getNamespaceURI();
- log.debug("JAXBContext [types=" + javaTypes + ",tns=" +
targetNS + "]");
- jaxbCtx = JAXBRIContext.newInstance(javaTypes.toArray(new Class[0]), typeRefs,
targetNS, false);
- }
- catch (JAXBException ex)
- {
- throw new IllegalStateException("Cannot build JAXB context", ex);
- }
- }
-
- protected void populateXmlTypes(EndpointMetaData epMetaData)
- {
- for (OperationMetaData operation : epMetaData.getOperations())
- {
- // parameters
- for (ParameterMetaData paramMetaData : operation.getParameters())
- {
- populateXmlType(paramMetaData);
- }
-
- // return value
- ParameterMetaData returnParameter = operation.getReturnParameter();
- if (returnParameter != null)
- populateXmlType(returnParameter);
-
- // faults
- for (FaultMetaData faultMetaData : operation.getFaults())
- {
- populateXmlType(faultMetaData);
- }
- }
- }
-
- /**
- * Process an optional @HandlerChain annotation
- *
- * Location of the handler chain file. The location supports 2 formats.
- *
- * 1. An absolute java.net.URL in externalForm.
- * (ex:
http://myhandlers.foo.com/handlerfile1.xml)
- *
- * 2. A relative path from the source file or class file.
- * (ex: bar/handlerfile1.xml)
- */
- protected void processHandlerChain(EndpointMetaData epMetaData, Class<?>
wsClass)
- {
- if (wsClass.isAnnotationPresent(SOAPMessageHandlers.class))
- throw new WSException("Cannot combine @HandlerChain with
@SOAPMessageHandlers");
-
- HandlerChain anHandlerChain = wsClass.getAnnotation(HandlerChain.class);
-
- URL fileURL = null;
- String filename = anHandlerChain.file();
-
- // Try the filename as URL
- try
- {
- fileURL = new URL(filename);
- }
- catch (MalformedURLException ex)
- {
- // ignore
- }
-
- // Try the filename as File
- if (fileURL == null)
- {
- try
- {
- File file = new File(filename);
- if (file.exists())
- fileURL = file.toURL();
- }
- catch (MalformedURLException e)
- {
- // ignore
- }
- }
-
- // Try the filename as Resource
- if (fileURL == null)
- {
- fileURL = epMetaData.getClassLoader().getResource(filename);
- }
-
- // Try the filename relative to class
- if (fileURL == null)
- {
- String packagePath = wsClass.getPackage().getName().replace('.',
'/');
- fileURL = epMetaData.getClassLoader().getResource(packagePath + "/" +
filename);
- }
-
- if (fileURL == null)
- throw new WSException("Cannot resolve handler file '" + filename +
"' on " + wsClass.getName());
-
- try
- {
- HandlerChainsMetaData handlerChainsMetaData = null;
- InputStream is = fileURL.openStream();
- try
- {
- Unmarshaller unmarshaller =
UnmarshallerFactory.newInstance().newUnmarshaller();
- unmarshaller.setValidation(true);
- unmarshaller.setSchemaValidation(true);
- unmarshaller.setEntityResolver(new JBossWSEntityResolver());
- ObjectModelFactory factory = new HandlerChainFactory();
- handlerChainsMetaData = (HandlerChainsMetaData)unmarshaller.unmarshal(is,
factory, null);
- }
- finally
- {
- is.close();
- }
-
- // Setup the endpoint handlers
- for (HandlerChainMetaData handlerChainMetaData :
handlerChainsMetaData.getHandlerChains())
- {
- for (UnifiedHandlerMetaData uhmd : handlerChainMetaData.getHandlers())
- {
- epMetaData.addHandler(uhmd.getHandlerMetaDataJAXWS(epMetaData,
HandlerType.ENDPOINT));
- }
- }
- }
- catch (RuntimeException rte)
- {
- throw rte;
- }
- catch (Exception ex)
- {
- throw new WSException("Cannot process handler chain: " + filename,
ex);
- }
- }
-
- protected void processOrGenerateWSDL(Class wsClass, ServiceMetaData serviceMetaData,
URL wsdlLocation, EndpointMetaData epMetaData)
- {
if (wsdlLocation != null)
{
serviceMetaData.setWsdlLocation(wsdlLocation);
@@ -915,165 +279,4 @@
}
}
}
-
- protected void processSOAPBinding(EndpointMetaData epMetaData, Class<?>
wsClass)
- {
-
- if (!wsClass.isAnnotationPresent(SOAPBinding.class))
- return;
-
- SOAPBinding anSoapBinding = wsClass.getAnnotation(SOAPBinding.class);
-
- SOAPBinding.Style attrStyle = anSoapBinding.style();
- Style style = (attrStyle == SOAPBinding.Style.RPC ? Style.RPC : Style.DOCUMENT);
- epMetaData.setStyle(style);
-
- SOAPBinding.Use attrUse = anSoapBinding.use();
- if (attrUse == SOAPBinding.Use.ENCODED)
- throw new WSException("SOAP encoding is not supported for JSR-181
deployments");
-
- epMetaData.setEncodingStyle(Use.LITERAL);
-
- ParameterStyle paramStyle = anSoapBinding.parameterStyle();
- epMetaData.setParameterStyle(paramStyle);
- }
-
- // If the implementation bean does not implement a service endpoint interface and
- // there are no @WebMethod annotations in the implementation bean (excluding
- // @WebMethod annotations used to exclude inherited @WebMethods), all public
- // methods other than those inherited from java.lang.Object will be exposed as Web
- // Service operations, subject to the inheritance rules specified in Common
- // Annotations for the Java Platform [12], section 2.1.
- protected void processWebMethods(EndpointMetaData epMetaData, Class wsClass)
- {
- epMetaData.clearOperations();
-
- // Process @WebMethod annotations
- int webMethodCount = 0;
- for (Method method : wsClass.getMethods())
- {
- WebMethod annotation = method.getAnnotation(WebMethod.class);
- boolean exclude = annotation != null && annotation.exclude();
- if (!exclude && (annotation != null || wsClass.isInterface()))
- {
- processWebMethod(epMetaData, method);
- webMethodCount++;
- }
- }
-
- // @WebService should expose all inherited methods if @WebMethod is never
specified
- if (webMethodCount == 0 && !wsClass.isInterface())
- {
- for (Method method : wsClass.getMethods())
- {
- WebMethod annotation = method.getAnnotation(WebMethod.class);
- boolean exclude = annotation != null && annotation.exclude();
- if (!exclude && method.getDeclaringClass() != Object.class)
- {
- processWebMethod(epMetaData, method);
- webMethodCount++;
- }
- }
- }
-
- if (webMethodCount == 0)
- throw new WSException("No exposable methods found");
- }
-
- protected void resetMetaDataBuilder(ClassLoader loader)
- {
- wrapperGenerator = new DynamicWrapperGenerator(loader);
- javaTypes.clear();
- typeRefs.clear();
- jaxbCtx = null;
- }
-
- public ServerEndpointMetaData buildEndpointMetaData(UnifiedMetaData wsMetaData,
UnifiedDeploymentInfo udi, Class<?> sepClass, String linkName)
- {
- try
- {
- EndpointResult result = processWebService(wsMetaData, sepClass, udi);
-
- // Clear the java types, etc.
- resetMetaDataBuilder(udi.classLoader);
-
- ServerEndpointMetaData sepMetaData = result.sepMetaData;
- ServiceMetaData serviceMetaData = result.serviceMetaData;
- Class<?> seiClass = result.epClass;
-
- sepMetaData.setLinkName(linkName);
- sepMetaData.setServiceEndpointImplName(sepClass.getName());
- sepMetaData.setServiceEndpointInterfaceName(seiClass.getName());
-
- // Assign the WS-Security configuration,
- WSSecurityConfigFactory wsseConfFactory =
WSSecurityConfigFactory.newInstance();
- WSSecurityConfiguration securityConfiguration =
wsseConfFactory.createConfiguration(udi);
- serviceMetaData.setSecurityConfiguration(securityConfiguration);
-
- // Process an optional @SOAPBinding annotation
- processSOAPBinding(sepMetaData, seiClass);
-
- // Process an optional @BindingType annotation
- processBindingType(sepMetaData, seiClass);
-
- // Process web methods
- processWebMethods(sepMetaData, seiClass);
-
- // Init the transport guarantee
- initTransportGuaranteeJSE(udi, sepMetaData, linkName);
-
- // Initialize types
- createJAXBContext(sepMetaData);
- populateXmlTypes(sepMetaData);
-
- // Process or generate WSDL
- processOrGenerateWSDL(seiClass, serviceMetaData, result.wsdlLocation,
sepMetaData);
-
- // process config name and config file amongst others
- // Note, that @PortComponent needs to be defined on the endpoint not the SEI
- processPortComponent(udi, sepClass, linkName, sepMetaData);
-
- // setup handler chain from config
- sepMetaData.configure(sepMetaData);
-
- // Process an optional @HandlerChain annotation
- if (sepClass.isAnnotationPresent(HandlerChain.class))
- {
- processHandlerChain(sepMetaData, sepClass);
- }
- else if (seiClass.isAnnotationPresent(HandlerChain.class))
- {
- processHandlerChain(sepMetaData, seiClass);
- }
-
- // Sanity check: read the generated WSDL and initialize the schema model
- WSDLDefinitions wsdlDefinitions = serviceMetaData.getWsdlDefinitions();
- JBossXSModel schemaModel =
WSDLUtils.getSchemaModel(wsdlDefinitions.getWsdlTypes());
- serviceMetaData.getTypesMetaData().setSchemaModel(schemaModel);
-
- // Init the endpoint address
- MetaDataBuilder.initEndpointAddress(udi, sepMetaData, linkName);
-
- // replace the SOAP address
- MetaDataBuilder.replaceAddressLocation(sepMetaData);
-
- // Process an optional @SOAPMessageHandlers annotation
- if (sepClass.isAnnotationPresent(SOAPMessageHandlers.class) ||
seiClass.isAnnotationPresent(SOAPMessageHandlers.class))
- log.warn("@SOAPMessageHandlers is deprecated as of JAX-WS 2.0 with no
replacement.");
-
- // init service endpoint id
- ObjectName sepID = MetaDataBuilder.createServiceEndpointID(udi, sepMetaData);
- sepMetaData.setServiceEndpointID(sepID);
-
- return sepMetaData;
- }
- catch (RuntimeException rte)
- {
- throw rte;
- }
- catch (Exception ex)
- {
- throw new WSException("Cannot build meta data: " + ex.getMessage(),
ex);
- }
- }
}
Modified:
trunk/jbossws-tests/src/main/java/org/jboss/test/ws/tools/java2xsd/SchemaModelTestCase.java
===================================================================
---
trunk/jbossws-tests/src/main/java/org/jboss/test/ws/tools/java2xsd/SchemaModelTestCase.java 2007-01-16
04:10:04 UTC (rev 1977)
+++
trunk/jbossws-tests/src/main/java/org/jboss/test/ws/tools/java2xsd/SchemaModelTestCase.java 2007-01-16
07:52:19 UTC (rev 1978)
@@ -55,6 +55,7 @@
"<sequence>" +
"<element name='a' type='int'/>" +
"<element name='b' type='int'/>" +
+ "<element name='d' nillable='true'
type='dateTime'/>" +
"</sequence>" +
"</complexType>" +
"</schema>";