cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r515610 - in /incubator/cxf/trunk: rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ rt/transports/http2/src/main/java/org/apache/cxf/transport/servlet/ systests/src/test/java/org/apache/cxf/systest/handlers/
Date Wed, 07 Mar 2007 15:34:37 GMT
Author: jliu
Date: Wed Mar  7 07:34:36 2007
New Revision: 515610

URL: http://svn.apache.org/viewvc?view=rev&rev=515610
Log:
CXF-441: the env entries from Servlet context can be injected into handler using the @Resource
annotation 

Added:
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
  (with props)
    incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
  (with props)
Modified:
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
    incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationUsingAddNumbersTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java

Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java?view=diff&rev=515610&r1=515609&r2=515610
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
Wed Mar  7 07:34:36 2007
@@ -48,6 +48,7 @@
 import org.apache.cxf.BusException;
 import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.endpoint.EndpointPublisher;
+import org.apache.cxf.resource.ResourceManager;
 import org.apache.cxf.resource.URIResolver;
 import org.apache.cxf.transport.DestinationFactory;
 import org.apache.cxf.transport.DestinationFactoryManager;
@@ -84,7 +85,7 @@
 
     public void init(ServletConfig servletConfig) throws ServletException {
         super.init(servletConfig);
-
+        
         String busid = servletConfig.getInitParameter("bus.id");
         if (null != busid) {
             WeakReference<Bus> ref = BUS_MAP.get(busid);
@@ -96,6 +97,7 @@
             // try to pull an existing ApplicationContext out of the
             // ServletContext
             ServletContext svCtx = getServletContext();
+
             
             // Spring 1.x
             ApplicationContext ctx = (ApplicationContext)svCtx
@@ -132,6 +134,9 @@
 
         // build endpoints from the web.xml or a config file
         buildEndpoints(servletConfig);
+        
+        ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
+        resourceManager.addResourceResolver(new ServletContextResourceResolver());
     }
     
     // Need to get to know all frontend's endpoint information

Added: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java?view=auto&rev=515610
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
(added)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
Wed Mar  7 07:34:36 2007
@@ -0,0 +1,51 @@
+/**
+ * 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.cxf.transport.servlet;
+
+import java.io.InputStream;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+
+import org.apache.cxf.resource.ResourceResolver;
+
+
+public class ServletContextResourceResolver implements ResourceResolver {
+
+    public final InputStream getAsStream(final String string) {
+        return null;
+    }
+
+    public final <T> T resolve(final String entryName, final Class<T> clz) {
+        Object obj = null;
+        try {
+            InitialContext ic = new InitialContext();
+            obj = ic.lookup(entryName);
+        } catch (NamingException e) {
+            //do nothing
+        }
+        
+        if (obj != null && obj.getClass().isAssignableFrom(clz)) {
+            return clz.cast(obj);
+        }
+        return null;
+    }
+}

Propchange: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java?view=diff&rev=515610&r1=515609&r2=515610
==============================================================================
--- incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
(original)
+++ incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
Wed Mar  7 07:34:36 2007
@@ -48,6 +48,7 @@
 import org.apache.cxf.BusException;
 import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.endpoint.EndpointPublisher;
+import org.apache.cxf.resource.ResourceManager;
 import org.apache.cxf.resource.URIResolver;
 import org.apache.cxf.transport.DestinationFactory;
 import org.apache.cxf.transport.DestinationFactoryManager;
@@ -132,6 +133,9 @@
 
         // build endpoints from the web.xml or a config file
         buildEndpoints(servletConfig);
+        
+        ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
+        resourceManager.addResourceResolver(new ServletContextResourceResolver());
     }
     
     // Need to get to know all frontend's endpoint information

Added: incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java?view=auto&rev=515610
==============================================================================
--- incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
(added)
+++ incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
Wed Mar  7 07:34:36 2007
@@ -0,0 +1,51 @@
+/**
+ * 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.cxf.transport.servlet;
+
+import java.io.InputStream;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+
+import org.apache.cxf.resource.ResourceResolver;
+
+
+public class ServletContextResourceResolver implements ResourceResolver {
+
+    public final InputStream getAsStream(final String string) {
+        return null;
+    }
+
+    public final <T> T resolve(final String entryName, final Class<T> clz) {
+        Object obj = null;
+        try {
+            InitialContext ic = new InitialContext();
+            obj = ic.lookup(entryName);
+        } catch (NamingException e) {
+            //do nothing
+        }
+        
+        if (obj != null && obj.getClass().isAssignableFrom(clz)) {
+            return clz.cast(obj);
+        }
+        return null;
+    }
+}

Propchange: incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationUsingAddNumbersTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationUsingAddNumbersTest.java?view=diff&rev=515610&r1=515609&r2=515610
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationUsingAddNumbersTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/HandlerInvocationUsingAddNumbersTest.java
Wed Mar  7 07:34:36 2007
@@ -34,6 +34,9 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.resource.ResourceManager;
 import org.apache.cxf.systest.common.ClientServerSetupBase;
 import org.apache.cxf.systest.common.ClientServerTestBase;
 import org.apache.handlers.AddNumbers;
@@ -119,6 +122,24 @@
         
         assertTrue(h.isPostConstructInvoked());      
     }  
+    
+    public void testHandlerInjectingResource() throws Exception {
+        //When CXF is deployed in a servlet container, ServletContextResourceResolver is
used to resolve 
+        //Servlet context resources.
+        Bus bus = BusFactory.getDefaultBus();
+        ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
+        resourceManager.addResourceResolver(new TestResourceResolver());
+       
+        URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
+
+        AddNumbersServiceWithAnnotation service = new AddNumbersServiceWithAnnotation(wsdl,
serviceName);
+        AddNumbers port = (AddNumbers)service.getPort(portName, AddNumbers.class);
+
+        List<Handler> handlerChain = ((BindingProvider)port).getBinding().getHandlerChain();
+        SmallNumberHandler h = (SmallNumberHandler)handlerChain.get(0);
+        
+        assertEquals("injectedValue", h.getInjectedString());      
+    } 
     
     private void addHandlersProgrammatically(BindingProvider bp, Handler...handlers) {
         List<Handler> handlerChain = bp.getBinding().getHandlerChain();

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java?view=diff&rev=515610&r1=515609&r2=515610
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/SmallNumberHandler.java
Wed Mar  7 07:34:36 2007
@@ -21,6 +21,7 @@
 import java.util.Map;
 
 import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.ws.LogicalMessage;
@@ -37,7 +38,10 @@
  * handles addition of small numbers.
  */
 public class SmallNumberHandler extends TestHandlerBase implements LogicalHandler<LogicalMessageContext>
{
-
+    @Resource(name = "handlerResource")
+    String injectedString; 
+    
+    
     public SmallNumberHandler() {
         this(true); 
     } 
@@ -120,9 +124,12 @@
     @PostConstruct
     public void doPostConstruct() {
         methodCalled("doPostConstruct");
-        //System.out.println("-----------doPost-------------");
     }
     
+    public String getInjectedString() {
+        return injectedString;        
+    }
+        
     private boolean isSmall(int i) {
         return i > 0 && i <= 10;
     }



Mime
View raw message