Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2012, 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.ws.common.configuration;
 
 import static org.jboss.ws.common.Loggers.ROOT_LOGGER;
 import static org.jboss.ws.common.Messages.MESSAGES;
 
 import java.util.List;
 import java.util.Map;
 
 
Facility class for setting Client config

Author(s):
alessio.soldano@jboss.com
Since:
29-May-2012
 
 public class ConfigHelper implements ClientConfigurer
 {
    private static final Map<StringStringbindingIDs = new HashMap<StringString>(8);
    static {
       .put(."##SOAP11_HTTP");
       .put(."##SOAP12_HTTP");
       .put(."##SOAP11_HTTP_MTOM");
       .put(."##SOAP12_HTTP_MTOM");
       .put(."##XML_HTTP");
    }
    
    @Override
    public void setConfigHandlers(BindingProvider portString configFileString configName)
    {
       Class<?> clazz = !(port instanceof Dispatch) ? port.getClass() : null;
       ClientConfig config = readConfig(configFileconfigNameclazz);
       setupConfigHandlers(port.getBinding(), config);
    }
 
    @Override
    public void setConfigProperties(Object clientString configFileString configName)
    {
       throw .operationNotSupportedBy("setConfigProperties"this.getClass());
    }
    
    protected ClientConfig readConfig(String configFileString configNameClass<?> clientProxyClass) {
       if (configFile != null) {
          InputStream is = null;
          try
          {
             is = SecurityActions.getContextClassLoader().getResourceAsStream(configFile);
             if (is != null) {
                ConfigRoot config = ConfigMetaDataParser.parse(is);
                if (config != null) {
                   if (configName == null) {
                      for (Class<?> itf : clientProxyClass.getInterfaces()) {
                        ClientConfig cc = config.getClientConfigByName(itf.getName());
                        if (cc != null) {
                           return cc;
                        }
                     }
                  } else {
                     ClientConfig cc = config.getClientConfigByName(configName);
                     if (cc != null) {
                        return cc;
                     }
                  }
               }
            }
         }
         catch (Exception e)
         {
            throw .couldNotReadConfiguration(configFilee);
         }
         finally
         {
            if (is != null) {
               try {
                  is.close();
               } catch (IOException e) { } //ignore
            }
         }
      } else {
         if (configName != null) {
            InputStream is = null;
            try
            {
               is = SecurityActions.getContextClassLoader().getResourceAsStream(.);
               if (is != null) {
                  ConfigRoot config = ConfigMetaDataParser.parse(is);
                  ClientConfig cc = config != null ? config.getClientConfigByName(configName) : null;
                  if (cc != null) {
                     return cc;
                  }
               }
            }
            catch (Exception e)
            {
               throw .couldNotReadConfiguration(configFilee);
            }
            finally
            {
               if (is != null) {
                  try {
                     is.close();
                  } catch (IOException e) { } //ignore
               }
            }
         }
         try {
            ServerConfig sc = getServerConfig();
            if (sc != null) {
               ClientConfig cf = sc.getClientConfig(configName);
               if (cf != null) {
                  return cf;
               }
            }
         } catch (Exception e) {
            throw .configurationNotFound(configName);
         }
      }
      throw .configurationNotFound(configName);
   }
   
   
Setups a given Binding instance using a specified CommonConfig

Parameters:
binding the Binding instance to setup
config the CommonConfig with the input configuration
   @SuppressWarnings("rawtypes")
   public void setupConfigHandlers(Binding bindingCommonConfig config)
   {
      if (config != null) {
         //start with the use handlers only to remove the previously set configuration
         List<HandleruserHandlers = getNonConfigHandlers(binding.getHandlerChain());
         List<Handlerhandlers = convertToHandlers(config.getPreHandlerChains(), binding.getBindingID(), true); //PRE
         handlers.addAll(userHandlers); //ENDPOINT
         handlers.addAll(convertToHandlers(config.getPostHandlerChains(), binding.getBindingID(), false)); //POST
         binding.setHandlerChain(handlers);
      }
   }
   
   @SuppressWarnings("rawtypes")
   private static List<HandlergetNonConfigHandlers(List<HandlerhandlerChain) {
      List<Handlerlist = new LinkedList<Handler>();
      for (Handler h : handlerChain) {
         if (!(h instanceof ConfigDelegateHandler)) {
            list.add(h);
         }
      }
      return list;
   }
   
   @SuppressWarnings({"rawtypes""unchecked"})
   private static List<HandlerconvertToHandlers(List<UnifiedHandlerChainMetaDatahandlerChainsString bindingIDboolean isPre)
   {
      List<Handlerhandlers = new LinkedList<Handler>();
      if (handlerChains != null && !handlerChains.isEmpty())
      {
         final String protocolBinding = .get(bindingID);
         for (UnifiedHandlerChainMetaData handlerChain : handlerChains)
         {
            if (handlerChain.getPortNamePattern() != null || handlerChain.getServiceNamePattern() != null)
            {
               .filtersNotSupported();
            }
            if (matchProtocolBinding(protocolBindinghandlerChain.getProtocolBindings())) {
               for (UnifiedHandlerMetaData uhmd : handlerChain.getHandlers())
               {
                  if (uhmd.getInitParams() != null && !uhmd.getInitParams().isEmpty())
                  {
                     .initParamsNotSupported();
                  }
                  Object h = newInstance(uhmd.getHandlerClass());
                  if (h != null)
                  {
                     if (h instanceof Handler)
                     {
                        if (h instanceof LogicalHandler)
                        {
                           handlers.add(new LogicalConfigDelegateHandler((LogicalHandler)hisPre));
                        }
                        else if (h instanceof SOAPHandler)
                        {
                           handlers.add(new SOAPConfigDelegateHandler((SOAPHandler)hisPre));
                        }
                        else
                        {
                           handlers.add(new ConfigDelegateHandler((Handler)hisPre));
                        }
                     }
                     else
                     {
                        throw .notJAXWSHandler(uhmd.getHandlerClass());
                     }
                  }
               }
            }
         }
      }
      return handlers;
   }
   
   private static boolean matchProtocolBinding(String currentProtocolBindingString handlerChainProtocolBindings) {
      if (handlerChainProtocolBindings == null)
         return true;
      List<StringprotocolBindings = new LinkedList<String>();
      if (handlerChainProtocolBindings != null) {
         StringTokenizer st = new StringTokenizer(handlerChainProtocolBindings" "false);
         while (st.hasMoreTokens()) {
            protocolBindings.add(st.nextToken());
         }
      }
      return protocolBindings.contains(currentProtocolBinding);
   }
   
   private static Object newInstance(String className)
   {
      try
      {
         ClassLoader loader = new DelegateClassLoader(ClassLoaderProvider.getDefaultProvider()
               .getServerIntegrationClassLoader(), SecurityActions.getContextClassLoader());
         Class<?> clazz = SecurityActions.loadClass(loaderclassName);
         return clazz.newInstance();
      }
      catch (Exception e)
      {
         .cannotAddHandler(classNamee);
         return null;
      }
   }
   
   private static ServerConfig getServerConfig()
   {
      final ClassLoader cl = ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader();
      final ServerConfigFactory scf = SPIProvider.getInstance().getSPI(ServerConfigFactory.classcl);
      return scf != null ? scf.getServerConfig() : null;
   }
New to GrepCode? Check out our FAQ X