<commit_before>/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2009, 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.cxf.client;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.soap.MTOMFeature;

import org.apache.cxf.configuration.Configurer;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedPortComponentRefMetaData;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedServiceRefMetaData;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedStubPropertyMetaData;

/**
 * A CXF configurer that sets the serviceref data in the JaxWsProxyFactoryBean
 *
 * @author <EMAIL>
 * @since 21-Jul-2009
 */
public class ServiceRefStubPropertyConfigurer implements Configurer
{
   private UnifiedServiceRefMetaData serviceRefMD;
   private Configurer delegate;

   public ServiceRefStubPropertyConfigurer(UnifiedServiceRefMetaData serviceRefMD, Configurer delegate)
   {
      this.serviceRefMD = serviceRefMD;
      this.delegate = delegate;
   }

   public void configureBean(Object beanInstance)
   {
      if (beanInstance instanceof JaxWsProxyFactoryBean)
      {
         configureJaxWsProxyFactoryBean((JaxWsProxyFactoryBean)beanInstance);
      }
      if (delegate != null)
      {
         delegate.configureBean(beanInstance);
      }
   }

   public void configureBean(String name, Object beanInstance)
   {
      if (beanInstance instanceof JaxWsProxyFactoryBean)
      {
         configureJaxWsProxyFactoryBean((JaxWsProxyFactoryBean)beanInstance);
      }
      if (delegate != null)
      {
         delegate.configureBean(name, beanInstance);
      }
   }
   
   private synchronized void configureJaxWsProxyFactoryBean(JaxWsProxyFactoryBean proxyFactory)
   {
      Class<?> clazz = proxyFactory.getServiceClass();
      UnifiedPortComponentRefMetaData upcmd = serviceRefMD.getPortComponentRef(clazz != null ? clazz.getName() : null, proxyFactory.getServiceName());
      if (upcmd != null)
      {
         setProperties(proxyFactory, upcmd);
         setMTOM((JaxWsServiceFactoryBean)proxyFactory.getServiceFactory(), upcmd);
      }
   }
   
   private void setMTOM(JaxWsServiceFactoryBean serviceFactoryBean, UnifiedPortComponentRefMetaData upcmd)
   {
      if (upcmd.getEnableMTOM())
      {
         List<WebServiceFeature> features = new LinkedList<WebServiceFeature>();
         List<WebServiceFeature> prevFeatures = serviceFactoryBean.getWsFeatures();
         if (prevFeatures != null)
         {
            features.addAll(prevFeatures);
         }
         features.add(new MTOMFeature(true));
         serviceFactoryBean.setWsFeatures(features);
      }
   }
   
   private void setProperties(JaxWsProxyFactoryBean proxyFactory, UnifiedPortComponentRefMetaData upcmd)
   {
      Map<String, Object> properties = proxyFactory.getProperties();
      if (properties == null)
      {
         properties = new HashMap<String, Object>();
         proxyFactory.setProperties(properties);
      }
      for (UnifiedStubPropertyMetaData prop : upcmd.getStubProperties())
      {
         properties.put(prop.getPropName(), prop.getPropValue());
      }
   }
}
<commit_msg>[JBWS-2997] Ignore exception when service qname is not available<commit_after>/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2009, 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.cxf.client;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.xml.namespace.QName;
import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.soap.MTOMFeature;

import org.apache.cxf.configuration.Configurer;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedPortComponentRefMetaData;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedServiceRefMetaData;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedStubPropertyMetaData;

/**
 * A CXF configurer that sets the serviceref data in the JaxWsProxyFactoryBean
 *
 * @author <EMAIL>
 * @since 21-Jul-2009
 */
public class ServiceRefStubPropertyConfigurer implements Configurer
{
   private UnifiedServiceRefMetaData serviceRefMD;
   private Configurer delegate;

   public ServiceRefStubPropertyConfigurer(UnifiedServiceRefMetaData serviceRefMD, Configurer delegate)
   {
      this.serviceRefMD = serviceRefMD;
      this.delegate = delegate;
   }

   public void configureBean(Object beanInstance)
   {
      if (beanInstance instanceof JaxWsProxyFactoryBean)
      {
         configureJaxWsProxyFactoryBean((JaxWsProxyFactoryBean)beanInstance);
      }
      if (delegate != null)
      {
         delegate.configureBean(beanInstance);
      }
   }

   public void configureBean(String name, Object beanInstance)
   {
      if (beanInstance instanceof JaxWsProxyFactoryBean)
      {
         configureJaxWsProxyFactoryBean((JaxWsProxyFactoryBean)beanInstance);
      }
      if (delegate != null)
      {
         delegate.configureBean(name, beanInstance);
      }
   }
   
   private synchronized void configureJaxWsProxyFactoryBean(JaxWsProxyFactoryBean proxyFactory)
   {
      Class<?> clazz = proxyFactory.getServiceClass();
      UnifiedPortComponentRefMetaData upcmd = serviceRefMD.getPortComponentRef(clazz != null ? clazz.getName() : null, getServiceName(proxyFactory));
      if (upcmd != null)
      {
         setProperties(proxyFactory, upcmd);
         setMTOM((JaxWsServiceFactoryBean)proxyFactory.getServiceFactory(), upcmd);
      }
   }
   
   private static QName getServiceName(JaxWsProxyFactoryBean proxyFactory)
   {
      try
      {
         return proxyFactory.getServiceName();
      }
      catch (Exception e) //ignore
      {
         return null;
      }
   }
   
   private void setMTOM(JaxWsServiceFactoryBean serviceFactoryBean, UnifiedPortComponentRefMetaData upcmd)
   {
      if (upcmd.getEnableMTOM())
      {
         List<WebServiceFeature> features = new LinkedList<WebServiceFeature>();
         List<WebServiceFeature> prevFeatures = serviceFactoryBean.getWsFeatures();
         if (prevFeatures != null)
         {
            features.addAll(prevFeatures);
         }
         features.add(new MTOMFeature(true));
         serviceFactoryBean.setWsFeatures(features);
      }
   }
   
   private void setProperties(JaxWsProxyFactoryBean proxyFactory, UnifiedPortComponentRefMetaData upcmd)
   {
      Map<String, Object> properties = proxyFactory.getProperties();
      if (properties == null)
      {
         properties = new HashMap<String, Object>();
         proxyFactory.setProperties(properties);
      }
      for (UnifiedStubPropertyMetaData prop : upcmd.getStubProperties())
      {
         properties.put(prop.getPropName(), prop.getPropValue());
      }
   }
}

{'fraction_non_alphanumeric': 0.08150646430578977, 'fraction_numerical': 0.006295671725688589, 'mean_word_length': 3.5761316872427984, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 5}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4049980', 'n_tokens_mistral': 2528, 'n_tokens_neox': 2456, 'n_words': 654}