cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r728696 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/javascript/src/test/java/org/a...
Date Mon, 22 Dec 2008 14:02:19 GMT
Author: sergeyb
Date: Mon Dec 22 06:02:18 2008
New Revision: 728696

URL: http://svn.apache.org/viewvc?rev=728696&view=rev
Log:
JAXRS : fixing resource injection issue which leads to JAXWS WebServiceContext being lost
if jaxws:endpoint is initialized first

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalMessageContext.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
    cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/MtoMTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalMessageContext.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalMessageContext.java?rev=728696&r1=728695&r2=728696&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalMessageContext.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalMessageContext.java
Mon Dec 22 06:02:18 2008
@@ -35,47 +35,47 @@
     implements MessageContext {
 
     public Object get(Object key) {
-        return get().get(key);
+        return get() != null ? get().get(key) : null;
     }
 
     public <T> T getContext(Class<T> contextClass) {
-        return get().getContext(contextClass);
+        return get() != null ? get().getContext(contextClass) : null;
     }
 
     public HttpHeaders getHttpHeaders() {
-        return get().getHttpHeaders();
+        return get() != null ? get().getHttpHeaders() : null;
     }
 
     public HttpServletRequest getHttpServletRequest() {
-        return get().getHttpServletRequest();
+        return get() != null ? get().getHttpServletRequest() : null;
     }
 
     public HttpServletResponse getHttpServletResponse() {
-        return get().getHttpServletResponse();
+        return get() != null ? get().getHttpServletResponse() : null;
     }
 
     public Providers getProviders() {
-        return get().getProviders();
+        return get() != null ? get().getProviders() : null;
     }
 
     public SecurityContext getSecurityContext() {
-        return get().getSecurityContext();
+        return get() != null ? get().getSecurityContext() : null;
     }
 
     public ServletConfig getServletConfig() {
-        return get().getServletConfig();
+        return get() != null ? get().getServletConfig() : null;
     }
 
     public ServletContext getServletContext() {
-        return get().getServletContext();
+        return get() != null ? get().getServletContext() : null;
     }
 
     public UriInfo getUriInfo() {
-        return get().getUriInfo();
+        return get() != null ? get().getUriInfo() : null;
     }
 
     public Request getRequest() {
-        return get().getRequest();
+        return get() != null ? get().getRequest() : null;
     }
 
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java?rev=728696&r1=728695&r2=728696&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
Mon Dec 22 06:02:18 2008
@@ -79,7 +79,8 @@
                         fieldProxyMap = new HashMap<Field, ThreadLocalProxy>();
                     }
                     fieldProxyMap.put(f, InjectionUtils.createThreadLocalProxy(f.getType()));
-                } else if (a.annotationType() == Resource.class) {
+                } else if (a.annotationType() == Resource.class 
+                           && AnnotationUtils.isContextClass(f.getType())) {
                     if (resourceFields == null) {
                         resourceFields = new ArrayList<Field>();
                     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java?rev=728696&r1=728695&r2=728696&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
Mon Dec 22 06:02:18 2008
@@ -24,6 +24,7 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -47,6 +48,7 @@
 import javax.ws.rs.ext.ContextResolver;
 import javax.ws.rs.ext.Providers;
 
+import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 
 public final class AnnotationUtils {
@@ -75,7 +77,10 @@
         classes.add(Request.class);
         classes.add(HttpServletRequest.class);
         classes.add(HttpServletResponse.class);
+        classes.add(ServletConfig.class);
         classes.add(ServletContext.class);
+        // CXF-specific
+        classes.add(MessageContext.class);
         return classes;
     }
     

Modified: cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/MtoMTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/MtoMTest.java?rev=728696&r1=728695&r2=728696&view=diff
==============================================================================
--- cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/MtoMTest.java (original)
+++ cxf/trunk/rt/javascript/src/test/java/org/apache/cxf/javascript/MtoMTest.java Mon Dec
22 06:02:18 2008
@@ -85,7 +85,7 @@
         Notifier notifier = 
             testUtilities.rhinoCallConvert("testMtoMReply", Notifier.class, 
                                            testUtilities.javaToJS(getAddress()));
-        boolean notified = notifier.waitForJavascript(1000 * 10);
+        boolean notified = notifier.waitForJavascript(1000 * 30);
         assertTrue(notified);
         Integer errorStatus = testUtilities.rhinoEvaluateConvert("globalErrorStatus", Integer.class);
         String errorText = testUtilities.rhinoEvaluateConvert("globalErrorStatusText", String.class);

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java?rev=728696&r1=728695&r2=728696&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSoapRestImpl.java
Mon Dec 22 06:02:18 2008
@@ -22,18 +22,27 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import javax.jws.WebService;
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.xml.ws.WebServiceContext;
+
+import org.apache.cxf.jaxrs.ext.MessageContext;
 
-@WebService
 public class BookStoreSoapRestImpl implements BookStoreJaxrsJaxws {
 
     private Map<Long, Book> books = new HashMap<Long, Book>();
     
+    @Resource
+    private WebServiceContext jaxwsContext;
+    @Resource
+    private MessageContext jaxrsContext;
+    
     public BookStoreSoapRestImpl() {
         init();
     }
     
     public Book getBook(Long id) {
+        System.out.println(getContentType());
         return books.get(id);
     }
     
@@ -49,4 +58,17 @@
         book.setName("CXF in Action");
         books.put(book.getId(), book);
     }
+ 
+    private String getContentType() {
+        
+        // TODO : it may be worth indeed to introduce a shared ServiceContext
+        // such that users combining JAXWS and JAXRS won't have to write if/else code 
+        HttpServletRequest request = jaxrsContext.getHttpServletRequest();
+        if (request == null) {
+            request = (HttpServletRequest)jaxwsContext.getMessageContext().get(
+                 javax.xml.ws.handler.MessageContext.SERVLET_REQUEST);
+        }
+        return request.getContentType();
+    }
+    
 }



Mime
View raw message