geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r566374 - in /geronimo/server/trunk/modules: geronimo-axis2/src/main/java/org/apache/geronimo/axis2/ geronimo-axis2/src/main/java/org/apache/geronimo/axis2/pojo/ geronimo-axis2/src/test/java/org/apache/geronimo/axis2/ geronimo-cxf/src/main/...
Date Wed, 15 Aug 2007 22:47:06 GMT
Author: gawor
Date: Wed Aug 15 15:47:05 2007
New Revision: 566374

URL: http://svn.apache.org/viewvc?view=rev&rev=566374
Log:
use the annotation Holder object for injections for POJO web services

Added:
    geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WebServiceContextAnnotationHelper.java
  (with props)
    geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/annotations/AnnotationHolder.java
  (with props)
Modified:
    geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainer.java
    geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/pojo/POJOWebServiceContainer.java
    geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/pojo/POJOWebServiceContainerFactoryGBean.java
    geronimo/server/trunk/modules/geronimo-axis2/src/test/java/org/apache/geronimo/axis2/Axis2WebServiceContainerTest.java
    geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/pojo/POJOEndpoint.java
    geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/pojo/POJOWebServiceContainer.java
    geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/pojo/POJOWebServiceContainerFactoryGBean.java
    geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceBuilder.java

Modified: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainer.java?view=diff&rev=566374&r1=566373&r2=566374
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainer.java
(original)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainer.java
Wed Aug 15 15:47:05 2007
@@ -95,6 +95,7 @@
     protected WSDLQueryHandler wsdlQueryHandler;
     protected Binding binding;
     protected JAXWSAnnotationProcessor annotationProcessor;
+    protected Context context;
 
     public Axis2WebServiceContainer(PortInfo portInfo,
                                     String endpointClassName,
@@ -105,6 +106,7 @@
         this.endpointClassName = endpointClassName;
         this.portInfo = portInfo;
         this.configurationBaseUrl = configurationBaseUrl;
+        this.context = context;
         this.jndiResolver = new ServerJNDIResolver(context);
     }
 
@@ -168,7 +170,7 @@
     }
 
     protected void doService(final Request request, final Response response)
