Package org.jboss.wsf.framework.deployment

Source Code of org.jboss.wsf.framework.deployment.EndpointAddressDeploymentAspect

/*
* 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.framework.deployment;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.jboss.wsf.spi.SPIProvider;
import org.jboss.wsf.spi.SPIProviderResolver;
import org.jboss.wsf.spi.annotation.WebContext;
import org.jboss.wsf.spi.deployment.DeploymentAspect;
import org.jboss.wsf.spi.deployment.Deployment;
import org.jboss.wsf.spi.deployment.Endpoint;
import org.jboss.wsf.spi.deployment.Deployment.DeploymentType;
import org.jboss.wsf.spi.management.ServerConfig;
import org.jboss.wsf.spi.management.ServerConfigFactory;
import org.jboss.wsf.spi.metadata.j2ee.JSEArchiveMetaData;
import org.jboss.wsf.spi.metadata.j2ee.JSESecurityMetaData;
import org.jboss.wsf.spi.metadata.j2ee.JSESecurityMetaData.JSEResourceCollection;

/**
* A deployer that assigns the endpoint address.
*
* @author Thomas.Diesler@jboss.org
* @since 19-May-2007
*/
public class EndpointAddressDeploymentAspect extends DeploymentAspect
{
   @Override
   public void create(Deployment dep)
   {
      String contextRoot = dep.getService().getContextRoot();
      if (contextRoot == null)
         throw new IllegalStateException("Cannot obtain context root");
     
      SPIProvider provider = SPIProviderResolver.getInstance().getProvider();
      ServerConfigFactory spi = provider.getSPI(ServerConfigFactory.class);
      ServerConfig serverConfig = spi.getServerConfig();
     
      String host = serverConfig.getWebServiceHost();
      int port = serverConfig.getWebServicePort();
      int securePort = serverConfig.getWebServiceSecurePort();
      for (Endpoint ep : dep.getService().getEndpoints())
      {
         boolean confidential = isConfidentialTransportGuarantee(dep, ep);
         int currentPort = confidential ? securePort : port;
         String hostAndPort = host + (currentPort > 0 ? ":" + currentPort : "");
         String urlPattern = ep.getURLPattern();
         if (urlPattern == null)
            throw new IllegalStateException("Cannot obtain url pattern");

         if (urlPattern.endsWith("/*"))
            urlPattern = urlPattern.substring(0, urlPattern.length() - 2);

         String protocol = confidential ? "https://" : "http://";
         ep.setAddress(protocol + hostAndPort + contextRoot + urlPattern);
      }
   }
  
   protected boolean isConfidentialTransportGuarantee(Deployment dep, Endpoint ep)
   {
      String transportGuarantee = null;
      if (DeploymentType.JAXWS_JSE == dep.getType())
      {
         JSEArchiveMetaData webMetaData = dep.getAttachment(JSEArchiveMetaData.class);
         if (webMetaData != null)
         {
            String servletLink = ep.getShortName();
            Map<String, String> servletMappings = webMetaData.getServletMappings();
            String urlPattern = servletMappings.get(servletLink);
  
            if (urlPattern == null)
               throw new RuntimeException("Cannot find <url-pattern> for servlet-name: " + servletLink);
  
            List<JSESecurityMetaData> securityList = webMetaData.getSecurityMetaData();
            for (JSESecurityMetaData currentSecurity : securityList)
            {
               if (currentSecurity.getTransportGuarantee() != null && currentSecurity.getTransportGuarantee().length() > 0)
               {
                  for (JSEResourceCollection currentCollection : currentSecurity.getWebResources())
                  {
                     for (String currentUrlPattern : currentCollection.getUrlPatterns())
                     {
                        if (urlPattern.equals(currentUrlPattern) || "/*".equals(currentUrlPattern))
                        {
                           transportGuarantee = currentSecurity.getTransportGuarantee();
                        }
                     }
                  }
               }
            }
         }
      }
      else
      {
         //TODO Unify annotation scans
         Class implClass = ep.getTargetBeanClass();
         WebContext anWebContext = (WebContext)implClass.getAnnotation(WebContext.class);
         if (anWebContext != null)
         {
            transportGuarantee = anWebContext.transportGuarantee();
         }
      }
      return "CONFIDENTIAL".equals(transportGuarantee);
   }
  
}
TOP

Related Classes of org.jboss.wsf.framework.deployment.EndpointAddressDeploymentAspect

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.