[jbossws-commits] JBossWS SVN: r8425 - in stack/metro/trunk/modules: server/src/main/java/org/jboss/wsf/stack/metro and 1 other directories.
jbossws-commits at lists.jboss.org
jbossws-commits at lists.jboss.org
Fri Oct 10 04:57:33 EDT 2008
Author: alessio.soldano at jboss.com
Date: 2008-10-10 04:57:33 -0400 (Fri, 10 Oct 2008)
New Revision: 8425
Added:
stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/WsgenWrapperGenerator.java
Modified:
stack/metro/trunk/modules/resources/src/main/resources/resources/jbossws-deploy-macros.xml
stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/DeploymentDescriptorParserExt.java
stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/metadata/RuntimeModelDeploymentAspect.java
Log:
[JBWS-2129] svn merge -r 8388:HEAD https://svn.jboss.org/repos/jbossws/stack/metro/branches/asoldano
Modified: stack/metro/trunk/modules/resources/src/main/resources/resources/jbossws-deploy-macros.xml
===================================================================
--- stack/metro/trunk/modules/resources/src/main/resources/resources/jbossws-deploy-macros.xml 2008-10-09 16:13:21 UTC (rev 8424)
+++ stack/metro/trunk/modules/resources/src/main/resources/resources/jbossws-deploy-macros.xml 2008-10-10 08:57:33 UTC (rev 8425)
@@ -74,6 +74,7 @@
<include name="**/http.jar"/>
<include name="**/jaxb-api.jar"/>
<include name="**/jaxb-impl.jar"/>
+ <include name="**/jaxb-xjc.jar"/>
<include name="**/jaxrpc-api.jar"/>
<include name="**/jaxws-local-transport.jar"/>
<include name="**/jaxws-rt.jar"/>
Modified: stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/DeploymentDescriptorParserExt.java
===================================================================
--- stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/DeploymentDescriptorParserExt.java 2008-10-09 16:13:21 UTC (rev 8424)
+++ stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/DeploymentDescriptorParserExt.java 2008-10-10 08:57:33 UTC (rev 8425)
@@ -36,6 +36,10 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding.ParameterStyle;
+import javax.jws.soap.SOAPBinding.Style;
+import javax.jws.soap.SOAPBinding.Use;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
@@ -45,6 +49,7 @@
import javax.xml.ws.soap.MTOMFeature;
import javax.xml.ws.soap.SOAPBinding;
+import org.jboss.wsf.spi.deployment.UnifiedVirtualFile;
import org.xml.sax.EntityResolver;
import com.sun.xml.ws.api.BindingID;
@@ -77,6 +82,7 @@
* @author WS Development Team
* @author Kohsuke Kawaguchi
* @author Thomas.Diesler at jboss.org
+ * @author alessio.soldano at jboss.org
* @since 10-May-2007
*/
public class DeploymentDescriptorParserExt<A>
@@ -103,6 +109,8 @@
private final ClassLoader classLoader;
private final ResourceLoader loader;
private final AdapterFactory<A> adapterFactory;
+
+ private UnifiedVirtualFile archiveFile;
private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(DeploymentDescriptorParserExt.class);
@@ -298,6 +306,15 @@
ensureNoContent(reader);
Invoker invoker = createInvoker(implementorClass);
+
+ //Generate wrappers
+ if (isWrapperGenerationRequired(implementorClass))
+ {
+ WsgenWrapperGenerator wrapperGenerator = new WsgenWrapperGenerator(System.out);
+ ClassLoader newClassLoader = wrapperGenerator.generate(implementationName, classLoader, archiveFile.toURL());
+ Thread.currentThread().setContextClassLoader(newClassLoader);
+ }
+
WSEndpoint<?> endpoint = WSEndpoint.create(implementorClass, !handlersSetInDD, invoker,
serviceName, portName, container, binding, primaryWSDL, docs.values(), createEntityResolver(this.loader), false);
adapters.add(adapterFactory.createAdapter(name, urlPattern, endpoint));
@@ -308,6 +325,20 @@
}
return adapters;
}
+
+ private boolean isWrapperGenerationRequired(Class<?> endpoint)
+ {
+ WebService webServiceAnnotation = endpoint.getAnnotation(WebService.class);
+ if (webServiceAnnotation == null)
+ return false;
+ String wsdlLocation = webServiceAnnotation.wsdlLocation();
+ if (wsdlLocation != null && !"".equals(wsdlLocation))
+ return false; //provided wsdlLocation means a top-down (contract first) development is used, thus the user should use wsimport
+ javax.jws.soap.SOAPBinding soapBinding = endpoint.getAnnotation(javax.jws.soap.SOAPBinding.class);
+ if (soapBinding == null)
+ return true; //no @SOAPBinding means default settings, ie. doc/lit wrapped
+ return !(ParameterStyle.BARE.equals(soapBinding.parameterStyle()) || Style.RPC.equals(soapBinding.style()) || Use.ENCODED.equals(soapBinding.use()));
+ }
protected Invoker createInvoker(Class<?> implementorClass)
{
@@ -597,4 +628,9 @@
throw new LocatableWebServiceException(ServerMessages.RUNTIME_PARSER_CLASS_NOT_FOUND(name), e, reader);
}
}
+
+ public void setArchiveFile(UnifiedVirtualFile file)
+ {
+ this.archiveFile = file;
+ }
}
Copied: stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/WsgenWrapperGenerator.java (from rev 8424, stack/metro/branches/asoldano/modules/server/src/main/java/org/jboss/wsf/stack/metro/WsgenWrapperGenerator.java)
===================================================================
--- stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/WsgenWrapperGenerator.java (rev 0)
+++ stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/WsgenWrapperGenerator.java 2008-10-10 08:57:33 UTC (rev 8425)
@@ -0,0 +1,221 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.wsf.stack.metro;
+
+import java.io.File;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlSeeAlso;
+import javax.xml.ws.EndpointReference;
+import javax.xml.ws.WebServiceException;
+
+import org.jboss.logging.Logger;
+import org.jboss.util.file.JarUtils;
+import org.jboss.wsf.spi.SPIProvider;
+import org.jboss.wsf.spi.SPIProviderResolver;
+import org.jboss.wsf.spi.management.ServerConfig;
+import org.jboss.wsf.spi.management.ServerConfigFactory;
+
+import com.sun.tools.ws.wscompile.WsgenTool;
+
+/**
+ *
+ * @author alessio.soldano at jboss.com
+ * @since 06-Oct-2008
+ */
+public class WsgenWrapperGenerator
+{
+ private static Logger log = Logger.getLogger(WsgenWrapperGenerator.class);
+
+ private OutputStream outputStream;
+ private ServerConfig serverConfig;
+
+ public WsgenWrapperGenerator(OutputStream outputStream)
+ {
+ this.outputStream = outputStream;
+ }
+
+ public ClassLoader generate(String endpoint, ClassLoader classLoader, URL archiveUrl)
+ {
+ log.debug("ImplementationName: " + endpoint);
+ log.debug("Archive file: " + archiveUrl);
+ File tempDir = getTempDir(archiveUrl);
+ log.debug("Temp directory: " + tempDir);
+
+ if (!checkWsgenRequirements())
+ {
+ return classLoader;
+ }
+
+ WsgenTool wsgen = new WsgenTool(outputStream);
+ List<String> args = new ArrayList<String>();
+ args.add("-cp");
+ args.add(getClasspath(classLoader, archiveUrl));
+ args.add("-d");
+ args.add(tempDir.getAbsolutePath());
+ args.add("-verbose");
+ args.add(endpoint);
+ try
+ {
+ log.debug("Invoking Wsgen with the following parameters: " + args);
+ if (!wsgen.run(args.toArray(new String[0])))
+ throw new WebServiceException("Wsgen invocation failed: see the logs for details.");
+
+ URLClassLoader newClassloader = new URLClassLoader(new URL[] { tempDir.toURL() }, classLoader);
+ return newClassloader;
+ }
+ catch (Exception e)
+ {
+ throw new WebServiceException("Unable to generate wrapper classes", e);
+ }
+ }
+
+ private static boolean checkWsgenRequirements()
+ {
+ Class<?> epRef = EndpointReference.class;
+ Class<?> xmlSeeAlso = XmlSeeAlso.class;
+ String epRefUrl = epRef.getResource('/'+epRef.getName().replace('.','/')+".class").toExternalForm();
+ String xmlSeeAlsoUrl = xmlSeeAlso.getResource('/'+xmlSeeAlso.getName().replace('.','/')+".class").toExternalForm();
+ log.debug("EndpointReference.class loaded from: " + epRefUrl);
+ log.debug("XmlSeeAlso.class loaded from: " + xmlSeeAlsoUrl);
+ if (!epRefUrl.startsWith("jar:") || !xmlSeeAlsoUrl.startsWith("jar:"))
+ {
+ log.warn("[JBWS-2342] wsgen tool does not support jaxws-api and jaxb libraries loaded through vfszip. " +
+ "Try running this with JDK6 so that they're provided by the JDK runtime. Wrapper generation skipped.");
+ return false;
+ }
+ return true;
+ }
+
+ private ServerConfig getServerConfig()
+ {
+ if (serverConfig == null)
+ {
+ SPIProvider provider = SPIProviderResolver.getInstance().getProvider();
+ ServerConfigFactory spi = provider.getSPI(ServerConfigFactory.class);
+ serverConfig = spi.getServerConfig();
+ }
+ return serverConfig;
+ }
+
+ protected String getClasspath(ClassLoader classLoader, URL archiveUrl)
+ {
+ StringBuffer sb = new StringBuffer();
+ ServerConfig cfg = getServerConfig();
+ File clientDir = new File(cfg.getHomeDir(), "client");
+ File[] libs = clientDir.listFiles();
+ if (libs != null && libs.length > 0)
+ {
+ for (File lib : libs)
+ {
+ sb.append(lib.getAbsolutePath()).append(File.pathSeparator);
+ }
+ sb.delete(sb.length() - 1, sb.length());
+ }
+ URL[] urls = getURLs(classLoader, archiveUrl);
+ for (URL url : urls)
+ {
+ sb.append(File.pathSeparator);
+ sb.append(url.getPath());
+ }
+ return sb.toString();
+ }
+
+ protected File getTempDir(URL archiveUrl)
+ {
+ File tempJBossWSDir = new File(getServerConfig().getServerTempDir(), "jbossws");
+ if (!tempJBossWSDir.exists())
+ tempJBossWSDir.mkdir();
+ String archivePath = archiveUrl.getPath();
+ if (archivePath.endsWith(File.separator))
+ archivePath = archivePath.substring(0, archivePath.length() - 1);
+ String archiveName = archivePath.substring(archivePath.lastIndexOf(File.separator));
+ File tempDir = new File(tempJBossWSDir, archiveName + "-" + new Date().getTime());
+ if (!tempDir.exists())
+ tempDir.mkdir();
+ return tempDir;
+ }
+
+ private URL[] getURLs(ClassLoader classLoader, URL archiveUrl)
+ {
+ List<URL> urls = new LinkedList<URL>();
+ try
+ {
+ if (archiveUrl.toString().endsWith(".war"))
+ {
+ List<URL> innerUrlList = new LinkedList<URL>();
+ if (classLoader instanceof URLClassLoader)
+ {
+ innerUrlList.addAll(Arrays.asList(((URLClassLoader)classLoader).getURLs()));
+ }
+ if (innerUrlList.isEmpty())
+ {
+ File dest = getTempDir(archiveUrl);
+ JarUtils.unjar(archiveUrl.openStream(), dest);
+ File webInf = new File(dest, "WEB-INF");
+ if (webInf.exists())
+ {
+ innerUrlList.add(webInf.toURL());
+ innerUrlList.add(new File(webInf, "classes").toURL());
+ }
+ }
+ urls.addAll(innerUrlList);
+ }
+ else if (archiveUrl.toString().endsWith(".jar"))
+ {
+ if (new File(archiveUrl.getPath()).exists())
+ {
+ urls.add(archiveUrl);
+ }
+ else
+ {
+ File dest = getTempDir(archiveUrl);
+ JarUtils.unjar(archiveUrl.openStream(), dest);
+ urls.add(dest.toURL());
+ }
+ }
+ else if (archiveUrl.toString().endsWith(".war/"))
+ {
+ File webInf = new File(archiveUrl.getFile(), "WEB-INF");
+ if (webInf.exists())
+ {
+ urls.add(webInf.toURL());
+ urls.add(new File(webInf, "classes").toURL());
+ }
+ }
+ else
+ throw new WebServiceException("Unsupported deployment archive: " + archiveUrl);
+ }
+ catch (Exception e)
+ {
+ throw new WebServiceException("Cannot get classpath URLs for archive: " + archiveUrl, e);
+ }
+ return (URL[])urls.toArray(new URL[0]);
+ }
+}
Modified: stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/metadata/RuntimeModelDeploymentAspect.java
===================================================================
--- stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/metadata/RuntimeModelDeploymentAspect.java 2008-10-09 16:13:21 UTC (rev 8424)
+++ stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/metadata/RuntimeModelDeploymentAspect.java 2008-10-10 08:57:33 UTC (rev 8425)
@@ -104,11 +104,14 @@
// Parse the descriptor file and build endpoint infos
DeploymentDescriptorParserExt<ServletAdapter> parser =
createDeploymentDescriptorParser(runtimeLoader, container, resourceLoader, adapterList);
+
+ parser.setArchiveFile(vfsRoot);
URL sunJaxWsXml = getDDUrlFromContext(deployment);
List<ServletAdapter> adapters = parser.parse(sunJaxWsXml.toExternalForm(), sunJaxWsXml.openStream());
+
for(ServletAdapter adapter : adapters)
{
for(Endpoint ep : deployment.getService().getEndpoints())
More information about the jbossws-commits
mailing list