cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r711635 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalHttpServletResponse.java main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Date Wed, 05 Nov 2008 17:39:39 GMT
Author: sergeyb
Date: Wed Nov  5 09:39:37 2008
New Revision: 711635

URL: http://svn.apache.org/viewvc?rev=711635&view=rev
Log:
JAX-RS : minor fix to enable @Resource proxies plus adding HttpServletResponse proxy

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalHttpServletResponse.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/utils/JAXRSUtilsTest.java

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalHttpServletResponse.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalHttpServletResponse.java?rev=711635&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalHttpServletResponse.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalHttpServletResponse.java
Wed Nov  5 09:39:37 2008
@@ -0,0 +1,179 @@
+/**
+ * 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.IOException;
+import java.io.PrintWriter;
+import java.util.Locale;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+
+public class ThreadLocalHttpServletResponse extends AbstractThreadLocalProxy<HttpServletResponse>

+    implements HttpServletResponse {
+
+    public void addCookie(Cookie cookie) {
+        get().addCookie(cookie);
+        
+    }
+
+    public void addDateHeader(String name, long date) {
+        get().addDateHeader(name, date);
+    }
+
+    public void addHeader(String name, String value) {
+        get().addHeader(name, value);
+        
+    }
+
+    public void addIntHeader(String name, int value) {
+        get().addIntHeader(name, value);
+        
+    }
+
+    public boolean containsHeader(String name) {
+        return get().containsHeader(name);
+    }
+
+    public String encodeRedirectURL(String url) {
+        return get().encodeRedirectURL(url);
+    }
+
+    @SuppressWarnings("deprecation")
+    public String encodeRedirectUrl(String url) {
+        return get().encodeRedirectUrl(url);
+    }
+
+    public String encodeURL(String url) {
+        return get().encodeURL(url);
+    }
+
+    @SuppressWarnings("deprecation")
+    public String encodeUrl(String url) {
+        return get().encodeUrl(url);
+    }
+
+    public void sendError(int sc) throws IOException {
+        get().sendError(sc);
+    }
+
+    public void sendError(int sc, String msg) throws IOException {
+        get().sendError(sc, msg);
+    }
+
+    public void sendRedirect(String location) throws IOException {
+        get().sendRedirect(location);
+    }
+
+    public void setDateHeader(String name, long date) {
+        get().setDateHeader(name, date);
+    }
+
+    public void setHeader(String name, String value) {
+        get().setHeader(name, value);
+        
+    }
+
+    public void setIntHeader(String name, int value) {
+        get().setIntHeader(name, value);
+    }
+
+    public void setStatus(int sc) {
+        get().setStatus(sc);
+        
+    }
+
+    @SuppressWarnings("deprecation")
+    public void setStatus(int sc, String sm) {
+        get().setStatus(sc, sm);
+    }
+
+    public void flushBuffer() throws IOException {
+        get().flushBuffer();
+        
+    }
+
+    public int getBufferSize() {
+        return get().getBufferSize();
+    }
+
+    public String getCharacterEncoding() {
+        return get().getCharacterEncoding();
+    }
+
+    public String getContentType() {
+        return get().getContentType();
+    }
+
+    public Locale getLocale() {
+        return get().getLocale();
+    }
+
+    public ServletOutputStream getOutputStream() throws IOException {
+        return get().getOutputStream();
+    }
+
+    public PrintWriter getWriter() throws IOException {
+        return get().getWriter();
+    }
+
+    public boolean isCommitted() {
+        return get().isCommitted();
+    }
+
+    public void reset() {
+        get().reset();
+        
+    }
+
+    public void resetBuffer() {
+        get().resetBuffer();
+        
+    }
+
+    public void setBufferSize(int size) {
+        get().setBufferSize(size);
+        
+    }
+
+    public void setCharacterEncoding(String charset) {
+        get().setCharacterEncoding(charset);
+        
+    }
+
+    public void setContentLength(int len) {
+        get().setContentLength(len);
+        
+    }
+
+    public void setContentType(String type) {
+        get().setContentType(type);
+        
+    }
+
+    public void setLocale(Locale loc) {
+        get().setLocale(loc);
+        
+    }
+
+    
+
+}

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

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalHttpServletResponse.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=711635&r1=711634&r2=711635&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
Wed Nov  5 09:39:37 2008
@@ -41,6 +41,7 @@
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Request;
@@ -55,6 +56,7 @@
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalContextResolver;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpHeaders;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpServletRequest;
+import org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpServletResponse;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalMessageBodyWorkers;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalRequest;
@@ -296,6 +298,8 @@
             proxy = new ThreadLocalHttpServletRequest();
         } else if (ServletContext.class.isAssignableFrom(type)) {
             proxy = new ThreadLocalServletContext();
+        } else if (HttpServletResponse.class.isAssignableFrom(type)) {
+            proxy = new ThreadLocalHttpServletResponse();
         }
         return proxy;
     }
@@ -314,6 +318,11 @@
             ThreadLocalProxy proxy = cri.getContextFieldProxy(f);
             InjectionUtils.injectFieldValue(f, instance, proxy);
         }
+        
+        for (Field f : cri.getResourceFields()) {
+            ThreadLocalProxy proxy = cri.getResourceFieldProxy(f);
+            InjectionUtils.injectFieldValue(f, instance, proxy);
+        }
     }
     
     @SuppressWarnings("unchecked")

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=711635&r1=711634&r2=711635&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
Wed Nov  5 09:39:37 2008
@@ -700,6 +700,10 @@
         m.put(Message.PROTOCOL_HEADERS, new HashMap<String, List<String>>());
         ServletContext servletContextMock = EasyMock.createNiceMock(ServletContext.class);
         m.put(AbstractHTTPDestination.HTTP_CONTEXT, servletContextMock);
+        HttpServletRequest httpRequest = EasyMock.createNiceMock(HttpServletRequest.class);
+        m.put(AbstractHTTPDestination.HTTP_REQUEST, httpRequest);
+        HttpServletResponse httpResponse = EasyMock.createNiceMock(HttpServletResponse.class);
+        m.put(AbstractHTTPDestination.HTTP_RESPONSE, httpResponse);
         
         InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance());
         InjectionUtils.injectContextFields(c, cri, m);
@@ -720,6 +724,37 @@
   
         assertSame(servletContextMock, 
                    ((ThreadLocalProxy)c.getThreadLocalServletContext()).get());
+        assertSame(servletContextMock, 
+                   ((ThreadLocalProxy)c.getServletContext()).get());
+        
+        assertSame(httpRequest, 
+                   ((ThreadLocalProxy)c.getServletRequest()).get());
+        assertSame(httpResponse, 
+                   ((ThreadLocalProxy)c.getServletResponse()).get());
+    }
+    
+    @Test
+    public void testSingletonHttpResourceFields() throws Exception {
+        
+        ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
+        Customer c = new Customer();
+        cri.setResourceProvider(new SingletonResourceProvider(c));
+                
+        Message m = new MessageImpl();
+        ServletContext servletContextMock = EasyMock.createNiceMock(ServletContext.class);
+        m.put(AbstractHTTPDestination.HTTP_CONTEXT, servletContextMock);
+        HttpServletRequest httpRequest = EasyMock.createNiceMock(HttpServletRequest.class);
+        m.put(AbstractHTTPDestination.HTTP_REQUEST, httpRequest);
+        HttpServletResponse httpResponse = EasyMock.createNiceMock(HttpServletResponse.class);
+        m.put(AbstractHTTPDestination.HTTP_RESPONSE, httpResponse);
+        InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance());
+        InjectionUtils.injectResourceFields(c, cri, m);
+        assertSame(servletContextMock, 
+                   ((ThreadLocalProxy)c.getServletContextResource()).get());
+        assertSame(httpRequest, 
+                   ((ThreadLocalProxy)c.getServletRequestResource()).get());
+        assertSame(httpResponse, 
+                   ((ThreadLocalProxy)c.getServletResponseResource()).get());
     }
     
     @Test



Mime
View raw message