You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2016/09/13 20:44:16 UTC
svn commit: r1760595 - in /felix/trunk/http:
base/src/main/java/org/apache/felix/http/base/internal/
base/src/main/java/org/apache/felix/http/base/internal/dispatch/
base/src/main/java/org/apache/felix/http/base/internal/service/
base/src/main/java/org...
Author: cziegeler
Date: Tue Sep 13 20:44:15 2016
New Revision: 1760595
URL: http://svn.apache.org/viewvc?rev=1760595&view=rev
Log:
FELIX-5344 : HTTP_WHITEBOARD_TARGET doesn't work reliably
Modified:
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/DispatcherServlet.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/service/HttpServiceFactoryTest.java
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
felix/trunk/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyServiceTest.java
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java?rev=1760595&r1=1760594&r2=1760595&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java Tue Sep 13 20:44:15 2016
@@ -19,13 +19,13 @@ package org.apache.felix.http.base.inter
public abstract class AbstractHttpActivator
extends AbstractActivator
{
- private DispatcherServlet dispatcher;
+ private DispatcherServlet dispatcherServlet;
private EventDispatcher eventDispatcher;
private HttpServiceController controller;
protected final DispatcherServlet getDispatcherServlet()
{
- return this.dispatcher;
+ return this.dispatcherServlet;
}
protected final EventDispatcher getEventDispatcher()
@@ -38,18 +38,20 @@ public abstract class AbstractHttpActiva
return this.controller;
}
+ @Override
protected void doStart()
throws Exception
{
this.controller = new HttpServiceController(getBundleContext());
- this.dispatcher = new DispatcherServlet(this.controller);
+ this.dispatcherServlet = new DispatcherServlet(this.controller.getDispatcher());
this.eventDispatcher = new EventDispatcher(this.controller);
}
+ @Override
protected void doStop()
throws Exception
{
this.controller.unregister();
- this.dispatcher.destroy();
+ this.dispatcherServlet.destroy();
}
}
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/DispatcherServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/DispatcherServlet.java?rev=1760595&r1=1760594&r2=1760595&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/DispatcherServlet.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/DispatcherServlet.java Tue Sep 13 20:44:15 2016
@@ -18,46 +18,30 @@ package org.apache.felix.http.base.inter
import java.io.IOException;
-import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.felix.http.base.internal.dispatch.Dispatcher;
+
/**
* The dispatcher servlet is registered in the container.
*
- * When {@link #init(ServletConfig)} is called, the Http services are registered
- * and started, when {@link #destroy()} is called the services are stopped
- * and unregistered.
*/
public final class DispatcherServlet extends HttpServlet
{
- private final HttpServiceController controller;
+ private final Dispatcher controller;
- public DispatcherServlet(final HttpServiceController controller)
+ public DispatcherServlet(final Dispatcher controller)
{
this.controller = controller;
}
@Override
- public void init(final ServletConfig config) throws ServletException
- {
- super.init(config);
- this.controller.register(getServletContext());
- }
-
- @Override
- public void destroy()
- {
- this.controller.unregister();
- super.destroy();
- }
-
- @Override
protected void service(final HttpServletRequest req, final HttpServletResponse res)
throws ServletException, IOException
{
- this.controller.getDispatcher().dispatch(req, res);
+ this.controller.dispatch(req, res);
}
}
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java?rev=1760595&r1=1760594&r2=1760595&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java Tue Sep 13 20:44:15 2016
@@ -51,7 +51,7 @@ public final class HttpServiceController
this.whiteboardManager = new WhiteboardManager(bundleContext, this.httpServiceFactory, this.registry);
}
- Dispatcher getDispatcher()
+ public Dispatcher getDispatcher()
{
return this.dispatcher;
}
@@ -99,22 +99,16 @@ public final class HttpServiceController
};
}
- public void setProperties(final Hashtable<String, Object> props)
- {
- this.httpServiceFactory.setProperties(props);
- this.whiteboardManager.setProperties(props);
- }
-
/**
* Start the http and http whiteboard service in the provided context.
* @param containerContext The container context.
*/
- public void register(@Nonnull final ServletContext containerContext)
+ public void register(@Nonnull final ServletContext containerContext, @Nonnull final Hashtable<String, Object> props)
{
this.registry.init();
- this.httpServiceFactory.start(containerContext);
- this.whiteboardManager.start(containerContext);
+ this.httpServiceFactory.start(containerContext, props);
+ this.whiteboardManager.start(containerContext, props);
this.dispatcher.setWhiteboardManager(this.whiteboardManager);
}
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java?rev=1760595&r1=1760594&r2=1760595&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java Tue Sep 13 20:44:15 2016
@@ -69,16 +69,20 @@ public final class Dispatcher
*/
public void dispatch(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException
{
+ final WhiteboardManager mgr = this.whiteboardManager;
+ if ( mgr != null )
+ {
+ // not active, always return 404
+ res.sendError(404);
+ return;
+ }
+
// check for invalidating session(s) first
final HttpSession session = req.getSession(false);
if ( session != null )
{
final Set<Long> ids = HttpSessionWrapper.getExpiredSessionContextIds(session);
- final WhiteboardManager mgr = this.whiteboardManager;
- if ( mgr != null )
- {
- this.whiteboardManager.sessionDestroyed(session, ids);
- }
+ this.whiteboardManager.sessionDestroyed(session, ids);
}
// get full decoded path for dispatching
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java?rev=1760595&r1=1760594&r2=1760595&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java Tue Sep 13 20:44:15 2016
@@ -18,6 +18,7 @@ package org.apache.felix.http.base.inter
import java.util.Hashtable;
+import javax.annotation.Nonnull;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionListener;
@@ -99,8 +100,18 @@ public final class HttpServiceFactory
this.sessionAttributeListenerManager = new HttpSessionAttributeListenerManager(bundleContext);
}
- public void start(final ServletContext context)
+ public void start(final ServletContext context,
+ @Nonnull final Hashtable<String, Object> props)
{
+ this.httpServiceProps.clear();
+ this.httpServiceProps.putAll(props);
+
+ if ( this.httpServiceProps.get(HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT) != null )
+ {
+ this.httpServiceProps.put(OBSOLETE_REG_PROPERTY_ENDPOINTS,
+ this.httpServiceProps.get(HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT));
+ }
+
this.context = context;
this.contextAttributeListenerManager.open();
this.requestListenerManager.open();
@@ -133,6 +144,8 @@ public final class HttpServiceFactory
this.requestAttributeListenerManager.close();
this.sessionListenerManager.close();
this.sessionAttributeListenerManager.close();
+
+ this.httpServiceProps.clear();
}
@Override
@@ -193,23 +206,6 @@ public final class HttpServiceFactory
return (Long) this.httpServiceReg.getReference().getProperty(Constants.SERVICE_ID);
}
- public void setProperties(final Hashtable<String, Object> props)
- {
- this.httpServiceProps.clear();
- this.httpServiceProps.putAll(props);
-
- if ( this.httpServiceProps.get(HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT) != null )
- {
- this.httpServiceProps.put(OBSOLETE_REG_PROPERTY_ENDPOINTS,
- this.httpServiceProps.get(HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT));
- }
-
- if (this.httpServiceReg != null)
- {
- this.httpServiceReg.setProperties(this.httpServiceProps);
- }
- }
-
private boolean getBoolean(final String property)
{
String prop = this.bundleContext.getProperty(property);
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java?rev=1760595&r1=1760594&r2=1760595&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java Tue Sep 13 20:44:15 2016
@@ -138,8 +138,11 @@ public final class WhiteboardManager
* Start the whiteboard manager
* @param containerContext The servlet context
*/
- public void start(final ServletContext containerContext)
+ public void start(final ServletContext containerContext, @Nonnull final Dictionary<String, Object> httpServiceProps)
{
+ // runtime service gets the same props for now
+ this.serviceRuntime.setAllAttributes(httpServiceProps);
+
this.serviceRuntime.setAttribute(HttpServiceRuntimeConstants.HTTP_SERVICE_ID,
Collections.singletonList(this.httpServiceFactory.getHttpServiceServiceId()));
this.runtimeServiceReg = this.httpBundleContext.registerService(HttpServiceRuntime.class,
@@ -240,19 +243,6 @@ public final class WhiteboardManager
this.webContext = null;
}
- public void setProperties(final Hashtable<String, Object> props)
- {
- // runtime service gets the same props for now
- this.serviceRuntime.setAllAttributes(props);
-
- if (this.runtimeServiceReg != null)
- {
- this.serviceRuntime.setAttribute(HttpServiceRuntimeConstants.HTTP_SERVICE_ID,
- Collections.singletonList(this.httpServiceFactory.getHttpServiceServiceId()));
- this.runtimeServiceReg.setProperties(this.serviceRuntime.getAttributes());
- }
- }
-
public void sessionDestroyed(@Nonnull final HttpSession session, final Set<Long> contextIds)
{
for(final Long contextId : contextIds)
Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/service/HttpServiceFactoryTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/service/HttpServiceFactoryTest.java?rev=1760595&r1=1760594&r2=1760595&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/service/HttpServiceFactoryTest.java (original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/service/HttpServiceFactoryTest.java Tue Sep 13 20:44:15 2016
@@ -18,6 +18,8 @@
*/
package org.apache.felix.http.base.internal.service;
+import java.util.Hashtable;
+
import javax.servlet.ServletContext;
import org.apache.felix.http.base.internal.registry.HandlerRegistry;
@@ -48,7 +50,7 @@ public class HttpServiceFactoryTest {
hsf.getService(Mockito.mock(Bundle.class), null));
ServletContext sctx = Mockito.mock(ServletContext.class);
- hsf.start(sctx);
+ hsf.start(sctx, new Hashtable<String, Object>());
HttpService svc = hsf.getService(Mockito.mock(Bundle.class), null);
Assert.assertNotNull(svc);
Modified: felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java?rev=1760595&r1=1760594&r2=1760595&view=diff
==============================================================================
--- felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java (original)
+++ felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java Tue Sep 13 20:44:15 2016
@@ -176,7 +176,7 @@ public final class JettyService extends
}
}
- private void publishServiceProperties()
+ private Hashtable<String, Object> getServiceProperties()
{
Hashtable<String, Object> props = new Hashtable<String, Object>();
// Add some important configuration properties...
@@ -184,7 +184,7 @@ public final class JettyService extends
addEndpointProperties(props, null);
// propagate the new service properties to the actual HTTP service...
- this.controller.setProperties(props);
+ return props;
}
public void updated(Dictionary props)
@@ -219,13 +219,13 @@ public final class JettyService extends
this.connectorTracker.close();
this.connectorTracker = null;
}
-
+
if (this.loadBalancerCustomizerTracker != null)
{
this.loadBalancerCustomizerTracker.close();
this.loadBalancerCustomizerTracker = null;
- }
-
+ }
+
try
{
this.server.stop();
@@ -284,13 +284,13 @@ public final class JettyService extends
this.server.setHandler(this.parent);
this.server.start();
- if (this.config.isProxyLoadBalancerConnection())
+ if (this.config.isProxyLoadBalancerConnection())
{
customizerWrapper = new CustomizerWrapper();
this.loadBalancerCustomizerTracker = new LoadBalancerCustomizerFactoryTracker(this.context, customizerWrapper);
this.loadBalancerCustomizerTracker.open();
}
-
+
final StringBuilder message = new StringBuilder("Started Jetty ").append(version).append(" at port(s)");
if (this.config.isUseHttp() && initializeHttp())
{
@@ -304,7 +304,7 @@ public final class JettyService extends
this.connectorTracker = new ConnectorFactoryTracker(this.context, this.server);
this.connectorTracker.open();
-
+
if (this.server.getConnectors() != null && this.server.getConnectors().length > 0)
{
message.append(" on context path ").append(this.config.getContextPath());
@@ -325,10 +325,11 @@ public final class JettyService extends
message.append("]");
SystemLogger.info(message.toString());
- publishServiceProperties();
+ this.controller.register(context.getServletContext(), getServiceProperties());
}
else
{
+ this.controller.unregister();
this.stopJetty();
SystemLogger.error("Jetty stopped (no connectors available)", null);
}
@@ -369,7 +370,7 @@ public final class JettyService extends
configureConnector(connector, this.config.getHttpPort());
- if (this.config.isProxyLoadBalancerConnection())
+ if (this.config.isProxyLoadBalancerConnection())
{
connFactory.getHttpConfiguration().addCustomizer(customizerWrapper);
}
@@ -395,11 +396,11 @@ public final class JettyService extends
HttpConfiguration httpConfiguration = connFactory.getHttpConfiguration();
httpConfiguration.addCustomizer(new SecureRequestCustomizer());
- if (this.config.isProxyLoadBalancerConnection())
+ if (this.config.isProxyLoadBalancerConnection())
{
httpConfiguration.addCustomizer(customizerWrapper);
}
-
+
configureConnector(connector, this.config.getHttpsPort());
return startConnector(connector);
}
Modified: felix/trunk/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyServiceTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyServiceTest.java?rev=1760595&r1=1760594&r2=1760595&view=diff
==============================================================================
--- felix/trunk/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyServiceTest.java (original)
+++ felix/trunk/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyServiceTest.java Tue Sep 13 20:44:15 2016
@@ -110,7 +110,7 @@ public class JettyServiceTest
Matchers.any(Dictionary.class))).thenReturn(reg);
httpServiceController = new HttpServiceController(mockBundleContext);
- dispatcherServlet = new DispatcherServlet(httpServiceController);
+ dispatcherServlet = new DispatcherServlet(httpServiceController.getDispatcher());
jettyService = new JettyService(mockBundleContext, dispatcherServlet, mockEventDispatcher, httpServiceController);
jettyService.start();