[jbossws-commits] JBossWS SVN: r8397 - in stack/metro/branches/asoldano/modules/server/src/main/java/org/jboss/wsf/stack/metro: metadata and 1 other directory.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Wed Oct 8 10:27:31 EDT 2008


Author: alessio.soldano at jboss.com
Date: 2008-10-08 10:27:31 -0400 (Wed, 08 Oct 2008)
New Revision: 8397

Added:
   stack/metro/branches/asoldano/modules/server/src/main/java/org/jboss/wsf/stack/metro/WsgenWrapperGenerator.java
Modified:
   stack/metro/branches/asoldano/modules/server/src/main/java/org/jboss/wsf/stack/metro/DeploymentDescriptorParserExt.java
   stack/metro/branches/asoldano/modules/server/src/main/java/org/jboss/wsf/stack/metro/metadata/RuntimeModelDeploymentAspect.java
Log:
[JBWS-2129] First raw implementation, based on wsgen


Modified: stack/metro/branches/asoldano/modules/server/src/main/java/org/jboss/wsf/stack/metro/DeploymentDescriptorParserExt.java
===================================================================
--- stack/metro/branches/asoldano/modules/server/src/main/java/org/jboss/wsf/stack/metro/DeploymentDescriptorParserExt.java	2008-10-08 14:25:37 UTC (rev 8396)
+++ stack/metro/branches/asoldano/modules/server/src/main/java/org/jboss/wsf/stack/metro/DeploymentDescriptorParserExt.java	2008-10-08 14:27:31 UTC (rev 8397)
@@ -27,6 +27,7 @@
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -45,6 +46,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;
@@ -103,6 +105,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 +302,12 @@
 
             ensureNoContent(reader);
             Invoker invoker = createInvoker(implementorClass);
+            
+            //Generate wrappers
+            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));
@@ -597,4 +607,9 @@
          throw new LocatableWebServiceException(ServerMessages.RUNTIME_PARSER_CLASS_NOT_FOUND(name), e, reader);
       }
    }
+   
+   public void setArchiveFile(UnifiedVirtualFile file)
+   {
+      this.archiveFile = file;
+   }
 }