-            throws Exception {
+            throws Exception {        
         initContextRoot(request);
 
         if (LOG.isDebugEnabled()) {

Modified: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/pojo/POJOWebServiceContainer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/pojo/POJOWebServiceContainer.java?view=diff&rev=566374&r1=566373&r2=566374
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/pojo/POJOWebServiceContainer.java
(original)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/pojo/POJOWebServiceContainer.java
Wed Aug 15 15:47:05 2007
@@ -36,7 +36,7 @@
 import org.apache.geronimo.axis2.Axis2WebServiceContainer;
 import org.apache.geronimo.jaxws.JAXWSAnnotationProcessor;
 import org.apache.geronimo.jaxws.PortInfo;
-import org.apache.geronimo.jaxws.annotations.AnnotationException;
+import org.apache.geronimo.jaxws.annotations.AnnotationHolder;
 
 /**
  * @version $Rev$ $Date$
@@ -47,13 +47,16 @@
     
     private Object endpointInstance;
     private String contextRoot = null;
+    private AnnotationHolder holder;
     
     public POJOWebServiceContainer(PortInfo portInfo,
                                    String endpointClassName,
                                    ClassLoader classLoader,
                                    Context context,
-                                   URL configurationBaseUrl) {
-        super(portInfo, endpointClassName, classLoader, context, configurationBaseUrl); 
      
+                                   URL configurationBaseUrl,
+                                   AnnotationHolder holder) {
+        super(portInfo, endpointClassName, classLoader, context, configurationBaseUrl);
+        this.holder = holder;
     }
     
     @Override
@@ -66,10 +69,18 @@
          */
         FactoryRegistry.setFactory(EndpointLifecycleManagerFactory.class, 
                                    new POJOEndpointLifecycleManagerFactory());
-               
-        this.endpointInstance = this.endpointClass.newInstance();
-        
+                       
         this.configurationContext.setServicePath(this.portInfo.getLocation());
+        
+        // instantiate and inject resources into service
+        try {
+            this.endpointInstance = this.holder.newInstance(this.endpointClass.getName(),

+                                                            this.endpointClass.getClassLoader(),

+                                                            this.context);
+        } catch (Exception e) {
+            throw new WebServiceException("Service resource injection failed", e);
+        }
+        
         this.annotationProcessor = 
             new JAXWSAnnotationProcessor(this.jndiResolver, new POJOWebServiceContext());
 
@@ -81,12 +92,6 @@
             throw new WebServiceException("Error configuring handlers", e);
         }
         
-        // inject resources into service
-        try {
-            injectResources(this.endpointInstance);
-        } catch (AnnotationException e) {
-            throw new WebServiceException("Service resource injection failed", e);
-        }
     }
     
     @Override
@@ -146,7 +151,11 @@
         
         // call service preDestroy
         if (this.endpointInstance != null) {
-            this.annotationProcessor.invokePreDestroy(this.endpointInstance);
+            try {
+                this.holder.destroyInstance(this.endpointInstance);
+            } catch (Exception e) {
+                LOG.warn("Error calling @PreDestroy method", e); 
+            }
         }
         
         super.destroy();

Modified: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/pojo/POJOWebServiceContainerFactoryGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/pojo/POJOWebServiceContainerFactoryGBean.java?view=diff&rev=566374&r1=566373&r2=566374
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/pojo/POJOWebServiceContainerFactoryGBean.java
(original)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/pojo/POJOWebServiceContainerFactoryGBean.java
Wed Aug 15 15:47:05 2007
@@ -29,8 +29,10 @@
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.jaxws.annotations.AnnotationHolder;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
+import org.apache.geronimo.naming.reference.SimpleReference;
 import org.apache.geronimo.transaction.GeronimoUserTransaction;
 import org.apache.geronimo.webservices.WebServiceContainer;
 import org.apache.geronimo.webservices.WebServiceContainerFactory;
@@ -47,6 +49,7 @@
     private final String endpointClassName;
     private URL configurationBaseUrl;
     private Context context;
+    private AnnotationHolder holder;
 
     public POJOWebServiceContainerFactoryGBean(org.apache.geronimo.jaxws.PortInfo portInfo,
                                                String endpointClassName,
@@ -54,10 +57,15 @@
                                                Map componentContext,
                                                Kernel kernel,
                                                TransactionManager transactionManager,
-                                               URL configurationBaseUrl)
+                                               URL configurationBaseUrl,
+                                               AnnotationHolder holder)
         throws InstantiationException, IllegalAccessException, ClassNotFoundException {
         
         if (componentContext != null) {
+            
+            // The name should match WebServiceContextAnnotationHelper.RELATIVE_JNDI_NAME
+            componentContext.put("env/WebServiceContext", new WebServiceContextReference());
+            
             GeronimoUserTransaction userTransaction = new GeronimoUserTransaction(transactionManager);
             try {
                 this.context = EnterpriseNamingContext.createEnterpriseNamingContext(componentContext,
@@ -72,11 +80,12 @@
         this.portInfo = portInfo;
         this.classLoader = classLoader;
         this.endpointClassName = endpointClassName;
-        this.configurationBaseUrl = configurationBaseUrl;
+        this.configurationBaseUrl = configurationBaseUrl;   
+        this.holder = holder;
     }
 
     public WebServiceContainer getWebServiceContainer() {
-        POJOWebServiceContainer container = new POJOWebServiceContainer(portInfo, endpointClassName,
classLoader, context, configurationBaseUrl);
+        POJOWebServiceContainer container = new POJOWebServiceContainer(portInfo, endpointClassName,
classLoader, context, configurationBaseUrl, holder);
         try {
             container.init();
         } catch (Exception e) {
@@ -85,6 +94,12 @@
         return container;
     }
 
+    private static class WebServiceContextReference extends SimpleReference {
+        public Object getContent() throws NamingException {
+            return new POJOWebServiceContext();
+        }        
+    }
+    
     public static final GBeanInfo GBEAN_INFO;
 
     static {
@@ -96,9 +111,10 @@
         infoBuilder.addAttribute("kernel", Kernel.class, false);
         infoBuilder.addReference("TransactionManager", TransactionManager.class, NameFactory.TRANSACTION_MANAGER);
         infoBuilder.addAttribute("configurationBaseUrl", URL.class, true);
+        infoBuilder.addAttribute("holder", AnnotationHolder.class, true);
 
         infoBuilder.setConstructor(new String[]{"portInfo", "endpointClassName", "classLoader",
-                "componentContext", "kernel", "TransactionManager", "configurationBaseUrl"});
+                "componentContext", "kernel", "TransactionManager", "configurationBaseUrl",
"holder"});
         GBEAN_INFO = infoBuilder.getBeanInfo();
     }
 

Modified: geronimo/server/trunk/modules/geronimo-axis2/src/test/java/org/apache/geronimo/axis2/Axis2WebServiceContainerTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/test/java/org/apache/geronimo/axis2/Axis2WebServiceContainerTest.java?view=diff&rev=566374&r1=566373&r2=566374
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/test/java/org/apache/geronimo/axis2/Axis2WebServiceContainerTest.java
(original)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/test/java/org/apache/geronimo/axis2/Axis2WebServiceContainerTest.java
Wed Aug 15 15:47:05 2007
@@ -28,6 +28,7 @@
 
 import org.apache.geronimo.axis2.pojo.POJOWebServiceContainer;
 import org.apache.geronimo.jaxws.PortInfo;
+import org.apache.geronimo.jaxws.annotations.AnnotationHolder;
 import org.apache.geronimo.kernel.util.XmlUtil;
 import org.apache.geronimo.webservices.WebServiceContainer.Request;
 import org.w3c.dom.Document;
@@ -72,7 +73,7 @@
         Axis2Response res = new Axis2Response("text/xml; charset=utf-8", "127.0.0.1", null,
null, 8080, out);
         
         String endpointClassName = "org.apache.geronimo.axis2.testdata.simple.HelloWorld";
-        POJOWebServiceContainer container = new POJOWebServiceContainer(portInfo, endpointClassName,
cl, null, null);
+        POJOWebServiceContainer container = new POJOWebServiceContainer(portInfo, endpointClassName,
cl, null, null, AnnotationHolder.EMPTY);
         container.init();
         container.invoke(req, res);
         out.flush();
@@ -146,7 +147,7 @@
                 ByteArrayOutputStream out = new ByteArrayOutputStream();
                 Axis2Response res = new Axis2Response("text/xml; charset=utf-8", "127.0.0.1",
null, null, 8080, out);
 
-                POJOWebServiceContainer container = new POJOWebServiceContainer(portInfo,
endPointClassName, cl, null, null);
+                POJOWebServiceContainer container = new POJOWebServiceContainer(portInfo,
endPointClassName, cl, null, null, AnnotationHolder.EMPTY);
                 container.init();
                 container.invoke(req, res);
                 System.out.println("Response "+out);

Modified: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/pojo/POJOEndpoint.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/pojo/POJOEndpoint.java?view=diff&rev=566374&r1=566373&r2=566374
==============================================================================
--- geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/pojo/POJOEndpoint.java
(original)
+++ geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/pojo/POJOEndpoint.java
Wed Aug 15 15:47:05 2007
@@ -20,8 +20,11 @@
 
 import java.net.URL;
 
+import javax.naming.Context;
 import javax.xml.ws.WebServiceException;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.cxf.Bus;
 import org.apache.cxf.jaxws.JAXWSMethodInvoker;
 import org.apache.cxf.jaxws.context.WebServiceContextImpl;
@@ -32,18 +35,22 @@
 import org.apache.geronimo.jaxws.JAXWSAnnotationProcessor;
 import org.apache.geronimo.jaxws.JAXWSUtils;
 import org.apache.geronimo.jaxws.JNDIResolver;
-import org.apache.geronimo.jaxws.annotations.AnnotationException;
+import org.apache.geronimo.jaxws.annotations.AnnotationHolder;
 
 public class POJOEndpoint extends CXFEndpoint {
   
-    public POJOEndpoint(Bus bus, URL configurationBaseUrl, Object instance) {
+    private static final Log LOG = LogFactory.getLog(POJOEndpoint.class);
+    
+    private AnnotationHolder holder;
+
+    public POJOEndpoint(Bus bus, URL configurationBaseUrl, Class instance) {
         super(bus, instance);
         
         String bindingURI = null;
         if (this.portInfo.getProtocolBinding() != null) {
             bindingURI = JAXWSUtils.getBindingURI(this.portInfo.getProtocolBinding());
         }
-        implInfo = new GeronimoJaxWsImplementorInfo(implementor.getClass(), bindingURI);
+        implInfo = new GeronimoJaxWsImplementorInfo(instance, bindingURI);
 
         serviceFactory = new JaxWsServiceFactoryBean(implInfo);        
         serviceFactory.setBus(bus);
@@ -63,7 +70,20 @@
 
         service = serviceFactory.create();
         
-        service.setInvoker(new JAXWSMethodInvoker(instance));       
+        this.holder = bus.getExtension(AnnotationHolder.class);
+        
+        Context context = bus.getExtension(Context.class);
+        
+        // instantiate and inject resources into service
+        try {
+            this.implementor = this.holder.newInstance(instance.getName(), 
+                                                       instance.getClassLoader(), 
+                                                       context);
+        } catch (Exception e) {
+            throw new WebServiceException("Service resource injection failed", e);
+        }
+        
+        service.setInvoker(new JAXWSMethodInvoker(this.implementor));       
 
         JNDIResolver jndiResolver = (JNDIResolver) bus.getExtension(JNDIResolver.class);
         this.annotationProcessor = new JAXWSAnnotationProcessor(jndiResolver, new WebServiceContextImpl());
@@ -77,13 +97,6 @@
         } catch (Exception e) {
             throw new WebServiceException("Error configuring handlers", e);
         }
-
-        // inject resources into service
-        try {
-            injectResources(this.implementor);
-        } catch (AnnotationException e) {
-            throw new WebServiceException("Service resource injection failed", e);
-        }
     }
 
     public void stop() {
@@ -91,7 +104,13 @@
         destroyHandlers();
 
         // call service preDestroy
-        this.annotationProcessor.invokePreDestroy(this.implementor);
+        if (this.implementor != null) {
+            try {
+                this.holder.destroyInstance(this.implementor);
+            } catch (Exception e) {
+                LOG.warn("Error calling @PreDestroy method", e); 
+            }
+        }
 
         // shutdown server
         super.stop();

Modified: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/pojo/POJOWebServiceContainer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/pojo/POJOWebServiceContainer.java?view=diff&rev=566374&r1=566373&r2=566374
==============================================================================
--- geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/pojo/POJOWebServiceContainer.java
(original)
+++ geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/pojo/POJOWebServiceContainer.java
Wed Aug 15 15:47:05 2007
@@ -26,7 +26,7 @@
     
     public POJOWebServiceContainer(Bus bus,
                                    URL configurationBaseUrl,                            
     
-                                   Object target) {
+                                   Class target) {
         super(bus, configurationBaseUrl, target);
         this.destination.setPassSecurityContext(true);
     }
@@ -34,7 +34,7 @@
     protected CXFEndpoint publishEndpoint(Object target) {
         assert target != null : "null target received";
 
-        POJOEndpoint ep = new POJOEndpoint(bus, configurationBaseUrl, target);
+        POJOEndpoint ep = new POJOEndpoint(bus, configurationBaseUrl, (Class)target);
         ep.publish("http://nopath");
         return ep;
     }

Modified: geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/pojo/POJOWebServiceContainerFactoryGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/pojo/POJOWebServiceContainerFactoryGBean.java?view=diff&rev=566374&r1=566373&r2=566374
==============================================================================
--- geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/pojo/POJOWebServiceContainerFactoryGBean.java
(original)
+++ geronimo/server/trunk/modules/geronimo-cxf/src/main/java/org/apache/geronimo/cxf/pojo/POJOWebServiceContainerFactoryGBean.java
Wed Aug 15 15:47:05 2007
@@ -27,6 +27,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.cxf.Bus;
+import org.apache.cxf.jaxws.context.WebServiceContextImpl;
 import org.apache.geronimo.cxf.CXFCatalogUtils;
 import org.apache.geronimo.cxf.CXFWebServiceContainer;
 import org.apache.geronimo.gbean.GBeanInfo;
@@ -35,8 +36,10 @@
 import org.apache.geronimo.jaxws.JNDIResolver;
 import org.apache.geronimo.jaxws.PortInfo;
 import org.apache.geronimo.jaxws.ServerJNDIResolver;
+import org.apache.geronimo.jaxws.annotations.AnnotationHolder;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
+import org.apache.geronimo.naming.reference.SimpleReference;
 import org.apache.geronimo.transaction.GeronimoUserTransaction;
 import org.apache.geronimo.webservices.WebServiceContainer;
 import org.apache.geronimo.webservices.WebServiceContainerFactory;
@@ -49,7 +52,7 @@
     private static final Log LOG = LogFactory.getLog(POJOWebServiceContainerFactoryGBean.class);
 
     private final Bus bus;
-    private final Object endpointInstance;
+    private final Class servletClass;
     private final URL configurationBaseUrl;
 
     public POJOWebServiceContainerFactoryGBean(PortInfo portInfo,
@@ -58,7 +61,8 @@
                                                Map componentContext,
                                                Kernel kernel,
                                                TransactionManager transactionManager,
-                                               URL configurationBaseUrl)
+                                               URL configurationBaseUrl,
+                                               AnnotationHolder holder)
             throws ClassNotFoundException, 
                    IllegalAccessException,
                    InstantiationException {
@@ -66,6 +70,10 @@
         Context context = null;
         
         if (componentContext != null) {
+            
+            // The name should match WebServiceContextAnnotationHelper.RELATIVE_JNDI_NAME
+            componentContext.put("env/WebServiceContext", new WebServiceContextReference());
+            
             GeronimoUserTransaction userTransaction = new GeronimoUserTransaction(transactionManager);
             try {
                 context = EnterpriseNamingContext.createEnterpriseNamingContext(componentContext,
@@ -80,11 +88,12 @@
         this.bus = CXFWebServiceContainer.getBus();     
         this.configurationBaseUrl = configurationBaseUrl;
         
-        Class endpointClass = classLoader.loadClass(endpointClassName);
-        this.endpointInstance = endpointClass.newInstance();
+        this.servletClass = classLoader.loadClass(endpointClassName);
         
         this.bus.setExtension(new ServerJNDIResolver(context), JNDIResolver.class);
-        this.bus.setExtension(portInfo, PortInfo.class);   
+        this.bus.setExtension(portInfo, PortInfo.class); 
+        this.bus.setExtension(context, Context.class);
+        this.bus.setExtension(holder, AnnotationHolder.class);
         
         CXFCatalogUtils.loadOASISCatalog(this.bus, 
                                          this.configurationBaseUrl, 
@@ -92,9 +101,15 @@
     }
     
     public WebServiceContainer getWebServiceContainer() {
-        return new POJOWebServiceContainer(bus, configurationBaseUrl, endpointInstance);
+        return new POJOWebServiceContainer(bus, configurationBaseUrl, servletClass);
     }
 
+    private static class WebServiceContextReference extends SimpleReference {
+        public Object getContent() throws NamingException {
+            return new WebServiceContextImpl();
+        }
+    }
+    
     public static final GBeanInfo GBEAN_INFO;
 
     static {
@@ -106,6 +121,7 @@
         infoBuilder.addAttribute("kernel", Kernel.class, false);
         infoBuilder.addReference("TransactionManager", TransactionManager.class, NameFactory.TRANSACTION_MANAGER);
         infoBuilder.addAttribute("configurationBaseUrl", URL.class, true);
+        infoBuilder.addAttribute("holder", AnnotationHolder.class, true);
 
         infoBuilder.setConstructor(new String[]{
                 "portInfo", 
@@ -114,7 +130,8 @@
                 "componentContext", 
                 "kernel", 
                 "TransactionManager", 
-                "configurationBaseUrl"
+                "configurationBaseUrl",
+                "holder"
         });
         
         GBEAN_INFO = infoBuilder.getBeanInfo();

Modified: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceBuilder.java?view=diff&rev=566374&r1=566373&r2=566374
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/JAXWSServiceBuilder.java
Wed Aug 15 15:47:05 2007
@@ -42,6 +42,7 @@
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.j2ee.annotation.Holder;
 import org.apache.geronimo.j2ee.deployment.EARContext;
 import org.apache.geronimo.j2ee.deployment.Module;
 import org.apache.geronimo.j2ee.deployment.WebModule;
@@ -49,6 +50,7 @@
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.jaxws.JAXWSUtils;
 import org.apache.geronimo.jaxws.PortInfo;
+import org.apache.geronimo.jaxws.annotations.AnnotationHolder;
 import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.classloader.JarFileClassLoader;
@@ -329,13 +331,23 @@
         }
         
         Map componentContext = null;
+        Holder moduleHolder = null;
         try {
             GBeanData moduleGBean = context.getGBeanInstance(context.getModuleName());
             componentContext = (Map)moduleGBean.getAttribute("componentContext");
+            moduleHolder = (Holder)moduleGBean.getAttribute("holder");
         } catch (GBeanNotFoundException e) {
             LOG.warn("ModuleGBean not found. JNDI resource injection will not work.");
         }
 
+        AnnotationHolder serviceHolder = 
+            (AnnotationHolder)sharedContext.get(WebServiceContextAnnotationHelper.class.getName());
+        if (serviceHolder == null) {
+            serviceHolder = new AnnotationHolder(moduleHolder);
+            WebServiceContextAnnotationHelper.addWebServiceContextInjections(serviceHolder,
module.getClassFinder());
+            sharedContext.put(WebServiceContextAnnotationHelper.class.getName(), serviceHolder);
+        }
+        
         String location = portInfo.getLocation();
         LOG.info("Configuring JAX-WS Web Service: " + servletName + " at " + location);
 
@@ -344,6 +356,7 @@
         containerFactoryData.setAttribute("portInfo", portInfo);
         containerFactoryData.setAttribute("endpointClassName", servletClassName);
         containerFactoryData.setAttribute("componentContext", componentContext);
+        containerFactoryData.setAttribute("holder", serviceHolder);
         try {
             context.addGBean(containerFactoryData);
         } catch (GBeanAlreadyExistsException e) {
@@ -358,12 +371,12 @@
             containerFactoryData.setReferencePattern("TransactionManager",
                                                      ((EARContext)context).getTransactionManagerName());
         }
-
+        
         initialize(containerFactoryData, servletClass, portInfo, module);
         
         return true;
     }
-
+        
     protected abstract GBeanInfo getContainerFactoryGBeanInfo();
 
     public boolean configureEJB(GBeanData targetGBean,

Added: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WebServiceContextAnnotationHelper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WebServiceContextAnnotationHelper.java?view=auto&rev=566374
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WebServiceContextAnnotationHelper.java
(added)
+++ geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WebServiceContextAnnotationHelper.java
Wed Aug 15 15:47:05 2007
@@ -0,0 +1,83 @@
+/**
+ *  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.jaxws.builder;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import javax.annotation.Resource;
+import javax.xml.ws.WebServiceContext;
+
+import org.apache.geronimo.j2ee.annotation.Holder;
+import org.apache.geronimo.j2ee.annotation.Injection;
+import org.apache.xbean.finder.ClassFinder;
+
+public class WebServiceContextAnnotationHelper {
+      
+    public static final String RELATIVE_JNDI_NAME = "env/WebServiceContext";
+    public static final String ABSOLUTE_JNDI_NAME = "java:comp/" + RELATIVE_JNDI_NAME;
+    
+    public static void addWebServiceContextInjections(Holder holder, ClassFinder finder)
{        
+        List<Field> fields = finder.findAnnotatedFields(Resource.class);
+        for (Field field : fields) {
+            Resource resource = (Resource) field.getAnnotation(Resource.class);
+            Class type = getInjectionType(resource.type(), null, field);
+            if (WebServiceContext.class == type) {
+                holder.addInjection(field.getDeclaringClass().getName(), 
+                                    new Injection(field.getDeclaringClass().getName(), getInjectionName(null,
field), ABSOLUTE_JNDI_NAME));
+            }
+        }
+        List<Method> methods = finder.findAnnotatedMethods(Resource.class);
+        for (Method method : methods) {
+            Resource resource = (Resource) method.getAnnotation(Resource.class);
+            Class type = getInjectionType(resource.type(), method, null);
+            if (WebServiceContext.class == type) {
+                holder.addInjection(method.getDeclaringClass().getName(), 
+                                    new Injection(method.getDeclaringClass().getName(), getInjectionName(method,
null), ABSOLUTE_JNDI_NAME));
+            }            
+        }
+    }
+    
+    private static Class<?> getInjectionType(Class<?> type, Method method, Field
field) {
+        if (type == null || Object.class == type) {
+            if (field != null) {
+                return field.getType();
+            } else if (method != null) {
+                return method.getParameterTypes()[0];
+            } else {
+                throw new IllegalArgumentException("You must supply exactly one of Method,
Field");
+            }
+        } else {
+            return type;
+        }
+    }
+    
+    private static String getInjectionName(Method method, Field field) {
+        if (method != null) {
+            String injectionJavaType = method.getName().substring(3);
+            StringBuilder stringBuilder = new StringBuilder(injectionJavaType);
+            stringBuilder.setCharAt(0, Character.toLowerCase(stringBuilder.charAt(0)));
+            return stringBuilder.toString();
+        } else if (field != null) {
+            return field.getName();
+        } else {
+            throw new IllegalArgumentException("You must supply exactly one of Method, Field");
+        }
+    }
+
+}

Propchange: geronimo/server/trunk/modules/geronimo-jaxws-builder/src/main/java/org/apache/geronimo/jaxws/builder/WebServiceContextAnnotationHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/annotations/AnnotationHolder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/annotations/AnnotationHolder.java?view=auto&rev=566374
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/annotations/AnnotationHolder.java
(added)
+++ geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/annotations/AnnotationHolder.java
Wed Aug 15 15:47:05 2007
@@ -0,0 +1,45 @@
+/**
+ *  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.jaxws.annotations;
+
+import javax.naming.Context;
+
+import org.apache.geronimo.j2ee.annotation.Holder;
+import org.apache.geronimo.naming.java.RootContext;
+
+public class AnnotationHolder extends Holder {
+
+    public static final AnnotationHolder EMPTY = new AnnotationHolder();
+    
+    public AnnotationHolder() {        
+    }
+
+    public AnnotationHolder(Holder holder) {
+        super(holder);
+    }
+
+    public Object newInstance(String className, ClassLoader classLoader, Context context)
throws IllegalAccessException, InstantiationException {
+        Context oldContext = RootContext.getComponentContext();
+        try {
+            RootContext.setComponentContext(context);
+            return super.newInstance(className, classLoader, context);
+        } finally {
+            RootContext.setComponentContext(oldContext);
+        }
+    }
+    
+}

Propchange: geronimo/server/trunk/modules/geronimo-jaxws/src/main/java/org/apache/geronimo/jaxws/annotations/AnnotationHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message