geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r497935 - in /geronimo/server/trunk/modules: geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/ geronimo-cxf/ geronimo-cxf/src/main/java/org/apache/geronimo/cxf/
Date Fri, 19 Jan 2007 20:09:45 GMT
Author: djencks
Date: Fri Jan 19 12:09:45 2007
New Revision: 497935

URL: http://svn.apache.org/viewvc?view=rev&rev=497935
Log:
GERONIMO-2756 basic @Resource injection for cxf web services

Added:
    geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/JNDIResourceResolver.java
  (with props)
Modified:
    geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFBuilder.java
    geronimo/server/trunk/modules/geronimo-cxf/pom.xml
    geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java
    geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainerFactoryGBean.java

Modified: geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFBuilder.java?view=diff&rev=497935&r1=497934&r2=497935
==============================================================================
--- geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-cxf-builder/src/main/java/org/apache/geronimo/cxf/builder/CXFBuilder.java
Fri Jan 19 12:09:45 2007
@@ -29,6 +29,7 @@
 import java.util.Collections;
 import java.util.jar.JarFile;
 import java.util.logging.Logger;
+import java.util.logging.Level;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
@@ -53,6 +54,7 @@
 import org.apache.geronimo.cxf.CXFWebServiceContainerFactoryGBean;
 import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.deployment.DeploymentContext;
 import org.apache.geronimo.deployment.service.EnvironmentBuilder;
 import org.apache.geronimo.deployment.util.DeploymentUtil;
@@ -156,6 +158,13 @@
             return false;
         }
 
+        Map componentContext = null;
+        try {
+            GBeanData moduleGBean = context.getGBeanInstance(context.getModuleName()); 
+            componentContext = (Map)moduleGBean.getAttribute("componentContext");
+        } catch (GBeanNotFoundException e) {
+            LOG.warning("ModuleGBean not found. JNDI resource injection will not work.");
+        }
 
         LOG.info("configuring POJO webservice: " + servletName + " sei: " + seiClassName);
 
@@ -168,6 +177,7 @@
         GBeanData containerFactoryData = new GBeanData(containerFactoryName, CXFWebServiceContainerFactoryGBean.GBEAN_INFO);
         containerFactoryData.setAttribute("portInfo", portInfo);
         containerFactoryData.setAttribute("endpointClassName", seiClassName);
