cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r705235 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/impl/tl/ main/java/org/apache/cxf/jaxrs/utils/ test/java/org/apache/cxf/jaxrs/ test/java/org/apache/cxf/jaxrs/utils/
Date Thu, 16 Oct 2008 13:12:53 GMT
Author: sergeyb
Date: Thu Oct 16 06:12:51 2008
New Revision: 705235

URL: http://svn.apache.org/viewvc?rev=705235&view=rev
Log:
JAX-RS : adding a thread-local ServletContext handler

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalServletContext.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalServletContext.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalServletContext.java?rev=705235&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalServletContext.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalServletContext.java
Thu Oct 16 06:12:51 2008
@@ -0,0 +1,141 @@
+/**
+ * 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.jaxrs.impl.tl;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Set;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+public class ThreadLocalServletContext extends AbstractThreadLocalProxy<ServletContext>

+    implements ServletContext {
+
+    public Object getAttribute(String name) {
+        return get().getAttribute(name);
+    }
+
+    public Enumeration getAttributeNames() {
+        return get().getAttributeNames();
+    }
+
+    public ServletContext getContext(String uripath) {
+        return get().getContext(uripath);
+    }
+
+    public String getContextPath() {
+        return get().getContextPath();
+    }
+
+    public String getInitParameter(String name) {
+        return get().getInitParameter(name);
+    }
+
+    public Enumeration getInitParameterNames() {
+        return get().getInitParameterNames();
+    }
+
+    public int getMajorVersion() {
+        return get().getMajorVersion();
+    }
+
+    public String getMimeType(String file) {
+        return get().getMimeType(file);
+    }
+
+    public int getMinorVersion() {
+        return get().getMinorVersion();
+    }
+
+    public RequestDispatcher getNamedDispatcher(String name) {
+        return get().getNamedDispatcher(name);
+    }
+
+    public String getRealPath(String path) {
+        return get().getRealPath(path);
+    }
+
+    public RequestDispatcher getRequestDispatcher(String path) {
+        return get().getRequestDispatcher(path);
+    }
+
+    public URL getResource(String path) throws MalformedURLException {
+        return get().getResource(path);
+    }
+
+    public InputStream getResourceAsStream(String path) {
+        return get().getResourceAsStream(path);
+    }
+
+    public Set getResourcePaths(String path) {
+        return get().getResourcePaths(path);
+    }
+
+    public String getServerInfo() {
+        return get().getServerInfo();
+    }
+
+    @SuppressWarnings("deprecation")
+    public Servlet getServlet(String name) throws ServletException {
+        return get().getServlet(name);
+    }
+
+    public String getServletContextName() {
+        return get().getServletContextName();
+    }
+
+    @SuppressWarnings("deprecation")
+    public Enumeration getServletNames() {
+        return get().getServletNames();
+    }
+
+    @SuppressWarnings("deprecation")
+    public Enumeration getServlets() {
+        return get().getServlets();
+    }
+
+    public void log(String msg) {
+        get().log(msg);        
+    }
+
+    @SuppressWarnings("deprecation")
+    public void log(Exception exception, String msg) {
+        get().log(exception, msg);
+    }
+
+    public void log(String message, Throwable throwable) {
+        get().log(message, throwable);
+    }
+
+    public void removeAttribute(String name) {
+        get().removeAttribute(name);
+    }
+
+    public void setAttribute(String name, Object object) {
+        get().setAttribute(name, object);
+        
+    }
+
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalServletContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalServletContext.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=705235&r1=705234&r2=705235&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Thu Oct 16 06:12:51 2008
@@ -39,6 +39,7 @@
 import java.util.TreeSet;
 import java.util.logging.Logger;
 
+import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MultivaluedMap;
@@ -58,6 +59,7 @@
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalRequest;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalSecurityContext;
+import org.apache.cxf.jaxrs.impl.tl.ThreadLocalServletContext;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalUriInfo;
 import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
 import org.apache.cxf.message.Message;
@@ -292,6 +294,8 @@
             proxy = new ThreadLocalMessageBodyWorkers();
         } else if (HttpServletRequest.class.isAssignableFrom(type)) {
             proxy = new ThreadLocalHttpServletRequest();
+        } else if (ServletContext.class.isAssignableFrom(type)) {
+            proxy = new ThreadLocalServletContext();
         }
         return proxy;
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=705235&r1=705234&r2=705235&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java Thu Oct 16
06:12:51 2008
@@ -76,6 +76,7 @@
     @Context private HttpServletRequest servletRequest2;
     @Context private HttpServletResponse servletResponse2;
     @Context private ServletContext servletContext2;
+    private ServletContext servletContext3;
     
     @Context private UriInfo uriInfo2;
     private String queryParam;
@@ -106,6 +107,15 @@
         uriInfo = ui;
     }
     
+    @Context
+    public void setServletContext(ServletContext sc) {
+        servletContext3 = sc;
+    }
+    
+    public ServletContext getThreadLocalServletContext() {
+        return servletContext3;
+    }
+    
     @QueryParam("a")
     public void setA(String a) {
         queryParam = a;

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=705235&r1=705234&r2=705235&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Thu Oct 16 06:12:51 2008
@@ -671,12 +671,15 @@
         ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
         Customer c = new Customer();
         cri.setResourceProvider(new SingletonResourceProvider(c));
-        InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance());
-        
+                
         Message m = new MessageImpl();
         m.put(Message.PROTOCOL_HEADERS, new HashMap<String, List<String>>());
+        ServletContext servletContextMock = EasyMock.createNiceMock(ServletContext.class);
+        m.put(AbstractHTTPDestination.HTTP_CONTEXT, servletContextMock);
         
+        InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance());
         InjectionUtils.injectContextFields(c, cri, m);
+        InjectionUtils.injectContextMethods(c, cri, m);
         assertSame(ThreadLocalUriInfo.class, c.getUriInfo2().getClass());
         assertSame(UriInfoImpl.class, 
                    ((ThreadLocalProxy)c.getUriInfo2()).get().getClass());
@@ -688,7 +691,11 @@
                    ((ThreadLocalProxy)c.getSecurityContext()).get().getClass());
         assertSame(MessageBodyWorkersImpl.class, 
                    ((ThreadLocalProxy)c.getBodyWorkers()).get().getClass());
-        
+        assertSame(MessageBodyWorkersImpl.class, 
+                   ((ThreadLocalProxy)c.getBodyWorkers()).get().getClass());
+  
+        assertSame(servletContextMock, 
+                   ((ThreadLocalProxy)c.getThreadLocalServletContext()).get());
     }
     
     @Test



Mime
View raw message