Home » geronimo-2.2-source-release » org.apache.geronimo.cxf.pojo » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package org.apache.geronimo.cxf.pojo;
   19   
   20   import java.net.URL;
   21   import java.util.Map;
   22   
   23   import javax.naming.Context;
   24   import javax.naming.NamingException;
   25   import javax.transaction.TransactionManager;
   26   
   27   import org.slf4j.Logger;
   28   import org.slf4j.LoggerFactory;
   29   import org.apache.cxf.Bus;
   30   import org.apache.cxf.jaxws.context.WebServiceContextImpl;
   31   import org.apache.geronimo.cxf.CXFCatalogUtils;
   32   import org.apache.geronimo.cxf.CXFWebServiceContainer;
   33   import org.apache.geronimo.gbean.GBeanInfo;
   34   import org.apache.geronimo.gbean.GBeanInfoBuilder;
   35   import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
   36   import org.apache.geronimo.jaxws.JAXWSUtils;
   37   import org.apache.geronimo.jaxws.JNDIResolver;
   38   import org.apache.geronimo.jaxws.PortInfo;
   39   import org.apache.geronimo.jaxws.ServerJNDIResolver;
   40   import org.apache.geronimo.jaxws.annotations.AnnotationHolder;
   41   import org.apache.geronimo.kernel.Kernel;
   42   import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
   43   import org.apache.geronimo.naming.reference.SimpleReference;
   44   import org.apache.geronimo.transaction.GeronimoUserTransaction;
   45   import org.apache.geronimo.webservices.WebServiceContainer;
   46   import org.apache.geronimo.webservices.WebServiceContainerFactory;
   47   
   48   /**
   49    * @version $Rev: 508298 $ $Date: 2007-02-15 22:25:05 -0500 (Thu, 15 Feb 2007) $
   50    */
   51   public class POJOWebServiceContainerFactoryGBean implements WebServiceContainerFactory {
   52   
   53       private static final Logger LOG = LoggerFactory.getLogger(POJOWebServiceContainerFactoryGBean.class);
   54   
   55       private final Bus bus;
   56       private final Class servletClass;
   57       private final URL configurationBaseUrl;
   58   
   59       public POJOWebServiceContainerFactoryGBean(PortInfo portInfo,
   60                                                  String endpointClassName,
   61                                                  ClassLoader classLoader,
   62                                                  Map componentContext,
   63                                                  Kernel kernel,
   64                                                  TransactionManager transactionManager,
   65                                                  URL configurationBaseUrl,
   66                                                  AnnotationHolder holder,
   67                                                  String contextRoot)
   68               throws ClassNotFoundException, 
   69                      IllegalAccessException,
   70                      InstantiationException {
   71           
   72           Context context = null;
   73           
   74           if (componentContext != null) {
   75               
   76               // The name should match WebServiceContextAnnotationHelper.RELATIVE_JNDI_NAME
   77               componentContext.put("env/WebServiceContext", new WebServiceContextReference());
   78               
   79               GeronimoUserTransaction userTransaction = new GeronimoUserTransaction(transactionManager);
   80               try {
   81                   context = EnterpriseNamingContext.createEnterpriseNamingContext(componentContext,
   82                                                                                   userTransaction,
   83                                                                                   kernel,
   84                                                                                   classLoader);
   85               } catch (NamingException e) {
   86                   LOG.warn("Failed to create naming context", e);
   87               }
   88           }
   89   
   90           this.bus = CXFWebServiceContainer.getBus();     
   91           this.configurationBaseUrl = configurationBaseUrl;
   92           
   93           this.servletClass = classLoader.loadClass(endpointClassName);
   94           
   95           this.bus.setExtension(new ServerJNDIResolver(context), JNDIResolver.class);
   96           this.bus.setExtension(portInfo, PortInfo.class); 
   97           this.bus.setExtension(context, Context.class);
   98           this.bus.setExtension(holder, AnnotationHolder.class);
   99           
  100           URL catalog = JAXWSUtils.getOASISCatalogURL(this.configurationBaseUrl, 
  101                                                       classLoader, 
  102                                                       JAXWSUtils.DEFAULT_CATALOG_WEB);
  103           if (catalog != null) {
  104               CXFCatalogUtils.loadOASISCatalog(this.bus, catalog);
  105           }
  106       }
  107       
  108       public WebServiceContainer getWebServiceContainer() {
  109           return new POJOWebServiceContainer(bus, configurationBaseUrl, servletClass);
  110       }
  111   
  112       private static class WebServiceContextReference extends SimpleReference {
  113           public Object getContent() throws NamingException {
  114               return new WebServiceContextImpl();
  115           }
  116       }
  117       
  118       public static final GBeanInfo GBEAN_INFO;
  119   
  120       static {
  121           GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(POJOWebServiceContainerFactoryGBean.class, GBeanInfoBuilder.DEFAULT_J2EE_TYPE);
  122           infoBuilder.addAttribute("portInfo", PortInfo.class, true, true);
  123           infoBuilder.addAttribute("endpointClassName", String.class, true, true);
  124           infoBuilder.addAttribute("classLoader", ClassLoader.class, false);
  125           infoBuilder.addAttribute("componentContext", Map.class, true, true);
  126           infoBuilder.addAttribute("kernel", Kernel.class, false);
  127           infoBuilder.addReference("TransactionManager", TransactionManager.class, NameFactory.JTA_RESOURCE);
  128           infoBuilder.addAttribute("configurationBaseUrl", URL.class, true);
  129           infoBuilder.addAttribute("holder", AnnotationHolder.class, true);
  130           infoBuilder.addAttribute("contextRoot", String.class, true, true);
  131   
  132           infoBuilder.setConstructor(new String[]{
  133                   "portInfo", 
  134                   "endpointClassName", 
  135                   "classLoader",
  136                   "componentContext", 
  137                   "kernel", 
  138                   "TransactionManager", 
  139                   "configurationBaseUrl",
  140                   "holder",
  141                   "contextRoot"
  142           });
  143           
  144           GBEAN_INFO = infoBuilder.getBeanInfo();
  145       }
  146   
  147       public static GBeanInfo getGBeanInfo() {
  148           return GBEAN_INFO;
  149       }
  150   }

Home » geronimo-2.2-source-release » org.apache.geronimo.cxf.pojo » [javadoc | source]