+        containerFactoryData.setAttribute("componentContext", componentContext);
         try {
             context.addGBean(containerFactoryData);
         } catch (GBeanAlreadyExistsException e) {

Modified: geronimo/server/trunk/modules/geronimo-cxf/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/pom.xml?view=diff&rev=497935&r1=497934&r2=497935
==============================================================================
--- geronimo/server/trunk/modules/geronimo-cxf/pom.xml (original)
+++ geronimo/server/trunk/modules/geronimo-cxf/pom.xml Fri Jan 19 12:09:45 2007
@@ -41,6 +41,12 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.geronimo.modules</groupId>
+            <artifactId>geronimo-naming</artifactId>
+            <version>${version}</version>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-rt-frontend-jaxws</artifactId>
         </dependency>

Modified: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java?view=diff&rev=497935&r1=497934&r2=497935
==============================================================================
--- geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java
(original)
+++ geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainer.java
Fri Jan 19 12:09:45 2007
@@ -16,6 +16,8 @@
  */
 package org.apache.geronimo.cxf;
 
+import javax.naming.Context;
+
 import org.apache.cxf.Bus;
 import org.apache.cxf.binding.xml.XMLConstants;
 import org.apache.cxf.jaxws.EndpointImpl;
@@ -23,6 +25,7 @@
 import org.apache.cxf.transport.DestinationFactoryManager;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.wsdl11.ServiceWSDLBuilder;
+import org.apache.cxf.resource.ResourceManager;
 
 import org.apache.geronimo.webservices.WebServiceContainer;
 
@@ -39,12 +42,17 @@
     private final GeronimoDestination destination;
     private final Bus bus;
 
-    public CXFWebServiceContainer(PortInfo portInfo, Object target, Bus bus) {
+    public CXFWebServiceContainer(PortInfo portInfo, Object target, Bus bus, Context context)
{
         //TODO actually use portInfo
         this.bus = bus;
 
         List ids = new ArrayList();
         ids.add("http://schemas.xmlsoap.org/wsdl/soap/http");
+
+        ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
+        if (context != null) {
+            resourceManager.addResourceResolver(new JNDIResourceResolver(context));
+        }
 
         DestinationFactoryManager destinationFactoryManager = bus.getExtension(DestinationFactoryManager.class);
         GeronimoDestinationFactory factory = new GeronimoDestinationFactory(bus);

Modified: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainerFactoryGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainerFactoryGBean.java?view=diff&rev=497935&r1=497934&r2=497935
==============================================================================
--- geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainerFactoryGBean.java
(original)
+++ geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/CXFWebServiceContainerFactoryGBean.java
Fri Jan 19 12:09:45 2007
@@ -17,11 +17,19 @@
 
 package org.apache.geronimo.cxf;
 
+import java.util.Map;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.cxf.CXFBusFactory;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
 import org.apache.geronimo.webservices.WebServiceContainer;
 import org.apache.geronimo.webservices.WebServiceContainerFactory;
 
@@ -30,11 +38,30 @@
  */
 public class CXFWebServiceContainerFactoryGBean implements WebServiceContainerFactory {
 
+    private static final Logger LOG = 
+        Logger.getLogger(CXFWebServiceContainerFactoryGBean.class.getName());
+
     private final PortInfo portInfo;
     private final Bus bus;
     private final Object endpointInstance;
+    private Context context;
+ 
+    public CXFWebServiceContainerFactoryGBean(PortInfo portInfo, 
+                                              String endpointClassName, 
+                                              ClassLoader classLoader,
+                                              Map componentContext,
+                                              Kernel kernel)
+        throws ClassNotFoundException, IllegalAccessException, InstantiationException {
+        
+        // TODO: get access to the transaction manager
+        if (componentContext != null) {
+            try {
+                this.context = EnterpriseNamingContext.createEnterpriseNamingContext(componentContext,
null, kernel, classLoader);
+            } catch (NamingException e) {
+                LOG.log(Level.WARNING, "Failed to create naming context", e);
+            }
+        }
 
-    public CXFWebServiceContainerFactoryGBean(PortInfo portInfo, String endpointClassName,
ClassLoader classLoader) throws ClassNotFoundException, IllegalAccessException, InstantiationException
{
         this.portInfo = portInfo;
         this.bus = new CXFBusFactory().getDefaultBus();
         Class endpointClass = classLoader.loadClass(endpointClassName);
@@ -42,7 +69,7 @@
     }
 
     public WebServiceContainer getWebServiceContainer() {
-        return new CXFWebServiceContainer(portInfo, endpointInstance, bus);
+        return new CXFWebServiceContainer(portInfo, endpointInstance, bus, context);
     }
 
     public static final GBeanInfo GBEAN_INFO;
@@ -52,7 +79,11 @@
         infoBuilder.addAttribute("portInfo", PortInfo.class, true, true);
         infoBuilder.addAttribute("endpointClassName", String.class, true, true);
         infoBuilder.addAttribute("classLoader", ClassLoader.class, false);
-        infoBuilder.setConstructor(new String[] {"portInfo", "endpointClassName", "classLoader"});
+        infoBuilder.addAttribute("componentContext", Map.class, true, true);
+        infoBuilder.addAttribute("kernel", Kernel.class, false);
+
+        infoBuilder.setConstructor(new String[] {"portInfo", "endpointClassName", "classLoader",

+                                                 "componentContext", "kernel"});
         GBEAN_INFO = infoBuilder.getBeanInfo();
     }
 

Added: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/JNDIResourceResolver.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/JNDIResourceResolver.java?view=auto&rev=497935
==============================================================================
--- geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/JNDIResourceResolver.java
(added)
+++ geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/JNDIResourceResolver.java
Fri Jan 19 12:09:45 2007
@@ -0,0 +1,73 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.cxf;
+
+import java.io.InputStream;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.resource.ResourceResolver;
+
+import org.apache.geronimo.naming.java.RootContext;
+
+public class JNDIResourceResolver implements ResourceResolver {
+
+    private static final Logger LOG = 
+        Logger.getLogger(JNDIResourceResolver.class.getName());
+
+    private Context componentContext;
+
+    public JNDIResourceResolver(Context context) {
+        this.componentContext = context;
+    }
+    
+    public final InputStream getAsStream(final String string) {
+        return null;
+    }
+
+    public final <T> T resolve(final String name, final Class<T> clz) {
+        // Ignore those
+        if ( ("bus".equals(name) && clz.equals(Bus.class)) ||
+             ("mtomEnabled".equals(name) && clz.equals(boolean.class)) ) {
+            return null;
+        }
+
+        Context oldContext = RootContext.getComponentContext();
+        try {
+            RootContext.setComponentContext(componentContext);
+
+            Context ctx = new InitialContext();
+            ctx = (Context)ctx.lookup("java:comp/env");
+                
+            LOG.fine("Looking up '" + name + "'");
+
+            Object o = ctx.lookup(name);
+                        
+            return clz.cast(o);
+            
+        } catch (NamingException e) {
+            LOG.log(Level.FINE, "JNDI lookup failed", e);
+            return null;
+        } finally {
+            RootContext.setComponentContext(oldContext);
+        }
+    }
+}

Propchange: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/JNDIResourceResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/JNDIResourceResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/JNDIResourceResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message