You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/08/13 10:31:52 UTC

[2/4] git commit: CAMEL-7691: camel-serlvet - Potential NPE if no servlet name configured for osgi

CAMEL-7691: camel-serlvet - Potential NPE if no servlet name configured for osgi


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7507c492
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7507c492
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7507c492

Branch: refs/heads/camel-2.12.x
Commit: 7507c4928e937122d679fdfecbc15f02f7060024
Parents: 13b5793
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Aug 13 10:25:17 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Aug 13 10:31:29 2014 +0200

----------------------------------------------------------------------
 .../servlet/osgi/OsgiServletRegisterer.java     | 28 ++++++++++++++------
 1 file changed, 20 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7507c492/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/osgi/OsgiServletRegisterer.java
----------------------------------------------------------------------
diff --git a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/osgi/OsgiServletRegisterer.java b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/osgi/OsgiServletRegisterer.java
index 6c786ad..429f9e5 100644
--- a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/osgi/OsgiServletRegisterer.java
+++ b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/osgi/OsgiServletRegisterer.java
@@ -20,6 +20,7 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 import javax.servlet.http.HttpServlet;
 
+import org.apache.camel.util.ObjectHelper;
 import org.osgi.service.http.HttpContext;
 import org.osgi.service.http.HttpService;
 
@@ -38,8 +39,11 @@ public class OsgiServletRegisterer {
      * of the form "/" is used to denote the root alias.
      */
     private String alias;
-    
-    private String servletName;
+
+    /**
+     * The servlet name.
+     */
+    private String servletName = "CamelServlet";
 
     /**
      * Servlet to be registered
@@ -47,14 +51,16 @@ public class OsgiServletRegisterer {
     private HttpServlet servlet;
     
     /**
-     * HttpService to register with. Get this with osgi:reference in the spring
-     * context
+     * HttpService to register with. Get this with osgi:reference in the blueprint/spring-dm file
      */
     private HttpService httpService;
     
     private HttpContext httpContext;
     
     private boolean alreadyRegistered;
+
+    // The servlet will default have to match on uri prefix as some endpoints may do so
+    private volatile boolean matchOnUriPrefix = true;
     
     public void setHttpService(HttpService httpService) {
         this.httpService = httpService;
@@ -75,14 +81,20 @@ public class OsgiServletRegisterer {
     public void setHttpContext(HttpContext httpContext) {
         this.httpContext = httpContext;
     }
- 
+
+    public void setMatchOnUriPrefix(boolean matchOnUriPrefix) {
+        this.matchOnUriPrefix = matchOnUriPrefix;
+    }
+
     public void register() throws Exception {
-        HttpContext actualHttpContext = (httpContext == null) 
+        ObjectHelper.notEmpty(alias, "alias", this);
+        ObjectHelper.notEmpty(servletName, "servletName", this);
+
+        HttpContext actualHttpContext = (httpContext == null)
             ? httpService.createDefaultHttpContext()
             : httpContext;
         final Dictionary<String, String> initParams = new Hashtable<String, String>();
-        // The servlet will always have to match on uri prefix as some endpoints may do so
-        initParams.put("matchOnUriPrefix", "true");
+        initParams.put("matchOnUriPrefix", matchOnUriPrefix ? "true" : "false");
         initParams.put("servlet-name", servletName);
         httpService.registerServlet(alias, servlet, initParams, actualHttpContext);
         alreadyRegistered = true;