Added: stack/metro/branches/asoldano/modules/server/src/main/java/org/jboss/wsf/stack/metro/WsgenWrapperGenerator.java
===================================================================
--- stack/metro/branches/asoldano/modules/server/src/main/java/org/jboss/wsf/stack/metro/WsgenWrapperGenerator.java	                        (rev 0)
+++ stack/metro/branches/asoldano/modules/server/src/main/java/org/jboss/wsf/stack/metro/WsgenWrapperGenerator.java	2008-10-08 14:27:31 UTC (rev 8397)
@@ -0,0 +1,254 @@
+/*
+ * 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.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+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 java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+import javax.xml.ws.WebServiceException;
+
+import org.jboss.logging.Logger;
+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.info("ImplementationName: " + endpoint);
+      log.info("Archive file: " + archiveUrl);
+      File tempDir = getTempDir(archiveUrl);
+      log.info("Temp directory: " + tempDir);
+
+      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("-keep"); //TODO!!! sources should not be needed
+      args.add("-verbose");
+      args.add("-s"); //TODO!!! sources should not be needed
+      args.add(tempDir.getAbsolutePath());
+      args.add(endpoint);
+      try
+      {
+         log.info("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 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.getServerTempDir(), "/../../../client/"); //TODO!!!!
+      //TODO!! read all client jars
+      sb.append(new File(clientDir, "jboss-ejb3x.jar").getAbsolutePath()).append(File.pathSeparator);
+      sb.append(new File(clientDir, "jbossall-client.jar").getAbsolutePath()).append(File.pathSeparator);
+      sb.append(new File(clientDir, "jsr181-api.jar").getAbsolutePath()).append(File.pathSeparator);
+      sb.append(new File(clientDir, "jbossws-spi.jar").getAbsolutePath()).append(File.pathSeparator);
+      sb.append(new File(clientDir, "jbossws-common.jar").getAbsolutePath()).append(File.pathSeparator);
+      sb.append(new File(clientDir, "jbossws-framework.jar").getAbsolutePath());
+      URL[] urls = getURLs(classLoader, archiveUrl);
+      for (URL url : urls)
+      {
+         sb.append(File.pathSeparator);
+         sb.append(url.toString());
+      }
+      return sb.toString();
+   }
+
+   protected File getTempDir(URL archiveUrl)
+   {
+      File tempJBossWSDir = new File(getServerConfig().getServerTempDir(), "jbossws");
+      if (!tempJBossWSDir.exists())
+         tempJBossWSDir.mkdir();
+      String archivePath = archiveUrl.toString();
+      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>();
+
+//      //This does not work when deploying through the jbossws testsuite (i.e. not dropping the archive to the deploy dir)
+//      if (classLoader instanceof URLClassLoader)
+//      {
+//         urls.addAll(Arrays.asList(((URLClassLoader)classLoader).getURLs()));
+//      }
+//      else
+//      {
+//         urls.add(archiveFile.toURL());
+//      }
+
+      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);
+               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 //jar
+         {
+            if (new File(archiveUrl.getPath()).exists())
+            {
+               urls.add(archiveUrl);
+            }
+            else
+            {
+               File dest = getTempDir(archiveUrl);
+               unjar(archiveUrl.openStream(), dest);
+               urls.add(dest.toURL());
+            }
+         }
+      }
+      catch (Exception e)
+      {
+         throw new WebServiceException("Cannot get classpath URLs for archive: " + archiveUrl, e);
+      }
+      return (URL[])urls.toArray(new URL[0]);
+   }
+
+   public static void unjar(InputStream in, File dest) throws IOException
+   {
+      if (!dest.exists())
+         dest.mkdirs();
+      if (!dest.isDirectory())
+         throw new IOException("Destination must be a directory.");
+      JarInputStream jin = new JarInputStream(in);
+      byte buffer[] = new byte[1024];
+      for (ZipEntry entry = jin.getNextEntry(); entry != null; entry = jin.getNextEntry())
+      {
+         String fileName = entry.getName();
+         if (fileName.charAt(fileName.length() - 1) == '/')
+            fileName = fileName.substring(0, fileName.length() - 1);
+         if (fileName.charAt(0) == '/')
+            fileName = fileName.substring(1);
+         if (File.separatorChar != '/')
+            fileName = fileName.replace('/', File.separatorChar);
+         File file = new File(dest, fileName);
+         if (entry.isDirectory())
+         {
+            file.mkdirs();
+            jin.closeEntry();
+            continue;
+         }
+         File parent = file.getParentFile();
+         if (parent != null && !parent.exists())
+            parent.mkdirs();
+         OutputStream out = new FileOutputStream(file);
+         for (int len = 0; (len = jin.read(buffer, 0, buffer.length)) != -1;)
+            out.write(buffer, 0, len);
+
+         out.flush();
+         out.close();
+         jin.closeEntry();
+         file.setLastModified(entry.getTime());
+      }
+
+      Manifest mf = jin.getManifest();
+      if (mf != null)
+      {
+         File file = new File(dest, "META-INF/MANIFEST.MF");
+         File parent = file.getParentFile();
+         if (!parent.exists())
+            parent.mkdirs();
+         OutputStream out = new FileOutputStream(file);
+         mf.write(out);
+         out.flush();
+         out.close();
+      }
+      jin.close();
+   }
+
+}


Property changes on: stack/metro/branches/asoldano/modules/server/src/main/java/org/jboss/wsf/stack/metro/WsgenWrapperGenerator.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: stack/metro/branches/asoldano/modules/server/src/main/java/org/jboss/wsf/stack/metro/metadata/RuntimeModelDeploymentAspect.java
===================================================================
--- stack/metro/branches/asoldano/modules/server/src/main/java/org/jboss/wsf/stack/metro/metadata/RuntimeModelDeploymentAspect.java	2008-10-08 14:25:37 UTC (rev 8396)
+++ stack/metro/branches/asoldano/modules/server/src/main/java/org/jboss/wsf/stack/metro/metadata/RuntimeModelDeploymentAspect.java	2008-10-08 14:27:31 UTC (rev 8397)
@@ -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