Author: alessio.soldano(a)jboss.com
Date: 2008-11-12 04:59:04 -0500 (Wed, 12 Nov 2008)
New Revision: 8707
Removed:
stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/WsgenWrapperGenerator.java
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/DeploymentDescriptorParserJBWS.java
Log:
[JBWS-2396] Disable wrapper generator
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-11-12
09:28:35 UTC (rev 8706)
+++
stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/DeploymentDescriptorParserExt.java 2008-11-12
09:59:04 UTC (rev 8707)
@@ -291,7 +291,6 @@
ensureNoContent(reader);
Invoker invoker = createInvoker(implementorClass);
- generateWrappers(implementorClass, this.classLoader);
WSEndpoint<?> endpoint = WSEndpoint.create(implementorClass,
!handlersSetInDD, invoker,
serviceName, portName, container, binding, primaryWSDL, docs.values(),
createEntityResolver(this.loader), false);
@@ -309,11 +308,6 @@
Invoker invoker =
InstanceResolver.createDefault(implementorClass).createInvoker();
return invoker;
}
-
- protected void generateWrappers(Class<?> implementorClass, ClassLoader
classLoader)
- {
- //default implementation does nothing
- }
/**
* @param ddBindingId
Modified:
stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/DeploymentDescriptorParserJBWS.java
===================================================================
---
stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/DeploymentDescriptorParserJBWS.java 2008-11-12
09:28:35 UTC (rev 8706)
+++
stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/DeploymentDescriptorParserJBWS.java 2008-11-12
09:59:04 UTC (rev 8707)
@@ -21,22 +21,10 @@
*/
package org.jboss.wsf.stack.metro;
-import java.lang.reflect.Method;
import java.net.MalformedURLException;
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
import javax.ejb.Stateless;
-import javax.jws.WebMethod;
-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.ws.WebFault;
-import javax.xml.ws.WebServiceException;
-import org.jboss.logging.Logger;
import org.jboss.wsf.spi.deployment.UnifiedVirtualFile;
import com.sun.xml.ws.api.server.Container;
@@ -80,90 +68,6 @@
return invoker;
}
- @Override
- protected void generateWrappers(Class<?> implementorClass, ClassLoader
classLoader)
- {
- //Generate wrappers
- if (isWrapperGenerationEnabled() &&
isWrapperGenerationRequired(implementorClass, classLoader))
- {
- WsgenWrapperGenerator wrapperGenerator = new WsgenWrapperGenerator(System.out);
- ClassLoader newClassLoader =
wrapperGenerator.generate(implementorClass.getName(), classLoader, archiveFile.toURL());
- Thread.currentThread().setContextClassLoader(newClassLoader);
- }
- }
-
- private boolean isWrapperGenerationEnabled()
- {
- boolean noWrappersGeneration =
Boolean.getBoolean(Constants.NO_WRAPPERS_GENERATION);
- if (noWrappersGeneration)
- Logger.getLogger(this.getClass()).debug("Wrapper generation
disabled");
- return !noWrappersGeneration;
- }
-
- private boolean isWrapperGenerationRequired(Class<?> endpoint, ClassLoader
classLoader)
- {
- 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
-
- String endpointInterface = webServiceAnnotation.endpointInterface();
- javax.jws.soap.SOAPBinding soapBinding;
- if (endpointInterface == null || "".equalsIgnoreCase(endpointInterface))
- {
- if (isFaultWrapperGenerationRequired(endpoint))
- return true;
- soapBinding = endpoint.getAnnotation(javax.jws.soap.SOAPBinding.class);
- }
- else
- {
- //Using the SEI to get annotations
- Class<?> sei;
- try
- {
- sei = Class.forName(endpointInterface, true, classLoader);
- }
- catch (ClassNotFoundException e)
- {
- throw new WebServiceException(e);
- }
- if (isFaultWrapperGenerationRequired(sei))
- return true;
- soapBinding = sei.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()));
- }
-
- private boolean isFaultWrapperGenerationRequired(Class<?> clazz)
- {
- Method[] classMethods = clazz.getMethods();
- boolean webMethodAnnUsed = false;
- List<Method> webMethods = new LinkedList<Method>();
- for (Method m : classMethods)
- {
- if (m.getAnnotation(WebMethod.class) != null)
- {
- webMethods.add(m);
- webMethodAnnUsed = true;
- }
- }
- List<Method> methods = webMethodAnnUsed ? webMethods :
Arrays.asList(classMethods);
- for (Method m : methods)
- {
- Class<?>[] exceptionClasses = m.getExceptionTypes();
- for (Class<?> exceptionClass : exceptionClasses)
- {
- if (exceptionClass.getAnnotation(WebFault.class) != null)
- return true;
- }
- }
- return false;
- }
-
public void setArchiveFile(UnifiedVirtualFile file)
{
this.archiveFile = file;
Deleted:
stack/metro/trunk/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 2008-11-12
09:28:35 UTC (rev 8706)
+++
stack/metro/trunk/modules/server/src/main/java/org/jboss/wsf/stack/metro/WsgenWrapperGenerator.java 2008-11-12
09:59:04 UTC (rev 8707)
@@ -1,221 +0,0 @@
-/*
- * 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(a)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("/"))
- archivePath = archivePath.substring(0, archivePath.length() - 1);
- String archiveName =
archivePath.substring(archivePath.lastIndexOf("/"));
- 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") ||
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]);
- }
-}