Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.metadata;
 
 
 
 import java.net.URL;
 import java.util.Map;
 import java.util.List;

Creates a Metro runtime model and associates it with the deployment. Doing so requires a valid runtime loader present, that will act as a temporary thread local classloader.

The spi.Endpoint carries a Metro ServletAdapter that is associated with the runtime model:
(Endpoint.getAttachment(ServletAdapter.class)) This adapter acts as the main entry point for SOAP/HTTP requests. Please note that the current implementation doesnt support the stream based RequestHandler API.

Author(s):
Heiko.Braun@jboss.com
See also:
org.jboss.wsf.stack.metro.RequestHandlerImpl
org.jboss.wsf.stack.metro.DeploymentDescriptorParserExt
 
 {
    private static final org.jboss.logging.Logger log = Logger.getLogger(RuntimeModelDeploymentAspect.class);
    protected static final String JAXWS_RI_RUNTIME = "/WEB-INF/sun-jaxws.xml";
    public static final String PARAM_SUN_JAXWS_URL = "jbossws-sun-jaxws-url";
    
    public void start(Deployment deployment)
    {
       ClassLoader runtimeLoader = deployment.getRuntimeClassLoader();
       if(null == runtimeLoader)
          throw new IllegalArgumentException("Null runtimeLoader");
 
       ClassLoader origClassLoader = Thread.currentThread().getContextClassLoader();
       try
       {
          // Metro uses the thread context classloader in several places
          Thread.currentThread().setContextClassLoader(runtimeLoader);
 
          UnifiedVirtualFile vfsRoot = null;
          if (deployment instanceof ArchiveDeployment)
          {
             vfsRoot = ((ArchiveDeployment)deployment).getRootFile();
          }
          else
          {                        
             vfsRoot = new ResourceLoaderAdapter(runtimeLoader);
          }
 
          ResourceLoader resourceLoader = new VFSResourceLoader(vfsRoot);
          JBossWSContainer container = new JBossWSContainer(resourceLoader);
         // TODO: refactor to general HTTPAdapter usage 
         ServletAdapterList adapterList = new ServletAdapterList();
         // Parse the descriptor file and build endpoint infos
         DeploymentDescriptorParserExt<ServletAdapterparser =
           createDeploymentDescriptorParser(runtimeLoadercontainerresourceLoaderadapterListvfsRoot);
         
         URL sunJaxWsXml = getDDUrlFromContext(deployment);
         
         List<ServletAdapteradapters = parser.parse(sunJaxWsXml.toExternalForm(), sunJaxWsXml.openStream());
         
         for(ServletAdapter adapter : adapters)
         {            
            for(Endpoint ep : deployment.getService().getEndpoints())
            {
               // TODO matching need to be improved
               boolean nameEquals = ep.getShortName().equals(adapter.getName());
               boolean beanEquals = ep.getTargetBeanClass().equals(adapter.getEndpoint().getImplementationClass()); 
               if(nameEquals && beanEquals)
               {
                  MessageStreamAdapter msgStreamAdapter = ..createAdapter(adapter.getName(), nulladapter.getEndpoint()); 
                  // TODO JBWS-1869: Support stream based RequestHandler API 
                  if (ep.getAttachment(MessageStreamAdapter.class) == null// TODO: review to don't insert the same attachments multiple times 
                     ep.addAttachment(MessageStreamAdapter.classmsgStreamAdapter); // do it only once
                  if (ep.getAttachment(ServletAdapter.class) == null)
                     ep.addAttachment(ServletAdapter.classadapter); // TODO: review to don't insert the same attachments multiple times
                  break;
               }
            }                       
         }
      }
      catch (Throwable e)
      {         
         throw new WebServiceException("Failed to build METRO runtime model"e);
      }
      finally
      {
         Thread.currentThread().setContextClassLoader(origClassLoader);
      }
   }
   @SuppressWarnings("unchecked")
   private URL getDDUrlFromContext(Deployment deploymentthrows MalformedURLException
   {
      Map<StringStringcontextProperties =
      return new URL(contextProperties.get());
   }

   
Externalized for integration
   (
      ClassLoader classLoader,
      JBossWSContainer container,
      ResourceLoader resourceLoader,
      UnifiedVirtualFile vfsRoot
   )
   {
      DeploymentDescriptorParserJBWS<ServletAdapterparser = new DeploymentDescriptorParserJBWS<ServletAdapter>(classLoaderresourceLoadercontaineradapterList);
      parser.setArchiveFile(vfsRoot);
      return parser;
   }

   
Externalized for integration
   {
      return vfsRoot.findChild().toURL();
   }

   
Provides access to javax.servlet.ServletContext via com.sun.xml.ws.api.server.Container. Pipes can get ServletContext from Container and use it to load some resources.
   private static class JBossWSContainer extends Container
   {
      private ResourceLoader resourceLoader;
      private Module module = new Module()
      {
         private final List<BoundEndpointendpoints = new ArrayList<BoundEndpoint>();
         public List<BoundEndpointgetBoundEndpoints()
         {
            return ;
         }
      };
      JBossWSContainer(ResourceLoader loader)
      {
         this. = loader;
      }
      @SuppressWarnings("unchecked")
      public <T> T getSPI(Class<T> spiType)
      {
         if (spiType == Module.class)
         {
            return spiType.cast();
         }
         if(spiType == ResourceInjector.class)
         {
            return (T).;
         }
         if (spiType == ServerPipelineHook.class)
         {
            return (T)new MessageLogPipelineHook();
         }
         if(spiType == ServletContext.class)
         {
            return (T)new FakeServletContext();
         }
         .warn("Unable to resolve SPI for type: " + spiType);
         return null;
      }
   }
New to GrepCode? Check out our FAQ X