cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6593] Protecting against NPE if TL contexts are refreshed
Date Tue, 15 Sep 2015 11:37:35 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes b41bf2602 -> 0405291ed


[CXF-6593] Protecting against NPE if TL contexts are refreshed


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/0405291e
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/0405291e
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/0405291e

Branch: refs/heads/2.7.x-fixes
Commit: 0405291edfe2951f3921e00f0ca48c46535a6f4c
Parents: b41bf26
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Tue Sep 15 12:31:29 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Tue Sep 15 12:36:59 2015 +0100

----------------------------------------------------------------------
 .../impl/tl/ThreadLocalMessageContext.java      | 59 ++++++++++++++------
 .../cxf/jaxrs/impl/tl/ThreadLocalProviders.java | 24 ++++++--
 .../org/apache/cxf/jaxrs/utils/JAXRSUtils.java  | 10 +++-
 3 files changed, 70 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/0405291e/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalMessageContext.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalMessageContext.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalMessageContext.java
index 8b1d143..bd926fd 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalMessageContext.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalMessageContext.java
@@ -30,70 +30,95 @@ import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.Providers;
 
 import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.ext.MessageContextImpl;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.apache.cxf.message.Message;
 
 public class ThreadLocalMessageContext extends AbstractThreadLocalProxy<MessageContext>

     implements MessageContext {
 
     public Object get(Object key) {
-        return get() != null ? get().get(key) : null;
+        MessageContext mc = getCurrentMessageContext();
+        return mc != null ? mc.get(key) : null;
     }
     
     public <T> T getContext(Class<T> contextClass) {
-        return get() != null ? get().getContext(contextClass) : null;
+        MessageContext mc = getCurrentMessageContext();
+        return mc != null ? mc.getContext(contextClass) : null;
     }
 
     public HttpHeaders getHttpHeaders() {
-        return get() != null ? get().getHttpHeaders() : null;
+        MessageContext mc = getCurrentMessageContext();
+        return mc != null ? mc.getHttpHeaders() : null;
     }
 
     public HttpServletRequest getHttpServletRequest() {
-        return get() != null ? get().getHttpServletRequest() : null;
+        MessageContext mc = getCurrentMessageContext();
+        return mc != null ? mc.getHttpServletRequest() : null;
     }
 
     public HttpServletResponse getHttpServletResponse() {
-        return get() != null ? get().getHttpServletResponse() : null;
+        MessageContext mc = getCurrentMessageContext();
+        return mc != null ? mc.getHttpServletResponse() : null;
     }
 
     public Providers getProviders() {
-        return get() != null ? get().getProviders() : null;
+        MessageContext mc = getCurrentMessageContext();
+        return mc != null ? mc.getProviders() : null;
     }
 
     public SecurityContext getSecurityContext() {
-        return get() != null ? get().getSecurityContext() : null;
+        MessageContext mc = getCurrentMessageContext();
+        return mc != null ? mc.getSecurityContext() : null;
     }
 
     public ServletConfig getServletConfig() {
-        return get() != null ? get().getServletConfig() : null;
+        MessageContext mc = getCurrentMessageContext();
+        return mc != null ? mc.getServletConfig() : null;
     }
 
     public ServletContext getServletContext() {
-        return get() != null ? get().getServletContext() : null;
+        MessageContext mc = getCurrentMessageContext();
+        return mc != null ? mc.getServletContext() : null;
     }
 
     public UriInfo getUriInfo() {
-        return get() != null ? get().getUriInfo() : null;
+        MessageContext mc = getCurrentMessageContext();
+        return mc != null ? mc.getUriInfo() : null;
     }
 
     public Request getRequest() {
-        return get() != null ? get().getRequest() : null;
+        MessageContext mc = getCurrentMessageContext();
+        return mc != null ? mc.getRequest() : null;
     }
 
     public void put(Object key, Object value) {
-        if (get() != null) {
-            get().put(key, value);
+        MessageContext mc = getCurrentMessageContext();
+        if (mc != null) {
+            mc.put(key, value);
         }
     }
 
     public <T, E> T getResolver(Class<T> resolverClass, Class<E> resolveClazz)
{
-        return get() != null ? get().getResolver(resolverClass, resolveClazz) : null;
+        MessageContext mc = getCurrentMessageContext();
+        return mc != null ? mc.getResolver(resolverClass, resolveClazz) : null;
     }
 
     public <T> T getContent(Class<T> format) {
-        return get() != null ? get().getContent(format) : null;
+        MessageContext mc = getCurrentMessageContext();
+        return mc != null ? mc.getContent(format) : null;
     }
 
     public Object getContextualProperty(Object key) {
-        return get() != null ? get().getContextualProperty(key) : null;
+        MessageContext mc = getCurrentMessageContext();
+        return mc != null ? mc.getContextualProperty(key) : null;
+    }
+    private MessageContext getCurrentMessageContext() {
+        MessageContext mc = get();
+        return mc != null ? mc : getMessageContextImpl();
+    }
+    private MessageContext getMessageContextImpl() {
+        Message m = JAXRSUtils.getCurrentMessage();
+        return m != null ? new MessageContextImpl(m) : null;
     }
-
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/0405291e/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProviders.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProviders.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProviders.java
index a18d95b..bf19585 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProviders.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalProviders.java
@@ -29,6 +29,10 @@ import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Providers;
 
+import org.apache.cxf.jaxrs.impl.ProvidersImpl;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.apache.cxf.message.Message;
+
 public class ThreadLocalProviders extends AbstractThreadLocalProxy<Providers>
        implements Providers {
 
@@ -36,22 +40,34 @@ public class ThreadLocalProviders extends AbstractThreadLocalProxy<Providers>
                                                          Type genericType, 
                                                          Annotation[] annotations,
                                                          MediaType mediaType) {
-        return get().getMessageBodyReader(type, genericType, annotations, mediaType);
+        Providers p = getCurrentProviders();
+        return p != null ? p.getMessageBodyReader(type, genericType, annotations, mediaType)
: null;
     }
 
     public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type,

                                                          Type genericType, 
                                                          Annotation[] annotations,
                                                          MediaType mediaType) {
-        return get().getMessageBodyWriter(type, genericType, annotations, mediaType);
+        Providers p = getCurrentProviders();
+        return p != null ? p.getMessageBodyWriter(type, genericType, annotations, mediaType)
: null;
     }
 
     public <T> ContextResolver<T> getContextResolver(Class<T> contextType,
MediaType mediaType) {
-        return get().getContextResolver(contextType, mediaType);
+        Providers p = getCurrentProviders();
+        return p != null ? p.getContextResolver(contextType, mediaType) : null;
     }
 
     public <T extends Throwable> ExceptionMapper<T> getExceptionMapper(Class<T>
type) {
-        return get().getExceptionMapper(type);
+        Providers p = getCurrentProviders();
+        return p != null ? p.getExceptionMapper(type) : null;
     }
 
+    private Providers getCurrentProviders() {
+        Providers p = get();
+        return p != null ? p : getProvidersImpl();
+    }
+    private Providers getProvidersImpl() {
+        Message m = JAXRSUtils.getCurrentMessage();
+        return m != null ? new ProvidersImpl(JAXRSUtils.getContextMessage(m)) : null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/0405291e/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
index 130c75e..a5371dd 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
@@ -987,12 +987,18 @@ public final class JAXRSUtils {
         return instance;
     }
     
-    public static <T> T createContextValue(Message m, Type genericType, Class<T>
clazz) {
- 
+    public static Message getContextMessage(Message m) {
+        
         Message contextMessage = m.getExchange() != null ? m.getExchange().getInMessage()
: m;
         if (contextMessage == null && Boolean.FALSE.equals(m.get(Message.INBOUND_MESSAGE)))
{
             contextMessage = m;
         }
+        return contextMessage;
+    }
+    
+    public static <T> T createContextValue(Message m, Type genericType, Class<T>
clazz) {
+ 
+        Message contextMessage = getContextMessage(m);
         Object o = null;
         if (UriInfo.class.isAssignableFrom(clazz)) {
             o = createUriInfo(contextMessage);


Mime
View raw message