summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/core/src/main/java
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-06-18 07:06:31 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-06-18 07:06:31 +0000
commit51bf2ceb4c1f9742e3945a68154bfd8abec76121 (patch)
tree33f82e6550f7bc7d05091ba2e78f8c2a69a6dad1 /sca-java-2.x/trunk/modules/core/src/main/java
parent1f2fae11626783faca4725ef5fb05b8f9dd8d974 (diff)
Check for message context being null to prevent NPE when these methods are called from a new thread.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@955860 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/core/src/main/java')
-rw-r--r--sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java33
1 files changed, 30 insertions, 3 deletions
diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java
index 1b2d79e4f1..5d0527682e 100644
--- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java
+++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/RequestContextImpl.java
@@ -43,9 +43,17 @@ public class RequestContextImpl implements RequestContext {
}
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 implements RequestContext {
}
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 implements RequestContext {
@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();