cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject git commit: Fix a startup race condition that could lead to a NPE
Date Tue, 03 Jun 2014 18:47:54 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 8b457fda0 -> 8c138e035


Fix a startup race condition that could lead to a NPE


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

Branch: refs/heads/master
Commit: 8c138e03557e85601a5f2a4a10905eda5673590f
Parents: 8b457fd
Author: Daniel Kulp <dkulp@apache.org>
Authored: Tue Jun 3 11:52:18 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Tue Jun 3 14:47:51 2014 -0400

----------------------------------------------------------------------
 .../http_jetty/JettyHTTPDestination.java        |  6 ++--
 .../transport/http/AbstractHTTPDestination.java | 33 +++++++++++++-------
 2 files changed, 25 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/8c138e03/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
----------------------------------------------------------------------
diff --git a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
index c82a9ba..703b552 100644
--- a/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
+++ b/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPDestination.java
@@ -51,6 +51,7 @@ import org.apache.cxf.transport.http.AbstractHTTPDestination;
 import org.apache.cxf.transport.http.DestinationRegistry;
 import org.apache.cxf.transport.http_jetty.continuations.JettyContinuationProvider;
 import org.apache.cxf.transport.https.CertConstraintsJaxBUtils;
+import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
 import org.eclipse.jetty.http.Generator;
 import org.eclipse.jetty.io.AbstractConnection;
 import org.eclipse.jetty.server.AbstractHttpConnection.Output;
@@ -242,8 +243,9 @@ public class JettyHTTPDestination extends AbstractHTTPDestination {
                 setHeadFalse(c);
             }
         }
-        if (getServer().isSetRedirectURL()) {
-            resp.sendRedirect(getServer().getRedirectURL());
+        HTTPServerPolicy sp = getServer();
+        if (sp.isSetRedirectURL()) {
+            resp.sendRedirect(sp.getRedirectURL());
             resp.flushBuffer();
             baseRequest.setHandled(true);
             return;

http://git-wip-us.apache.org/repos/asf/cxf/blob/8c138e03/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
index 019a515..62367c5 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
@@ -111,7 +111,7 @@ public abstract class AbstractHTTPDestination
     protected final String path;
 
     // Configuration values
-    protected HTTPServerPolicy serverPolicy;
+    protected volatile HTTPServerPolicy serverPolicy;
     protected String contextMatchStrategy = "stem";
     protected boolean fixedParameterOrder;
     protected boolean multiplexWithAddress;
@@ -513,18 +513,28 @@ public abstract class AbstractHTTPDestination
         cproviderFactory = bus.getExtension(ContinuationProviderFactory.class);
     }
 
-    private void calcServerPolicy(Message m) {
+    private synchronized HTTPServerPolicy calcServerPolicyInternal(Message m) {
+        HTTPServerPolicy sp = serverPolicy;
         if (!serverPolicyCalced) {
             PolicyDataEngine pde = bus.getExtension(PolicyDataEngine.class);
             if (pde != null) {
-                serverPolicy = pde.getServerEndpointPolicy(m, endpointInfo, this, new ServerPolicyCalculator());
+                sp = pde.getServerEndpointPolicy(m, endpointInfo, this, new ServerPolicyCalculator());
             }
-            if (null == serverPolicy) {
-                serverPolicy = endpointInfo.getTraversedExtensor(
+            if (null == sp) {
+                sp = endpointInfo.getTraversedExtensor(
                         new HTTPServerPolicy(), HTTPServerPolicy.class);
             }
+            serverPolicy = sp;
+            serverPolicyCalced = true;
+        }
+        return sp;
+    }
+    private HTTPServerPolicy calcServerPolicy(Message m) {
+        HTTPServerPolicy sp = serverPolicy;
+        if (!serverPolicyCalced) {
+            sp = calcServerPolicyInternal(m);
         }
-        serverPolicyCalced = true;
+        return sp;
     }
     
     /**
@@ -581,9 +591,9 @@ public abstract class AbstractHTTPDestination
         }
 
         cacheInput(outMessage);
-        calcServerPolicy(outMessage);
-        if (serverPolicy != null) {
-            new Headers(outMessage).setFromServerPolicy(serverPolicy);
+        HTTPServerPolicy sp = calcServerPolicy(outMessage);
+        if (sp != null) {
+            new Headers(outMessage).setFromServerPolicy(sp);
         }
 
         OutputStream responseStream = null;
@@ -879,8 +889,7 @@ public abstract class AbstractHTTPDestination
     }
 
     public HTTPServerPolicy getServer() {
-        calcServerPolicy(null);
-        return serverPolicy;
+        return calcServerPolicy(null);
     }
 
     public void setServer(HTTPServerPolicy server) {
@@ -892,7 +901,7 @@ public abstract class AbstractHTTPDestination
     
     public void assertMessage(Message message) {
         PolicyDataEngine pde = bus.getExtension(PolicyDataEngine.class);
-        pde.assertMessage(message, serverPolicy, new ServerPolicyCalculator());
+        pde.assertMessage(message, calcServerPolicy(message), new ServerPolicyCalculator());
     }
 
     public boolean canAssert(QName type) {


Mime
View raw message