[grizzly~git:218e5253] [2.3.x] + fix issue #1663

  • From: oleksiys@...
  • To: commits@...
  • Subject: [grizzly~git:218e5253] [2.3.x] + fix issue #1663
  • Date: Sat, 15 Mar 2014 00:05:48 +0000

Project:    grizzly
Repository: git
Revision:   218e5253687467c2049409b35ef6bfa8ab2350d8
Author:     oleksiys
Date:       2014-03-15 00:05:34 UTC
Link:       

Log Message:
------------
[2.3.x] + fix issue #1663
https://java.net/jira/browse/GRIZZLY-1663
"NPE when registering a servlet in grizzly-httpservice"


Revisions:
----------
218e5253687467c2049409b35ef6bfa8ab2350d8


Modified Paths:
---------------
extras/grizzly-httpservice/src/main/java/org/glassfish/grizzly/osgi/httpservice/OSGiCleanMapper.java
extras/grizzly-httpservice/src/main/java/org/glassfish/grizzly/osgi/httpservice/OSGiMainHandler.java


Diffs:
------
--- 
a/extras/grizzly-httpservice/src/main/java/org/glassfish/grizzly/osgi/httpservice/OSGiCleanMapper.java
+++ 
b/extras/grizzly-httpservice/src/main/java/org/glassfish/grizzly/osgi/httpservice/OSGiCleanMapper.java
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2009-2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2014 Oracle and/or its affiliates. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -40,7 +40,6 @@
 
 package org.glassfish.grizzly.osgi.httpservice;
 
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -70,11 +69,11 @@ class OSGiCleanMapper {
     private static final Set<Servlet> registeredServlets = new 
HashSet<Servlet>(16);
 
     private Set<String> localAliases = new HashSet<String>(4);
-    private HashMap<HttpContext, ArrayList<OSGiServletHandler>> 
contextServletHandlerMap =
-            new HashMap<HttpContext, ArrayList<OSGiServletHandler>>(3);
+    private final HashMap<HttpContext, List<OSGiServletHandler>> 
contextServletHandlerMap =
+            new HashMap<HttpContext, List<OSGiServletHandler>>(3);
     private final Logger logger;
 
-    protected Map<HttpContext, OSGiServletContext> 
httpContextToServletContextMap =
+    protected final Map<HttpContext, OSGiServletContext> 
httpContextToServletContextMap =
                 new HashMap<HttpContext, OSGiServletContext>();
 
 
@@ -272,7 +271,7 @@ class OSGiCleanMapper {
         return contextServletHandlerMap.get(httpContext);
     }
 
-    public void addContext(HttpContext httpContext, 
ArrayList<OSGiServletHandler> servletHandlers) {
+    public void addContext(HttpContext httpContext, List<OSGiServletHandler> 
servletHandlers) {
         contextServletHandlerMap.put(httpContext, servletHandlers);
         httpContextToServletContextMap.put(httpContext, new 
OSGiServletContext(httpContext, logger));
     }--- 
a/extras/grizzly-httpservice/src/main/java/org/glassfish/grizzly/osgi/httpservice/OSGiMainHandler.java
+++ 
b/extras/grizzly-httpservice/src/main/java/org/glassfish/grizzly/osgi/httpservice/OSGiMainHandler.java
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2009-2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2014 Oracle and/or its affiliates. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -57,7 +57,6 @@ import org.glassfish.grizzly.http.server.HttpHandler;
 import org.glassfish.grizzly.http.server.Request;
 import org.glassfish.grizzly.http.server.Response;
 import org.glassfish.grizzly.http.server.util.MappingData;
-import org.glassfish.grizzly.http.util.HttpStatus;
 
 /**
  * OSGi Main HttpHandler.
@@ -438,10 +437,11 @@ public class OSGiMainHandler extends HttpHandler 
implements OSGiHandler {
             Servlet servlet, HttpContext httpContext, Dictionary initparams) 
{
         OSGiServletHandler osgiServletHandler;
 
-        if (mapper.containsContext(httpContext) && 
mapper.getContext(httpContext) != null) {
+        List<OSGiServletHandler> servletHandlers =
+                mapper.getContext(httpContext);
+        if (servletHandlers != null) {
             logger.debug("Reusing ServletHandler");
             // new servlet handler for same configuration, different servlet 
and alias
-            List<OSGiServletHandler> servletHandlers = 
mapper.getContext(httpContext);
             osgiServletHandler = 
servletHandlers.get(0).newServletHandler(servlet);
             servletHandlers.add(osgiServletHandler);
         } else {
@@ -457,16 +457,22 @@ public class OSGiMainHandler extends HttpHandler 
implements OSGiHandler {
             } else {
                 params = new HashMap<String, String>(0);
             }
-            OSGiServletContext servletContext = 
mapper.getServletContext(httpContext);
+
+            servletHandlers = new ArrayList<OSGiServletHandler>(1);
+            mapper.addContext(httpContext, servletHandlers);
+            
+            final OSGiServletContext servletContext =
+                    mapper.getServletContext(httpContext);
+
+            assert servletContext != null;
+
             osgiServletHandler =
                     new OSGiServletHandler(servlet,
                                            httpContext,
                                            servletContext,
                                            params,
                                            logger);
-            ArrayList<OSGiServletHandler> servletHandlers = new 
ArrayList<OSGiServletHandler>(1);
             servletHandlers.add(osgiServletHandler);
-            mapper.addContext(httpContext, servletHandlers);
             
osgiServletHandler.setFilterChainFactory(servletContext.getFilterChainFactory());
 
         }





[grizzly~git:218e5253] [2.3.x] + fix issue #1663

oleksiys 03/15/2014
Terms of Use; Privacy Policy; Copyright ©2013-2016 (revision 20151030.c1dd42a)
 
 
Close
loading
Please Confirm
Close