tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sl...@apache.org
Subject svn commit: r955860 - /tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java
Date Fri, 18 Jun 2010 07:06:31 GMT
Author: slaws
Date: Fri Jun 18 07:06:31 2010
New Revision: 955860

URL: http://svn.apache.org/viewvc?rev=955860&view=rev
Log:
Check for message context being null to prevent NPE when these methods are called from a new
thread. 

Modified:
    tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java

Modified: tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java?rev=955860&r1=955859&r2=955860&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java
Fri Jun 18 07:06:31 2010
@@ -43,9 +43,17 @@ public class RequestContextImpl implemen
     }
 
     public Subject getSecuritySubject() {
-        Subject subject = null;
         
-        for (Object header : ThreadMessageContext.getMessageContext().getHeaders().values()){
+        Message msgContext = ThreadMessageContext.getMessageContext();
+        
+        if (msgContext == null){
+            // message in thread context could be null if the user has 
+            // spun up a new thread inside their component implementation 
+            return null;
+        }
+        
+        Subject subject = null;
+        for (Object header : msgContext.getHeaders().values()){
             if (header instanceof Subject){
                 subject  = (Subject)header;
                 break;
@@ -55,11 +63,24 @@ public class RequestContextImpl implemen
     }
 
     public String getServiceName() {
-        return ThreadMessageContext.getMessageContext().getTo().getService().getName();
+        Message msgContext = ThreadMessageContext.getMessageContext();
+        
+        if (msgContext != null){
+            return msgContext.getTo().getService().getName();
+        } else {
+            // message in thread context could be null if the user has 
+            // spun up a new thread inside their component implementation 
+            return null;
+        }
     }
 
     public <B> ServiceReference<B> getServiceReference() {
         Message msgContext = ThreadMessageContext.getMessageContext();
+        if (msgContext == null){
+            // message in thread context could be null if the user has 
+            // spun up a new thread inside their component implementation 
+            return null;
+        }
         // FIXME: [rfeng] Is this the service reference matching the caller side?
         RuntimeEndpoint to = (RuntimeEndpoint) msgContext.getTo();
         RuntimeComponent component = (RuntimeComponent) to.getComponent();
@@ -80,6 +101,12 @@ public class RequestContextImpl implemen
     @SuppressWarnings("unchecked")
     public <CB> ServiceReference<CB> getCallbackReference() {
         Message msgContext = ThreadMessageContext.getMessageContext();
+        if (msgContext == null){
+            // message in thread context could be null if the user has 
+            // spun up a new thread inside their component implementation 
+            return null;
+        }
+        
         Endpoint to = msgContext.getTo();
         RuntimeComponentService service = (RuntimeComponentService) to.getService();
         RuntimeComponentReference callbackReference = (RuntimeComponentReference)service.getCallbackReference();



Mime
View raw message