Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Auge2014-09-03 15:55:08 +0000
committerThomas Watson2014-10-09 21:07:07 +0000
commit969c6babcd9159645f4bbaf4d3dfa7cf37f77700 (patch)
treee579973fb8aaceff7519c82723e114b2737e9f1e
parentb6ef7db37fe2d9f04cb56a1e305102695df5f9cd (diff)
downloadrt.equinox.bundles-969c6babcd9159645f4bbaf4d3dfa7cf37f77700.tar.gz
rt.equinox.bundles-969c6babcd9159645f4bbaf4d3dfa7cf37f77700.tar.xz
rt.equinox.bundles-969c6babcd9159645f4bbaf4d3dfa7cf37f77700.zip
Bug 436698 - [http] [RFC 189] Implement the proposed R6 Http Whiteboard
Service Change-Id: I02ad089ca28959e9613d85f709ff39b0ee1b15e4 Signed-off-by: Raymond Auge <raymond.auge@liferay.com>
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/.classpath2
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/.settings/org.eclipse.jdt.core.prefs11
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/META-INF/MANIFEST.MF9
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/build.properties3
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/META-INF/MANIFEST.MF9
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/WBFilter2_component.xml9
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/WBServlet1_component.xml8
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/WBServlet2_component.xml8
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testErrorPage1_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testErrorPage2_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter10_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter11_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter12_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter13_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter14_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter15_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter16_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter1_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter2_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter3_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter4_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter5_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter6_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter7_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter8_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter9_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource1_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource2_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource3_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource4_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource5_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet10_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet11_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet4_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet5_component.xml8
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet6_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet7_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet8_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet9_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServletContextHelper10_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServletContext_component.xml6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractTestResource.java86
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractTestServlet.java46
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractWhiteboardTestFilter.java66
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractWhiteboardTestServlet.java43
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestErrorPage1.java84
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestErrorPage2.java87
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter1.java57
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter10.java61
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter11.java64
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter12.java64
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter13.java56
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter14.java60
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter15.java64
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter16.java64
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter2.java60
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter3.java63
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter4.java65
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter5.java57
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter6.java60
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter7.java63
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter8.java65
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter9.java56
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource1.java26
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource2.java53
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource3.java39
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource4.java55
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource5.java39
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet10.java61
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet11.java63
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet4.java35
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet5.java43
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet6.java38
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet7.java38
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet8.java45
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet9.java45
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServletContext1.java44
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServletContextHelper10.java69
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/resource1.txt1
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/util/BaseFilter.java68
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/util/CharResponseWrapper.java55
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/wb/t1/WBServlet1.java32
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/wb/t2/WBFilter2.java34
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/wb/t2/WBServlet2.java32
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/http.context.test/1/test1
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/http.context.test/2/test1
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java1719
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/bundle/BundleInstaller.java79
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/resource1.txt1
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseAsyncServlet.java82
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseHttpContext.java (renamed from bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/DefaultHttpContext.java)38
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseHttpSessionAttributeListener.java44
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServlet.java76
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServletContextAttributeListener.java44
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServletContextListener.java37
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServletRequestAttributeListener.java44
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServletRequestListener.java37
-rw-r--r--bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/ServletRequestAdvisor.java68
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/.classpath2
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/.settings/.api_filters86
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/.settings/org.eclipse.jdt.core.prefs111
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/.settings/org.eclipse.jdt.ui.prefs13
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/META-INF/MANIFEST.MF20
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/build.properties2
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/osgi/osgi.annotation.jarbin0 -> 13199 bytes
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/pom.xml2
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/ExtendedHttpService.java263
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/HttpServiceServlet.java7
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Activator.java253
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/FilterConfigImpl.java52
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/FilterRegistration.java122
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceFactory.java39
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceImpl.java690
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java722
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServletRequestAdaptor.java153
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ProxyServlet.java283
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletConfigImpl.java53
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletContextAdaptor.java162
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletRegistration.java74
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ContextController.java1059
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/DefaultServletContextHelper.java63
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/DispatchTargets.java74
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ProxyContext.java (renamed from bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ProxyContext.java)64
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ServletContextHelperWrapper.java108
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextFilterTrackerCustomizer.java125
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextListenerTrackerCustomizer.java90
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextResourceTrackerCustomizer.java88
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextServletTrackerCustomizer.java118
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/FilterTrackerCustomizer.java70
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ListenerTrackerCustomizer.java76
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/RegistrationServiceTrackerCustomizer.java77
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ResourceTrackerCustomizer.java70
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ServletTrackerCustomizer.java72
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/NullContextNamesException.java25
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/NullServletContextHelperException.java25
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/PatternInUseException.java26
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/RegisteredFilterException.java27
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/RegisteredServletContextHelperException.java28
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/ServletAlreadyRegisteredException.java28
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/EndpointRegistration.java160
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/FilterRegistration.java173
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ListenerRegistration.java143
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/MatchableRegistration.java81
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/Registration.java (renamed from bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Registration.java)34
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ResourceRegistration.java51
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java78
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/FilterChainImpl.java (renamed from bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/FilterChainImpl.java)35
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/FilterConfigImpl.java56
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletRequestBuilder.java291
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletResponseWrapperImpl.java50
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpSessionAdaptor.java (renamed from bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpSessionAdaptor.java)71
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/Match.java21
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/NamedDispatcherAdaptor.java80
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ProxyServlet.java90
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/RequestDispatcherAdaptor.java (renamed from bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/RequestDispatcherAdaptor.java)17
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ResourceServlet.java (renamed from bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ResourceServlet.java)35
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ResponseStateHandler.java212
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ServletConfigImpl.java56
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ServletContextAdaptor.java326
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/Const.java36
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/EventListeners.java118
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/HttpTuple.java49
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/ServiceReferenceMap.java69
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/StringPlus.java42
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/UMDictionaryMap.java97
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/UMMapDictionary.java72
166 files changed, 11513 insertions, 1288 deletions
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/.classpath b/bundles/org.eclipse.equinox.http.servlet.tests/.classpath
index 7aada446..f46b60d3 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/.classpath
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/.classpath
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="bundles_src/tb1" output="bundles_bin/tb1"/>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.http.servlet.tests/.settings/org.eclipse.jdt.core.prefs
index d4cbd54c..8000cd6c 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/.settings/org.eclipse.jdt.core.prefs
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/.settings/org.eclipse.jdt.core.prefs
@@ -1,12 +1,11 @@
-#Wed Oct 19 14:22:52 EDT 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
-org.eclipse.jdt.core.compiler.source=1.3
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.http.servlet.tests/META-INF/MANIFEST.MF
index dd83e156..4f66a429 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/META-INF/MANIFEST.MF
@@ -3,13 +3,18 @@ Bundle-ManifestVersion: 2
Bundle-Name: org.eclipse.equinox.http.servlet.tests
Bundle-SymbolicName: org.eclipse.equinox.http.servlet.tests
Bundle-Version: 1.0.0.qualifier
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Activator: org.eclipse.equinox.http.servlet.tests.bundle.Activator
Import-Package: javax.servlet;version="2.6.0",
javax.servlet.http;version="2.6.0",
junit.framework;version="4.8.2",
+ org.eclipse.equinox.http.servlet;version="1.1.0",
org.eclipse.osgi.service.urlconversion;version="1.0.0",
org.osgi.framework;version="1.6.0",
- org.osgi.service.http;version="1.2.1",
+ org.osgi.service.http;version="1.2.2",
+ org.osgi.service.http.context;version="1.0.0",
+ org.osgi.service.http.runtime;version="1.0.0",
+ org.osgi.service.http.runtime.dto;version="1.0.0",
+ org.osgi.service.http.whiteboard;version="1.0.0",
org.osgi.util.tracker;version="1.5.0"
Bundle-ActivationPolicy: lazy
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/build.properties b/bundles/org.eclipse.equinox.http.servlet.tests/build.properties
index 8cd66c8a..c7580a67 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/build.properties
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/build.properties
@@ -12,7 +12,8 @@ source.. = src/
bin.includes = .,\
META-INF/,\
bundles_bin/tb1.jar,\
- about.html
+ about.html,\
+ http.context.test/
jars.compile.order = .,\
bundles_bin/tb1.jar
source.bundles_bin/tb1.jar = bundles_src/tb1/
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/META-INF/MANIFEST.MF
index c2607114..52736086 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/META-INF/MANIFEST.MF
@@ -9,5 +9,12 @@ Bundle-Version: 1.0.0.qualifier
Service-Component: OSGI-INF/*_component.xml
Import-Package: javax.servlet,
javax.servlet.http,
- org.osgi.service.http
+ org.eclipse.equinox.http.servlet;version="1.1.0",
+ org.osgi.framework,
+ org.osgi.service.component,
+ org.osgi.service.http;version="1.2.2",
+ org.osgi.service.http.context;version="1.0.0",
+ org.osgi.service.http.runtime;version="1.0.0",
+ org.osgi.service.http.runtime.dto;version="1.0.0",
+ org.osgi.service.http.whiteboard;version="1.0.0"
Require-Bundle: org.eclipse.equinox.ds;bundle-version="1.3.100"
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/WBFilter2_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/WBFilter2_component.xml
new file mode 100644
index 00000000..df5b5888
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/WBFilter2_component.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.wb.t2.WBFilter2"/>
+ <service>
+ <provide interface="javax.servlet.Filter"/>
+ </service>
+ <property name="char" type="Character" value="b"/>
+ <property name="osgi.http.whiteboard.filter.pattern" type="String" value="/WBServlet2/*"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/WBServlet1_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/WBServlet1_component.xml
new file mode 100644
index 00000000..9c74f870
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/WBServlet1_component.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.wb.t1.WBServlet1"/>
+ <service>
+ <provide interface="javax.servlet.Servlet"/>
+ </service>
+ <property name="osgi.http.whiteboard.servlet.pattern" value="/WBServlet1/*"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/WBServlet2_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/WBServlet2_component.xml
new file mode 100644
index 00000000..f5e72ca7
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/WBServlet2_component.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.wb.t2.WBServlet2"/>
+ <service>
+ <provide interface="javax.servlet.Servlet"/>
+ </service>
+ <property name="osgi.http.whiteboard.servlet.pattern" value="/WBServlet2/*"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testErrorPage1_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testErrorPage1_component.xml
new file mode 100644
index 00000000..8ff23ed6
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testErrorPage1_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestErrorPage1"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testErrorPage2_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testErrorPage2_component.xml
new file mode 100644
index 00000000..7d04bfec
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testErrorPage2_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestErrorPage2"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter10_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter10_component.xml
new file mode 100644
index 00000000..9c7ed6ed
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter10_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestFilter10"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter11_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter11_component.xml
new file mode 100644
index 00000000..118a59dc
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter11_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestFilter11"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter12_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter12_component.xml
new file mode 100644
index 00000000..0070903a
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter12_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestFilter12"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter13_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter13_component.xml
new file mode 100644
index 00000000..601a10ac
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter13_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestFilter13"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter14_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter14_component.xml
new file mode 100644
index 00000000..e106cca9
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter14_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestFilter14"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter15_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter15_component.xml
new file mode 100644
index 00000000..2599a531
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter15_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestFilter15"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter16_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter16_component.xml
new file mode 100644
index 00000000..351c433e
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter16_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestFilter16"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter1_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter1_component.xml
new file mode 100644
index 00000000..9ff5dbd2
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter1_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestFilter1"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter2_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter2_component.xml
new file mode 100644
index 00000000..b626c065
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter2_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestFilter2"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter3_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter3_component.xml
new file mode 100644
index 00000000..df3cc7d8
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter3_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestFilter3"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter4_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter4_component.xml
new file mode 100644
index 00000000..cbb5bf6e
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter4_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestFilter4"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter5_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter5_component.xml
new file mode 100644
index 00000000..4d5e9e98
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter5_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestFilter5"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter6_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter6_component.xml
new file mode 100644
index 00000000..37a14ad5
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter6_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestFilter6"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter7_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter7_component.xml
new file mode 100644
index 00000000..d9757cae
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter7_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestFilter7"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter8_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter8_component.xml
new file mode 100644
index 00000000..09fff66c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter8_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestFilter8"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter9_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter9_component.xml
new file mode 100644
index 00000000..9d7cff9b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testFilter9_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestFilter9"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource1_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource1_component.xml
new file mode 100644
index 00000000..9788cb97
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource1_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestResource1"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource2_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource2_component.xml
new file mode 100644
index 00000000..cb149f41
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource2_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestResource2"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource3_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource3_component.xml
new file mode 100644
index 00000000..86a2cca9
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource3_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestResource3"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource4_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource4_component.xml
new file mode 100644
index 00000000..560f63ad
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource4_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestResource4"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource5_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource5_component.xml
new file mode 100644
index 00000000..0484fb5c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testResource5_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestResource5"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet10_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet10_component.xml
new file mode 100644
index 00000000..fc977502
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet10_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestServlet10"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet11_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet11_component.xml
new file mode 100644
index 00000000..0ae31a78
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet11_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestServlet11"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet4_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet4_component.xml
new file mode 100644
index 00000000..881b261c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet4_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestServlet4"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet5_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet5_component.xml
new file mode 100644
index 00000000..5c3f40b0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet5_component.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestServlet5"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+ <reference interface="org.osgi.service.http.runtime.HttpServiceRuntime"
+ bind="setHttpServiceRuntime"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet6_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet6_component.xml
new file mode 100644
index 00000000..c3522372
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet6_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestServlet6"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet7_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet7_component.xml
new file mode 100644
index 00000000..26d30bf8
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet7_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestServlet7"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet8_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet8_component.xml
new file mode 100644
index 00000000..a1dee1dd
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet8_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestServlet8"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet9_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet9_component.xml
new file mode 100644
index 00000000..ce3a94a9
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServlet9_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestServlet9"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServletContextHelper10_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServletContextHelper10_component.xml
new file mode 100644
index 00000000..34f48876
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServletContextHelper10_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestServletContextHelper10"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServletContext_component.xml b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServletContext_component.xml
new file mode 100644
index 00000000..948cfd25
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/OSGI-INF/testServletContext_component.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true">
+ <implementation class="org.eclipse.equinox.http.servlet.tests.tb1.TestServletContext1"/>
+ <reference interface="org.osgi.service.http.HttpService"
+ bind="setHttpService"/>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractTestResource.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractTestResource.java
new file mode 100644
index 00000000..e8bfd548
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractTestResource.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * The parent class for the various test servlets. This class is responsible
+ * for registering the servlet with the HttpService, and handles the HTTP GET
+ * requests by providing a template method that is implemented by subclasses.
+ */
+@SuppressWarnings("deprecation")
+public abstract class AbstractTestResource {
+ protected static final String STATUS_OK = "OK"; //$NON-NLS-1$
+ protected static final String STATUS_ERROR = "ERROR"; //$NON-NLS-1$
+
+ private HttpService service;
+
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ HttpService service = getHttpService();
+ String alias = getAlias();
+ service.registerResources(alias, getName() , null);
+ }
+
+ protected final String createDefaultAlias() {
+ return '/' + getSimpleClassName();
+ }
+
+ protected final String extensionAlias() {
+ return "*." + getSimpleClassName();
+ }
+
+ protected final String regexAlias() {
+ return createDefaultAlias() + "/*";
+ }
+
+ public void deactivate() {
+ HttpService service = getHttpService();
+ String alias = getAlias();
+ service.unregister(alias);
+ }
+
+ protected String getAlias() {
+ return createDefaultAlias();
+ }
+
+ protected HttpService getHttpService() {
+ return service;
+ }
+
+ protected String getName() {
+ Class<?> clazz = getClass();
+ Package javaPackage = clazz.getPackage();
+ return "/" + javaPackage.getName().replaceAll("\\.", "/");
+ }
+
+ private String getSimpleClassName() {
+ Class<?> clazz = getClass();
+ return clazz.getSimpleName();
+ }
+
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print(AbstractTestResource.STATUS_OK);
+ }
+
+ public final void setHttpService(HttpService service) {
+ this.service = service;
+ }
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractTestServlet.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractTestServlet.java
index e16d5e8b..fbec6000 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractTestServlet.java
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractTestServlet.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation and others.
+ * Copyright (c) 2011, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,33 +7,39 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
*******************************************************************************/
package org.eclipse.equinox.http.servlet.tests.tb;
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.Map;
+
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.osgi.service.component.ComponentContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
/*
- * The parent class for the various test servlets. This class is responsible
+ * The parent class for the various test servlets. This class is responsible
* for registering the servlet with the HttpService, and handles the HTTP GET
* requests by providing a template method that is implemented by subclasses.
*/
+@SuppressWarnings("deprecation")
public abstract class AbstractTestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
- protected static final String STATUS_OK = "OK"; //$NON-NLS-1$
+ protected static final String STATUS_OK = "OK"; //$NON-NLS-1$
protected static final String STATUS_ERROR = "ERROR"; //$NON-NLS-1$
-
+
private HttpService service;
-
- public final void activate() throws ServletException, NamespaceException {
+ private Map<String, Object> properties;
+
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
HttpService service = getHttpService();
String alias = getAlias();
service.registerServlet(alias, this, null, null);
@@ -42,13 +48,22 @@ public abstract class AbstractTestServlet extends HttpServlet {
protected final String createDefaultAlias() {
return '/' + getSimpleClassName();
}
-
- public final void deactivate() {
+
+ protected final String extensionAlias() {
+ return "*." + getSimpleClassName();
+ }
+
+ protected final String regexAlias() {
+ return createDefaultAlias() + "/*";
+ }
+
+ public void deactivate() {
HttpService service = getHttpService();
String alias = getAlias();
service.unregister(alias);
}
+ @Override
protected final void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter writer = response.getWriter();
try {
@@ -57,25 +72,26 @@ public abstract class AbstractTestServlet extends HttpServlet {
writer.close();
}
}
-
+
protected String getAlias() {
return createDefaultAlias();
}
- private HttpService getHttpService() {
+ protected HttpService getHttpService() {
return service;
}
-
- private String getSimpleClassName() {
- Class clazz = getClass();
+
+ protected String getSimpleClassName() {
+ Class<?> clazz = getClass();
return clazz.getSimpleName();
}
protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
writer.print(AbstractTestServlet.STATUS_OK);
}
-
- public final void setHttpService(HttpService service) {
+
+ public final void setHttpService(HttpService service, Map<String, Object> properties) {
this.service = service;
+ this.properties = properties;
}
}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractWhiteboardTestFilter.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractWhiteboardTestFilter.java
new file mode 100644
index 00000000..d2096d56
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractWhiteboardTestFilter.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.equinox.http.servlet.tests.util.CharResponseWrapper;
+
+/**
+ * @author Raymond Augé
+ */
+public abstract class AbstractWhiteboardTestFilter implements Filter {
+
+ public abstract char getChar();
+
+ @Override
+ public void destroy() {
+ //
+ }
+
+ @Override
+ public void doFilter(
+ ServletRequest request, ServletResponse response,
+ FilterChain chain)
+ throws IOException, ServletException {
+
+ CharResponseWrapper charResponseWrapper = new CharResponseWrapper(
+ (HttpServletResponse) response);
+
+ chain.doFilter(request, charResponseWrapper);
+
+ String output = charResponseWrapper.toString();
+
+ response.setContentLength(output.length() + 2);
+
+ PrintWriter writer = response.getWriter();
+ writer.print(getChar());
+ writer.print(output);
+ writer.print(getChar());
+ writer.close();
+ }
+
+ @Override
+ public void init(FilterConfig arg0) throws ServletException {
+ //
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractWhiteboardTestServlet.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractWhiteboardTestServlet.java
new file mode 100644
index 00000000..0219addb
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb/AbstractWhiteboardTestServlet.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author Raymond Augé
+ */
+public class AbstractWhiteboardTestServlet extends HttpServlet {
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ PrintWriter writer = response.getWriter();
+
+ try {
+ handleDoGet(request, writer);
+ }
+ finally {
+ writer.close();
+ }
+ }
+
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print(AbstractTestServlet.STATUS_OK);
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestErrorPage1.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestErrorPage1.java
new file mode 100644
index 00000000..d94078b0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestErrorPage1.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.Filter;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestErrorPage1 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(this, "S1", new String[] {regexAlias()}, null, false, null, null);
+ service.registerServlet(errorServlet, "E1", null, new String[] {"403", "404"}, false, null, null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregisterServlet(this, null);
+ service.unregisterServlet(errorServlet, null);
+ }
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException ,IOException {
+
+ response.sendError(403);
+ }
+
+ Filter f1 = new BaseFilter('b');
+ Servlet errorServlet = new HttpServlet() {
+
+ @Override
+ protected void service(
+ HttpServletRequest request, HttpServletResponse response)
+ throws ServletException ,IOException {
+
+ if (response.isCommitted()) {
+ System.out.println("Problem?");
+
+ return;
+ }
+
+ PrintWriter writer = response.getWriter();
+
+ String requestURI = (String)request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI);
+ Integer status = (Integer)request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
+
+ writer.print(status + " ERROR : " + requestURI);
+ }
+
+ };
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestErrorPage2.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestErrorPage2.java
new file mode 100644
index 00000000..28689fd0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestErrorPage2.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.Filter;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestErrorPage2 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(this, "S1", new String[] {regexAlias()}, null, false, null, null);
+ service.registerServlet(errorServlet, "E1", null, new String[] {MyException.class.getName()}, false, null, null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregisterServlet(this, null);
+ service.unregisterServlet(errorServlet, null);
+ }
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException ,IOException {
+
+ throw new MyException();
+ }
+
+ Filter f1 = new BaseFilter('b');
+ Servlet errorServlet = new HttpServlet() {
+
+ @Override
+ protected void service(
+ HttpServletRequest request, HttpServletResponse response)
+ throws ServletException ,IOException {
+
+ if (response.isCommitted()) {
+ System.out.println("Problem?");
+
+ return;
+ }
+
+ PrintWriter writer = response.getWriter();
+
+ String requestURI = (String)request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI);
+ String exception = (String)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE);
+
+ writer.print(exception + " ERROR : " + requestURI);
+ }
+
+ };
+
+ public class MyException extends ServletException {
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter1.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter1.java
new file mode 100644
index 00000000..1c8b9b56
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter1.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import java.util.Hashtable;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestFilter1 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(regexAlias(), this, null, null);
+ service.registerFilter(regexAlias(), f1, new Hashtable<String, String>(), null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(regexAlias());
+ service.unregisterFilter(f1);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ private Filter f1 = new BaseFilter('b');
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter10.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter10.java
new file mode 100644
index 00000000..121c0804
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter10.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestFilter10 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(regexAlias(), this, null, null);
+ service.registerFilter(
+ f1, "F1", new String[] {regexAlias()}, null, null, false, 0, null, null);
+
+ service.registerFilter(
+ f2, "F2", new String[] {regexAlias()}, null, null, false, 0, null, null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(regexAlias(), null);
+ service.unregisterFilter(f1, null);
+ service.unregisterFilter(f2, null);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ Filter f1 = new BaseFilter('c');
+ Filter f2 = new BaseFilter('b');
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter11.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter11.java
new file mode 100644
index 00000000..90ea38e2
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter11.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestFilter11 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(regexAlias(), this, null, null);
+ service.registerFilter(
+ f1, "F1", new String[] {regexAlias()}, null, null, false, 0, null, null);
+ service.registerFilter(
+ f2, "F2", new String[] {regexAlias()}, null, null, false, 0, null, null);
+ service.registerFilter(
+ f3, "F3", new String[] {regexAlias()}, null, null, false, 0, null, null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(regexAlias(), null);
+ service.unregisterFilter(f1, null);
+ service.unregisterFilter(f2, null);
+ service.unregisterFilter(f3, null);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ Filter f1 = new BaseFilter('c');
+ Filter f2 = new BaseFilter('b');
+ Filter f3 = new BaseFilter('d');
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter12.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter12.java
new file mode 100644
index 00000000..f8d9b360
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter12.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestFilter12 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(regexAlias(), this, null, null);
+ service.registerFilter(
+ f1, "F1", new String[] {regexAlias()}, null, null, false, 0, null, null);
+ service.registerFilter(
+ f2, "F2", new String[] {regexAlias()}, null, null, false, 0, null, null);
+ service.registerFilter(
+ f3, "F3", new String[] {regexAlias()}, null, null, false, 1, null, null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(regexAlias(), null);
+ service.unregisterFilter(f1, null);
+ service.unregisterFilter(f2, null);
+ service.unregisterFilter(f3, null);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ Filter f1 = new BaseFilter('c');
+ Filter f2 = new BaseFilter('b');
+ Filter f3 = new BaseFilter('d');
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter13.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter13.java
new file mode 100644
index 00000000..6a44ea46
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter13.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestFilter13 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(extensionAlias(), this, null, null);
+ service.registerFilter(
+ f1, "F1", new String[] {extensionAlias()}, null, null, false, 0, null, null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(extensionAlias(), null);
+ service.unregisterFilter(f1, null);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ Filter f1 = new BaseFilter('b');
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter14.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter14.java
new file mode 100644
index 00000000..08206c28
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter14.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestFilter14 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(extensionAlias(), this, null, null);
+ service.registerFilter(
+ f1, "F1", new String[] {extensionAlias()}, null, null, false, 0, null, null);
+ service.registerFilter(
+ f2, "F2", new String[] {extensionAlias()}, null, null, false, 0, null, null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(extensionAlias(), null);
+ service.unregisterFilter(f1, null);
+ service.unregisterFilter(f2, null);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ Filter f1 = new BaseFilter('c');
+ Filter f2 = new BaseFilter('b');
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter15.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter15.java
new file mode 100644
index 00000000..4dd39233
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter15.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestFilter15 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(extensionAlias(), this, null, null);
+ service.registerFilter(
+ f1, "F1", new String[] {extensionAlias()}, null, null, false, 0, null, null);
+ service.registerFilter(
+ f2, "F2", new String[] {extensionAlias()}, null, null, false, 0, null, null);
+ service.registerFilter(
+ f3, "F3", new String[] {extensionAlias()}, null, null, false, 0, null, null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(extensionAlias(), null);
+ service.unregisterFilter(f1, null);
+ service.unregisterFilter(f2, null);
+ service.unregisterFilter(f3, null);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ Filter f1 = new BaseFilter('c');
+ Filter f2 = new BaseFilter('b');
+ Filter f3 = new BaseFilter('d');
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter16.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter16.java
new file mode 100644
index 00000000..da7bb9eb
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter16.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestFilter16 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(extensionAlias(), this, null, null);
+ service.registerFilter(
+ f1, "F1", new String[] {extensionAlias()}, null, null, false, 0, null, null);
+ service.registerFilter(
+ f2, "F2", new String[] {extensionAlias()}, null, null, false, 0, null, null);
+ service.registerFilter(
+ f3, "F3", new String[] {extensionAlias()}, null, null, false, 1, null, null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(extensionAlias(), null);
+ service.unregisterFilter(f1, null);
+ service.unregisterFilter(f2, null);
+ service.unregisterFilter(f3, null);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ Filter f1 = new BaseFilter('c');
+ Filter f2 = new BaseFilter('b');
+ Filter f3 = new BaseFilter('d');
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter2.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter2.java
new file mode 100644
index 00000000..0f4682f0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter2.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import java.util.Hashtable;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestFilter2 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(regexAlias(), this, null, null);
+ service.registerFilter(regexAlias(), f1, new Hashtable<String, String>(), null);
+ service.registerFilter(regexAlias(), f2, new Hashtable<String, String>(), null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(regexAlias());
+ service.unregisterFilter(f1);
+ service.unregisterFilter(f2);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ Filter f1 = new BaseFilter('c');
+ Filter f2 = new BaseFilter('b');
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter3.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter3.java
new file mode 100644
index 00000000..6b94f188
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter3.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import java.util.Hashtable;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestFilter3 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(regexAlias(), this, null, null);
+ service.registerFilter(regexAlias(), f1, new Hashtable<String, String>(), null);
+ service.registerFilter(regexAlias(), f2, new Hashtable<String, String>(), null);
+ service.registerFilter(regexAlias(), f3, new Hashtable<String, String>(), null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(regexAlias());
+ service.unregisterFilter(f1);
+ service.unregisterFilter(f2);
+ service.unregisterFilter(f3);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ Filter f1 = new BaseFilter('c');
+ Filter f2 = new BaseFilter('b');
+ Filter f3 = new BaseFilter('d');
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter4.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter4.java
new file mode 100644
index 00000000..5f0d6547
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter4.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import java.util.Hashtable;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestFilter4 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(regexAlias(), this, null, null);
+ service.registerFilter(regexAlias(), f1, new Hashtable<String, String>(), null);
+ service.registerFilter(regexAlias(), f2, new Hashtable<String, String>(), null);
+ Hashtable<String, String> hashtable = new Hashtable<String, String>();
+ hashtable.put("filter-priority", "1");
+ service.registerFilter(regexAlias(), f3, hashtable, null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(regexAlias());
+ service.unregisterFilter(f1);
+ service.unregisterFilter(f2);
+ service.unregisterFilter(f3);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ Filter f1 = new BaseFilter('c');
+ Filter f2 = new BaseFilter('b');
+ Filter f3 = new BaseFilter('d');
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter5.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter5.java
new file mode 100644
index 00000000..ea00df75
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter5.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import java.util.Hashtable;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestFilter5 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(extensionAlias(), this, null, null);
+ service.registerFilter(extensionAlias(), f1, new Hashtable<String, String>(), null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(extensionAlias());
+ service.unregisterFilter(f1);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ Filter f1 = new BaseFilter('b');
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter6.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter6.java
new file mode 100644
index 00000000..73ad8530
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter6.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import java.util.Hashtable;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestFilter6 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(extensionAlias(), this, null, null);
+ service.registerFilter(extensionAlias(), f1, new Hashtable<String, String>(), null);
+ service.registerFilter(extensionAlias(), f2, new Hashtable<String, String>(), null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(extensionAlias());
+ service.unregisterFilter(f1);
+ service.unregisterFilter(f2);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ Filter f1 = new BaseFilter('c');
+ Filter f2 = new BaseFilter('b');
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter7.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter7.java
new file mode 100644
index 00000000..041995c8
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter7.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import java.util.Hashtable;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestFilter7 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(extensionAlias(), this, null, null);
+ service.registerFilter(extensionAlias(), f1, new Hashtable<String, String>(), null);
+ service.registerFilter(extensionAlias(), f2, new Hashtable<String, String>(), null);
+ service.registerFilter(extensionAlias(), f3, new Hashtable<String, String>(), null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(extensionAlias());
+ service.unregisterFilter(f1);
+ service.unregisterFilter(f2);
+ service.unregisterFilter(f3);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ Filter f1 = new BaseFilter('c');
+ Filter f2 = new BaseFilter('b');
+ Filter f3 = new BaseFilter('d');
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter8.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter8.java
new file mode 100644
index 00000000..7e6a957f
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter8.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import java.util.Hashtable;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestFilter8 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(extensionAlias(), this, null, null);
+ service.registerFilter(extensionAlias(), f1, new Hashtable<String, String>(), null);
+ service.registerFilter(extensionAlias(), f2, new Hashtable<String, String>(), null);
+ Hashtable<String, String> hashtable = new Hashtable<String, String>();
+ hashtable.put("filter-priority", "1");
+ service.registerFilter(extensionAlias(), f3, hashtable, null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(extensionAlias());
+ service.unregisterFilter(f1);
+ service.unregisterFilter(f2);
+ service.unregisterFilter(f3);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ Filter f1 = new BaseFilter('c');
+ Filter f2 = new BaseFilter('b');
+ Filter f3 = new BaseFilter('d');
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter9.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter9.java
new file mode 100644
index 00000000..f30f2ac9
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestFilter9.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestFilter9 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerServlet(regexAlias(), this, null, null);
+ service.registerFilter(
+ f1, "F1", new String[] {regexAlias()}, null, null, false, 0, null, null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(regexAlias());
+ service.unregisterFilter(f1);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ Filter f1 = new BaseFilter('b');
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource1.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource1.java
new file mode 100644
index 00000000..9b56423a
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource1.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestResource;
+
+/**
+ * @author Raymond Augé
+ */
+public class TestResource1 extends AbstractTestResource {
+
+ @Override
+ protected String getAlias() {
+ return regexAlias();
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource2.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource2.java
new file mode 100644
index 00000000..bf8d4531
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource2.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.util.Hashtable;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestResource;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/**
+ * @author Raymond Augé
+ */
+public class TestResource2 extends AbstractTestResource {
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerResources(regexAlias(), getName() , null);
+ service.registerFilter(regexAlias(), f1, new Hashtable<String, String>(), null);
+ service.registerFilter(regexAlias(), f2, new Hashtable<String, String>(), null);
+ service.registerFilter(regexAlias(), f3, new Hashtable<String, String>(), null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(regexAlias());
+ service.unregisterFilter(f1);
+ service.unregisterFilter(f2);
+ service.unregisterFilter(f3);
+ }
+
+ private Filter f1 = new BaseFilter('c');
+ private Filter f2 = new BaseFilter('b');
+ private Filter f3 = new BaseFilter('d');
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource3.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource3.java
new file mode 100644
index 00000000..9557c941
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource3.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import javax.servlet.ServletException;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestResource;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/**
+ * @author Raymond Augé
+ */
+public class TestResource3 extends AbstractTestResource {
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerResources(new String[] {regexAlias()}, getName(), null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(regexAlias(), null);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource4.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource4.java
new file mode 100644
index 00000000..bb5a9aff
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource4.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.util.Hashtable;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestResource;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/**
+ * @author Raymond Augé
+ */
+public class TestResource4 extends AbstractTestResource {
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerResources(regexAlias(), getName() , null);
+ service.registerFilter(regexAlias(), f1, new Hashtable<String, String>(), null);
+ service.registerFilter(regexAlias(), f2, new Hashtable<String, String>(), null);
+ Hashtable<String, String> hashtable = new Hashtable<String, String>();
+ hashtable.put("filter-priority", "1");
+ service.registerFilter(regexAlias(), f3, hashtable, null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(regexAlias());
+ service.unregisterFilter(f1);
+ service.unregisterFilter(f2);
+ service.unregisterFilter(f3);
+ }
+
+ private Filter f1 = new BaseFilter('c');
+ private Filter f2 = new BaseFilter('b');
+ private Filter f3 = new BaseFilter('d');
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource5.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource5.java
new file mode 100644
index 00000000..c6b60c30
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestResource5.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import javax.servlet.ServletException;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestResource;
+
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+
+/**
+ * @author Raymond Augé
+ */
+public class TestResource5 extends AbstractTestResource {
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.registerResources(new String[] {"/"}, getName(), null);
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister("/", null);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet10.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet10.java
new file mode 100644
index 00000000..45dbf0eb
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet10.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+
+/**
+ * @author Raymond Augé
+ */
+public class TestServlet10 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ ServletContext servletContext = getServletContext();
+
+ InputStream in = servletContext.getResourceAsStream(
+ "/org/eclipse/equinox/http/servlet/tests/tb1/resource1.txt");
+ OutputStream out = response.getOutputStream();
+
+ try {
+ byte[] buffer = new byte[2048];
+ int bytesRead;
+
+ while ((bytesRead = in.read(buffer)) != -1) {
+ out.write(buffer, 0, bytesRead);
+ }
+ }
+ finally {
+ out.close();
+ in.close();
+ }
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ //
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet11.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet11.java
new file mode 100644
index 00000000..baae515c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet11.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+
+/**
+ * @author Raymond Augé
+ */
+public class TestServlet11 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ ServletContext servletContext = getServletContext();
+
+ ClassLoader classLoader = servletContext.getClassLoader();
+
+ InputStream in = classLoader.getResourceAsStream(
+ "/org/eclipse/equinox/http/servlet/tests/tb1/resource1.txt");
+ OutputStream out = response.getOutputStream();
+
+ try {
+ byte[] buffer = new byte[2048];
+ int bytesRead;
+
+ while ((bytesRead = in.read(buffer)) != -1) {
+ out.write(buffer, 0, bytesRead);
+ }
+ }
+ finally {
+ out.close();
+ in.close();
+ }
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ //
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet4.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet4.java
new file mode 100644
index 00000000..d799b3c4
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet4.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+
+/**
+ * @author Raymond Augé
+ */
+public class TestServlet4 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ ServletContext servletContext = getServletContext();
+ writer.print(servletContext.getContextPath());
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet5.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet5.java
new file mode 100644
index 00000000..189975a2
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet5.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import java.util.Map;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+
+import org.osgi.framework.Constants;
+import org.osgi.service.http.runtime.HttpServiceRuntime;
+
+/**
+ * @author Raymond Augé
+ */
+public class TestServlet5 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+ private Map<String, Object> properties;
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print(properties.get(Constants.SERVICE_DESCRIPTION));
+ }
+
+ public void setHttpServiceRuntime(HttpServiceRuntime httpServiceRuntime, Map<String, Object> properties) {
+ this.properties = properties;
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet6.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet6.java
new file mode 100644
index 00000000..95eb5367
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet6.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+
+/**
+ * @author Raymond Augé
+ */
+public class TestServlet6 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected String getAlias() {
+ return extensionAlias();
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet7.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet7.java
new file mode 100644
index 00000000..a9fe36b5
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet7.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+
+/**
+ * @author Raymond Augé
+ */
+public class TestServlet7 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected String getAlias() {
+ return regexAlias();
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet8.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet8.java
new file mode 100644
index 00000000..9fc95b49
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet8.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+
+/**
+ * @author Raymond Augé
+ */
+public class TestServlet8 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ RequestDispatcher requestDispatcher =
+ request.getRequestDispatcher("/TestServlet5");
+
+ requestDispatcher.include(request, response);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ //
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet9.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet9.java
new file mode 100644
index 00000000..6da0d8a7
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServlet9.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+
+/**
+ * @author Raymond Augé
+ */
+public class TestServlet9 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ RequestDispatcher requestDispatcher =
+ request.getServletContext().getNamedDispatcher(TestServlet5.class.getName());
+
+ requestDispatcher.include(request, response);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ //
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServletContext1.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServletContext1.java
new file mode 100644
index 00000000..b07d9d5e
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServletContext1.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import java.util.Set;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestServletContext1 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ ServletContext servletContext = request.getServletContext();
+ Set<String> resourcePaths = servletContext.getResourcePaths("/org/eclipse/equinox/http/servlet/tests/tb1");
+
+ for (String resourcePath : resourcePaths) {
+ if (resourcePath.endsWith("/org/eclipse/equinox/http/servlet/tests/tb1/resource1.txt")) {
+ writer.print(resourcePath);
+ }
+ }
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServletContextHelper10.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServletContextHelper10.java
new file mode 100644
index 00000000..a0636c3e
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/TestServletContextHelper10.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.tb1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import java.util.Hashtable;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractTestServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseFilter;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.http.NamespaceException;
+import org.osgi.service.http.context.ServletContextHelper;
+
+/*
+ * This servlet is registered with the HttpService via the immediate DS
+ * component OSGI-INF/testServlet1_component.xml.
+ */
+public class TestServletContextHelper10 extends AbstractTestServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void activate(ComponentContext componentContext) throws ServletException, NamespaceException {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+
+ BundleContext bundleContext = componentContext.getBundleContext();
+ Bundle bundle = bundleContext.getBundle();
+
+ servletContextHelper = new ServletContextHelper(bundle) {};
+
+ service.registerServletContextHelper(servletContextHelper, bundle, new String[] {"a"}, "/a", null);
+ service.registerServlet(this, "S1", new String[] {regexAlias()}, null, false, null, "a");
+ service.registerFilter(f1, "F1", new String[] {regexAlias()}, null, null, false, 0, new Hashtable<String, String>(), "a");
+ }
+
+ @Override
+ public void deactivate() {
+ ExtendedHttpService service = (ExtendedHttpService)getHttpService();
+ service.unregister(regexAlias(), "a");
+ service.unregisterFilter(f1, "a");
+ service.unregisterServletContextHelper(servletContextHelper);
+ }
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+ private Filter f1 = new BaseFilter('c');
+ private ServletContextHelper servletContextHelper;
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/resource1.txt b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/resource1.txt
new file mode 100644
index 00000000..2e65efe2
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/tb1/resource1.txt
@@ -0,0 +1 @@
+a \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/util/BaseFilter.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/util/BaseFilter.java
new file mode 100644
index 00000000..d0c82968
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/util/BaseFilter.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.util;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author Raymond Augé
+ */
+public class BaseFilter implements Filter {
+
+ private char c;
+
+ public BaseFilter(char c) {
+ this.c = c;
+ }
+
+ @Override
+ public void destroy() {
+ //
+ }
+
+ @Override
+ public void doFilter(
+ ServletRequest request, ServletResponse response,
+ FilterChain chain)
+ throws IOException, ServletException {
+
+ CharResponseWrapper charResponseWrapper = new CharResponseWrapper(
+ (HttpServletResponse) response);
+
+ chain.doFilter(request, charResponseWrapper);
+
+ String output = charResponseWrapper.toString();
+
+ response.setContentLength(output.length() + 2);
+
+ PrintWriter writer = response.getWriter();
+ writer.print(c);
+ writer.print(output);
+ writer.print(c);
+ writer.close();
+ }
+
+ @Override
+ public void init(FilterConfig arg0) throws ServletException {
+ //
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/util/CharResponseWrapper.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/util/CharResponseWrapper.java
new file mode 100644
index 00000000..9e2c1642
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/util/CharResponseWrapper.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.util;
+
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+
+/**
+ * @author Raymond Augé
+ */
+public class CharResponseWrapper extends HttpServletResponseWrapper {
+ private CharArrayWriter output;
+
+ public CharResponseWrapper(HttpServletResponse response){
+ super(response);
+ output = new CharArrayWriter();
+ }
+
+ @Override
+ public ServletOutputStream getOutputStream() throws IOException {
+ return new ServletOutputStream() {
+
+ @Override
+ public void write(int b) throws IOException {
+ output.write(b);
+ }
+
+ };
+ }
+
+ @Override
+ public PrintWriter getWriter(){
+ return new PrintWriter(output);
+ }
+
+ @Override
+ public String toString() {
+ return output.toString();
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/wb/t1/WBServlet1.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/wb/t1/WBServlet1.java
new file mode 100644
index 00000000..f94c1288
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/wb/t1/WBServlet1.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.wb.t1;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractWhiteboardTestServlet;
+
+/**
+ * @author Raymond Augé
+ */
+public class WBServlet1 extends AbstractWhiteboardTestServlet {
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/wb/t2/WBFilter2.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/wb/t2/WBFilter2.java
new file mode 100644
index 00000000..0b4e620a
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/wb/t2/WBFilter2.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.wb.t2;
+
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractWhiteboardTestFilter;
+
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * @author Raymond Augé
+ */
+public class WBFilter2 extends AbstractWhiteboardTestFilter {
+
+ char c;
+
+ private void activate(ComponentContext componentContext) {
+ c = (Character)componentContext.getProperties().get("char");
+ }
+
+ @Override
+ public char getChar() {
+ return c;
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/wb/t2/WBServlet2.java b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/wb/t2/WBServlet2.java
new file mode 100644
index 00000000..5fc2876e
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/bundles_src/tb1/org/eclipse/equinox/http/servlet/tests/wb/t2/WBServlet2.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.wb.t2;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.equinox.http.servlet.tests.tb.AbstractWhiteboardTestServlet;
+
+/**
+ * @author Raymond Augé
+ */
+public class WBServlet2 extends AbstractWhiteboardTestServlet {
+
+ @Override
+ protected void handleDoGet(HttpServletRequest request, PrintWriter writer) throws ServletException, IOException {
+ writer.print('a');
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/http.context.test/1/test b/bundles/org.eclipse.equinox.http.servlet.tests/http.context.test/1/test
new file mode 100644
index 00000000..56a6051c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/http.context.test/1/test
@@ -0,0 +1 @@
+1 \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/http.context.test/2/test b/bundles/org.eclipse.equinox.http.servlet.tests/http.context.test/2/test
new file mode 100644
index 00000000..d8263ee9
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/http.context.test/2/test
@@ -0,0 +1 @@
+2 \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java
index ceb556d0..7f0e54fa 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation and others.
+ * Copyright (c) 2011, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,154 +7,1725 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
*******************************************************************************/
package org.eclipse.equinox.http.servlet.tests;
+import java.io.IOException;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
import junit.framework.Assert;
import junit.framework.TestCase;
+import org.eclipse.equinox.http.servlet.ExtendedHttpService;
import org.eclipse.equinox.http.servlet.tests.bundle.Activator;
import org.eclipse.equinox.http.servlet.tests.bundle.BundleAdvisor;
import org.eclipse.equinox.http.servlet.tests.bundle.BundleInstaller;
+import org.eclipse.equinox.http.servlet.tests.util.BaseAsyncServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseHttpContext;
+import org.eclipse.equinox.http.servlet.tests.util.BaseHttpSessionAttributeListener;
+import org.eclipse.equinox.http.servlet.tests.util.BaseServlet;
+import org.eclipse.equinox.http.servlet.tests.util.BaseServletContextAttributeListener;
+import org.eclipse.equinox.http.servlet.tests.util.BaseServletContextListener;
+import org.eclipse.equinox.http.servlet.tests.util.BaseServletRequestAttributeListener;
+import org.eclipse.equinox.http.servlet.tests.util.BaseServletRequestListener;
import org.eclipse.equinox.http.servlet.tests.util.ServletRequestAdvisor;
+
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.NamespaceException;
+import org.osgi.service.http.context.ServletContextHelper;
+import org.osgi.service.http.runtime.HttpServiceRuntime;
+import org.osgi.service.http.runtime.dto.ResourceDTO;
+import org.osgi.service.http.runtime.dto.RuntimeDTO;
+import org.osgi.service.http.runtime.dto.ServletContextDTO;
+import org.osgi.service.http.runtime.dto.ServletDTO;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+@SuppressWarnings("deprecation")
public class ServletTest extends TestCase {
- private static final String EQUINOX_DS_BUNDLE = "org.eclipse.equinox.ds"; //$NON-NLS-1$
- private static final String EQUINOX_JETTY_BUNDLE = "org.eclipse.equinox.http.jetty"; //$NON-NLS-1$
- private static final String JETTY_PROPERTY_PREFIX = "org.eclipse.equinox.http.jetty."; //$NON-NLS-1$
- private static final String OSGI_HTTP_PORT_PROPERTY = "org.osgi.service.http.port"; //$NON-NLS-1$
- private static final String STATUS_OK = "OK"; //$NON-NLS-1$
- private static final String TEST_BUNDLES_BINARY_DIRECTORY = "/bundles_bin/"; //$NON-NLS-1$
- private static final String TEST_BUNDLE_1 = "tb1"; //$NON-NLS-1$
-
- private static final String[] BUNDLES = new String[] {
- ServletTest.EQUINOX_DS_BUNDLE
- };
- private BundleInstaller installer;
- private BundleAdvisor advisor;
- private ServletRequestAdvisor requestAdvisor;
+ @Override
+ public void setUp() throws Exception {
+ BundleContext bundleContext = getBundleContext();
+ installer = new BundleInstaller(ServletTest.TEST_BUNDLES_BINARY_DIRECTORY, bundleContext);
+ advisor = new BundleAdvisor(bundleContext);
+ String port = getPort();
+ String contextPath = getContextPath();
+ requestAdvisor = new ServletRequestAdvisor(port, contextPath);
+ startBundles();
+ stopJetty();
+ startJetty();
+ }
- private BundleContext getBundleContext() {
- return Activator.getBundleContext();
+ @Override
+ public void tearDown() throws Exception {
+ stopJetty();
+ stopBundles();
+ requestAdvisor = null;
+ advisor = null;
+ try {
+ installer.shutdown();
+ } finally {
+ installer = null;
+ }
}
-
- private String getJettyProperty(String key, String defaultValue) {
- String qualifiedKey = ServletTest.JETTY_PROPERTY_PREFIX + key;
- String value = getProperty(qualifiedKey);
- if (value == null) {
- value = defaultValue;
+
+ public void test_ErrorPage1() throws Exception {
+ String expected = "403 ERROR :";
+ String actual = null;
+ Map<String, List<String>> response = Collections.emptyMap();
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ response = requestAdvisor.request("TestErrorPage1/a", null);
}
- return value;
+ finally {
+ uninstallBundle(bundle);
+ }
+ String responseCode = response.get("responseCode").get(0);
+ actual = response.get("responseBody").get(0);
+
+ Assert.assertEquals("403", responseCode);
+ Assert.assertTrue(
+ "Expected <" + expected + "*> but got <" + actual + ">", actual.startsWith(expected));
}
-
- private String getPort() {
- String defaultPort = getProperty(ServletTest.OSGI_HTTP_PORT_PROPERTY);
- if (defaultPort == null) {
- defaultPort = "80"; //$NON-NLS-1$
+
+ public void test_ErrorPage2() throws Exception {
+ String expected = "org.eclipse.equinox.http.servlet.tests.tb1.TestErrorPage2$MyException ERROR :";
+ String actual = null;
+ Map<String, List<String>> response = Collections.emptyMap();
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ response = requestAdvisor.request("TestErrorPage2/a", null);
}
- return getJettyProperty("port", defaultPort); //$NON-NLS-1$
+ finally {
+ uninstallBundle(bundle);
+ }
+ String responseCode = response.get("responseCode").get(0);
+ actual = response.get("responseBody").get(0);
+
+ Assert.assertEquals("500", responseCode);
+ Assert.assertTrue(
+ "Expected <" + expected + "*> but got <" + actual + ">", actual.startsWith(expected));
}
-
- private String getProperty(String key) {
+
+ public void test_Filter1() throws Exception {
+ String expected = "bab";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestFilter1/bab");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Filter2() throws Exception {
+ String expected = "cbabc";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestFilter2/cbabc");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Filter3() throws Exception {
+ String expected = "cbdadbc";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestFilter3/cbdadbc");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Filter4() throws Exception {
+ String expected = "dcbabcd";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestFilter4/dcbabcd");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Filter5() throws Exception {
+ String expected = "bab";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("something/bab.TestFilter5");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Filter6() throws Exception {
+ String expected = "cbabc";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("something/cbabc.TestFilter6");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Filter7() throws Exception {
+ String expected = "cbdadbc";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("something/cbdadbc.TestFilter7");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Filter8() throws Exception {
+ String expected = "dcbabcd";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("something/dcbabcd.TestFilter8");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Filter9() throws Exception {
+ String expected = "bab";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestFilter9/bab");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Filter10() throws Exception {
+ String expected = "cbabc";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestFilter10/cbabc");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Filter11() throws Exception {
+ String expected = "cbdadbc";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestFilter11/cbdadbc");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Filter12() throws Exception {
+ String expected = "dcbabcd";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestFilter12/dcbabcd");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Filter13() throws Exception {
+ String expected = "bab";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("something/a.TestFilter13");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Filter14() throws Exception {
+ String expected = "cbabc";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("something/a.TestFilter14");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Filter15() throws Exception {
+ String expected = "cbdadbc";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("something/a.TestFilter15");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Filter16() throws Exception {
+ String expected = "dcbabcd";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("something/a.TestFilter16");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Registration1() throws Exception {
+ String expected = "Alias cannot be null";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerServlet(
+ null, new BaseServlet(), null, null);
+ }
+ catch(IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration2() throws Exception {
+ String pattern = "blah";
+ String expected = "Invalid pattern '" + pattern + "'";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerServlet(
+ pattern, new BaseServlet(), null, null);
+ }
+ catch(IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration3() throws Exception {
+ String pattern = "/blah/";
+ String expected = "Invalid pattern '" + pattern + "'";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerServlet(
+ pattern, new BaseServlet(), null, null);
+ }
+ catch(IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration4() throws Exception {
+ String pattern = "/blah";
+ String expected = "Pattern already in use: " + pattern;
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerServlet(
+ pattern, new BaseServlet(), null, null);
+ extendedHttpService.registerServlet(
+ pattern, new BaseServlet(), null, null);
+ }
+ catch(NamespaceException ne) {
+ Assert.assertEquals(expected, ne.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration5() throws Exception {
+ String alias = "/blah";
+ String expected = "Servlet cannot be null";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerServlet(
+ alias, null, null, null);
+ }
+ catch(IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration6() throws Exception {
+ String expected = "Servlet has already been registered:";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ Servlet servlet = new BaseServlet();
+
+ extendedHttpService.registerServlet("/blah1", servlet, null, null);
+ extendedHttpService.registerServlet("/blah2", servlet, null, null);
+ }
+ catch(ServletException se) {
+ Assert.assertTrue(se.getMessage().startsWith(expected));
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration1_1() throws Exception {
+ String expected = "Patterns or servletNames must contain a value.";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerServlet(
+ new BaseServlet(), "S1", null, null, false, null, null);
+ }
+ catch(IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration2_1() throws Exception {
+ String pattern = "blah";
+ String expected = "Invalid pattern '" + pattern + "'";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerServlet(
+ new BaseServlet(), "S1", new String[] {pattern}, null, false, null, null);
+ }
+ catch(IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration3_1() throws Exception {
+ String pattern = "/blah/";
+ String expected = "Invalid pattern '" + pattern + "'";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerServlet(
+ new BaseServlet(), "S1", new String[] {pattern}, null, false, null, null);
+ }
+ catch(IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration4_1() throws Exception {
+ String pattern = "/blah";
+ String expected = "Pattern already in use: " + pattern;
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerServlet(
+ new BaseServlet(), "S1", new String[] {pattern}, null, false, null, null);
+ extendedHttpService.registerServlet(
+ new BaseServlet(), "S1", new String[] {pattern}, null, false, null, null);
+ }
+ catch(NamespaceException ne) {
+ Assert.assertEquals(expected, ne.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration5_1() throws Exception {
+ String pattern = "/blah";
+ String expected = "Servlet cannot be null";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerServlet(
+ null, "S1", new String[] {pattern}, null, false, null, null);
+ }
+ catch(IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration6_1() throws Exception {
+ String expected = "Servlet has already been registered:";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ Servlet servlet = new BaseServlet();
+
+ extendedHttpService.registerServlet(
+ servlet, "S1", new String[] {"/blah1"}, null, false, null, null);
+ extendedHttpService.registerServlet(
+ servlet, "S1", new String[] {"/blah2"}, null, false, null, null);
+ }
+ catch(ServletException se) {
+ Assert.assertTrue(se.getMessage().startsWith(expected));
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration7() throws Exception {
+ String expected = "Filter cannot be null";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerFilter("/*", null, new Hashtable<String, String>(), null);
+ }
+ catch(IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration7_1() throws Exception {
+ String expected = "Filter cannot be null";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerFilter(
+ null, "F1", new String[] {"/*"}, null, null, false, 0, null, null);
+ }
+ catch(IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration7_2() throws Exception {
+ String expected = "Patterns or servletNames must contain a value.";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ Filter f1 = new EmptyFilter();
+
+ extendedHttpService.registerFilter(
+ f1, "F1", null, null, null, false, 0, null, null);
+ }
+ catch(IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration7_3() throws Exception {
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ Filter f1 = new EmptyFilter();
+
+ extendedHttpService.registerFilter(
+ f1, "F1", null, new String[] {"blah"}, null, false, 0, null, null);
+ }
+ catch(Exception e) {
+ Assert.fail();
+ }
+ }
+
+ public void test_Registration7_4() throws Exception {
+ String dispatcher = "BAD";
+ String expected = "Invalid dispatcher '" + dispatcher + "'";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ Filter f1 = new EmptyFilter();
+
+ extendedHttpService.registerFilter(
+ f1, "F1", new String[] {"/*"}, null, new String[] {dispatcher}, false, 0, null, null);
+ }
+ catch(IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration7_5() throws Exception {
+ String contextSelector = "blah";
+ String expected = "No valid ServletContextHelper for filter '(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=" + contextSelector + ")'";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ Filter f1 = new EmptyFilter();
+
+ extendedHttpService.registerFilter(
+ f1, "F1", new String[] {"/*"}, null, null, false, 0, null, contextSelector);
+ }
+ catch(IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration8() throws Exception {
+ String expected = "Filter has already been registered: ";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ Filter f1 = new Filter() {
+ @Override
+ public void destroy() {/**/}
+ @Override
+ public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {/**/}
+ @Override
+ public void init(FilterConfig arg0) throws ServletException {/**/}
+ };
+
+ extendedHttpService.registerFilter("/*", f1, new Hashtable<String, String>(), null);
+ extendedHttpService.registerFilter("/*", f1, new Hashtable<String, String>(), null);
+ }
+ catch(ServletException se) {
+ Assert.assertTrue(se.getMessage().startsWith(expected));
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration8_1() throws Exception {
+ String expected = "Filter has already been registered: ";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ Filter f1 = new EmptyFilter();
+
+ extendedHttpService.registerFilter(
+ f1, "F1", new String[] {"/*"}, null, null, false, 0, null, null);
+ extendedHttpService.registerFilter(
+ f1, "F1", new String[] {"/*"}, null, null, false, 0, null, null);
+ }
+ catch(ServletException se) {
+ Assert.assertTrue(se.getMessage().startsWith(expected));
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration9() throws Exception {
+ String expected = "Prefix cannot be null";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerResources("/blah", null, null);
+ }
+ catch(IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration10() throws Exception {
+ String prefix = "/blah2/";
+ String expected = "Invalid prefix '" + prefix + "'";
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerResources("/blah1", prefix, null);
+ }
+ catch(IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Registration11() throws Exception {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ Servlet servlet = new BaseServlet();
+
+ extendedHttpService.registerServlet("/blah1", servlet, null, null);
+
BundleContext bundleContext = getBundleContext();
- String value = bundleContext.getProperty(key);
- return value;
+
+ ServiceReference<HttpServiceRuntime> serviceReference =
+ bundleContext.getServiceReference(HttpServiceRuntime.class);
+ HttpServiceRuntime runtime = bundleContext.getService(serviceReference);
+
+ RuntimeDTO runtimeDTO = runtime.getRuntimeDTO();
+
+ ServletContextDTO[] servletContextDTOs = runtimeDTO.servletContextDTOs;
+
+ ServletDTO servletDTO = servletContextDTOs[0].servletDTOs[0];
+
+ Assert.assertFalse(servletDTO.asyncSupported);
+ Assert.assertEquals(servlet.getClass().getName(), servletDTO.name);
+ Assert.assertEquals("/blah1", servletDTO.patterns[0]);
+ Assert.assertTrue(servletDTO.serviceId < 0);
}
-
- private Bundle installBundle(String bundle) throws BundleException {
- return installer.installBundle(bundle);
+
+ public void test_Registration12() throws Exception {
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ BundleContext bundleContext = getBundleContext();
+
+ ServiceReference<HttpServiceRuntime> serviceReference =
+ bundleContext.getServiceReference(HttpServiceRuntime.class);
+ HttpServiceRuntime runtime = bundleContext.getService(serviceReference);
+
+ RuntimeDTO runtimeDTO = runtime.getRuntimeDTO();
+
+ ServletContextDTO[] servletContextDTOs = runtimeDTO.servletContextDTOs;
+
+ ServletContextDTO servletContextDTO = servletContextDTOs[0];
+
+ Assert.assertNotNull(servletContextDTO.contextName);
+ Assert.assertTrue(servletContextDTO.names.length > 0);
+ }
+ finally {
+ uninstallBundle(bundle);
+ }
}
- public void setUp() throws Exception {
+ public void test_Registration13() throws Exception {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerResources("/blah1", "/foo", null);
+
BundleContext bundleContext = getBundleContext();
- installer = new BundleInstaller(ServletTest.TEST_BUNDLES_BINARY_DIRECTORY, bundleContext);
- advisor = new BundleAdvisor(bundleContext);
- String port = getPort();
- requestAdvisor = new ServletRequestAdvisor(port);
- startBundles();
- stopJetty();
- startJetty();
+
+ ServiceReference<HttpServiceRuntime> serviceReference =
+ bundleContext.getServiceReference(HttpServiceRuntime.class);
+ HttpServiceRuntime runtime = bundleContext.getService(serviceReference);
+
+ RuntimeDTO runtimeDTO = runtime.getRuntimeDTO();
+
+ ServletContextDTO[] servletContextDTOs = runtimeDTO.servletContextDTOs;
+
+ ResourceDTO resourceDTO = servletContextDTOs[0].resourceDTOs[0];
+
+ Assert.assertEquals("/blah1/*", resourceDTO.patterns[0]);
+ Assert.assertEquals("/foo", resourceDTO.prefix);
+ Assert.assertTrue(resourceDTO.serviceId < 0);
}
- private void startBundles() throws BundleException {
- for (int i = 0; i < ServletTest.BUNDLES.length; i++) {
- String bundle = ServletTest.BUNDLES[i];
- advisor.startBundle(bundle);
+ public void test_Resource1() throws Exception {
+ String expected = "a";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestResource1/resource1.txt");
+ } finally {
+ uninstallBundle(bundle);
}
+ Assert.assertEquals(expected, actual);
}
- private void startJetty() throws BundleException {
- advisor.startBundle(ServletTest.EQUINOX_JETTY_BUNDLE);
+ public void test_Resource2() throws Exception {
+ String expected = "cbdadbc";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestResource2/resource1.txt");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
}
- private void stopBundles() throws BundleException {
- for (int i = ServletTest.BUNDLES.length - 1; i >= 0; i--) {
- String bundle = ServletTest.BUNDLES[i];
- advisor.stopBundle(bundle);
+ public void test_Resource3() throws Exception {
+ String expected = "a";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestResource3/resource1.txt");
+ } finally {
+ uninstallBundle(bundle);
}
+ Assert.assertEquals(expected, actual);
}
- private void stopJetty() throws BundleException {
- advisor.stopBundle(ServletTest.EQUINOX_JETTY_BUNDLE);
+ public void test_Resource4() throws Exception {
+ String expected = "dcbabcd";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestResource4/resource1.txt");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
}
- public void tearDown() throws Exception {
- stopJetty();
- stopBundles();
- requestAdvisor = null;
- advisor = null;
+ public void test_Resource5() throws Exception {
+ String expected = "Patterns must contain a value.";
+ String prefix =
+ "/" + getClass().getPackage().getName().replaceAll("\\.", "/");
+
try {
- installer.shutdown();
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerResources((String[])null, prefix, null);
+ }
+ catch (IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Resource5_1() throws Exception {
+ String expected = "dcbabcd";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestResource4/resource1.txt");
} finally {
- installer = null;
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Resource6() throws Exception {
+ String expected = "Patterns must contain a value.";
+ String prefix =
+ "/" + getClass().getPackage().getName().replaceAll("\\.", "/");
+
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerResources(new String[0], prefix, null);
+ }
+ catch (IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Resource7() throws Exception {
+ String expected = "Prefix cannot be null";
+
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerResources(
+ new String[] {"/files/*"}, null, null);
+ }
+ catch (IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
}
+
+ Assert.fail();
}
- public void test_TestServlet1() throws Exception {
+ public void test_Resource8() throws Exception {
+ String pattern = "files/*";
+ String expected = "Invalid pattern '" + pattern + "'";
+
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerResources(
+ new String[] {pattern}, "/tmp", null);
+ }
+ catch (IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Resource9() throws Exception {
+ String pattern = "/files/";
+ String expected = "Invalid pattern '" + pattern + "'";
+
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerResources(
+ new String[] {pattern}, "/tmp", null);
+ }
+ catch (IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_Runtime() throws Exception {
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+
+ BundleContext bundleContext = getBundleContext();
+
+ ServiceReference<HttpServiceRuntime> serviceReference = bundleContext.getServiceReference(HttpServiceRuntime.class);
+ HttpServiceRuntime runtime = bundleContext.getService(serviceReference);
+
+ Assert.assertNotNull(runtime);
+
+ RuntimeDTO runtimeDTO = runtime.getRuntimeDTO();
+
+ ServletContextDTO[] servletContextDTOs = runtimeDTO.servletContextDTOs;
+
+ Assert.assertTrue(servletContextDTOs.length > 0);
+
+ ServletContextDTO servletContextDTO = servletContextDTOs[0];
+
+ Assert.assertNotNull(servletContextDTO.contextName);
+ } finally {
+ uninstallBundle(bundle);
+ }
+ }
+
+ public void test_Servlet1() throws Exception {
String expected = ServletTest.STATUS_OK;
String actual;
Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
try {
bundle.start();
- actual = requestAdvisor.request("TestServlet1"); //$NON-NLS-1$
+ actual = requestAdvisor.request("TestServlet1");
} finally {
uninstallBundle(bundle);
}
Assert.assertEquals(expected, actual);
}
-
- public void test_TestServlet2() throws Exception {
- String expected = "3"; //$NON-NLS-1$
+
+ public void test_Servlet2() throws Exception {
+ String expected = "3";
String actual;
Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
try {
bundle.start();
- actual = requestAdvisor.request("TestServlet2"); //$NON-NLS-1$
+ actual = requestAdvisor.request("TestServlet2");
Assert.assertEquals(expected, actual);
} finally {
uninstallBundle(bundle);
}
- Assert.assertEquals(expected, actual);
+ Assert.assertEquals(expected, actual);
}
- public void test_TestServlet3() throws Exception {
+ public void test_Servlet3() throws Exception {
String expected = ServletTest.STATUS_OK;
String actual;
Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
try {
bundle.start();
- actual = requestAdvisor.request("TestServlet3"); //$NON-NLS-1$
+ actual = requestAdvisor.request("TestServlet3");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Servlet4() throws Exception {
+ String expected = System.getProperty(ServletTest.JETTY_PROPERTY_PREFIX + "context.path", "");
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestServlet4");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Servlet5() throws Exception {
+ String expected = "Equinox Jetty-based Http Service";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestServlet5");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Servlet6() throws Exception {
+ String expected = "a";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("something/a.TestServlet6");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Servlet7() throws Exception {
+ String expected = "a";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestServlet7/a");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Servlet8() throws Exception {
+ String expected = "Equinox Jetty-based Http Service";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestServlet8");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Servlet9() throws Exception {
+ String expected = "Equinox Jetty-based Http Service";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestServlet9");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Servlet10() throws Exception {
+ String expected = "a";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestServlet10");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_Servlet11() throws Exception {
+ String expected = "a";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestServlet11");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_ServletContext1() throws Exception {
+ String expected = "/org/eclipse/equinox/http/servlet/tests/tb1/resource1.txt";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("TestServletContext1");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+
+ }
+
+ public void test_ServletContextHelper1() throws Exception {
+ String expected = "ServletContexHelper cannot be null.";
+
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ extendedHttpService.registerServletContextHelper(null, null, null, null, null);
+ }
+ catch (IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_ServletContextHelper2() throws Exception {
+ String expected = "ContextNames must contain a value.";
+
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ BundleContext bundleContext = getBundleContext();
+ Bundle bundle = bundleContext.getBundle();
+
+ ServletContextHelper servletContextHelper = new ServletContextHelper(bundle) {};
+
+ extendedHttpService.registerServletContextHelper(
+ servletContextHelper, bundle, null, null, null);
+ }
+ catch (IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_ServletContextHelper3() throws Exception {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+ BundleContext bundleContext = getBundleContext();
+ Bundle bundle = bundleContext.getBundle();
+ ServletContextHelper servletContextHelper = new ServletContextHelper(bundle){};
+
+ try {
+ extendedHttpService.registerServletContextHelper(
+ servletContextHelper, bundle, new String[] {"a"}, null, null);
+ }
+ catch (Exception e) {
+ Assert.fail();
+ }
+ finally {
+ extendedHttpService.unregisterServletContextHelper(
+ servletContextHelper);
+ }
+ }
+
+ public void test_ServletContextHelper4() throws Exception {
+ String expected = "ServletContextHelper not found: ";
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+ BundleContext bundleContext = getBundleContext();
+ Bundle bundle = bundleContext.getBundle();
+ ServletContextHelper servletContextHelper = new ServletContextHelper(bundle){};
+
+ try {
+ extendedHttpService.registerServletContextHelper(
+ servletContextHelper, bundle, new String[] {"a"}, null, null);
+
+ extendedHttpService.unregisterServletContextHelper(
+ servletContextHelper);
+
+ try {
+ extendedHttpService.unregisterServletContextHelper(
+ servletContextHelper);
+
+ Assert.fail();
+ }
+ catch (IllegalArgumentException iae) {
+ Assert.assertTrue(iae.getMessage().startsWith(expected));
+ }
+ }
+ catch (Exception e) {
+ Assert.fail();
+ }
+ }
+
+ public void test_ServletContextHelper5() throws Exception {
+ String contextSelector = "a";
+ String expected = "No valid ServletContextHelper for filter '(" +
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=" +
+ contextSelector + ")'";
+
+ try {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ Servlet s1 = new BaseServlet();
+ extendedHttpService.registerServlet(
+ s1, "S1", new String[] {"/s1"}, null, false, null, "a");
+ }
+ catch (IllegalArgumentException iae) {
+ Assert.assertEquals(expected, iae.getMessage());
+
+ return;
+ }
+
+ Assert.fail();
+ }
+
+ public void test_ServletContextHelper6() throws Exception {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+ BundleContext bundleContext = getBundleContext();
+ Bundle bundle = bundleContext.getBundle();
+ ServletContextHelper servletContextHelper = new ServletContextHelper(bundle){};
+ Servlet s1 = new BaseServlet();
+
+ try {
+ extendedHttpService.registerServletContextHelper(
+ servletContextHelper, bundle, new String[] {"a"}, null, null);
+
+ extendedHttpService.registerServlet(
+ s1, "S1", new String[] {"/s1"}, null, false, null, "a");
+ }
+ catch (IllegalArgumentException iae) {
+ Assert.fail();
+ }
+ finally {
+ extendedHttpService.unregisterServlet(s1, "a");
+ extendedHttpService.unregisterServletContextHelper(
+ servletContextHelper);
+ }
+ }
+
+ public void test_ServletContextHelper7() throws Exception {
+ String expected = "a";
+
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+ BundleContext bundleContext = getBundleContext();
+ Bundle bundle = bundleContext.getBundle();
+
+ ServletContextHelper servletContextHelper = new ServletContextHelper(bundle){};
+ Servlet s1 = new BaseServlet("a");
+
+ try {
+ extendedHttpService.registerServletContextHelper(
+ servletContextHelper, bundle, new String[] {"a"}, null, null);
+
+ extendedHttpService.registerServlet(
+ s1, "S1", new String[] {"/s1"}, null, false, null, "a");
+
+ String actual = requestAdvisor.request("s1");
+
+ Assert.assertEquals(expected, actual);
+ }
+ finally {
+ extendedHttpService.unregisterServlet(s1, "a");
+ extendedHttpService.unregisterServletContextHelper(
+ servletContextHelper);
+ }
+ }
+
+ public void test_ServletContextHelper8() throws Exception {
+ String expected = "b";
+
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+ BundleContext bundleContext = getBundleContext();
+ Bundle bundle = bundleContext.getBundle();
+ ServletContextHelper servletContextHelper = new ServletContextHelper(bundle){};
+ Servlet s1 = new BaseServlet("b");
+
+ try {
+ extendedHttpService.registerServletContextHelper(
+ servletContextHelper, bundle, new String[] {"a"}, "/a", null);
+
+ extendedHttpService.registerServlet(
+ s1, "S1", new String[] {"/s1"}, null, false, null, "a");
+
+ String actual = requestAdvisor.request("a/s1");
+
+ Assert.assertEquals(expected, actual);
+ }
+ finally {
+ extendedHttpService.unregisterServlet(s1, "a");
+ extendedHttpService.unregisterServletContextHelper(
+ servletContextHelper);
+ }
+ }
+
+ public void test_ServletContextHelper9() throws Exception {
+ String expected1 = "c";
+ String expected2 = "d";
+
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+ BundleContext bundleContext = getBundleContext();
+ Bundle bundle = bundleContext.getBundle();
+
+ ServletContextHelper servletContextHelper = new ServletContextHelper(bundle){};
+ Servlet s1 = new BaseServlet(expected1);
+ Servlet s2 = new BaseServlet(expected2);
+
+ try {
+ extendedHttpService.registerServletContextHelper(
+ servletContextHelper, bundle, new String[] {"a"}, "/a", null);
+
+ extendedHttpService.registerServlet(
+ s1, "S1", new String[] {"/s"}, null, false, null, null);
+
+ extendedHttpService.registerServlet(
+ s2, "S1", new String[] {"/s"}, null, false, null, "a");
+
+ String actual = requestAdvisor.request("s");
+
+ Assert.assertEquals(expected1, actual);
+
+ actual = requestAdvisor.request("a/s");
+
+ Assert.assertEquals(expected2, actual);
+ }
+ finally {
+ extendedHttpService.unregisterServlet(s1, null);
+ extendedHttpService.unregisterServlet(s2, "a");
+ extendedHttpService.unregisterServletContextHelper(
+ servletContextHelper);
+ }
+ }
+
+ public void test_ServletContextHelper10() throws Exception {
+ String expected = "cac";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("a/TestServletContextHelper10/a");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ private static final String HTTP_CONTEXT_TEST_ROOT = "http.context.test";
+
+ public void test_ServletContextHelper11() throws Exception {
+ BaseHttpContext ctx1 = new BaseHttpContext(true, HTTP_CONTEXT_TEST_ROOT + "/1", getBundleContext().getBundle());
+ BaseHttpContext ctx2 = new BaseHttpContext(true, HTTP_CONTEXT_TEST_ROOT + "/2", getBundleContext().getBundle());
+ String actual;
+ try {
+ getHttpService().registerResources("/" + HTTP_CONTEXT_TEST_ROOT + "/1", "", ctx1);
+ getHttpService().registerResources("/" + HTTP_CONTEXT_TEST_ROOT + "/2", "", ctx2);
+ actual = requestAdvisor.request(HTTP_CONTEXT_TEST_ROOT + "/1/test");
+ Assert.assertEquals("1", actual);
+ actual = requestAdvisor.request(HTTP_CONTEXT_TEST_ROOT + "/2/test");
+ Assert.assertEquals("2", actual);
+ }
+ finally {
+ try {
+ getHttpService().unregister("/" + HTTP_CONTEXT_TEST_ROOT + "/1");
+ getHttpService().unregister("/" + HTTP_CONTEXT_TEST_ROOT + "/2");
+ } catch (IllegalArgumentException e) {
+ // ignore
+ }
+ }
+ }
+
+ public void test_Listener1() throws Exception {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ BaseServletContextListener scl1 =
+ new BaseServletContextListener();
+
+ extendedHttpService.registerListener(scl1, null);
+ extendedHttpService.unregisterListener(scl1, null);
+
+ Assert.assertTrue(scl1.initialized.get());
+ Assert.assertTrue(scl1.destroyed.get());
+ }
+
+ public void test_Listener2() throws Exception {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+ BundleContext bundleContext = getBundleContext();
+ Bundle bundle = bundleContext.getBundle();
+
+ ServletContextHelper servletContextHelper = new ServletContextHelper(bundle){};
+
+ try{
+ extendedHttpService.registerServletContextHelper(
+ servletContextHelper, bundle, new String[] {"a"}, "/a", null);
+
+ BaseServletContextListener scl1 =
+ new BaseServletContextListener();
+
+ extendedHttpService.registerListener(scl1, "a");
+ extendedHttpService.unregisterListener(scl1, "a");
+
+ Assert.assertTrue(scl1.initialized.get());
+ Assert.assertTrue(scl1.destroyed.get());
+ }
+ finally {
+ extendedHttpService.unregisterServletContextHelper(
+ servletContextHelper);
+ }
+ }
+
+ public void test_Listener3() throws Exception {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+ BundleContext bundleContext = getBundleContext();
+ Bundle bundle = bundleContext.getBundle();
+
+ ServletContextHelper servletContextHelper = new ServletContextHelper(bundle){};
+ BaseServletContextListener scl1 = new BaseServletContextListener();
+
+ try {
+ extendedHttpService.registerServletContextHelper(
+ servletContextHelper, bundle, new String[] {"a"}, "/a", null);
+
+ extendedHttpService.registerListener(scl1, "a");
+
+ Assert.assertTrue(scl1.initialized.get());
+ }
+ finally {
+ extendedHttpService.unregisterListener(scl1, "a");
+ extendedHttpService.unregisterServletContextHelper(
+ servletContextHelper);
+ Assert.assertTrue(scl1.destroyed.get());
+ }
+ }
+
+ public void test_Listener4() throws Exception {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ BaseServletContextAttributeListener scal1 =
+ new BaseServletContextAttributeListener();
+
+ extendedHttpService.registerListener(scal1, null);
+
+ Servlet s1 = new BaseServlet("a");
+ extendedHttpService.registerServlet(
+ s1, "S1", new String[] {"/s"}, null, false, null, null);
+
+ requestAdvisor.request("s");
+
+ Assert.assertTrue(scal1.added.get());
+ Assert.assertFalse(scal1.replaced.get());
+ Assert.assertFalse(scal1.removed.get());
+
+ requestAdvisor.request("s");
+
+ Assert.assertTrue(scal1.added.get());
+ Assert.assertTrue(scal1.replaced.get());
+ Assert.assertFalse(scal1.removed.get());
+
+ requestAdvisor.request("s");
+
+ Assert.assertTrue(scal1.added.get());
+ Assert.assertTrue(scal1.replaced.get());
+ Assert.assertTrue(scal1.removed.get());
+ }
+
+ public void test_Listener5() throws Exception {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ BaseServletRequestListener srl1 = new BaseServletRequestListener();
+
+ extendedHttpService.registerListener(srl1, null);
+
+ Servlet s1 = new BaseServlet("a");
+ extendedHttpService.registerServlet(
+ s1, "S1", new String[] {"/s"}, null, false, null, null);
+
+ requestAdvisor.request("s");
+
+ Assert.assertTrue(srl1.initialized.get());
+ Assert.assertTrue(srl1.destroyed.get());
+ }
+
+ public void test_Listener6() throws Exception {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ BaseServletRequestAttributeListener sral1 = new BaseServletRequestAttributeListener();
+
+ extendedHttpService.registerListener(sral1, null);
+
+ Servlet s1 = new BaseServlet("a");
+ extendedHttpService.registerServlet(
+ s1, "S1", new String[] {"/s"}, null, false, null, null);
+
+ requestAdvisor.request("s");
+
+ Assert.assertTrue(sral1.added.get());
+ Assert.assertTrue(sral1.replaced.get());
+ Assert.assertTrue(sral1.removed.get());
+ }
+
+ public void test_Listener7() throws Exception {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ BaseHttpSessionAttributeListener hsal1 =
+ new BaseHttpSessionAttributeListener();
+
+ extendedHttpService.registerListener(hsal1, null);
+
+ Servlet s1 = new BaseServlet("test_Listener7");
+ extendedHttpService.registerServlet(
+ s1, "S1", new String[] {"/s"}, null, false, null, null);
+
+ Map<String, List<String>> responseMap = requestAdvisor.request("s", null);
+
+ Assert.assertTrue(hsal1.added.get());
+ Assert.assertFalse(hsal1.replaced.get());
+ Assert.assertFalse(hsal1.removed.get());
+
+ List<String> list = responseMap.get("Set-Cookie");
+
+ String sessionId = "";
+
+ for (String string : list) {
+ if (string.startsWith("JSESSIONID=")) {
+ sessionId = string;
+
+ int pos = sessionId.indexOf(';');
+ if (pos != -1) {
+ sessionId = sessionId.substring(0, pos);
+ }
+ }
+ }
+
+ Map<String, List<String>> requestHeaders = new HashMap<String, List<String>>();
+ requestHeaders.put("Cookie", Arrays.asList(sessionId));
+
+ requestAdvisor.request("s", requestHeaders);
+
+ Assert.assertTrue(hsal1.added.get());
+ Assert.assertTrue(hsal1.replaced.get());
+ Assert.assertFalse(hsal1.removed.get());
+
+ requestAdvisor.request("s", requestHeaders);
+
+ Assert.assertTrue(hsal1.added.get());
+ Assert.assertTrue(hsal1.replaced.get());
+ Assert.assertTrue(hsal1.removed.get());
+ }
+
+ public void test_Listener8() throws Exception {
+ ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+ Servlet s1 = new BaseAsyncServlet("test_Listener8");
+ extendedHttpService.registerServlet(
+ s1, "S1", new String[] {"/s"}, null, true, null, null);
+
+ String output1 = requestAdvisor.request("s");
+
+ Assert.assertTrue(output1, output1.endsWith("test_Listener8"));
+ }
+
+ public void test_WBServlet1() throws Exception {
+ String expected = "a";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("WBServlet1/a");
+ } finally {
+ uninstallBundle(bundle);
+ }
+ Assert.assertEquals(expected, actual);
+ }
+
+ public void test_WBServlet2() throws Exception {
+ String expected = "bab";
+ String actual;
+ Bundle bundle = installBundle(ServletTest.TEST_BUNDLE_1);
+ try {
+ bundle.start();
+ actual = requestAdvisor.request("WBServlet2/a");
} finally {
uninstallBundle(bundle);
}
Assert.assertEquals(expected, actual);
}
-
+
+ private BundleContext getBundleContext() {
+ return Activator.getBundleContext();
+ }
+
+ private String getContextPath() {
+ return getJettyProperty("context.path", "");
+ }
+
+ private HttpService getHttpService() {
+ ServiceReference<HttpService> serviceReference = getBundleContext().getServiceReference(HttpService.class);
+ return getBundleContext().getService(serviceReference);
+ }
+
+ private String getJettyProperty(String key, String defaultValue) {
+ String qualifiedKey = ServletTest.JETTY_PROPERTY_PREFIX + key;
+ String value = getProperty(qualifiedKey);
+ if (value == null) {
+ value = defaultValue;
+ }
+ return value;
+ }
+
+ private String getPort() {
+ String defaultPort = getProperty(ServletTest.OSGI_HTTP_PORT_PROPERTY);
+ if (defaultPort == null) {
+ defaultPort = "80";
+ }
+ return getJettyProperty("port", defaultPort);
+ }
+
+ private String getProperty(String key) {
+ BundleContext bundleContext = getBundleContext();
+ String value = bundleContext.getProperty(key);
+ return value;
+ }
+
+ private Bundle installBundle(String bundle) throws BundleException {
+ return installer.installBundle(bundle);
+ }
+
+ private void startBundles() throws BundleException {
+ for (String bundle : ServletTest.BUNDLES) {
+ advisor.startBundle(bundle);
+ }
+ }
+
+ private void startJetty() throws BundleException {
+ advisor.startBundle(ServletTest.EQUINOX_JETTY_BUNDLE);
+ }
+
+ private void stopBundles() throws BundleException {
+ for (int i = ServletTest.BUNDLES.length - 1; i >= 0; i--) {
+ String bundle = ServletTest.BUNDLES[i];
+ advisor.stopBundle(bundle);
+ }
+ }
+
+ private void stopJetty() throws BundleException {
+ advisor.stopBundle(ServletTest.EQUINOX_JETTY_BUNDLE);
+ }
+
private void uninstallBundle(Bundle bundle) throws BundleException {
installer.uninstallBundle(bundle);
}
+
+ private static final String EQUINOX_DS_BUNDLE = "org.eclipse.equinox.ds";
+ private static final String EQUINOX_JETTY_BUNDLE = "org.eclipse.equinox.http.jetty";
+ private static final String JETTY_PROPERTY_PREFIX = "org.eclipse.equinox.http.jetty.";
+ private static final String OSGI_HTTP_PORT_PROPERTY = "org.osgi.service.http.port";
+ private static final String STATUS_OK = "OK";
+ private static final String TEST_BUNDLES_BINARY_DIRECTORY = "/bundles_bin/";
+ private static final String TEST_BUNDLE_1 = "tb1";
+
+ private static final String[] BUNDLES = new String[] {
+ ServletTest.EQUINOX_DS_BUNDLE
+ };
+
+ private BundleInstaller installer;
+ private BundleAdvisor advisor;
+ private ServletRequestAdvisor requestAdvisor;
+
+ class EmptyFilter implements Filter {
+ @Override
+ public void destroy() {/**/}
+ @Override
+ public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {/**/}
+ @Override
+ public void init(FilterConfig arg0) throws ServletException {/**/}
+ }
+
}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/bundle/BundleInstaller.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/bundle/BundleInstaller.java
index a2be4eda..6b257ade 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/bundle/BundleInstaller.java
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/bundle/BundleInstaller.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2009 IBM Corporation and others.
+ * Copyright (c) 2006, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,17 +7,20 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
*******************************************************************************/
package org.eclipse.equinox.http.servlet.tests.bundle;
import java.io.IOException;
+
import java.net.URL;
+
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import org.eclipse.osgi.service.urlconversion.URLConverter;
+
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -27,13 +30,13 @@ import org.osgi.util.tracker.ServiceTracker;
public class BundleInstaller {
private BundleContext context;
private String rootLocation;
- private HashMap bundles = new HashMap();
- private ServiceTracker converter;
+ private HashMap<String, Bundle> bundles = new HashMap<String, Bundle>();
+ private ServiceTracker<Object, Object> converter;
public BundleInstaller(String bundlesRoot, BundleContext context) throws InvalidSyntaxException {
this.context = context;
rootLocation = bundlesRoot;
- converter = new ServiceTracker(context, context.createFilter("(&(objectClass=" + URLConverter.class.getName() + ")(protocol=bundleentry))"), null);
+ converter = new ServiceTracker<Object, Object>(context, context.createFilter("(&(objectClass=" + URLConverter.class.getName() + ")(protocol=bundleentry))"), null);
converter.open();
}
@@ -42,51 +45,60 @@ public class BundleInstaller {
}
synchronized public Bundle installBundle(String name, boolean track) throws BundleException {
- if (bundles == null && track)
+ if (bundles == null && track) {
return null;
+ }
String location = getBundleLocation(name);
Bundle bundle = context.installBundle(location);
- if (track)
+ if (track) {
bundles.put(name, bundle);
+ }
return bundle;
}
public String getBundleLocation(String name) throws BundleException {
String bundleFileName = rootLocation + "/" + name;
URL bundleURL = context.getBundle().getEntry(bundleFileName);
- if (bundleURL == null)
+ if (bundleURL == null) {
bundleURL = context.getBundle().getEntry(bundleFileName + ".jar");
- if (bundleURL == null)
+ }
+ if (bundleURL == null) {
throw new BundleException("Could not find bundle to install at: " + name);
+ }
try {
bundleURL = ((URLConverter) converter.getService()).resolve(bundleURL);
} catch (IOException e) {
throw new BundleException("Converter error", e);
}
String location = bundleURL.toExternalForm();
- if ("file".equals(bundleURL.getProtocol()))
+ if ("file".equals(bundleURL.getProtocol())) {
location = "reference:" + location;
+ }
return location;
}
synchronized public Bundle updateBundle(String fromName, String toName) throws BundleException {
- if (bundles == null)
+ if (bundles == null) {
return null;
- Bundle fromBundle = (Bundle) bundles.get(fromName);
- if (fromBundle == null)
+ }
+ Bundle fromBundle = bundles.get(fromName);
+ if (fromBundle == null) {
throw new BundleException("The bundle to update does not exist!! " + fromName);
+ }
String bundleFileName = rootLocation + "/" + toName;
URL bundleURL = context.getBundle().getEntry(bundleFileName);
- if (bundleURL == null)
+ if (bundleURL == null) {
bundleURL = context.getBundle().getEntry(bundleFileName + ".jar");
+ }
try {
bundleURL = ((URLConverter) converter.getService()).resolve(bundleURL);
} catch (IOException e) {
throw new BundleException("Converter error", e);
}
String location = bundleURL.toExternalForm();
- if ("file".equals(bundleURL.getProtocol()))
+ if ("file".equals(bundleURL.getProtocol())) {
location = "reference:" + location;
+ }
try {
fromBundle.update(new URL(location).openStream());
} catch (Exception e) {
@@ -98,21 +110,23 @@ public class BundleInstaller {
}
synchronized public Bundle uninstallBundle(String name) throws BundleException {
- if (bundles == null)
+ if (bundles == null) {
return null;
- Bundle bundle = (Bundle) bundles.remove(name);
- if (bundle == null)
+ }
+ Bundle bundle = bundles.remove(name);
+ if (bundle == null) {
return null;
+ }
bundle.uninstall();
return bundle;
}
-
+
synchronized public void uninstallBundle(Bundle b) throws BundleException {
- if (bundles == null)
+ if (bundles == null) {
return;
+ }
if (bundles.containsValue(b)) {
- for (Iterator it = bundles.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
+ for (Map.Entry<String, Bundle> entry : bundles.entrySet()) {
if (entry.getValue().equals(b)) {
bundles.remove(entry.getKey());
break;
@@ -123,11 +137,12 @@ public class BundleInstaller {
}
synchronized public Bundle[] uninstallAllBundles() throws BundleException {
- if (bundles == null)
+ if (bundles == null) {
return null;
- ArrayList result = new ArrayList(bundles.size());
- for (Iterator iter = bundles.values().iterator(); iter.hasNext();) {
- Bundle bundle = (Bundle) iter.next();
+ }
+ ArrayList<Bundle> result = new ArrayList<Bundle>(bundles.size());
+ for (Object element : bundles.values()) {
+ Bundle bundle = (Bundle) element;
try {
bundle.uninstall();
} catch (IllegalStateException e) {
@@ -136,18 +151,20 @@ public class BundleInstaller {
result.add(bundle);
}
bundles.clear();
- return (Bundle[]) result.toArray(new Bundle[result.size()]);
+ return result.toArray(new Bundle[result.size()]);
}
synchronized public Bundle getBundle(String name) {
- if (bundles == null)
+ if (bundles == null) {
return null;
- return (Bundle) bundles.get(name);
+ }
+ return bundles.get(name);
}
-
+
synchronized public Bundle[] shutdown() throws BundleException {
- if (bundles == null)
+ if (bundles == null) {
return null;
+ }
Bundle[] result = uninstallAllBundles();
converter.close();
bundles = null;
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/resource1.txt b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/resource1.txt
new file mode 100644
index 00000000..2e65efe2
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/resource1.txt
@@ -0,0 +1 @@
+a \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseAsyncServlet.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseAsyncServlet.java
new file mode 100644
index 00000000..ae9c0796
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseAsyncServlet.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.util;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+
+import javax.servlet.AsyncContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author Raymond Augé
+ */
+public class BaseAsyncServlet extends BaseServlet {
+
+ ScheduledThreadPoolExecutor executor =
+ (ScheduledThreadPoolExecutor)Executors.newScheduledThreadPool(4);
+
+ public BaseAsyncServlet() {
+ super();
+ }
+
+ public BaseAsyncServlet(String content) {
+ super(content);
+ }
+
+ @Override
+ protected void service(
+ HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ AsyncContext asyncContext = request.startAsync(request, response);
+
+ executor.execute(new AsyncOperation(asyncContext));
+ }
+
+ public class AsyncOperation implements Runnable {
+ AsyncContext asyncContext;
+
+ public AsyncOperation(AsyncContext asyncContext) {
+ this.asyncContext = asyncContext;
+ }
+
+ @Override
+ public void run() {
+ PrintWriter writer = null;
+
+ try {
+ writer = asyncContext.getResponse().getWriter();
+
+ writer.print(Thread.currentThread().getName());
+ writer.print(" - ");
+ writer.print(content);
+ }
+ catch (IOException ioe) {
+ ioe.printStackTrace();
+ }
+ finally {
+ if (writer != null) {
+ writer.close();
+ }
+
+ asyncContext.complete();
+ }
+ }
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/DefaultHttpContext.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseHttpContext.java
index b4d43fc5..5afcbf9f 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/DefaultHttpContext.java
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseHttpContext.java
@@ -1,42 +1,52 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Cognos Incorporated, IBM Corporation and others.
+ * Copyright (c) 2014 Raymond Augé and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
- * Cognos Incorporated - initial API and implementation
- * IBM Corporation - bug fixes and enhancements
- *******************************************************************************/
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
-package org.eclipse.equinox.http.servlet.internal;
+package org.eclipse.equinox.http.servlet.tests.util;
import java.io.IOException;
+
import java.net.URL;
+
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
import org.osgi.framework.Bundle;
import org.osgi.service.http.HttpContext;
-public class DefaultHttpContext implements HttpContext {
+public class BaseHttpContext implements HttpContext {
+ private final boolean handleSecurity;
+ private final String resourceRoot;
+ private final Bundle bundle;
- private Bundle bundle;
-
- public DefaultHttpContext(Bundle bundle) {
+ public BaseHttpContext(boolean handleSecurity, String resourceRoot,
+ Bundle bundle) {
+ this.handleSecurity = handleSecurity;
+ this.resourceRoot = resourceRoot;
this.bundle = bundle;
}
- public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException {
- // default behaviour assumes the container has already performed authentication
- return true;
+ @Override
+ public boolean handleSecurity(HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
+ return handleSecurity;
}
+ @Override
public URL getResource(String name) {
- return bundle.getResource(name);
+ return bundle.getEntry(resourceRoot + '/' + name);
}
+ @Override
public String getMimeType(String name) {
return null;
}
+
}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseHttpSessionAttributeListener.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseHttpSessionAttributeListener.java
new file mode 100644
index 00000000..7cca5789
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseHttpSessionAttributeListener.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.util;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.servlet.http.HttpSessionAttributeListener;
+import javax.servlet.http.HttpSessionBindingEvent;
+
+/**
+ * @author Raymond Augé
+ */
+public class BaseHttpSessionAttributeListener
+ implements HttpSessionAttributeListener {
+
+ public AtomicBoolean added = new AtomicBoolean(false);
+ public AtomicBoolean replaced = new AtomicBoolean(false);
+ public AtomicBoolean removed = new AtomicBoolean(false);
+
+ @Override
+ public void attributeAdded(HttpSessionBindingEvent arg0) {
+ added.set(true);
+ }
+
+ @Override
+ public void attributeRemoved(HttpSessionBindingEvent arg0) {
+ removed.set(true);
+ }
+
+ @Override
+ public void attributeReplaced(HttpSessionBindingEvent arg0) {
+ replaced.set(true);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServlet.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServlet.java
new file mode 100644
index 00000000..0ca0ce1a
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServlet.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.util;
+
+import java.io.IOException;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+/**
+ * @author Raymond Augé
+ */
+public class BaseServlet extends HttpServlet {
+
+ public static final String ATTRIBUTE = "content";
+
+ public BaseServlet() {
+ this("");
+ }
+
+ public BaseServlet(String content) {
+ this.content = content;
+ }
+
+ @Override
+ protected void service(
+ HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ request.setAttribute(ATTRIBUTE, content);
+ request.setAttribute(ATTRIBUTE, "replaced");
+ request.removeAttribute(ATTRIBUTE);
+
+ ServletContext servletContext = request.getServletContext();
+
+ if (servletContext.getAttribute(ATTRIBUTE) == null) {
+ servletContext.setAttribute(ATTRIBUTE, content);
+ }
+ else if (servletContext.getAttribute(ATTRIBUTE).equals(content)) {
+ servletContext.setAttribute(ATTRIBUTE, "replaced");
+ }
+ else {
+ servletContext.removeAttribute(ATTRIBUTE);
+ }
+
+ HttpSession session = request.getSession();
+
+ if (session.getAttribute(ATTRIBUTE) == null) {
+ session.setAttribute(ATTRIBUTE, content);
+ }
+ else if (session.getAttribute(ATTRIBUTE).equals(content)) {
+ session.setAttribute(ATTRIBUTE, "replaced");
+ }
+ else {
+ session.removeAttribute(ATTRIBUTE);
+ }
+
+ response.getWriter().print(content);
+ }
+
+ protected String content;
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServletContextAttributeListener.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServletContextAttributeListener.java
new file mode 100644
index 00000000..9614d37d
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServletContextAttributeListener.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.util;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.servlet.ServletContextAttributeEvent;
+import javax.servlet.ServletContextAttributeListener;
+
+/**
+ * @author Raymond Augé
+ */
+public class BaseServletContextAttributeListener
+ implements ServletContextAttributeListener {
+
+ public AtomicBoolean added = new AtomicBoolean(false);
+ public AtomicBoolean replaced = new AtomicBoolean(false);
+ public AtomicBoolean removed = new AtomicBoolean(false);
+
+ @Override
+ public void attributeAdded(ServletContextAttributeEvent arg0) {
+ added.set(true);
+ }
+
+ @Override
+ public void attributeRemoved(ServletContextAttributeEvent arg0) {
+ removed.set(true);
+ }
+
+ @Override
+ public void attributeReplaced(ServletContextAttributeEvent arg0) {
+ replaced.set(true);
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServletContextListener.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServletContextListener.java
new file mode 100644
index 00000000..f5bdfa8e
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServletContextListener.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.util;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+/**
+ * @author Raymond Augé
+ */
+public class BaseServletContextListener implements ServletContextListener {
+
+ public AtomicBoolean initialized = new AtomicBoolean(false);
+ public AtomicBoolean destroyed = new AtomicBoolean(false);
+
+ @Override
+ public void contextDestroyed(ServletContextEvent servletContextEvent) {
+ destroyed.set(true);
+ }
+
+ @Override
+ public void contextInitialized(ServletContextEvent servletContextEvent) {
+ initialized.set(true);
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServletRequestAttributeListener.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServletRequestAttributeListener.java
new file mode 100644
index 00000000..783d4536
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServletRequestAttributeListener.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.util;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.servlet.ServletRequestAttributeEvent;
+import javax.servlet.ServletRequestAttributeListener;
+
+/**
+ * @author Raymond Augé
+ */
+public class BaseServletRequestAttributeListener
+ implements ServletRequestAttributeListener {
+
+ public AtomicBoolean added = new AtomicBoolean(false);
+ public AtomicBoolean replaced = new AtomicBoolean(false);
+ public AtomicBoolean removed = new AtomicBoolean(false);
+
+ @Override
+ public void attributeAdded(ServletRequestAttributeEvent arg0) {
+ added.set(true);
+ }
+
+ @Override
+ public void attributeRemoved(ServletRequestAttributeEvent arg0) {
+ removed.set(true);
+ }
+
+ @Override
+ public void attributeReplaced(ServletRequestAttributeEvent arg0) {
+ replaced.set(true);
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServletRequestListener.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServletRequestListener.java
new file mode 100644
index 00000000..c61b366b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/BaseServletRequestListener.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.tests.util;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.ServletRequestListener;
+
+/**
+ * @author Raymond Augé
+ */
+public class BaseServletRequestListener implements ServletRequestListener {
+
+ public AtomicBoolean initialized = new AtomicBoolean(false);
+ public AtomicBoolean destroyed = new AtomicBoolean(false);
+
+ @Override
+ public void requestDestroyed(ServletRequestEvent arg0) {
+ destroyed.set(true);
+ }
+
+ @Override
+ public void requestInitialized(ServletRequestEvent arg0) {
+ initialized.set(true);
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/ServletRequestAdvisor.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/ServletRequestAdvisor.java
index e007fce9..25505cb7 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/ServletRequestAdvisor.java
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/util/ServletRequestAdvisor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation and others.
+ * Copyright (c) 2011, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,25 +7,38 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
*******************************************************************************/
package org.eclipse.equinox.http.servlet.tests.util;
import java.io.IOException;
import java.io.InputStream;
+
+import java.net.HttpURLConnection;
import java.net.URL;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
/*
* The ServletRequestAdvisor is responsible for composing URLs and using them
- * to performing servlet requests.
+ * to performing servlet requests.
*/
public class ServletRequestAdvisor extends Object {
+ private final String contextPath;
private final String port;
- public ServletRequestAdvisor(String port) {
+ public ServletRequestAdvisor(String port, String contextPath) {
super();
if (port == null)
+ {
throw new IllegalArgumentException("port must not be null"); //$NON-NLS-1$
+ }
this.port = port;
+ this.contextPath = contextPath;
}
private String createUrlSpec(String value) {
@@ -36,6 +49,7 @@ public class ServletRequestAdvisor extends Object {
buffer.append(host);
buffer.append(':');
buffer.append(port);
+ buffer.append(contextPath);
if (value != null) {
buffer.append('/');
buffer.append(value);
@@ -58,16 +72,60 @@ public class ServletRequestAdvisor extends Object {
String value = this + ": " + message; //$NON-NLS-1$
System.out.println(value);
}
-
+
public String request(String value) throws IOException {
String spec = createUrlSpec(value);
log("Requesting " + spec); //$NON-NLS-1$
URL url = new URL(spec);
- InputStream stream = url.openStream();
+
+ HttpURLConnection connection = (HttpURLConnection)url.openConnection();
+
+ connection.setInstanceFollowRedirects(false);
+ connection.setConnectTimeout(150 * 1000);
+ connection.setReadTimeout(150 * 1000);
+ connection.connect();
+
+ InputStream stream = connection.getInputStream();
try {
return drain(stream);
} finally {
stream.close();
}
}
+
+ public Map<String, List<String>> request(String value, Map<String, List<String>> headers) throws IOException {
+ String spec = createUrlSpec(value);
+ log("Requesting " + spec); //$NON-NLS-1$
+ URL url = new URL(spec);
+ HttpURLConnection conn = (HttpURLConnection)url.openConnection();
+
+ if (headers != null) {
+ for(Map.Entry<String, List<String>> entry : headers.entrySet()) {
+ for(String entryValue : entry.getValue()) {
+ conn.setRequestProperty(entry.getKey(), entryValue);
+ }
+ }
+ }
+
+ int responseCode = conn.getResponseCode();
+
+ Map<String, List<String>> map = new HashMap<String, List<String>>(conn.getHeaderFields());
+ map.put("responseCode", Collections.singletonList(String.valueOf(responseCode)));
+
+ InputStream stream;
+
+ if (responseCode >= 400) {
+ stream = conn.getErrorStream();
+ }
+ else {
+ stream = conn.getInputStream();
+ }
+
+ try {
+ map.put("responseBody", Arrays.asList(drain(stream)));
+ return map;
+ } finally {
+ stream.close();
+ }
+ }
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/.classpath b/bundles/org.eclipse.equinox.http.servlet/.classpath
index ce0c7a5d..121e527a 100644
--- a/bundles/org.eclipse.equinox.http.servlet/.classpath
+++ b/bundles/org.eclipse.equinox.http.servlet/.classpath
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.0%Foundation-1.0"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/bundles/org.eclipse.equinox.http.servlet/.settings/.api_filters b/bundles/org.eclipse.equinox.http.servlet/.settings/.api_filters
index e2bd7154..deaebe3c 100644
--- a/bundles/org.eclipse.equinox.http.servlet/.settings/.api_filters
+++ b/bundles/org.eclipse.equinox.http.servlet/.settings/.api_filters
@@ -1,5 +1,91 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.equinox.http.servlet" version="2">
+ <resource path="src/org/eclipse/equinox/http/servlet/ExtendedHttpService.java" type="org.eclipse.equinox.http.servlet.ExtendedHttpService">
+ <filter id="403804204">
+ <message_arguments>
+ <message_argument value="org.eclipse.equinox.http.servlet.ExtendedHttpService"/>
+ <message_argument value="registerFilter(Filter, String, String[], String[], String[], boolean, int, Map&lt;String,String&gt;, String)"/>
+ </message_arguments>
+ </filter>
+ <filter id="403804204">
+ <message_arguments>
+ <message_argument value="org.eclipse.equinox.http.servlet.ExtendedHttpService"/>
+ <message_argument value="registerListener(EventListener, String)"/>
+ </message_arguments>
+ </filter>
+ <filter id="403804204">
+ <message_arguments>
+ <message_argument value="org.eclipse.equinox.http.servlet.ExtendedHttpService"/>
+ <message_argument value="registerResources(String[], String, String)"/>
+ </message_arguments>
+ </filter>
+ <filter id="403804204">
+ <message_arguments>
+ <message_argument value="org.eclipse.equinox.http.servlet.ExtendedHttpService"/>
+ <message_argument value="registerServlet(Servlet, String, String[], String[], boolean, Map&lt;String,String&gt;, String)"/>
+ </message_arguments>
+ </filter>
+ <filter id="403804204">
+ <message_arguments>
+ <message_argument value="org.eclipse.equinox.http.servlet.ExtendedHttpService"/>
+ <message_argument value="registerServletContextHelper(ServletContextHelper, Bundle, String[], String, Map&lt;String,String&gt;)"/>
+ </message_arguments>
+ </filter>
+ <filter id="403804204">
+ <message_arguments>
+ <message_argument value="org.eclipse.equinox.http.servlet.ExtendedHttpService"/>
+ <message_argument value="registerServletContextHelper(ServletContextHelper, String[], String)"/>
+ </message_arguments>
+ </filter>
+ <filter id="403804204">
+ <message_arguments>
+ <message_argument value="org.eclipse.equinox.http.servlet.ExtendedHttpService"/>
+ <message_argument value="registerServletContextHelper(ServletContextHelper, String[], String, Map&lt;String,String&gt;)"/>
+ </message_arguments>
+ </filter>
+ <filter id="403804204">
+ <message_arguments>
+ <message_argument value="org.eclipse.equinox.http.servlet.ExtendedHttpService"/>
+ <message_argument value="unregister(String, String)"/>
+ </message_arguments>
+ </filter>
+ <filter id="403804204">
+ <message_arguments>
+ <message_argument value="org.eclipse.equinox.http.servlet.ExtendedHttpService"/>
+ <message_argument value="unregisterFilter(Filter, String)"/>
+ </message_arguments>
+ </filter>
+ <filter id="403804204">
+ <message_arguments>
+ <message_argument value="org.eclipse.equinox.http.servlet.ExtendedHttpService"/>
+ <message_argument value="unregisterListener(EventListener)"/>
+ </message_arguments>
+ </filter>
+ <filter id="403804204">
+ <message_arguments>
+ <message_argument value="org.eclipse.equinox.http.servlet.ExtendedHttpService"/>
+ <message_argument value="unregisterListener(EventListener, String)"/>
+ </message_arguments>
+ </filter>
+ <filter id="403804204">
+ <message_arguments>
+ <message_argument value="org.eclipse.equinox.http.servlet.ExtendedHttpService"/>
+ <message_argument value="unregisterServlet(Servlet)"/>
+ </message_arguments>
+ </filter>
+ <filter id="403804204">
+ <message_arguments>
+ <message_argument value="org.eclipse.equinox.http.servlet.ExtendedHttpService"/>
+ <message_argument value="unregisterServlet(Servlet, String)"/>
+ </message_arguments>
+ </filter>
+ <filter id="403804204">
+ <message_arguments>
+ <message_argument value="org.eclipse.equinox.http.servlet.ExtendedHttpService"/>
+ <message_argument value="unregisterServletContextHelper(ServletContextHelper)"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="src/org/eclipse/equinox/http/servlet/HttpServiceServlet.java" type="org.eclipse.equinox.http.servlet.HttpServiceServlet">
<filter id="576720909">
<message_arguments>
diff --git a/bundles/org.eclipse.equinox.http.servlet/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.http.servlet/.settings/org.eclipse.jdt.core.prefs
index f31f2500..dd2c5e66 100644
--- a/bundles/org.eclipse.equinox.http.servlet/.settings/org.eclipse.jdt.core.prefs
+++ b/bundles/org.eclipse.equinox.http.servlet/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,3 @@
-#Tue Aug 21 11:27:47 CDT 2007
eclipse.preferences.version=1
org.eclipse.jdt.core.builder.cleanOutputFolder=clean
org.eclipse.jdt.core.builder.duplicateResourceTask=warning
@@ -7,24 +6,24 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch
org.eclipse.jdt.core.circularClasspath=error
org.eclipse.jdt.core.classpath.exclusionPatterns=enabled
org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
org.eclipse.jdt.core.compiler.maxProblemPerUnit=1000
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=error
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
org.eclipse.jdt.core.compiler.problem.finalParameterBound=ignore
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
@@ -72,28 +71,32 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=en
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.source=1.3
+org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
-org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
-org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
-org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
-org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
-org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
-org.eclipse.jdt.core.formatter.alignment_for_assignment=0
-org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
-org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
-org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
-org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
-org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=32
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=32
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=32
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=32
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=32
+org.eclipse.jdt.core.formatter.alignment_for_assignment=1
+org.eclipse.jdt.core.formatter.alignment_for_binary_expression=36
+org.eclipse.jdt.core.formatter.alignment_for_compact_if=32
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=0
+org.eclipse.jdt.core.formatter.alignment_for_enum_constants=32
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=32
+org.eclipse.jdt.core.formatter.alignment_for_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
-org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
-org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
-org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
-org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
-org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
-org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
-org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=32
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=32
+org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
+org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=80
+org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=36
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=32
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=36
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=37
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
org.eclipse.jdt.core.formatter.blank_lines_after_package=1
org.eclipse.jdt.core.formatter.blank_lines_before_field=0
@@ -124,15 +127,21 @@ org.eclipse.jdt.core.formatter.comment.format_html=true
org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=false
org.eclipse.jdt.core.formatter.comment.format_line_comments=false
org.eclipse.jdt.core.formatter.comment.format_source_code=true
-org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false
-org.eclipse.jdt.core.formatter.comment.indent_root_tags=false
+org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true
+org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
-org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
org.eclipse.jdt.core.formatter.comment.line_length=80
+org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
+org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
+org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false
org.eclipse.jdt.core.formatter.compact_else_if=true
-org.eclipse.jdt.core.formatter.continuation_indentation=2
-org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
+org.eclipse.jdt.core.formatter.continuation_indentation=1
+org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=1
+org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
+org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
+org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
@@ -144,16 +153,22 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true
org.eclipse.jdt.core.formatter.indentation.size=4
-org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
-org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=insert
org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
-org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
-org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
-org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert
-org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert
@@ -196,7 +211,7 @@ org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
-org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
@@ -211,12 +226,14 @@ org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invoca
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
@@ -225,7 +242,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
-org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
@@ -240,11 +257,12 @@ org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invoc
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
-org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
-org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
@@ -295,6 +313,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invoc
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
@@ -304,6 +323,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=inser
org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
@@ -313,19 +333,24 @@ org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.join_lines_in_comments=true
+org.eclipse.jdt.core.formatter.join_wrapped_lines=true
org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
-org.eclipse.jdt.core.formatter.lineSplit=800
+org.eclipse.jdt.core.formatter.lineSplit=80
org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
-org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=false
-org.eclipse.jdt.core.formatter.tabulation.char=tab
+org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
+org.eclipse.jdt.core.formatter.tabulation.char=mixed
org.eclipse.jdt.core.formatter.tabulation.size=4
+org.eclipse.jdt.core.formatter.use_on_off_tags=false
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
+org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
org.eclipse.jdt.core.incompatibleJDKLevel=ignore
org.eclipse.jdt.core.incompleteClasspath=error
diff --git a/bundles/org.eclipse.equinox.http.servlet/.settings/org.eclipse.jdt.ui.prefs b/bundles/org.eclipse.equinox.http.servlet/.settings/org.eclipse.jdt.ui.prefs
index 21bd9f3c..998150e8 100644
--- a/bundles/org.eclipse.equinox.http.servlet/.settings/org.eclipse.jdt.ui.prefs
+++ b/bundles/org.eclipse.equinox.http.servlet/.settings/org.eclipse.jdt.ui.prefs
@@ -1,18 +1,21 @@
-#Tue Aug 21 11:30:07 CDT 2007
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
-formatter_profile=_core
-formatter_settings_version=11
+formatter_profile=_Eclipse [built-in] + Personal Changes
+formatter_settings_version=12
org.eclipse.jdt.ui.ignorelowercasenames=true
org.eclipse.jdt.ui.importorder=;
+org.eclipse.jdt.ui.javadoc=true
org.eclipse.jdt.ui.ondemandthreshold=3
org.eclipse.jdt.ui.staticondemandthreshold=3
+org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="false" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment"/><template autoinsert\="false" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment"/><template autoinsert\="false" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment"/><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*******************************************************************************\n * Copyright (c) ${date} Liferay, Inc.\n * All rights reserved. This program and the accompanying materials\n * are made available under the terms of the Eclipse Public License v1.0\n * which accompanies this distribution, and is available at\n * http\://www.eclipse.org/legal/epl-v10.html\n *\n * Contributors\:\n * Liferay, Inc. - initial API and implementation and/or initial \n * documentation\n ******************************************************************************/\n</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author Raymond Aug\u00E9\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="false" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment"/><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment"/><template autoinsert\="false" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment"/><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="false" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody"/><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">_log.error(${exception_var}, ${exception_var});</template><template autoinsert\="false" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">${body_statement}</template><template autoinsert\="false" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true
sp_cleanup.add_missing_deprecated_annotations=true
+sp_cleanup.add_missing_methods=false
sp_cleanup.add_missing_nls_tags=false
sp_cleanup.add_missing_override_annotations=true
+sp_cleanup.add_missing_override_annotations_interface_methods=false
sp_cleanup.add_serial_version_id=false
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=false
@@ -20,10 +23,12 @@ sp_cleanup.always_use_this_for_non_static_field_access=false
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.correct_indentation=false
-sp_cleanup.format_source_code=true
+sp_cleanup.format_source_code=false
+sp_cleanup.format_source_code_changes_only=false
sp_cleanup.make_local_variable_final=false
sp_cleanup.make_parameters_final=false
sp_cleanup.make_private_fields_final=true
+sp_cleanup.make_type_abstract_if_missing_method=false
sp_cleanup.make_variable_declarations_final=true
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=true
diff --git a/bundles/org.eclipse.equinox.http.servlet/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.http.servlet/META-INF/MANIFEST.MF
index 5603f139..c79c4e17 100644
--- a/bundles/org.eclipse.equinox.http.servlet/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.http.servlet/META-INF/MANIFEST.MF
@@ -3,18 +3,28 @@ Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.equinox.http.servlet
-Bundle-Version: 1.1.500.qualifier
+Bundle-Version: 1.2.0.qualifier
Bundle-Activator: org.eclipse.equinox.http.servlet.internal.Activator
Bundle-Localization: plugin
-Bundle-RequiredExecutionEnvironment: CDC-1.0/Foundation-1.0,
- J2SE-1.3
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: org.eclipse.equinox.http.servlet;version="1.1.0"
Import-Package: javax.servlet;version="[2.3.0,4.0.0)",
javax.servlet.annotation;version="2.6.0";resolution:=optional,
javax.servlet.descriptor;version="2.6.0";resolution:=optional,
javax.servlet.http;version="[2.3.0,4.0.0)",
- org.osgi.framework;version="1.3.0",
- org.osgi.service.http;version="[1.2,1.3)"
+ org.osgi.dto;version="[1.0.0,2.0)",
+ org.osgi.framework;version="[1.3.0,2.0)",
+ org.osgi.framework.wiring;version="[1.1.0,2.0)",
+ org.osgi.service.http;version="[1.2,1.3)",
+ org.osgi.service.http.context;version="[1.0,1.1)",
+ org.osgi.service.http.runtime;version="[1.0,1.1)",
+ org.osgi.service.http.runtime.dto;version="[1.0,1.1)",
+ org.osgi.service.http.whiteboard;version="[1.0,1.1)",
+ org.osgi.util.tracker;version="[1.5,2.0)"
Comment-Header: Both Eclipse-LazyStart and Bundle-ActivationPolicy are specified for compatibility with 3.2
Eclipse-LazyStart: true
Bundle-ActivationPolicy: lazy
+Provide-Capability: osgi.whiteboard;
+ osgi.whiteboard="osgi.http";
+ uses:="javax.servlet,javax.servlet.http";
+ version:Version="1.3"
diff --git a/bundles/org.eclipse.equinox.http.servlet/build.properties b/bundles/org.eclipse.equinox.http.servlet/build.properties
index 570200f1..cf3f2136 100644
--- a/bundles/org.eclipse.equinox.http.servlet/build.properties
+++ b/bundles/org.eclipse.equinox.http.servlet/build.properties
@@ -15,3 +15,5 @@ bin.includes = META-INF/,\
about.html,\
plugin.properties
src.includes = about.html
+
+jars.extra.classpath = osgi/osgi.annotation.jar
diff --git a/bundles/org.eclipse.equinox.http.servlet/osgi/osgi.annotation.jar b/bundles/org.eclipse.equinox.http.servlet/osgi/osgi.annotation.jar
new file mode 100644
index 00000000..dda27d2f
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/osgi/osgi.annotation.jar
Binary files differ
diff --git a/bundles/org.eclipse.equinox.http.servlet/pom.xml b/bundles/org.eclipse.equinox.http.servlet/pom.xml
index 98089783..b1ffbd86 100644
--- a/bundles/org.eclipse.equinox.http.servlet/pom.xml
+++ b/bundles/org.eclipse.equinox.http.servlet/pom.xml
@@ -19,6 +19,6 @@
</parent>
<groupId>org.eclipse.equinox</groupId>
<artifactId>org.eclipse.equinox.http.servlet</artifactId>
- <version>1.1.500-SNAPSHOT</version>
+ <version>1.2.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/ExtendedHttpService.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/ExtendedHttpService.java
index bcb586fc..8255ddfb 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/ExtendedHttpService.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/ExtendedHttpService.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation and others.
+ * Copyright (c) 2011, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,18 +7,23 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
*******************************************************************************/
package org.eclipse.equinox.http.servlet;
-import java.util.Dictionary;
-import javax.servlet.Filter;
-import javax.servlet.ServletException;
+import java.util.*;
+import javax.servlet.*;
+import org.osgi.annotation.versioning.ProviderType;
+import org.osgi.framework.Bundle;
import org.osgi.service.http.*;
+import org.osgi.service.http.context.ServletContextHelper;
/**
* @since 1.1
*/
+@ProviderType
public interface ExtendedHttpService extends HttpService {
+
/**
* @param alias name in the URI namespace at which the filter is registered
* @param filter the filter object to register
@@ -34,12 +39,155 @@ public interface ExtendedHttpService extends HttpService {
* @throws java.lang.IllegalArgumentException if any of the arguments are
* invalid
*/
- public void registerFilter(String alias, Filter filter, Dictionary initparams, HttpContext context) throws ServletException, NamespaceException;
+ public void registerFilter(String alias, Filter filter, Dictionary<String, String> initparams, HttpContext context) throws ServletException, NamespaceException;
+
+ /**
+ * @param filter the filter object to register
+ * @param name the name to use for the filter registration (required)
+ * @param patterns an array of URI patterns to which the filter will apply (optional) one of this or servletNames are required
+ * @param servletNames an array of servlet names to which a filter will apply (optional)
+ * @param dispatcher the array of dispatcher names to which the filter applies (default is REQUEST when empty or null)
+ * @param asyncSupported whether the filter applies to async servlets
+ * @param filterPriority the priority determines the order filters will take when other criteria still result in conflict
+ * @param initparams initialization arguments for the filter or
+ * <code>null</code> if there are none. This argument is used by the
+ * filter's <code>FilterConfig</code> object.
+ * @param contextSelector the name of a context under which to register the filter (if the strings starts with '(' it will be parsed as a OSGi filter string)
+ * @throws javax.servlet.ServletException if the filter's <code>init</code>
+ * method throws an exception, or the given filter object has
+ * already been registered.
+ * @throws java.lang.IllegalArgumentException if any of the arguments are
+ * invalid
+ *
+ * @since 1.2
+ */
+ public void registerFilter(
+ Filter filter, String name, String[] patterns,
+ String[] servletNames, String[] dispatcher,
+ boolean asyncSupported, int filterPriority,
+ Map<String, String> initparams, String contextSelector)
+ throws ServletException;
+
+ /**
+ * Register a listener implementing any of the following types:
+ * <ul>
+ * <li>javax.servlet.ServletContextListener</li>
+ * <li>javax.servlet.ServletContextAttributeListener</li>
+ * <li>javax.servlet.ServletRequestListener</li>
+ * <li>javax.servlet.ServletRequestAttributeListener</li>
+ * <li>javax.servlet.http.HttpSessionListener</li>
+ * <li>javax.servlet.http.HttpSessionAttributeListener</li>
+ * </ul>
+ *
+ * @param eventListener the listener object to register
+ * @param contextSelector the name of a context under which to register the filter (if the strings starts with '(' it will be parsed as a OSGi filter string)
+ * @throws ServletException if the listener is already registered
+ * @throws java.lang.IllegalArgumentException if any of the arguments are
+ * invalid
+ *
+ * @since 1.2
+ */
+ public void registerListener(
+ EventListener eventListener, String contextSelector)
+ throws ServletException;
+
+ /**
+ * @param patterns an array of URI patterns to which the filter will apply (optional) one of this or servletNames are required
+ * @param prefix the base name of the resources that will be registered
+ * @param contextSelector the name of a context under which to register the filter (if the strings starts with '(' it will be parsed as a OSGi filter string)
+ * @throws NamespaceException if the registration fails because the alias is
+ * already in use.
+ * @throws java.lang.IllegalArgumentException if any of the parameters are
+ * invalid
+ *
+ * @since 1.2
+ */
+ public void registerResources(
+ String[] patterns, String prefix, String contextSelector)
+ throws NamespaceException;
+
+ /**
+ * @param servlet the servlet object to register
+ * @param name the name to use for the filter registration (required)
+ * @param patterns an array of URI patterns to which the filter will apply (optional) one of this or servletNames are required
+ * @param errorPages an array of exception names and/or HTTP error codes for which the servlet will server error messages
+ * @param asyncSupported whether the servlet supports async request handling
+ * @param initparams initialization arguments for the servlet or
+ * <code>null</code> if there are none. This argument is used by the
+ * servlets's <code>ServletConfig</code> object.
+ * @param contextSelector the name of a context under which to register the servlet (if the strings starts with '(' it will be parsed as a OSGi filter string)
+ * @throws javax.servlet.ServletException if the servlet's <code>init</code>
+ * method throws an exception, or the given servlet object has
+ * already been registered.
+ * @throws java.lang.IllegalArgumentException if any of the arguments are
+ * invalid
+ *
+ * @since 1.2
+ */
+ public void registerServlet(
+ Servlet servlet, String name, String[] patterns,
+ String[] errorPages, boolean asyncSupported,
+ Map<String, String> initparams, String contextSelector)
+ throws ServletException, NamespaceException;
+
+ /**
+ * @param servletContextHelper the servletContextHelper object to register
+ * @param bundle the bundle to which the servletContextHelper is attached
+ * @param contextNames the contextNames to use for the servletContextHelper
+ * registration, the first one in the list is considered the official
+ * name and the others are aliases (at least 1 required)
+ * @param contextPath optional property for defining an additional context
+ * path for the context.
+ * @param initparams initialization arguments for the servlet context helper
+ * or <code>null</code> if there are none. These values are
+ * accessible via the ServletContext.
+ * @throws ServletException if the servletContextHelper is already registered
+ * @throws java.lang.IllegalArgumentException if any of the arguments are
+ * invalid
+ *
+ * @since 1.2
+ */
+ public void registerServletContextHelper(
+ ServletContextHelper servletContextHelper, Bundle bundle,
+ String[] contextNames, String contextPath,
+ Map<String, String> initparams)
+ throws ServletException;
+
+ /**
+ * Unregisters a previous registration done by {@code registerServlet} or
+ * {@code registerResources} methods with reference to a
+ * ServletContextHelper.
+ *
+ * <p>
+ * After this call, the registered pattern in the URI name-space of the
+ * ServletContextHelper will no longer be available. If the registration was
+ * for a servlet, the Http Service must call the {@code destroy} method of
+ * the servlet before returning.
+ * <p>
+ * If the bundle which performed the registration is stopped or otherwise
+ * "unget"s the Http Service without calling {@link #unregister(String, String)}
+ * then Http Service must automatically unregister the registration.
+ * However, if the registration was for a servlet, the {@code destroy}
+ * method of the servlet will not be called in this case since the bundle
+ * may be stopped. {@link #unregister(String, String)} must be explicitly
+ * called to cause the {@code destroy} method of the servlet to be called.
+ * This can be done in the {@code BundleActivator.stop} method of the bundle
+ * registering the servlet.
+ *
+ * @param pattern name in the URI name-space of the registration to unregister
+ * @param contextSelector the name of a context under which the filter was registered (if the strings starts with '(' it will be parsed as a OSGi filter string)
+ * @throws java.lang.IllegalArgumentException if there is no registration
+ * for the pattern or the calling bundle was not the bundle which
+ * registered the alias.
+ *
+ * @since 1.2
+ */
+ public void unregister(String pattern, String contextSelector);
/**
- * Unregisters a previous filter registration done by the
- * <code>registerFilter</code> method.
- *
+ * Unregisters a previous filter registration done by the
+ * <code>registerFilter</code> methods.
+ *
* <p>
* After this call, the registered filter will no
* longer be available. The Http Service must call the <code>destroy</code>
@@ -47,19 +195,114 @@ public interface ExtendedHttpService extends HttpService {
* <p>
* If the bundle which performed the registration is stopped or otherwise
* "unget"s the Http Service without calling {@link #unregisterFilter} then the Http
- * Service must automatically unregister the filter registration. However, the
+ * Service must automatically unregister the filter registration. However, the
* <code>destroy</code> method of the filter will not be called in this case since
* the bundle may be stopped.
* {@link #unregisterFilter} must be explicitly called to cause the
* <code>destroy</code> method of the filter to be called. This can be done
* in the <code>BundleActivator.stop</code> method of the
* bundle registering the filter.
- *
+ *
* @param filter the filter object to unregister
* @throws java.lang.IllegalArgumentException if there is no registration
* for the filter or the calling bundle was not the bundle which
* registered the filter.
+ * @deprecated
*/
+ @Deprecated
public void unregisterFilter(Filter filter);
+ /**
+ * Unregisters a previous filter registration done by the
+ * <code>registerFilter</code> methods.
+ *
+ * <p>
+ * After this call, the registered filter will no
+ * longer be available. The Http Service must call the <code>destroy</code>
+ * method of the filter before returning.
+ * <p>
+ * If the bundle which performed the registration is stopped or otherwise
+ * "unget"s the Http Service without calling {@link #unregisterFilter} then the Http
+ * Service must automatically unregister the filter registration. However, the
+ * <code>destroy</code> method of the filter will not be called in this case since
+ * the bundle may be stopped.
+ * {@link #unregisterFilter} must be explicitly called to cause the
+ * <code>destroy</code> method of the filter to be called. This can be done
+ * in the <code>BundleActivator.stop</code> method of the
+ * bundle registering the filter.
+ *
+ * @param filter the filter object to unregister
+ * @param contextSelector the name of a context under which the filter was registered (if the strings starts with '(' it will be parsed as a OSGi filter string)
+ * @throws java.lang.IllegalArgumentException if there is no registration
+ * for the filter or the calling bundle was not the bundle which
+ * registered the filter.
+ * @since 1.2
+ */
+ public void unregisterFilter(Filter filter, String contextSelector);
+
+ /**
+ * Unregisters a previous listener registration done by the
+ * <code>registerListener</code> methods.
+ *
+ * <p>
+ * After this call, the registered listener will no
+ * longer be available.
+ * <p>
+ *
+ * @param eventListener the listener object to unregister
+ * @param contextSelector the name of a context under which the listener was registered (if the strings starts with '(' it will be parsed as a OSGi filter string)
+ * @throws java.lang.IllegalArgumentException if there is no registration
+ * for the listener or the calling bundle was not the bundle which
+ * registered the listener.
+ *
+ * @since 1.2
+ */
+ public void unregisterListener(
+ EventListener eventListener, String contextSelector);
+
+ /**
+ * Unregisters a previous servlet registration done by the
+ * <code>registerServlet</code> methods.
+ *
+ * <p>
+ * After this call, the registered servlet will no
+ * longer be available.
+ * <p>
+ *
+ * @param servlet the servlet object to unregister
+ * @param contextSelector the name of a context under which the servlet was registered (if the strings starts with '(' it will be parsed as a OSGi filter string)
+ * @throws java.lang.IllegalArgumentException if there is no registration
+ * for the servlet or the calling bundle was not the bundle which
+ * registered the servlet.
+ *
+ * @since 1.2
+ */
+ public void unregisterServlet(Servlet servlet, String contextSelector);
+
+ /**
+ * Unregisters a previous servletContextHelper registration done by the
+ * <code>registerServletContextHelper</code> methods.
+ *
+ * <p>
+ * After this call, the registered servletContextHelper will no
+ * longer be available.
+ * <p>
+ * If the bundle which performed the registration is stopped or otherwise
+ * "unget"s the Http Service without calling {@link #unregisterServlet} then
+ * the Http Service must automatically unregister the servletContextHelper
+ * registration. {@link #unregisterServletContextHelper} must be explicitly
+ * called for the servletContextHelper to unregister and destroy all
+ * associated resources. This can be done in the <code>BundleActivator.stop</code>
+ * method of the bundle registering the servletContextHelper.
+ *
+ * @param servletContextHelper the servletContextHelper object to unregister
+ * @throws java.lang.IllegalArgumentException if there is no registration
+ * for the servletContextHelper or the calling bundle was not the
+ * bundle which registered the servletContextHelper.
+ *
+ * @since 1.2
+ */
+ public void unregisterServletContextHelper(
+ ServletContextHelper servletContextHelper);
+
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/HttpServiceServlet.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/HttpServiceServlet.java
index a511ae9c..535c7e73 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/HttpServiceServlet.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/HttpServiceServlet.java
@@ -1,17 +1,18 @@
/*******************************************************************************
- * Copyright (c) 2005, 2008 Cognos Incorporated, IBM Corporation and others.
+ * Copyright (c) 2005, 2014 Cognos Incorporated, IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Cognos Incorporated - initial API and implementation
* IBM Corporation - bug fixes and enhancements
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
*******************************************************************************/
package org.eclipse.equinox.http.servlet;
-import org.eclipse.equinox.http.servlet.internal.ProxyServlet;
+import org.eclipse.equinox.http.servlet.internal.servlet.ProxyServlet;
/**
* The HttpServiceServlet is the "public" side of a Servlet that when registered (and init() called) in a servlet container
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Activator.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Activator.java
index 99ab714a..7b7fcfa4 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Activator.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Activator.java
@@ -1,89 +1,250 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 Cognos Incorporated, IBM Corporation and others.
+ * Copyright (c) 2005, 2014 Cognos Incorporated, IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Cognos Incorporated - initial API and implementation
* IBM Corporation - bug fixes and enhancements
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
*******************************************************************************/
package org.eclipse.equinox.http.servlet.internal;
import java.util.*;
-import javax.servlet.ServletConfig;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import javax.servlet.*;
+import javax.servlet.http.HttpServlet;
import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.internal.servlet.ProxyServlet;
+import org.eclipse.equinox.http.servlet.internal.util.HttpTuple;
+import org.eclipse.equinox.http.servlet.internal.util.UMDictionaryMap;
import org.osgi.framework.*;
import org.osgi.service.http.HttpService;
+import org.osgi.service.http.runtime.HttpServiceRuntime;
+import org.osgi.service.http.runtime.HttpServiceRuntimeConstants;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
-public class Activator implements BundleActivator {
+public class Activator
+ implements BundleActivator, ServiceTrackerCustomizer<HttpServlet, HttpTuple> {
private static final String DEFAULT_SERVICE_DESCRIPTION = "Equinox Servlet Bridge"; //$NON-NLS-1$
private static final String DEFAULT_SERVICE_VENDOR = "Eclipse.org"; //$NON-NLS-1$
- private static final String[] HTTP_SERVICES_CLASSES = new String[] {HttpService.class.getName(), ExtendedHttpService.class.getName()};
+ private static final String[] HTTP_SERVICES_CLASSES = new String[] {
+ HttpService.class.getName(), ExtendedHttpService.class.getName()
+ };
- private static BundleContext context;
- private static Map serviceRegistrations = new HashMap();
+ private static volatile BundleContext context;
+ private static ConcurrentMap<ProxyServlet, Object> registrations =
+ new ConcurrentHashMap<ProxyServlet, Object>();
+
+ private ServiceTracker<HttpServlet, HttpTuple> serviceTracker;
+
+ public static void addProxyServlet(ProxyServlet proxyServlet) {
+ Object previousRegistration = registrations.putIfAbsent(
+ proxyServlet, proxyServlet);
+
+ if (!(previousRegistration instanceof ServiceRegistration) &&
+ (context != null)) {
+
+ ServiceRegistration<HttpServlet> serviceRegistration =
+ context.registerService(
+ HttpServlet.class, proxyServlet,
+ new Hashtable<String, Object>());
+
+ registrations.put(proxyServlet, serviceRegistration);
+ }
+ }
+
+ public static void unregisterHttpService(ProxyServlet proxyServlet) {
+ Object registration = registrations.remove(proxyServlet);
+
+ if (registration instanceof ServiceRegistration) {
+ ServiceRegistration<?> serviceRegistration =
+ (ServiceRegistration<?>)registration;
+
+ serviceRegistration.unregister();
+ }
+ }
public void start(BundleContext bundleContext) throws Exception {
- startHttpServiceProxy(bundleContext);
+ context = bundleContext;
+
+ processRegistrations();
+
+ serviceTracker = new ServiceTracker<HttpServlet, HttpTuple>(
+ context, HttpServlet.class, this);
+
+ serviceTracker.open();
}
public void stop(BundleContext bundleContext) throws Exception {
- stopHttpServiceProxy(bundleContext);
+ serviceTracker.close();
+ serviceTracker = null;
+ context = null;
}
- private static synchronized void startHttpServiceProxy(BundleContext bundleContext) {
- context = bundleContext;
- Object[] proxyServlets = serviceRegistrations.keySet().toArray();
- for (int i = 0; i < proxyServlets.length; ++i) {
- ServiceRegistration registration = registerHttpService((ProxyServlet) proxyServlets[i]);
- serviceRegistrations.put(proxyServlets[i], registration);
+ public HttpTuple addingService(
+ ServiceReference<HttpServlet> serviceReference) {
+
+ HttpServlet httpServlet = context.getService(serviceReference);
+
+ if (!(httpServlet instanceof ProxyServlet)) {
+ return null;
}
- }
- private static synchronized void stopHttpServiceProxy(BundleContext bundleContext) {
- Object[] proxyServlets = serviceRegistrations.keySet().toArray();
- for (int i = 0; i < proxyServlets.length; ++i) {
- ServiceRegistration registration = (ServiceRegistration) serviceRegistrations.put(proxyServlets[i], null);
- registration.unregister();
+ ProxyServlet proxyServlet = (ProxyServlet)httpServlet;
+
+ ServletConfig servletConfig = proxyServlet.getServletConfig();
+ ServletContext servletContext = servletConfig.getServletContext();
+
+ String[] httpServiceEndpoints = getHttpServiceEndpoints(
+ servletContext, servletConfig.getServletName());
+
+ Dictionary<String, Object> serviceProperties =
+ new Hashtable<String, Object>(3);
+
+ Enumeration<String> initparameterNames =
+ servletConfig.getInitParameterNames();
+
+ while (initparameterNames.hasMoreElements()) {
+ String name = initparameterNames.nextElement();
+
+ serviceProperties.put(
+ name, servletConfig.getInitParameter(name));
}
- serviceRegistrations.clear();
- context = null;
+
+ if (serviceProperties.get(Constants.SERVICE_VENDOR) == null) {
+ serviceProperties.put(
+ Constants.SERVICE_VENDOR, DEFAULT_SERVICE_VENDOR);
+ }
+
+ if (serviceProperties.get(Constants.SERVICE_DESCRIPTION) == null) {
+ serviceProperties.put(
+ Constants.SERVICE_DESCRIPTION, DEFAULT_SERVICE_DESCRIPTION);
+ }
+
+ if (serviceProperties.get(
+ HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT_ATTRIBUTE) == null) {
+
+ serviceProperties.put(
+ HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT_ATTRIBUTE,
+ httpServiceEndpoints);
+ }
+
+ // white board support
+
+ HttpServiceRuntimeImpl httpServiceRuntime = new HttpServiceRuntimeImpl(
+ context, servletContext,
+ new UMDictionaryMap<String, Object>(serviceProperties));
+
+ ServiceRegistration<HttpServiceRuntime> hsrRegistration =
+ context.registerService(
+ HttpServiceRuntime.class, httpServiceRuntime,
+ serviceProperties);
+
+ proxyServlet.setHttpServiceRuntimeImpl(httpServiceRuntime);
+
+ // imperative API support
+
+ HttpServiceFactory httpServiceFactory = new HttpServiceFactory(
+ httpServiceRuntime);
+
+ ServiceRegistration<?> hsfRegistration = context.registerService(
+ HTTP_SERVICES_CLASSES, httpServiceFactory, serviceProperties);
+
+ return new HttpTuple(
+ proxyServlet, httpServiceFactory, hsfRegistration,
+ httpServiceRuntime, hsrRegistration);
}
- static synchronized void addProxyServlet(ProxyServlet proxyServlet) {
- ServiceRegistration registration = null;
- if (context != null)
- registration = registerHttpService(proxyServlet);
+ public void modifiedService(
+ ServiceReference<HttpServlet> serviceReference, HttpTuple httpTuple) {
- serviceRegistrations.put(proxyServlet, registration);
+ removedService(serviceReference, httpTuple);
+ addingService(serviceReference);
}
- private static ServiceRegistration registerHttpService(ProxyServlet proxyServlet) {
- HttpServiceFactory factory = new HttpServiceFactory(proxyServlet);
- Dictionary serviceProperties = new Hashtable(2);
- ServletConfig config = proxyServlet.getServletConfig();
- Enumeration initparameterNames = config.getInitParameterNames();
- while (initparameterNames.hasMoreElements()) {
- String name = (String) initparameterNames.nextElement();
- serviceProperties.put(name, config.getInitParameter(name));
+ public void removedService(
+ ServiceReference<HttpServlet> serviceReference, HttpTuple httpTuple) {
+
+ context.ungetService(serviceReference);
+
+ httpTuple.destroy();
+ }
+
+ private String[] getHttpServiceEndpoints(
+ ServletContext servletContext, String servletName) {
+
+ int majorVersion = servletContext.getMajorVersion();
+
+ if (majorVersion < 3) {
+ servletContext.log(
+ "The http container does not support servlet 3.0+. " +
+ "Therefore, the value of " +
+ HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT_ATTRIBUTE +
+ " cannot be calculated.");
+
+ return new String[0];
+ }
+
+ String contextPath = servletContext.getContextPath();
+
+ ServletRegistration servletRegistration =
+ servletContext.getServletRegistration(servletName);
+
+ if (servletRegistration == null) {
+ return new String[0];
}
- if (serviceProperties.get(Constants.SERVICE_VENDOR) == null)
- serviceProperties.put(Constants.SERVICE_VENDOR, DEFAULT_SERVICE_VENDOR);
+ Collection<String> mappings = servletRegistration.getMappings();
+
+ List<String> httpServiceEndpoints = new ArrayList<String>();
+
+ for (String mapping : mappings) {
+ if (mapping.indexOf('/') == 0) {
+ if (mapping.charAt(mapping.length() - 1) == '*') {
+ mapping = mapping.substring(0, mapping.length() - 2);
+
+ if ((mapping.length() > 1) &&
+ (mapping.charAt(mapping.length() - 1) != '/')) {
- if (serviceProperties.get(Constants.SERVICE_DESCRIPTION) == null)
- serviceProperties.put(Constants.SERVICE_DESCRIPTION, DEFAULT_SERVICE_DESCRIPTION);
+ mapping += '/';
+ }
+ }
- return context.registerService(HTTP_SERVICES_CLASSES, factory, serviceProperties);
+ httpServiceEndpoints.add(contextPath + mapping);
+ }
+ }
+
+ return httpServiceEndpoints.toArray(
+ new String[httpServiceEndpoints.size()]);
}
- static synchronized void removeProxyServlet(ProxyServlet proxyServlet) {
- ServiceRegistration registration = (ServiceRegistration) serviceRegistrations.remove(proxyServlet);
- if (registration != null)
- registration.unregister();
+ private void processRegistrations() {
+ Iterator<Entry<ProxyServlet, Object>> iterator =
+ registrations.entrySet().iterator();
+
+ while (iterator.hasNext()) {
+ Entry<ProxyServlet, Object> entry = iterator.next();
+
+ ProxyServlet proxyServlet = entry.getKey();
+ Object value = entry.getValue();
+
+ if (!(value instanceof ServiceRegistration)) {
+ ServiceRegistration<HttpServlet> serviceRegistration =
+ context.registerService(
+ HttpServlet.class, proxyServlet,
+ new Hashtable<String, Object>());
+
+ entry.setValue(serviceRegistration);
+ }
+ }
}
-}
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/FilterConfigImpl.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/FilterConfigImpl.java
deleted file mode 100644
index 388b7809..00000000
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/FilterConfigImpl.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet.internal;
-
-import java.util.*;
-import javax.servlet.*;
-
-public class FilterConfigImpl implements FilterConfig {
-
- private static final Dictionary EMPTY_PARAMS = new Hashtable(0);
- private static final String FILTER_NAME = "filter-name"; //$NON-NLS-1$
- private Filter filter;
- private Dictionary initparams;
- private ServletContext servletContext;
-
- public FilterConfigImpl(Filter filter, Dictionary initparams, ServletContext servletContext) {
- this.filter = filter;
- this.initparams = (initparams != null) ? initparams : EMPTY_PARAMS;
- this.servletContext = servletContext;
- }
-
- /*
- * @see javax.servlet.FilterConfig#getFilterName()
- *
- * The OSGi Http Service does not specify a way to set a filter name at the API level. This
- * implementation will try to use the value of the "filter-name" initial parameter if available.
- */
- public String getFilterName() {
- String filterName = (String) initparams.get(FILTER_NAME);
- return (filterName != null) ? filterName : filter.getClass().getName();
- }
-
- public ServletContext getServletContext() {
- return servletContext;
- }
-
- public String getInitParameter(String name) {
- return (String) initparams.get(name);
- }
-
- public Enumeration getInitParameterNames() {
- return initparams.keys();
- }
-}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/FilterRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/FilterRegistration.java
deleted file mode 100644
index a976f271..00000000
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/FilterRegistration.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet.internal;
-
-import java.io.IOException;
-import javax.servlet.*;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.osgi.service.http.HttpContext;
-
-//This class wraps the filter object registered in the HttpService.registerFilter call, to manage the context classloader when handleRequests are being asked.
-public class FilterRegistration extends Registration implements Comparable {
-
- private static long nextSequenceNumber = 1L;
-
- private final Filter filter; //The actual filter object registered against the http service. All filter requests will eventually be delegated to it.
- private final HttpContext httpContext; //The context used during the registration of the filter
- private final ClassLoader registeredContextClassLoader;
- private final String prefix;
- private final String suffix;
- private final int priority;
- private final long sequenceNumber;
-
- public FilterRegistration(Filter filter, HttpContext context, String alias, int priority) {
- this.filter = filter;
- this.httpContext = context;
- registeredContextClassLoader = Thread.currentThread().getContextClassLoader();
-
- int lastSlash = alias.lastIndexOf('/');
- String lastSegment = alias.substring(alias.lastIndexOf('/') + 1);
- if (lastSegment.startsWith("*.")) { //$NON-NLS-1$
- prefix = alias.substring(0, lastSlash);
- suffix = lastSegment.substring(1);
- } else {
- prefix = alias.equals("/") ? "" : alias; //$NON-NLS-1$//$NON-NLS-2$
- suffix = null;
- }
-
- this.priority = priority;
- synchronized (FilterRegistration.class) {
- this.sequenceNumber = nextSequenceNumber++;
- }
- }
-
- public void destroy() {
- ClassLoader original = Thread.currentThread().getContextClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(registeredContextClassLoader);
- super.destroy();
- filter.destroy();
- } finally {
- Thread.currentThread().setContextClassLoader(original);
- }
- }
-
- //Delegate the init call to the actual filter
- public void init(FilterConfig filterConfig) throws ServletException {
- ClassLoader original = Thread.currentThread().getContextClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(registeredContextClassLoader);
- filter.init(filterConfig);
- } finally {
- Thread.currentThread().setContextClassLoader(original);
- }
- }
-
- //Delegate the handling of the request to the actual filter
- public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
- ClassLoader original = Thread.currentThread().getContextClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(registeredContextClassLoader);
- if (httpContext.handleSecurity(request, response))
- filter.doFilter(request, response, chain);
- } finally {
- Thread.currentThread().setContextClassLoader(original);
- }
- }
-
- public Filter getFilter() {
- return filter;
- }
-
- public HttpContext getHttpContext() {
- return httpContext;
- }
-
- public boolean matches(String dispatchPathInfo) {
- if (!dispatchPathInfo.startsWith(prefix))
- return false;
-
- // perfect match
- if (prefix.length() == dispatchPathInfo.length())
- return suffix == null;
-
- // check the next character is a path separator
- if (dispatchPathInfo.charAt(prefix.length()) != '/')
- return false;
-
- // check for an extension match
- if (suffix == null)
- return true;
-
- return dispatchPathInfo.endsWith(suffix) && dispatchPathInfo.length() > prefix.length() + suffix.length();
- }
-
- public int compareTo(Object other) {
- FilterRegistration otherFilterRegistration = (FilterRegistration) other;
- int priorityDifference = priority - otherFilterRegistration.priority;
- if (priorityDifference != 0)
- return -priorityDifference;
-
- return (sequenceNumber > otherFilterRegistration.sequenceNumber) ? 1 : -1;
- }
-}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceFactory.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceFactory.java
index e473c9d4..0c147cc9 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceFactory.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceFactory.java
@@ -1,35 +1,52 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 Cognos Incorporated, IBM Corporation and others.
+ * Copyright (c) 2005, 2014 Cognos Incorporated, IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Cognos Incorporated - initial API and implementation
* IBM Corporation - bug fixes and enhancements
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
*******************************************************************************/
package org.eclipse.equinox.http.servlet.internal;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import org.eclipse.equinox.http.servlet.internal.context.ContextController;
+import org.eclipse.equinox.http.servlet.internal.registration.Registration;
import org.osgi.framework.*;
+import org.osgi.service.http.HttpService;
-// Factory to create http services. This is because the service needs to be customized for each bundle in order to implement the default resource lookups.
-public class HttpServiceFactory implements ServiceFactory {
+// Factory to create http services. This is because the service needs to be
+// customized for each bundle in order to implement the default resource
+// lookups.
+public class HttpServiceFactory implements ServiceFactory<HttpService> {
- private ProxyServlet proxy;
+ private final HttpServiceRuntimeImpl httpServiceRuntime;
+ private final ConcurrentMap<ContextController, Map<Object, Registration<?, ?>>> registrations =
+ new ConcurrentHashMap<ContextController, Map<Object, Registration<?, ?>>>();
- public HttpServiceFactory(ProxyServlet proxy) {
- this.proxy = proxy;
+ public HttpServiceFactory(HttpServiceRuntimeImpl httpServiceRuntime) {
+ this.httpServiceRuntime = httpServiceRuntime;
}
- public Object getService(Bundle bundle, ServiceRegistration registration) {
- return new HttpServiceImpl(bundle, proxy);
+ public HttpService getService(
+ Bundle bundle, ServiceRegistration<HttpService> serviceRegistration) {
+
+ return new HttpServiceImpl(bundle, httpServiceRuntime, registrations);
}
- public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
- ((HttpServiceImpl) service).shutdown();
+ public void ungetService(
+ Bundle bundle, ServiceRegistration<HttpService> serviceRegistration,
+ HttpService httpService) {
+
+ HttpServiceImpl httpServiceImpl = (HttpServiceImpl)httpService;
+ httpServiceImpl.shutdown();
}
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceImpl.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceImpl.java
index 0d99739a..bb68b3a0 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceImpl.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceImpl.java
@@ -1,82 +1,298 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 Cognos Incorporated, IBM Corporation and others.
+ * Copyright (c) 2005, 2014 Cognos Incorporated, IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Cognos Incorporated - initial API and implementation
* IBM Corporation - bug fixes and enhancements
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
*******************************************************************************/
package org.eclipse.equinox.http.servlet.internal;
import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicLong;
import javax.servlet.*;
import org.eclipse.equinox.http.servlet.ExtendedHttpService;
+import org.eclipse.equinox.http.servlet.internal.context.*;
+import org.eclipse.equinox.http.servlet.internal.error.*;
+import org.eclipse.equinox.http.servlet.internal.registration.*;
+import org.eclipse.equinox.http.servlet.internal.registration.FilterRegistration;
+import org.eclipse.equinox.http.servlet.internal.registration.Registration;
+import org.eclipse.equinox.http.servlet.internal.registration.ServletRegistration;
+import org.eclipse.equinox.http.servlet.internal.util.StringPlus;
import org.osgi.framework.Bundle;
import org.osgi.service.http.*;
+import org.osgi.service.http.context.ServletContextHelper;
+import org.osgi.service.http.runtime.dto.ErrorPageDTO;
public class HttpServiceImpl implements HttpService, ExtendedHttpService {
- private Bundle bundle; //The bundle associated with this instance of http service
-
- private ProxyServlet proxy; //The proxy that does the dispatching of the incoming requests
-
- private Set aliases = new HashSet(); //Aliases registered against this particular instance of the service
- private Set filters = new HashSet(); //Filters registered against this particular instance of the service
+ private final Bundle bundle; //The bundle associated with this instance of http service
+ private final HttpServiceRuntimeImpl httpServiceRuntime;
+ private final ConcurrentMap<ContextController, Map<Object, Registration<?, ?>>> registrations;
+ private final ConcurrentMap<ServletContextHelper, ContextController> servletContextHelperRegistrations = new ConcurrentHashMap<ServletContextHelper, ContextController>();
+ private final ConcurrentMap<HttpContext, ServletContextHelper> contextMap = new ConcurrentHashMap<HttpContext, ServletContextHelper>();
+ private DefaultServletContextHelper defaultServletContextHelper;
+ private final AtomicLong legacyServiceIdGenerator;
private boolean shutdown = false; // We prevent use of this instance if HttpServiceFactory.ungetService has called unregisterAliases.
- public HttpServiceImpl(Bundle bundle, ProxyServlet proxy) {
+ public HttpServiceImpl(
+ Bundle bundle, HttpServiceRuntimeImpl httpServiceRuntime,
+ ConcurrentMap<ContextController, Map<Object, Registration<?, ?>>> registrations) {
+
this.bundle = bundle;
- this.proxy = proxy;
+ this.httpServiceRuntime = httpServiceRuntime;
+ this.registrations = registrations;
+ this.legacyServiceIdGenerator =
+ httpServiceRuntime.getLegacyServiceIdGenerator();
+ this.defaultServletContextHelper = new DefaultServletContextHelper(
+ this.bundle);
}
- //Clean up method
- synchronized void shutdown() {
- for (Iterator it = aliases.iterator(); it.hasNext();) {
- String alias = (String) it.next();
- proxy.unregister(alias, false);
- }
- aliases.clear();
+ /**
+ * @see HttpService#createDefaultHttpContext()
+ */
+ public synchronized HttpContext createDefaultHttpContext() {
+ checkShutdown();
+
+ return defaultServletContextHelper;
+ }
+
+ /**
+ * @see HttpService#registerFilter(String, Filter, Dictionary, HttpContext)
+ */
+ public synchronized void registerFilter(
+ String alias, Filter filter, Dictionary<String, String> initparams,
+ HttpContext httpContext)
+ throws ServletException {
+
+ checkShutdown();
- for (Iterator it = filters.iterator(); it.hasNext();) {
- Filter filter = (Filter) it.next();
- proxy.unregisterFilter(filter, false);
+ if (filter == null) {
+ throw new IllegalArgumentException("Filter cannot be null");
}
- filters.clear();
- shutdown = true;
+
+ ContextController contextController = getContextController(
+ null, httpContext);
+
+ Map<Object, Registration<?, ?>> contextRegistrations =
+ getContextRegistrations(contextController);
+
+ FilterRegistration filterRegistration =
+ contextController.addFilterRegistration(
+ alias, filter, initparams,
+ legacyServiceIdGenerator.decrementAndGet());
+
+ contextRegistrations.put(filter, filterRegistration);
}
- private void checkShutdown() {
- if (shutdown)
- throw new IllegalStateException("Service instance is already shutdown"); //$NON-NLS-1$
+ /**
+ * @see ExtendedHttpService#registerFilter(Filter, String, String[], String[], String[], boolean, int, Map, String)
+ */
+ public synchronized void registerFilter(
+ Filter filter, String name, String[] patterns, String[] servletNames,
+ String[] dispatcher, boolean asyncSupported, int filterPriority,
+ Map<String, String> initparams, String contextSelector)
+ throws ServletException {
+
+ checkShutdown();
+
+ ContextController contextController = getContextController(
+ contextSelector, null);
+
+ Map<Object, Registration<?, ?>> contextRegistrations =
+ getContextRegistrations(contextController);
+
+ FilterRegistration filterRegistration =
+ contextController.addFilterRegistration(
+ filter, asyncSupported, dispatcher, filterPriority, initparams,
+ name, patterns, legacyServiceIdGenerator.decrementAndGet(),
+ servletNames);
+
+ contextRegistrations.put(filter, filterRegistration);
+ }
+
+ public synchronized void registerListener(
+ EventListener eventListener, String contextSelector)
+ throws ServletException {
+
+ checkShutdown();
+
+ ContextController contextController = getContextController(
+ contextSelector, null);
+
+ Map<Object, Registration<?, ?>> contextRegistrations =
+ getContextRegistrations(contextController);
+
+ ListenerRegistration listenerRegistration =
+ contextController.addListenerRegistration(
+ eventListener, legacyServiceIdGenerator.decrementAndGet());
+
+ contextRegistrations.put(eventListener, listenerRegistration);
+ }
+
+ /**
+ * @see HttpService#registerResources(String, String, HttpContext)
+ */
+ public synchronized void registerResources(
+ String alias, String name, HttpContext httpContext)
+ throws NamespaceException {
+
+ checkShutdown();
+
+ ContextController contextController = getContextController(
+ null, httpContext);
+
+ checkResourcePatterns(new String[] {alias}, contextController);
+
+ Map<Object, Registration<?, ?>> contextRegistrations =
+ getContextRegistrations(contextController);
+
+ ResourceRegistration resourceRegistration =
+ contextController.addResourceRegistration(
+ alias, name, legacyServiceIdGenerator.decrementAndGet());
+
+ contextRegistrations.put(alias, resourceRegistration);
+ }
+
+ /**
+ * @see ExtendedHttpService#registerResources(String[], String, String)
+ */
+ public synchronized void registerResources(
+ String[] patterns, String prefix, String contextSelector)
+ throws NamespaceException {
+
+ checkShutdown();
+
+ ContextController contextController = getContextController(
+ contextSelector, null);
+
+ checkResourcePatterns(patterns, contextController);
+
+ Map<Object, Registration<?, ?>> contextRegistrations =
+ getContextRegistrations(contextController);
+
+ ResourceRegistration resourceRegistration =
+ contextController.addResourceRegistration(
+ patterns, prefix, legacyServiceIdGenerator.decrementAndGet());
+
+ for (String pattern : patterns) {
+ contextRegistrations.put(pattern, resourceRegistration);
+ }
}
/**
* @see HttpService#registerServlet(String, Servlet, Dictionary, HttpContext)
*/
- public synchronized void registerServlet(String alias, Servlet servlet, Dictionary initparams, HttpContext context) throws ServletException, NamespaceException {
+ public synchronized void registerServlet(
+ String alias, Servlet servlet,
+ Dictionary<String, String> initparams, HttpContext httpContext)
+ throws ServletException, NamespaceException {
+
checkShutdown();
- if (context == null) {
- context = createDefaultHttpContext();
+
+ if (alias == null) {
+ throw new IllegalArgumentException("Alias cannot be null");
}
- proxy.registerServlet(alias, servlet, initparams, context);
- aliases.add(alias);
+
+ ContextController contextController = getContextController(
+ null, httpContext);
+
+ checkServletPatterns(new String[] {alias}, null, contextController);
+
+ if (httpServiceRuntime.getRegisteredServlets().contains(servlet)) {
+ throw new ServletAlreadyRegisteredException(servlet);
+ }
+
+ Map<Object, Registration<?, ?>> contextRegistrations =
+ getContextRegistrations(contextController);
+
+ ServletRegistration servletRegistration =
+ contextController.addServletRegistration(
+ alias, servlet, initparams,
+ legacyServiceIdGenerator.decrementAndGet());
+
+ contextRegistrations.put(alias, servletRegistration);
}
/**
- * @see HttpService#registerResources(String, String, HttpContext)
+ * @see ExtendedHttpService#registerServlet(Servlet, String, String[], String[], boolean, Map, Servlet)
*/
- public synchronized void registerResources(String alias, String name, HttpContext context) throws NamespaceException {
+ public synchronized void registerServlet(
+ Servlet servlet, String name, String[] patterns,
+ String[] errorPages, boolean asyncSupported,
+ Map<String, String> initparams, String contextSelector)
+ throws ServletException, NamespaceException {
+
checkShutdown();
- if (context == null) {
- context = createDefaultHttpContext();
+
+ ContextController contextController = getContextController(
+ contextSelector, null);
+
+ checkServletPatterns(patterns, errorPages, contextController);
+
+ if (httpServiceRuntime.getRegisteredServlets().contains(servlet)) {
+ throw new ServletAlreadyRegisteredException(servlet);
+ }
+
+ Map<Object, Registration<?, ?>> contextRegistrations =
+ getContextRegistrations(contextController);
+
+ ServletRegistration servletRegistration =
+ contextController.addServletRegistration(
+ servlet, asyncSupported, errorPages, initparams, patterns,
+ legacyServiceIdGenerator.decrementAndGet(), name);
+
+ if (patterns != null) {
+ for (String pattern : patterns) {
+ contextRegistrations.put(pattern, servletRegistration);
+ }
+ }
+
+ if (errorPages != null) {
+ for (String errorPage : errorPages) {
+ contextRegistrations.put(errorPage, servletRegistration);
+ }
+ }
+ }
+
+ public synchronized void registerServletContextHelper(
+ ServletContextHelper servletContextHelper, Bundle bundle,
+ String[] contextNames, String contextPath,
+ Map<String, String> initparams)
+ throws ServletException {
+
+ checkShutdown();
+
+ if (servletContextHelper == null) {
+ throw new NullServletContextHelperException();
}
- proxy.registerResources(alias, name, context);
- aliases.add(alias);
+
+ if (servletContextHelperRegistrations.containsKey(servletContextHelper)) {
+ throw new RegisteredServletContextHelperException();
+ }
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+
+ if (initparams != null) {
+ properties.putAll(initparams);
+ }
+
+ ContextController contextController =
+ httpServiceRuntime.addServletContextHelper(
+ bundle, servletContextHelper, StringPlus.from(contextNames),
+ contextPath, legacyServiceIdGenerator.decrementAndGet(),
+ properties);
+
+ servletContextHelperRegistrations.put(
+ servletContextHelper, contextController);
}
/**
@@ -84,36 +300,404 @@ public class HttpServiceImpl implements HttpService, ExtendedHttpService {
*/
public synchronized void unregister(String alias) {
checkShutdown();
- if (aliases.remove(alias)) {
- proxy.unregister(alias, true);
- } else {
- throw new IllegalArgumentException("Alias not found: " + alias); //$NON-NLS-1$
+
+ EndpointRegistration<?> endpointRegistration = null;
+
+ for (HttpContext httpContext : contextMap.keySet()) {
+ ContextController contextController = getContextController(
+ null, httpContext);
+
+ Map<Object, Registration<?, ?>> contextRegistrations =
+ getContextRegistrations(contextController);
+
+ endpointRegistration =
+ (EndpointRegistration<?>)contextRegistrations.remove(alias);
+
+ if (endpointRegistration != null) {
+ for (String pattern : endpointRegistration.getPatterns()) {
+ contextRegistrations.remove(pattern);
+ }
+
+ endpointRegistration.destroy();
+ }
+ }
+
+ if (endpointRegistration == null) {
+ throw new IllegalArgumentException("Alias not found: " + alias);
+ }
+ }
+
+ @Override
+ public synchronized void unregister(String pattern, String contextSelector) {
+ checkShutdown();
+
+ ContextController contextController = getContextController(
+ contextSelector, null);
+
+ Map<Object, Registration<?, ?>> contextRegistrations =
+ getContextRegistrations(contextController);
+
+ EndpointRegistration<?> endpointRegistration =
+ (EndpointRegistration<?>)contextRegistrations.remove(pattern);
+
+ if (endpointRegistration != null) {
+ for (String curPattern : endpointRegistration.getPatterns()) {
+ contextRegistrations.remove(curPattern);
+ }
+
+ endpointRegistration.destroy();
+ }
+
+ if (endpointRegistration == null) {
+ throw new IllegalArgumentException("Pattern not found: " + pattern);
}
}
/**
- * @see HttpService#createDefaultHttpContext()
+ * @see ExtendedHttpService#unregisterFilter(Filter)
+ * @deprecated
*/
- public synchronized HttpContext createDefaultHttpContext() {
+ @Deprecated
+ public synchronized void unregisterFilter(Filter filter) {
checkShutdown();
- return new DefaultHttpContext(bundle);
+
+ FilterRegistration filterRegistration = null;
+
+ for (HttpContext httpContext : contextMap.keySet()) {
+ ContextController contextController = getContextController(
+ null, httpContext);
+
+ Map<Object, Registration<?, ?>> contextRegistrations =
+ getContextRegistrations(contextController);
+
+ filterRegistration =
+ (FilterRegistration)contextRegistrations.remove(filter);
+
+ if (filterRegistration != null) {
+ filterRegistration.destroy();
+ }
+ }
+
+ if (filterRegistration == null) {
+ throw new IllegalArgumentException("Filter not found: " + filter);
+ }
}
- public void registerFilter(String alias, Filter filter, Dictionary initparams, HttpContext context) throws ServletException {
+ @Override
+ public synchronized void unregisterFilter(
+ Filter filter, String contextSelector) {
+
+ ContextController contextController = getContextController(
+ contextSelector, null);
+
+ Map<Object, Registration<?, ?>> contextRegistrations =
+ getContextRegistrations(contextController);
+
+ FilterRegistration filterRegistration =
+ (FilterRegistration)contextRegistrations.remove(filter);
+
+ if (filterRegistration != null) {
+ filterRegistration.destroy();
+ }
+ else {
+ throw new IllegalArgumentException("Filter not found: " + filter);
+ }
+ }
+
+ public synchronized void unregisterListener(
+ EventListener eventListener, String contextSelector) {
+
checkShutdown();
- if (context == null) {
- context = createDefaultHttpContext();
+
+ ContextController contextController = getContextController(
+ contextSelector, null);
+
+ Map<Object, Registration<?, ?>> contextRegistrations =
+ getContextRegistrations(contextController);
+
+ ListenerRegistration listenerRegistration =
+ (ListenerRegistration)contextRegistrations.remove(eventListener);
+
+ if (listenerRegistration != null) {
+ listenerRegistration.destroy();
+ }
+ else {
+ throw new IllegalArgumentException(
+ "EventListener not found: " + eventListener);
+ }
+ }
+
+ public synchronized void unregisterServlet(
+ Servlet servlet, String contextSelector) {
+
+ ContextController contextController = getContextController(
+ contextSelector, null);
+
+ Map<Object, Registration<?, ?>> contextRegistrations =
+ getContextRegistrations(contextController);
+
+ ServletRegistration servletRegistration = null;
+
+ for (Registration<?, ?> curRegistration : contextRegistrations.values()) {
+ if (curRegistration.getT().equals(servlet)) {
+ servletRegistration = (ServletRegistration)curRegistration;
+
+ break;
+ }
+ }
+
+ if (servletRegistration != null) {
+ String[] patterns = servletRegistration.getPatterns();
+
+ if (patterns != null) {
+ for (String pattern : servletRegistration.getPatterns()) {
+ contextRegistrations.remove(pattern);
+ }
+ }
+
+ ErrorPageDTO errorPageDTO = servletRegistration.getErrorPageDTO();
+
+ if (errorPageDTO != null) {
+ for (long errorCode : errorPageDTO.errorCodes) {
+ contextRegistrations.remove(String.valueOf(errorCode));
+ }
+
+ for (String exception : errorPageDTO.exceptions) {
+ contextRegistrations.remove(exception);
+ }
+ }
+
+ servletRegistration.destroy();
+ }
+ else {
+ throw new IllegalArgumentException("Servlet not found: " + servlet);
}
- proxy.registerFilter(alias, filter, initparams, context);
- filters.add(filter);
}
- public void unregisterFilter(Filter filter) {
+ public synchronized void unregisterServletContextHelper(
+ ServletContextHelper servletContextHelper) {
+
checkShutdown();
- if (filters.remove(filter)) {
- proxy.unregisterFilter(filter, true);
- } else {
- throw new IllegalArgumentException("Filter not found."); //$NON-NLS-1$
+
+ ContextController contextController = servletContextHelperRegistrations.remove(
+ servletContextHelper);
+
+ if (contextController != null) {
+ httpServiceRuntime.removeContextController(contextController);
+ }
+ else {
+ throw new IllegalArgumentException(
+ "ServletContextHelper not found: " + servletContextHelper);
+ }
+ }
+
+ //Clean up method
+ synchronized void shutdown() {
+ for (ContextController contextController :
+ servletContextHelperRegistrations.values()) {
+
+ contextController.destroy();
+ }
+
+ servletContextHelperRegistrations.clear();
+
+ shutdown = true;
+ }
+
+ private void checkResourcePatterns(
+ String[] patterns, ContextController contextController)
+ throws NamespaceException {
+
+ if ((patterns == null) || (patterns.length == 0)) {
+ throw new IllegalArgumentException("Patterns must contain a value.");
+ }
+
+ for (EndpointRegistration<?> endpointRegistration :
+ contextController.getEndpointRegistrations()) {
+
+ String[] registeredPatterns = endpointRegistration.getPatterns();
+
+ if (registeredPatterns == null) {
+ continue;
+ }
+
+ for (String pattern : patterns) {
+ int pos = Arrays.binarySearch(registeredPatterns, pattern);
+
+ if (pos > -1) {
+ throw new PatternInUseException(pattern);
+ }
+ }
+ }
+ }
+
+ private void checkServletPatterns(
+ String[] patterns, String[] errorPages,
+ ContextController contextController)
+ throws NamespaceException {
+
+ if (((patterns == null) || (patterns.length == 0)) &&
+ ((errorPages == null) || errorPages.length == 0)) {
+
+ throw new IllegalArgumentException(
+ "Patterns or servletNames must contain a value.");
+ }
+
+ for (EndpointRegistration<?> endpointRegistration :
+ contextController.getEndpointRegistrations()) {
+
+ String[] registeredPatterns = endpointRegistration.getPatterns();
+
+ if ((patterns != null) && (registeredPatterns != null)) {
+ for (String pattern : patterns) {
+ int pos = Arrays.binarySearch(registeredPatterns, pattern);
+
+ if (pos > -1) {
+ throw new PatternInUseException(pattern);
+ }
+ }
+ }
+
+ if (errorPages != null) {
+ if (!(endpointRegistration instanceof ServletRegistration)) {
+ continue;
+ }
+
+ ServletRegistration servletRegistration = (ServletRegistration)endpointRegistration;
+
+ ErrorPageDTO errorPageDTO = servletRegistration.getErrorPageDTO();
+
+ if (errorPageDTO == null) {
+ continue;
+ }
+
+ String[] exceptions = errorPageDTO.exceptions;
+
+ for (String errorPage : errorPages) {
+ int pos = Arrays.binarySearch(exceptions, errorPage);
+
+ if (pos > -1) {
+ throw new NamespaceException(
+ "Error page already registered: " + errorPage);
+ }
+ }
+
+ long[] errorCodes = errorPageDTO.errorCodes;
+
+ for (String errorPage : errorPages) {
+ try {
+ long longValue = Long.parseLong(errorPage);
+
+ int pos = Arrays.binarySearch(errorCodes, longValue);
+
+ if (pos > -1) {
+ throw new NamespaceException(
+ "Error page already registered: " + errorPage);
+ }
+ }
+ catch (NumberFormatException nfe) {
+ }
+ }
+ }
+ }
+ }
+
+ private void checkShutdown() {
+ if (shutdown) {
+ throw new IllegalStateException(
+ "Service instance is already shutdown"); //$NON-NLS-1$
+ }
+ }
+
+ private synchronized ContextController getContextController(
+ String contextSelector, HttpContext httpContext) {
+
+ String calculatedContextSelector = calculateContextSelector(
+ contextSelector, httpContext);
+
+ org.osgi.framework.Filter targetFilter =
+ httpServiceRuntime.getContextSelectorFilter(
+ bundle, calculatedContextSelector);
+
+ ContextController contextController = httpServiceRuntime.getContextController(
+ targetFilter);
+
+ if (contextController != null) {
+ return contextController;
+ }
+
+ if (contextSelector != null) {
+ throw new IllegalArgumentException(
+ "No valid ServletContextHelper for filter '" +
+ targetFilter.toString() + '\'');
+ }
+
+ ServletContextHelper servletContextHelper = defaultServletContextHelper;
+
+ if (httpContext != null) {
+ servletContextHelper = contextMap.get(httpContext);
+ }
+
+ contextController = httpServiceRuntime.addServletContextHelper(
+ bundle, servletContextHelper,
+ Collections.singletonList(calculatedContextSelector),
+ null, legacyServiceIdGenerator.decrementAndGet(),
+ httpServiceRuntime.getAttributes());
+
+ servletContextHelperRegistrations.put(
+ servletContextHelper, contextController);
+
+ return contextController;
+ }
+
+ private Map<Object, Registration<?, ?>> getContextRegistrations(
+ ContextController contextController) {
+
+ Map<Object, Registration<?, ?>> map = registrations.get(
+ contextController);
+
+ if (map == null) {
+ map = new ConcurrentHashMap<Object, Registration<?,?>>();
+
+ Map<Object, Registration<?, ?>> existing = registrations.putIfAbsent(
+ contextController, map);
+
+ if (existing != null) {
+ map = existing;
+ }
}
+
+ return map;
}
+
+ private String calculateContextSelector(
+ String contextSelector, HttpContext httpContext) {
+
+ if (contextSelector != null) {
+ return contextSelector;
+ }
+
+ ServletContextHelper servletContextHelper = null;
+
+ if (httpContext == null) {
+ httpContext = defaultServletContextHelper;
+ }
+
+ servletContextHelper = contextMap.get(httpContext);
+
+ if (servletContextHelper == null) {
+ if (httpContext instanceof ServletContextHelper) {
+ servletContextHelper = (ServletContextHelper)httpContext;
+ }
+ else {
+ servletContextHelper = new ServletContextHelperWrapper(
+ httpContext, bundle);
+ }
+
+ contextMap.putIfAbsent(httpContext, servletContextHelper);
+ }
+
+ return String.valueOf(bundle.getBundleId()) + '#' + httpContext.hashCode();
+ }
+
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java
new file mode 100644
index 00000000..7ec6b5cf
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java
@@ -0,0 +1,722 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.Map.Entry;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicLong;
+import javax.servlet.*;
+import javax.servlet.Filter;
+import javax.servlet.http.*;
+import org.eclipse.equinox.http.servlet.internal.context.*;
+import org.eclipse.equinox.http.servlet.internal.customizer.*;
+import org.eclipse.equinox.http.servlet.internal.error.NullContextNamesException;
+import org.eclipse.equinox.http.servlet.internal.error.NullServletContextHelperException;
+import org.eclipse.equinox.http.servlet.internal.servlet.*;
+import org.eclipse.equinox.http.servlet.internal.util.Const;
+import org.eclipse.equinox.http.servlet.internal.util.StringPlus;
+import org.osgi.framework.*;
+import org.osgi.service.http.context.ServletContextHelper;
+import org.osgi.service.http.runtime.HttpServiceRuntime;
+import org.osgi.service.http.runtime.HttpServiceRuntimeConstants;
+import org.osgi.service.http.runtime.dto.*;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+/**
+ * @author Raymond Augé
+ */
+public class HttpServiceRuntimeImpl
+ implements
+ HttpServiceRuntime,
+ ServiceTrackerCustomizer<ServletContextHelper, ContextController> {
+
+ public HttpServiceRuntimeImpl(
+ BundleContext bundleContext, ServletContext parentServletContext,
+ Map<String, Object> attributes) {
+
+ this.bundleContext = bundleContext;
+ this.parentServletContext = parentServletContext;
+ this.attributes = Collections.unmodifiableMap(attributes);
+
+ contextServiceTracker =
+ new ServiceTracker<ServletContextHelper, ContextController>(
+ bundleContext, ServletContextHelper.class, this);
+
+ contextServiceTracker.open();
+
+ listenerServiceTracker =
+ new ServiceTracker<EventListener, EventListener>(
+ bundleContext, EventListener.class,
+ new ListenerTrackerCustomizer(bundleContext, this));
+
+ listenerServiceTracker.open();
+
+ filterServiceTracker = new ServiceTracker<Filter, Filter>(
+ bundleContext, getFilteFilter(),
+ new FilterTrackerCustomizer(bundleContext, this));
+
+ filterServiceTracker.open();
+
+ servletServiceTracker = new ServiceTracker<Servlet, Servlet>(
+ bundleContext, getServletFilter(),
+ new ServletTrackerCustomizer(bundleContext, this));
+
+ servletServiceTracker.open();
+
+ resourceServiceTracker = new ServiceTracker<Servlet, Servlet>(
+ bundleContext, getResourceFilter(),
+ new ResourceTrackerCustomizer(bundleContext, this));
+
+ resourceServiceTracker.open();
+ }
+
+ @Override
+ public synchronized ContextController addingService(
+ ServiceReference<ServletContextHelper> serviceReference) {
+
+ if (!matches(serviceReference)) {
+ return null;
+ }
+
+ List<String> contextNames = StringPlus.from(
+ serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME));
+
+ if (contextNames.isEmpty()) {
+ parentServletContext.log(
+ "This context's property " +
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME +
+ " is null. Ignoring!");
+
+ return null;
+ }
+
+ for (String contextName : contextNames) {
+ if (registeredContextNames.contains(contextName)) {
+ parentServletContext.log(
+ "ContextName " + contextName + " is already in use. Ignoring!");
+
+ return null;
+ }
+ }
+
+ String contextPath = (String)serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH);
+
+ if (contextPath == null) {
+ contextPath = Const.BLANK;
+ }
+
+ long serviceId = (Long)serviceReference.getProperty(
+ Constants.SERVICE_ID);
+
+ ServletContextHelper servletContextHelper = bundleContext.getService(
+ serviceReference);
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+
+ for (String key : serviceReference.getPropertyKeys()) {
+ properties.put(key, serviceReference.getProperty(key));
+ }
+
+ properties.putAll(attributes);
+
+ return addServletContextHelper(
+ serviceReference.getBundle(), servletContextHelper, contextNames,
+ contextPath, serviceId, properties);
+ }
+
+ public ContextController addServletContextHelper(
+ Bundle bundle, ServletContextHelper servletContextHelper,
+ List<String> contextNames, String contextPath, long serviceId,
+ Map<String, Object> properties) {
+
+ if (servletContextHelper == null) {
+ throw new NullServletContextHelperException();
+ }
+
+ if (controllerMap.containsKey(servletContextHelper)) {
+ throw new IllegalArgumentException(
+ "ServletContextHelper is already registered.");
+ }
+
+ if ((contextNames == null) || (contextNames.size() < 1)) {
+ throw new NullContextNamesException();
+ }
+
+ if (contextPath == null) {
+ contextPath = "";
+ }
+
+ ContextController contextController = createContextController(
+ bundle, servletContextHelper, contextNames, contextPath, serviceId,
+ properties);
+
+ if (contextController != null) {
+ for (String contextName : contextNames) {
+ registeredContextNames.add(contextName);
+ }
+ }
+
+ controllerMap.putIfAbsent(contextController, servletContextHelper);
+
+ return contextController;
+ }
+
+ @Override
+ public RequestInfoDTO calculateRequestInfoDTO(String path) {
+ RequestInfoDTO requestInfoDTO = new RequestInfoDTO();
+
+ requestInfoDTO.path = path;
+
+ try {
+ doDispatch(null, null, path, requestInfoDTO);
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ return requestInfoDTO;
+ }
+
+ public void destroy() {
+ resourceServiceTracker.close();
+ servletServiceTracker.close();
+ filterServiceTracker.close();
+ listenerServiceTracker.close();
+ contextServiceTracker.close();
+ controllerMap.clear();
+ contextPathMap.clear();
+ registeredServlets.clear();
+
+ attributes = null;
+ bundleContext = null;
+ contextPathMap = null;
+ legacyServiceIdGenerator = null;
+ parentServletContext = null;
+ registeredServlets = null;
+ contextServiceTracker = null;
+ }
+
+ public boolean doDispatch(
+ HttpServletRequest request, HttpServletResponse response,
+ String path)
+ throws ServletException, IOException {
+
+ return doDispatch(request, response, path, null);
+ }
+
+ public Map<String, Object> getAttributes() {
+ return attributes;
+ }
+
+ public Map<String, String> getAttributesAsInitParams() {
+ Map<String, String> initParameters = new HashMap<String, String>();
+
+ for (Entry<String, Object> entry : getAttributes().entrySet()) {
+ initParameters.put(
+ entry.getKey(), String.valueOf(entry.getValue()));
+ }
+
+ return initParameters;
+ }
+
+ public ContextController getOrAddContextController(
+ String contextSelector, BundleContext selectorBundleContext) {
+
+ Bundle bundle = selectorBundleContext.getBundle();
+
+ org.osgi.framework.Filter targetFilter = getContextSelectorFilter(
+ bundle, contextSelector);
+
+ ContextController contextController = getContextController(
+ targetFilter);
+
+ if (contextController != null) {
+ return contextController;
+ }
+
+ if (contextSelector == null) {
+ Hashtable<String, Object> properties = new Hashtable<String, Object>(
+ getAttributes());
+
+ properties.put(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME,
+ String.valueOf(bundle.getBundleId()));
+
+ selectorBundleContext.registerService(
+ ServletContextHelper.class, new ServletContextHelper(bundle) {},
+ properties);
+ }
+
+ return contextController = getContextController(targetFilter);
+ }
+
+ public ContextController getContextController(
+ org.osgi.framework.Filter targetFilter) {
+
+ for (ContextController contextController : controllerMap.keySet()) {
+ if (contextController.matches(targetFilter)) {
+ return contextController;
+ }
+ }
+
+ return null;
+ }
+
+ public org.osgi.framework.Filter getContextSelectorFilter(
+ Bundle bundle, String contextSelector) {
+
+ if (contextSelector == null) {
+ contextSelector = Const.OPEN_PAREN +
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME +
+ Const.EQUAL + String.valueOf(bundle.getBundleId()) +
+ Const.CLOSE_PAREN;
+ }
+ else if (!contextSelector.startsWith(Const.OPEN_PAREN)) {
+ contextSelector = Const.OPEN_PAREN +
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME +
+ Const.EQUAL + contextSelector + Const.CLOSE_PAREN;
+ }
+
+ try {
+ return FrameworkUtil.createFilter(contextSelector);
+ }
+ catch (InvalidSyntaxException ise) {
+ throw new IllegalArgumentException(ise);
+ }
+ }
+
+ public org.osgi.framework.Filter getFilteFilter() {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("(&(objectClass="); //$NON-NLS-1$
+ sb.append(Filter.class.getName());
+ sb.append(")(|("); //$NON-NLS-1$
+ sb.append(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN);
+ sb.append("=*)("); //$NON-NLS-1$
+ sb.append(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_REGEX);
+ sb.append("=*)("); //$NON-NLS-1$
+ sb.append(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_SERVLET);
+ sb.append("=*)))"); //$NON-NLS-1$
+
+ try {
+ return bundleContext.createFilter(sb.toString());
+ }
+ catch (InvalidSyntaxException ise) {
+ throw new IllegalArgumentException(ise);
+ }
+ }
+
+ public Set<Servlet> getRegisteredServlets() {
+ return registeredServlets;
+ }
+
+ public List<String> getHttpServiceEndpoints() {
+ return StringPlus.from(
+ attributes.get(
+ HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT_ATTRIBUTE));
+ }
+
+ public org.osgi.framework.Filter getResourceFilter() {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("(&(objectClass="); //$NON-NLS-1$
+ sb.append(Servlet.class.getName());
+ sb.append(")("); //$NON-NLS-1$
+ sb.append(HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PREFIX);
+ sb.append("=*)("); //$NON-NLS-1$
+ sb.append(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN);
+ sb.append("=*))"); //$NON-NLS-1$
+
+ try {
+ return bundleContext.createFilter(sb.toString());
+ }
+ catch (InvalidSyntaxException ise) {
+ throw new IllegalArgumentException(ise);
+ }
+ }
+
+ @Override
+ public RuntimeDTO getRuntimeDTO() {
+ RuntimeDTO runtimeDTO = new RuntimeDTO();
+
+ runtimeDTO.attributes = serializeAttributes();
+
+ // TODO
+
+ runtimeDTO.failedErrorPageDTOs = null;
+ runtimeDTO.failedFilterDTOs = null;
+ runtimeDTO.failedListenerDTOs = null;
+ runtimeDTO.failedResourceDTOs = null;
+ runtimeDTO.failedServletContextDTOs = null;
+ runtimeDTO.failedServletDTOs = null;
+ runtimeDTO.servletContextDTOs = getServletContextDTOs();
+
+ return runtimeDTO;
+ }
+
+ public org.osgi.framework.Filter getServletFilter() {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("(&(objectClass="); //$NON-NLS-1$
+ sb.append(Servlet.class.getName());
+ sb.append(")(|("); //$NON-NLS-1$
+ sb.append(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ERROR_PAGE);
+ sb.append("=*)("); //$NON-NLS-1$
+ sb.append(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN);
+ sb.append("=*))(!("); //$NON-NLS-1$
+ sb.append(HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PREFIX);
+ sb.append("=*)))"); //$NON-NLS-1$
+
+ try {
+ return bundleContext.createFilter(sb.toString());
+ }
+ catch (InvalidSyntaxException ise) {
+ throw new IllegalArgumentException(ise);
+ }
+ }
+
+ public void log(String message, Throwable t) {
+ parentServletContext.log(message, t);
+ }
+
+ public boolean matches(ServiceReference<?> serviceReference) {
+ String target = (String)serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_TARGET);
+
+ if (target == null) {
+ return true;
+ }
+
+ org.osgi.framework.Filter targetFilter;
+
+ try {
+ targetFilter = FrameworkUtil.createFilter(target);
+ }
+ catch (InvalidSyntaxException ise) {
+ throw new IllegalArgumentException(ise);
+ }
+
+ if (targetFilter.matches(attributes)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public synchronized void modifiedService(
+ ServiceReference<ServletContextHelper> serviceReference,
+ ContextController contextController) {
+
+ // do nothing
+ }
+
+ @Override
+ public synchronized void removedService(
+ ServiceReference<ServletContextHelper> serviceReference,
+ ContextController contextController) {
+
+ bundleContext.ungetService(serviceReference);
+
+ removeContextController(contextController);
+ }
+
+ public void removeContextController(ContextController contextController) {
+ Set<ContextController> contextControllers = getContextControllerPathSet(
+ contextController.getContextPath(), false);
+
+ if (contextControllers != null) {
+ contextControllers.remove(contextController);
+ }
+
+ for (String contextName : contextController.getContextNames()) {
+ registeredContextNames.remove(contextName);
+ }
+
+ controllerMap.remove(contextController);
+
+ contextController.destroy();
+ }
+
+ Set<ContextController> getContextControllerPathSet(
+ String contextPath, boolean add) {
+
+ if (contextPath == null) {
+ contextPath = "";
+ }
+
+ Set<ContextController> set = contextPathMap.get(contextPath);
+
+ if ((set == null) && add) {
+ set = new HashSet<ContextController>();
+
+ Set<ContextController> existingSet =
+ contextPathMap.putIfAbsent(contextPath, set);
+
+ if (existingSet != null) {
+ set = existingSet;
+ }
+ }
+
+ return set;
+ }
+
+ Set<ContextController> getContextControllers(String requestURI) {
+ int pos = requestURI.lastIndexOf('/');
+
+ do {
+ Set<ContextController> contextControllers = contextPathMap.get(
+ requestURI);
+
+ if (contextControllers != null) {
+ return contextControllers;
+ }
+
+ if (pos > -1) {
+ requestURI = requestURI.substring(0, pos);
+ pos = requestURI.lastIndexOf('/');
+
+ continue;
+ }
+
+ break;
+ }
+ while (true);
+
+ return null;
+ }
+
+ AtomicLong getLegacyServiceIdGenerator() {
+ return legacyServiceIdGenerator;
+ }
+
+ private ContextController createContextController(
+ Bundle bundle, ServletContextHelper servletContextHelper,
+ List<String> contextNames, String contextPath, long serviceId,
+ Map<String, Object> initParams) {
+
+ ContextController contextController = new ContextController(
+ bundle, servletContextHelper, new ProxyContext(parentServletContext),
+ this, contextNames, contextPath, serviceId, registeredServlets,
+ initParams);
+
+ Set<ContextController> contextControllers = getContextControllerPathSet(
+ contextPath, true);
+
+ contextControllers.add(contextController);
+
+ contextPathMap.put(contextPath, contextControllers);
+
+ return contextController;
+ }
+
+ private boolean doDispatch(
+ HttpServletRequest request, HttpServletResponse response,
+ String path, RequestInfoDTO requestInfoDTO)
+ throws ServletException, IOException {
+
+ // perfect match
+ if (doDispatch(
+ request, response, path, null, Match.EXACT, requestInfoDTO)) {
+
+ return true;
+ }
+
+ String extensionAlias = findExtensionAlias(path);
+
+ // extension match
+ if (doDispatch(
+ request, response, path, extensionAlias, Match.EXTENSION,
+ requestInfoDTO)) {
+
+ return true;
+ }
+
+ // regex match
+ if (doDispatch(
+ request, response, path, null, Match.REGEX, requestInfoDTO)) {
+
+ return true;
+ }
+
+ // handle '/' aliases
+ if (doDispatch(
+ request, response, path, null, Match.DEFAULT_SERVLET,
+ requestInfoDTO)) {
+
+ return true;
+ }
+
+ return false;
+ }
+
+ private boolean doDispatch(
+ HttpServletRequest request, HttpServletResponse response,
+ String requestURI, String extension, Match match,
+ RequestInfoDTO requestInfoDTO)
+ throws ServletException, IOException {
+
+ DispatchTargets dispatchTargets = getDispatchTargets(
+ request, requestURI, extension, match, requestInfoDTO);
+
+ if ((dispatchTargets == null) || (requestInfoDTO != null)) {
+ return false;
+ }
+
+ ContextController contextController =
+ dispatchTargets.getContextController();
+ DispatcherType dispatcherType = DispatcherType.REQUEST;
+
+ if (request.getAttribute("javax.servlet.include.request_uri") != null) {
+ request.setAttribute(
+ "javax.servlet.include.request_uri", requestURI);
+ request.setAttribute(
+ "javax.servlet.include.context_path",
+ contextController.getContextPath());
+ request.setAttribute(
+ "javax.servlet.include.servlet_path",
+ dispatchTargets.getServletPath());
+ request.setAttribute(
+ "javax.servlet.include.path_info",
+ dispatchTargets.getPathInfo());
+
+ dispatcherType = DispatcherType.INCLUDE;
+ }
+
+ HttpServletRequest wrappedRequest = new HttpServletRequestBuilder(
+ request, dispatchTargets).build();
+ HttpServletResponseWrapper wrapperResponse =
+ new HttpServletResponseWrapperImpl(response);
+
+ ResponseStateHandler responseStateHandler = new ResponseStateHandler(
+ wrappedRequest, wrapperResponse, dispatchTargets, dispatcherType);
+
+ responseStateHandler.processRequest();
+
+ return true;
+ }
+
+ private String findExtensionAlias(String alias) {
+ String lastSegment = alias.substring(alias.lastIndexOf('/') + 1);
+
+ int dot = lastSegment.lastIndexOf('.');
+
+ if (dot == -1) {
+ return null;
+ }
+
+ return lastSegment.substring(dot + 1);
+ }
+
+ private DispatchTargets getDispatchTargets(
+ HttpServletRequest request, String requestURI, String extension,
+ Match match, RequestInfoDTO requestInfoDTO) {
+
+ Set<ContextController> contextControllers = getContextControllers(
+ requestURI);
+
+ if ((contextControllers == null) || contextControllers.isEmpty()) {
+ return null;
+ }
+
+ String contextPath =
+ contextControllers.iterator().next().getContextPath();
+
+ requestURI = requestURI.substring(contextPath.length());
+
+ int pos = requestURI.lastIndexOf('/');
+
+ String servletPath = requestURI;
+ String pathInfo = Const.BLANK;
+
+ if (match == Match.DEFAULT_SERVLET) {
+ pathInfo = servletPath;
+ servletPath = Const.SLASH;
+ }
+
+ do {
+ for (ContextController contextController : contextControllers) {
+ DispatchTargets dispatchTargets =
+ contextController.getDispatchTargets(
+ request, null, requestURI, servletPath, pathInfo,
+ extension, match, requestInfoDTO);
+
+ if (dispatchTargets != null) {
+ return dispatchTargets;
+ }
+ }
+
+ if (extension != null) {
+ break;
+ }
+
+ if (pos > -1) {
+ String newServletPath = requestURI.substring(0, pos);
+ pathInfo = requestURI.substring(pos);
+ servletPath = newServletPath;
+ pos = servletPath.lastIndexOf('/');
+
+ continue;
+ }
+
+ break;
+ }
+ while (true);
+
+ return null;
+ }
+
+ private ServletContextDTO[] getServletContextDTOs() {
+ List<ServletContextDTO> servletContextDTOs =
+ new ArrayList<ServletContextDTO>();
+
+ for (ContextController contextController : controllerMap.keySet()) {
+ servletContextDTOs.add(contextController.getServletContextDTO());
+ }
+
+ return servletContextDTOs.toArray(
+ new ServletContextDTO[servletContextDTOs.size()]);
+ }
+
+ private Map<String, String> serializeAttributes() {
+ Map<String, String> temp = new HashMap<String, String>();
+
+ for (Map.Entry<String, Object> entry : attributes.entrySet()) {
+ temp.put(entry.getKey(), String.valueOf(entry.getValue()));
+ }
+
+ return temp;
+ }
+
+ private Map<String, Object> attributes;
+ private BundleContext bundleContext;
+ private ConcurrentMap<String, Set<ContextController>> contextPathMap =
+ new ConcurrentHashMap<String, Set<ContextController>>();
+ private ServiceTracker<ServletContextHelper, ContextController> contextServiceTracker;
+ private ConcurrentMap<ContextController, ServletContextHelper> controllerMap =
+ new ConcurrentHashMap<ContextController, ServletContextHelper>();
+ private ServiceTracker<Filter, Filter> filterServiceTracker;
+ private AtomicLong legacyServiceIdGenerator = new AtomicLong(0);
+ private ServiceTracker<EventListener, EventListener> listenerServiceTracker;
+ private ServletContext parentServletContext;
+ private Set<Servlet> registeredServlets = new HashSet<Servlet>();
+ private Set<String> registeredContextNames = new ConcurrentSkipListSet<String>();
+ private ServiceTracker<Servlet, Servlet> resourceServiceTracker;
+ private ServiceTracker<Servlet, Servlet> servletServiceTracker;
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServletRequestAdaptor.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServletRequestAdaptor.java
deleted file mode 100644
index b60c014a..00000000
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServletRequestAdaptor.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2007 Cognos Incorporated, IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Cognos Incorporated - initial API and implementation
- * IBM Corporation - bug fixes and enhancements
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet.internal;
-
-import javax.servlet.RequestDispatcher;
-import javax.servlet.Servlet;
-import javax.servlet.http.*;
-import org.osgi.service.http.HttpContext;
-
-public class HttpServletRequestAdaptor extends HttpServletRequestWrapper {
-
- private String alias;
- private Servlet servlet;
- private boolean isRequestDispatcherInclude;
-
- static final String INCLUDE_REQUEST_URI_ATTRIBUTE = "javax.servlet.include.request_uri"; //$NON-NLS-1$
- static final String INCLUDE_CONTEXT_PATH_ATTRIBUTE = "javax.servlet.include.context_path"; //$NON-NLS-1$
- static final String INCLUDE_SERVLET_PATH_ATTRIBUTE = "javax.servlet.include.servlet_path"; //$NON-NLS-1$
- static final String INCLUDE_PATH_INFO_ATTRIBUTE = "javax.servlet.include.path_info"; //$NON-NLS-1$
-
- public HttpServletRequestAdaptor(HttpServletRequest req, String alias, Servlet servlet) {
- super(req);
- this.alias = alias;
- this.servlet = servlet;
- isRequestDispatcherInclude = req.getAttribute(HttpServletRequestAdaptor.INCLUDE_REQUEST_URI_ATTRIBUTE) != null;
- }
-
- public String getAuthType() {
- String authType = (String) super.getAttribute(HttpContext.AUTHENTICATION_TYPE);
- if (authType != null)
- return authType;
-
- return super.getAuthType();
- }
-
- public String getRemoteUser() {
- String remoteUser = (String) super.getAttribute(HttpContext.REMOTE_USER);
- if (remoteUser != null)
- return remoteUser;
-
- return super.getRemoteUser();
- }
-
- public String getPathInfo() {
- if (isRequestDispatcherInclude)
- return super.getPathInfo();
-
- if (alias.equals("/")) { //$NON-NLS-1$
- return super.getPathInfo();
- }
- String pathInfo = super.getPathInfo().substring(alias.length());
- if (pathInfo.length() == 0)
- return null;
-
- return pathInfo;
- }
-
- public String getServletPath() {
- if (isRequestDispatcherInclude)
- return super.getServletPath();
-
- if (alias.equals("/")) { //$NON-NLS-1$
- return ""; //$NON-NLS-1$
- }
- return alias;
- }
-
- public String getContextPath() {
- if (isRequestDispatcherInclude)
- return super.getContextPath();
-
- return super.getContextPath() + super.getServletPath();
- }
-
- public Object getAttribute(String attributeName) {
- if (isRequestDispatcherInclude) {
- if (attributeName.equals(HttpServletRequestAdaptor.INCLUDE_CONTEXT_PATH_ATTRIBUTE)) {
- String contextPath = (String) super.getAttribute(HttpServletRequestAdaptor.INCLUDE_CONTEXT_PATH_ATTRIBUTE);
- if (contextPath == null || contextPath.equals("/")) //$NON-NLS-1$
- contextPath = ""; //$NON-NLS-1$
-
- String servletPath = (String) super.getAttribute(HttpServletRequestAdaptor.INCLUDE_SERVLET_PATH_ATTRIBUTE);
- if (servletPath == null || servletPath.equals("/")) //$NON-NLS-1$
- servletPath = ""; //$NON-NLS-1$
-
- return contextPath + servletPath;
- } else if (attributeName.equals(HttpServletRequestAdaptor.INCLUDE_SERVLET_PATH_ATTRIBUTE)) {
- if (alias.equals("/")) { //$NON-NLS-1$
- return ""; //$NON-NLS-1$
- }
- return alias;
- } else if (attributeName.equals(HttpServletRequestAdaptor.INCLUDE_PATH_INFO_ATTRIBUTE)) {
- String pathInfo = (String) super.getAttribute(HttpServletRequestAdaptor.INCLUDE_PATH_INFO_ATTRIBUTE);
- if (alias.equals("/")) { //$NON-NLS-1$
- return pathInfo;
- }
-
- pathInfo = pathInfo.substring(alias.length());
- if (pathInfo.length() == 0)
- return null;
-
- return pathInfo;
- }
- }
-
- return super.getAttribute(attributeName);
- }
-
- public RequestDispatcher getRequestDispatcher(String arg0) {
- return new RequestDispatcherAdaptor(super.getRequestDispatcher(super.getServletPath() + arg0));
- }
-
- public static String getDispatchPathInfo(HttpServletRequest req) {
- if (req.getAttribute(INCLUDE_REQUEST_URI_ATTRIBUTE) != null)
- return (String) req.getAttribute(INCLUDE_PATH_INFO_ATTRIBUTE);
-
- return req.getPathInfo();
- }
-
- public static String getDispatchServletPath(HttpServletRequest req) {
- if (req.getAttribute(INCLUDE_REQUEST_URI_ATTRIBUTE) != null) {
- String servletPath = (String) req.getAttribute(INCLUDE_SERVLET_PATH_ATTRIBUTE);
- return (servletPath == null) ? "" : servletPath; //$NON-NLS-1$
- }
- return req.getServletPath();
- }
-
- public HttpSession getSession() {
- HttpSession session = super.getSession();
- if (session != null)
- return new HttpSessionAdaptor(session, servlet);
-
- return null;
- }
-
- public HttpSession getSession(boolean create) {
- HttpSession session = super.getSession(create);
- if (session != null)
- return new HttpSessionAdaptor(session, servlet);
-
- return null;
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ProxyServlet.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ProxyServlet.java
deleted file mode 100644
index d4d3c4ec..00000000
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ProxyServlet.java
+++ /dev/null
@@ -1,283 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2012 Cognos Incorporated, IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Cognos Incorporated - initial API and implementation
- * IBM Corporation - bug fixes and enhancements
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet.internal;
-
-import java.io.IOException;
-import java.security.AccessController;
-import java.util.*;
-import javax.servlet.*;
-import javax.servlet.http.*;
-import org.osgi.service.http.HttpContext;
-import org.osgi.service.http.NamespaceException;
-
-/**
- * The ProxyServlet is the private side of a Servlet that when registered (and init() called) in a servlet container
- * will in-turn register and provide an OSGi Http Service implementation.
- * This class is not meant for extending or even using directly and is purely meant for registering
- * in a servlet container.
- */
-public class ProxyServlet extends HttpServlet {
-
- private static final long serialVersionUID = 4117456123807468871L;
- private Map servletRegistrations = new HashMap(); //alias --> servlet registration
- private Set registeredServlets = new HashSet(); //All the servlets objects that have been registered
-
- private Map filterRegistrations = new HashMap(); //filter --> filter registration;
- private ProxyContext proxyContext;
-
- public void init(ServletConfig config) throws ServletException {
- super.init(config);
- proxyContext = new ProxyContext(config.getServletContext());
- Activator.addProxyServlet(this);
- }
-
- public void destroy() {
- Activator.removeProxyServlet(this);
- proxyContext.destroy();
- proxyContext = null;
- super.destroy();
- }
-
- /**
- * @see HttpServlet#service(ServletRequest, ServletResponse)
- */
- protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- proxyContext.initializeServletPath(req);
- String alias = HttpServletRequestAdaptor.getDispatchPathInfo(req);
- if (alias == null)
- alias = "/"; //$NON-NLS-1$
-
- // perfect match
- if (processAlias(req, resp, alias, null))
- return;
-
- String extensionAlias = findExtensionAlias(alias);
- alias = alias.substring(0, alias.lastIndexOf('/'));
-
- // longest path match
- while (alias.length() != 0) {
- if (processAlias(req, resp, alias, extensionAlias))
- return;
- alias = alias.substring(0, alias.lastIndexOf('/'));
- }
-
- // default handler match
- if (extensionAlias != null)
- extensionAlias = extensionAlias.substring(1); // remove the leading '/'
- if (processAlias(req, resp, "/", extensionAlias)) //Handle '/' aliases //$NON-NLS-1$
- return;
- resp.sendError(HttpServletResponse.SC_NOT_FOUND, "ProxyServlet: " + req.getRequestURI()); //$NON-NLS-1$
- }
-
- private String findExtensionAlias(String alias) {
- String lastSegment = alias.substring(alias.lastIndexOf('/') + 1);
- int dot = lastSegment.lastIndexOf('.');
- if (dot == -1)
- return null;
- String extension = lastSegment.substring(dot + 1);
- if (extension.length() == 0)
- return null;
- return "/*." + extension; //$NON-NLS-1$
- }
-
- private boolean processAlias(HttpServletRequest req, HttpServletResponse resp, String alias, String extensionAlias) throws ServletException, IOException {
- ServletRegistration registration = null;
- List matchingFilterRegistrations = Collections.EMPTY_LIST;
- String dispatchPathInfo = HttpServletRequestAdaptor.getDispatchPathInfo(req);
- if (dispatchPathInfo == null)
- dispatchPathInfo = "/"; //$NON-NLS-1$
- synchronized (this) {
- if (extensionAlias == null)
- registration = (ServletRegistration) servletRegistrations.get(alias);
- else {
- registration = (ServletRegistration) servletRegistrations.get(alias + extensionAlias);
- if (registration != null) {
- // for regular ServletRegistrations extensions should be handled on the full alias
- if (!(registration.getServlet() instanceof ResourceServlet))
- alias = HttpServletRequestAdaptor.getDispatchPathInfo(req);
- } else
- registration = (ServletRegistration) servletRegistrations.get(alias);
- }
- if (registration != null) {
- registration.addReference();
- if (!filterRegistrations.isEmpty()) {
- matchingFilterRegistrations = new ArrayList();
- for (Iterator it = filterRegistrations.values().iterator(); it.hasNext();) {
- FilterRegistration filterRegistration = (FilterRegistration) it.next();
- if (filterRegistration.matches(dispatchPathInfo)) {
- matchingFilterRegistrations.add(filterRegistration);
- filterRegistration.addReference();
- }
- }
- }
- }
- }
- if (registration != null) {
- try {
- HttpServletRequest wrappedRequest = new HttpServletRequestAdaptor(req, alias, registration.getServlet());
- if (matchingFilterRegistrations.isEmpty()) {
- registration.service(wrappedRequest, resp);
- } else {
- Collections.sort(matchingFilterRegistrations);
- FilterChain chain = new FilterChainImpl(matchingFilterRegistrations, registration);
- chain.doFilter(wrappedRequest, resp);
- }
- } finally {
- registration.removeReference();
- for (Iterator it = matchingFilterRegistrations.iterator(); it.hasNext();) {
- FilterRegistration filterRegistration = (FilterRegistration) it.next();
- filterRegistration.removeReference();
- }
- }
- return true;
- }
- return false;
- }
-
- //Effective unregistration of servlet and resources as defined in HttpService#unregister()
- void unregister(String alias, boolean destroy) {
- ServletRegistration removedRegistration = null;
- synchronized (this) {
- removedRegistration = (ServletRegistration) servletRegistrations.remove(alias);
- if (removedRegistration != null) {
- registeredServlets.remove(removedRegistration.getServlet());
- }
- }
- if (removedRegistration != null) {
- try {
- if (destroy)
- removedRegistration.destroy();
- } finally {
- proxyContext.destroyContextAttributes(removedRegistration.getHttpContext());
- }
- }
- }
-
- //Effective registration of the servlet as defined HttpService#registerServlet()
- synchronized void registerServlet(String alias, Servlet servlet, Dictionary initparams, HttpContext httpContext) throws ServletException, NamespaceException {
- checkAlias(alias);
- if (servletRegistrations.containsKey(alias))
- throw new NamespaceException("The alias '" + alias + "' is already in use."); //$NON-NLS-1$//$NON-NLS-2$
-
- if (servlet == null)
- throw new IllegalArgumentException("Servlet cannot be null"); //$NON-NLS-1$
-
- if (registeredServlets.contains(servlet))
- throw new ServletException("This servlet has already been registered."); //$NON-NLS-1$
-
- ServletRegistration registration = new ServletRegistration(servlet, httpContext);
- ServletContext servletContext = createServletContext(httpContext);
- ServletConfig servletConfig = new ServletConfigImpl(servlet, initparams, servletContext);
-
- boolean initialized = false;
- proxyContext.createContextAttributes(httpContext);
- try {
- registration.init(servletConfig);
- initialized = true;
- } finally {
- if (!initialized)
- proxyContext.destroyContextAttributes(httpContext);
- }
- registeredServlets.add(servlet);
- servletRegistrations.put(alias, registration);
- }
-
- //Effective registration of the resources as defined HttpService#registerResources()
- synchronized void registerResources(String alias, String name, HttpContext httpContext) throws NamespaceException {
- checkName(name);
- Servlet resourceServlet = new ResourceServlet(name, httpContext, AccessController.getContext());
- try {
- registerServlet(alias, resourceServlet, null, httpContext);
- } catch (ServletException e) {
- throw new IllegalStateException("Unexpected ServletException throw when registering resources at alias " + alias + "."); //$NON-NLS-1$//$NON-NLS-2$
- }
- }
-
- private void checkName(String name) {
- if (name == null)
- throw new IllegalArgumentException("Name cannot be null"); //$NON-NLS-1$
-
- if (name.endsWith("/") && !name.equals("/")) //$NON-NLS-1$ //$NON-NLS-2$
- throw new IllegalArgumentException("Invalid Name '" + name + "'"); //$NON-NLS-1$//$NON-NLS-2$
- }
-
- private void checkAlias(String alias) {
- if (alias == null)
- throw new IllegalArgumentException("Alias cannot be null"); //$NON-NLS-1$
-
- if (!alias.startsWith("/") || (alias.endsWith("/") && !alias.equals("/"))) //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
- throw new IllegalArgumentException("Invalid alias '" + alias + "'"); //$NON-NLS-1$//$NON-NLS-2$
- }
-
- public void unregisterFilter(Filter filter, boolean destroy) {
- FilterRegistration removedRegistration = null;
- synchronized (this) {
- removedRegistration = (FilterRegistration) filterRegistrations.remove(filter);
- }
-
- if (removedRegistration != null) {
- try {
- if (destroy)
- removedRegistration.destroy();
- } finally {
- proxyContext.destroyContextAttributes(removedRegistration.getHttpContext());
- }
- }
- }
-
- public synchronized void registerFilter(String alias, Filter filter, Dictionary initparams, HttpContext httpContext) throws ServletException {
- checkAlias(alias);
- if (filter == null)
- throw new IllegalArgumentException("Filter cannot be null"); //$NON-NLS-1$
-
- if (filterRegistrations.containsKey(filter))
- throw new ServletException("This filter has already been registered."); //$NON-NLS-1$
-
- int filterPriority = findFilterPriority(initparams);
- FilterRegistration registration = new FilterRegistration(filter, httpContext, alias, filterPriority);
- ServletContext servletContext = createServletContext(httpContext);
- FilterConfig filterConfig = new FilterConfigImpl(filter, initparams, servletContext);
-
- boolean initialized = false;
- proxyContext.createContextAttributes(httpContext);
- try {
- registration.init(filterConfig);
- initialized = true;
- } finally {
- if (!initialized)
- proxyContext.destroyContextAttributes(httpContext);
- }
- filterRegistrations.put(filter, registration);
- }
-
- private ServletContext createServletContext(HttpContext httpContext) {
- ServletContextAdaptor adaptor = new ServletContextAdaptor(proxyContext, getServletContext(), httpContext, AccessController.getContext());
- return adaptor.createServletContext();
- }
-
- private int findFilterPriority(Dictionary initparams) {
- if (initparams == null)
- return 0;
- String filterPriority = (String) initparams.get("filter-priority"); //$NON-NLS-1$
- if (filterPriority == null)
- return 0;
-
- try {
- int result = Integer.parseInt(filterPriority);
- if (result >= -1000 && result <= 1000)
- return result;
- } catch (NumberFormatException e) {
- // fall through
- }
- throw new IllegalArgumentException("filter-priority must be an integer between -1000 and 1000 but was: " + filterPriority); //$NON-NLS-1$
- }
-}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletConfigImpl.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletConfigImpl.java
deleted file mode 100644
index 51951e14..00000000
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletConfigImpl.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2007 Cognos Incorporated, IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Cognos Incorporated - initial API and implementation
- * IBM Corporation - bug fixes and enhancements
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet.internal;
-
-import java.util.*;
-import javax.servlet.*;
-
-public class ServletConfigImpl implements ServletConfig {
-
- private static final Dictionary EMPTY_PARAMS = new Hashtable(0);
- private static final String SERVLET_NAME = "servlet-name"; //$NON-NLS-1$
- private Servlet servlet;
- private Dictionary initparams;
- private ServletContext servletContext;
-
- public ServletConfigImpl(Servlet servlet, Dictionary initparams, ServletContext servletContext) {
- this.servlet = servlet;
- this.initparams = (initparams != null) ? initparams : EMPTY_PARAMS;
- this.servletContext = servletContext;
- }
-
- /*
- * @see javax.servlet.ServletConfig#getServletName()
- *
- * The OSGi Http Service does not specify a way to set a servlet name at the API level. This
- * implementation will try to use the value of the "servlet-name" initial parameter if available.
- */
- public String getServletName() {
- String servletName = (String) initparams.get(SERVLET_NAME);
- return (servletName != null) ? servletName : servlet.getClass().getName();
- }
-
- public ServletContext getServletContext() {
- return servletContext;
- }
-
- public String getInitParameter(String name) {
- return (String) initparams.get(name);
- }
-
- public Enumeration getInitParameterNames() {
- return initparams.keys();
- }
-}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletContextAdaptor.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletContextAdaptor.java
deleted file mode 100644
index f9e60473..00000000
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletContextAdaptor.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2011 Cognos Incorporated, IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Cognos Incorporated - initial API and implementation
- * IBM Corporation - bug fixes and enhancements
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet.internal;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.*;
-import java.net.URL;
-import java.security.*;
-import java.util.*;
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletContext;
-import org.osgi.service.http.HttpContext;
-
-public class ServletContextAdaptor {
- private final static Map contextToHandlerMethods;
- static {
- contextToHandlerMethods = createContextToHandlerMethods();
- }
-
- private static Map createContextToHandlerMethods() {
- Map methods = new HashMap();
- Method[] handlerMethods = ServletContextAdaptor.class.getDeclaredMethods();
- for (int i = 0; i < handlerMethods.length; i++) {
- Method handlerMethod = handlerMethods[i];
- String name = handlerMethod.getName();
- Class[] parameterTypes = handlerMethod.getParameterTypes();
- try {
- Method method = ServletContext.class.getMethod(name, parameterTypes);
- methods.put(method, handlerMethod);
- } catch (NoSuchMethodException e) {
- // do nothing
- }
- }
- return methods;
- }
-
- final private ServletContext servletContext;
- final HttpContext httpContext;
- final private AccessControlContext acc;
- final private ProxyContext proxyContext;
-
- public ServletContextAdaptor(ProxyContext proxyContext, ServletContext servletContext, HttpContext httpContext, AccessControlContext acc) {
- this.servletContext = servletContext;
- this.httpContext = httpContext;
- this.acc = acc;
- this.proxyContext = proxyContext;
- }
-
- public ServletContext createServletContext() {
- Class clazz = getClass();
- ClassLoader classLoader = clazz.getClassLoader();
- Class[] interfaces = new Class[] {ServletContext.class};
- InvocationHandler invocationHandler = createInvocationHandler();
- return (ServletContext) Proxy.newProxyInstance(classLoader, interfaces, invocationHandler);
- }
-
- private InvocationHandler createInvocationHandler() {
- return new InvocationHandler() {
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- return ServletContextAdaptor.this.invoke(proxy, method, args);
- }
- };
- }
-
- Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- Method m = (Method) contextToHandlerMethods.get(method);
- if (m != null) {
- return m.invoke(this, args);
- }
- return method.invoke(servletContext, args);
- }
-
- /**
- * @see javax.servlet.ServletContext#getResourcePaths(java.lang.String)
- *
- * This method was added in the Servlet 2.3 API however the OSGi HttpService currently does not provide
- * support for this method in the HttpContext interface. To support "getResourcePaths(...) this
- * implementation uses reflection to check for and then call the associated HttpContext.getResourcePaths(...)
- * method opportunistically. Null is returned if the method is not present or fails.
- */
- public Set getResourcePaths(String name) {
- if (name == null || !name.startsWith("/")) //$NON-NLS-1$
- return null;
- try {
- Method getResourcePathsMethod = httpContext.getClass().getMethod("getResourcePaths", new Class[] {String.class}); //$NON-NLS-1$
- if (!getResourcePathsMethod.isAccessible())
- getResourcePathsMethod.setAccessible(true);
- return (Set) getResourcePathsMethod.invoke(httpContext, new Object[] {name});
- } catch (Exception e) {
- // ignore
- }
- return null;
- }
-
- public Object getAttribute(String attributeName) {
- Dictionary attributes = proxyContext.getContextAttributes(httpContext);
- return attributes.get(attributeName);
- }
-
- public Enumeration getAttributeNames() {
- Dictionary attributes = proxyContext.getContextAttributes(httpContext);
- return attributes.keys();
- }
-
- public void setAttribute(String attributeName, Object attributeValue) {
- Dictionary attributes = proxyContext.getContextAttributes(httpContext);
- attributes.put(attributeName, attributeValue);
- }
-
- public void removeAttribute(String attributeName) {
- Dictionary attributes = proxyContext.getContextAttributes(httpContext);
- attributes.remove(attributeName);
- }
-
- public String getMimeType(String name) {
- String mimeType = httpContext.getMimeType(name);
- return (mimeType != null) ? mimeType : servletContext.getMimeType(name);
- }
-
- public URL getResource(final String name) {
- try {
- return (URL) AccessController.doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws Exception {
- return httpContext.getResource(name);
- }
- }, acc);
- } catch (PrivilegedActionException e) {
- servletContext.log(e.getException().getMessage(), e.getException());
- }
- return null;
- }
-
- public InputStream getResourceAsStream(String name) {
- URL url = getResource(name);
- if (url != null) {
- try {
- return url.openStream();
- } catch (IOException e) {
- servletContext.log("Error opening stream for resource '" + name + "'", e); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- return null;
- }
-
- public RequestDispatcher getNamedDispatcher(String arg0) {
- return new RequestDispatcherAdaptor(servletContext.getNamedDispatcher(arg0));
- }
-
- public RequestDispatcher getRequestDispatcher(String arg0) {
- return new RequestDispatcherAdaptor(servletContext.getRequestDispatcher(proxyContext.getServletPath() + arg0));
- }
-}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletRegistration.java
deleted file mode 100644
index f3fae945..00000000
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ServletRegistration.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2010 Cognos Incorporated, IBM Corporation and others
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Cognos Incorporated - initial API and implementation
- * IBM Corporation - bug fixes and enhancements
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet.internal;
-
-import java.io.IOException;
-import javax.servlet.*;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.osgi.service.http.HttpContext;
-
-//This class wraps the servlet object registered in the HttpService.registerServlet call, to manage the context classloader when handleRequests are being asked.
-public class ServletRegistration extends Registration {
-
- private Servlet servlet; //The actual servlet object registered against the http service. All requests will eventually be delegated to it.
- private HttpContext httpContext; //The context used during the registration of the servlet
- private ClassLoader registeredContextClassLoader;
-
- public ServletRegistration(Servlet servlet, HttpContext context) {
- this.servlet = servlet;
- this.httpContext = context;
- registeredContextClassLoader = Thread.currentThread().getContextClassLoader();
- }
-
- public void destroy() {
- ClassLoader original = Thread.currentThread().getContextClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(registeredContextClassLoader);
- super.destroy();
- servlet.destroy();
- } finally {
- Thread.currentThread().setContextClassLoader(original);
- }
- }
-
- //Delegate the init call to the actual servlet
- public void init(ServletConfig servletConfig) throws ServletException {
- ClassLoader original = Thread.currentThread().getContextClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(registeredContextClassLoader);
- servlet.init(servletConfig);
- } finally {
- Thread.currentThread().setContextClassLoader(original);
- }
- }
-
- //Delegate the handling of the request to the actual servlet
- public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
- ClassLoader original = Thread.currentThread().getContextClassLoader();
- try {
- Thread.currentThread().setContextClassLoader(registeredContextClassLoader);
- if (httpContext.handleSecurity(req, resp))
- servlet.service(req, resp);
- } finally {
- Thread.currentThread().setContextClassLoader(original);
- }
- }
-
- public Servlet getServlet() {
- return servlet;
- }
-
- public HttpContext getHttpContext() {
- return httpContext;
- }
-}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ContextController.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ContextController.java
new file mode 100644
index 00000000..933683c0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ContextController.java
@@ -0,0 +1,1059 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.context;
+
+import java.io.IOException;
+import java.security.AccessController;
+import java.util.*;
+import javax.servlet.*;
+import javax.servlet.Filter;
+import javax.servlet.http.*;
+import org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl;
+import org.eclipse.equinox.http.servlet.internal.customizer.*;
+import org.eclipse.equinox.http.servlet.internal.error.RegisteredFilterException;
+import org.eclipse.equinox.http.servlet.internal.registration.*;
+import org.eclipse.equinox.http.servlet.internal.registration.FilterRegistration;
+import org.eclipse.equinox.http.servlet.internal.registration.ServletRegistration;
+import org.eclipse.equinox.http.servlet.internal.servlet.*;
+import org.eclipse.equinox.http.servlet.internal.util.*;
+import org.osgi.framework.*;
+import org.osgi.framework.wiring.BundleWiring;
+import org.osgi.service.http.context.ServletContextHelper;
+import org.osgi.service.http.context.ServletContextHelperContext;
+import org.osgi.service.http.runtime.dto.*;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * @author Raymond Augé
+ */
+public class ContextController implements ServletContextHelperContext {
+
+ public ContextController(
+ Bundle bundle, ServletContextHelper servletContextHelper,
+ ProxyContext proxyContext, HttpServiceRuntimeImpl httpServiceRuntime,
+ List<String> contextNames, String contextPath, long serviceId,
+ Set<Servlet> registeredServlets, Map<String, Object> attributes) {
+
+ this.bundle = bundle;
+ this.servletContextHelper = servletContextHelper;
+ this.proxyContext = proxyContext;
+ this.httpServiceRuntime = httpServiceRuntime;
+ this.contextNames = contextNames;
+ this.contextPath = contextPath;
+ this.contextServiceId = serviceId;
+ this.registeredServlets = registeredServlets;
+
+ attributes = new HashMap<String, Object>(attributes);
+ attributes.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, contextNames);
+ attributes.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, contextPath);
+ attributes.put(Constants.SERVICE_ID, serviceId);
+
+ this.attributes = attributes;
+
+ Map<String, String> initParams = new HashMap<String, String>();
+
+ for (String key : this.attributes.keySet()) {
+ initParams.put(key, String.valueOf(attributes.get(key)));
+ }
+
+ this.initParams = Collections.unmodifiableMap(initParams);
+
+ bundleContext = bundle.getBundleContext();
+
+ listenerServiceTracker = new ServiceTracker<EventListener, ListenerRegistration>(
+ bundleContext, EventListener.class,
+ new ContextListenerTrackerCustomizer(
+ bundleContext, httpServiceRuntime, this));
+
+ listenerServiceTracker.open();
+
+ filterServiceTracker = new ServiceTracker<Filter, FilterRegistration>(
+ bundleContext, getFilteFilter(),
+ new ContextFilterTrackerCustomizer(
+ bundleContext, httpServiceRuntime, this));
+
+ filterServiceTracker.open();
+
+ servletServiceTracker = new ServiceTracker<Servlet, ServletRegistration>(
+ bundleContext, getServletFilter(),
+ new ContextServletTrackerCustomizer(
+ bundleContext, httpServiceRuntime, this));
+
+ servletServiceTracker.open();
+
+ resourceServiceTracker = new ServiceTracker<Servlet, ResourceRegistration>(
+ bundleContext, getResourceFilter(),
+ new ContextResourceTrackerCustomizer(
+ bundleContext, httpServiceRuntime, this));
+
+ resourceServiceTracker.open();
+ }
+
+ public FilterRegistration addFilterRegistration(
+ String alias, Filter filter, Dictionary<String, String> initparams,
+ long serviceId)
+ throws ServletException {
+
+ checkShutdown();
+
+ if (filter == null) {
+ throw new IllegalArgumentException("Filter cannot be null");
+ }
+
+ String filterName = initparams.get(Const.FILTER_NAME);
+
+ filterName = (filterName != null) ? filterName :
+ filter.getClass().getName();
+
+ int filterPriority = findFilterPriority(initparams);
+
+ return addFilterRegistration(
+ filter, false, DISPATCHER, filterPriority,
+ new UMDictionaryMap<String, String>(initparams), filterName,
+ new String[] {alias}, serviceId, Const.EMPTY_ARRAY);
+ }
+
+ public FilterRegistration addFilterRegistration(
+ Filter filter, boolean asyncSupported, String[] dispatcher,
+ int filterPriority, Map<String, String> initparams, String name,
+ String[] patterns, long serviceId, String[] servletNames)
+ throws ServletException {
+
+ checkShutdown();
+
+ if (((patterns == null) || (patterns.length == 0)) &&
+ ((servletNames == null) || servletNames.length == 0)) {
+
+ throw new IllegalArgumentException(
+ "Patterns or servletNames must contain a value.");
+ }
+
+ if (patterns != null) {
+ for (String pattern : patterns) {
+ checkPattern(pattern);
+ }
+ }
+
+ if (name == null) {
+ name = filter.getClass().getName();
+ }
+
+ if (filter == null) {
+ throw new IllegalArgumentException("Filter cannot be null");
+ }
+
+ for (FilterRegistration filterRegistration : filterRegistrations) {
+ if (filterRegistration.getT().equals(filter)) {
+ throw new RegisteredFilterException(filter);
+ }
+ }
+
+ dispatcher = checkDispatcher(dispatcher);
+
+ FilterDTO filterDTO = new FilterDTO();
+
+ filterDTO.asyncSupported = asyncSupported;
+ filterDTO.dispatcher = sort(dispatcher);
+ filterDTO.initParams = initparams;
+ filterDTO.name = name;
+ filterDTO.patterns = sort(patterns);
+ // TODO
+ //filterDTO.regexps = sort(regexps);
+ filterDTO.serviceId = serviceId;
+ filterDTO.servletContextId = contextServiceId;
+ filterDTO.servletNames = sort(servletNames);
+
+ ServletContextHelper curServletContextHelper = getServletContextHelper(
+ bundle);
+
+ ServletContext servletContext = createServletContext(
+ bundle, curServletContextHelper);
+ FilterRegistration filterRegistration = new FilterRegistration(
+ filter, filterDTO, filterPriority, curServletContextHelper, this);
+ FilterConfig filterConfig = new FilterConfigImpl(
+ name, initparams, servletContext);
+
+ filterRegistration.init(filterConfig);
+
+ filterRegistrations.add(filterRegistration);
+
+ return filterRegistration;
+ }
+
+ public ListenerRegistration addListenerRegistration(
+ EventListener eventListener, long serviceId)
+ throws ServletException {
+
+ checkShutdown();
+
+ List<Class<? extends EventListener>> classes = getListenerClasses(
+ eventListener);
+
+ if (classes.isEmpty()) {
+ throw new IllegalArgumentException(
+ "EventListener does not implement a supported type.");
+ }
+
+ for (ListenerRegistration listenerRegistration : listenerRegistrations) {
+ if (listenerRegistration.getT().equals(eventListener)) {
+ throw new ServletException(
+ "EventListener has already been registered.");
+ }
+ }
+
+ ListenerDTO listenerDTO = new ListenerDTO();
+
+ listenerDTO.serviceId = serviceId;
+ listenerDTO.servletContextId = contextServiceId;
+ listenerDTO.types = asStringArray(classes);
+
+ ServletContextHelper curServletContextHelper = getServletContextHelper(
+ bundle);
+
+ ServletContext servletContext = createServletContext(
+ bundle, curServletContextHelper);
+ ListenerRegistration listenerRegistration = new ListenerRegistration(
+ eventListener, classes, listenerDTO, servletContext,
+ curServletContextHelper, this);
+
+ if (classes.contains(ServletContextListener.class)) {
+ ServletContextListener servletContextListener =
+ (ServletContextListener)listenerRegistration.getT();
+
+ servletContextListener.contextInitialized(
+ new ServletContextEvent(servletContext));
+ }
+
+ listenerRegistrations.add(listenerRegistration);
+
+ eventListeners.put(classes, listenerRegistration);
+
+ return listenerRegistration;
+ }
+
+ public ResourceRegistration addResourceRegistration(
+ String pattern, String prefix, long serviceId) {
+
+ checkShutdown();
+
+ if (pattern.startsWith("/*.")) { //$NON-NLS-1$
+ pattern = pattern.substring(1);
+ }
+ else if (!pattern.contains("*.") && //$NON-NLS-1$
+ !pattern.endsWith(Const.SLASH_STAR) &&
+ !pattern.endsWith(Const.SLASH)) {
+ pattern += Const.SLASH_STAR;
+ }
+
+ return addResourceRegistration(
+ new String[] {pattern}, prefix, serviceId);
+ }
+
+ public ResourceRegistration addResourceRegistration(
+ String[] patterns, String prefix, long serviceId) {
+
+ checkShutdown();
+
+ checkPrefix(prefix);
+
+ if ((patterns == null) || (patterns.length < 1)) {
+ throw new IllegalArgumentException(
+ "Patterns must contain a value.");
+ }
+
+ for (String pattern : patterns) {
+ checkPattern(pattern);
+ }
+
+ Servlet servlet = new ResourceServlet(
+ prefix, this, servletContextHelper, AccessController.getContext());
+
+ ResourceDTO resourceDTO = new ResourceDTO();
+
+ resourceDTO.patterns = sort(patterns);
+ resourceDTO.prefix = prefix;
+ resourceDTO.serviceId = serviceId;
+ resourceDTO.servletContextId = contextServiceId;
+
+ ServletContextHelper curServletContextHelper = getServletContextHelper(
+ bundle);
+
+ ServletContext servletContext = createServletContext(
+ bundle, curServletContextHelper);
+ ResourceRegistration resourceRegistration = new ResourceRegistration(
+ servlet, resourceDTO, curServletContextHelper, this);
+ ServletConfig servletConfig = new ServletConfigImpl(
+ resourceRegistration.getName(), new HashMap<String, String>(),
+ servletContext);
+
+ try {
+ resourceRegistration.init(servletConfig);
+ }
+ catch (ServletException e) {
+ return null;
+ }
+
+ endpointRegistrations.add(resourceRegistration);
+
+ registeredServlets.add(servlet);
+
+ return resourceRegistration;
+ }
+
+ public ServletRegistration addServletRegistration(
+ String pattern, Servlet servlet,
+ Dictionary<String, String> initparams, long serviceId)
+ throws ServletException {
+
+ checkShutdown();
+
+ if (servlet == null) {
+ throw new IllegalArgumentException("Servlet cannot be null");
+ }
+
+ String servletName = servlet.getClass().getName();
+
+ if ((initparams != null) && (initparams.get(Const.SERVLET_NAME) != null)) {
+ servletName = initparams.get(Const.SERVLET_NAME);
+ }
+
+ if (pattern == null) {
+ throw new IllegalArgumentException("Pattern cannot be null");
+ }
+
+ return addServletRegistration(
+ servlet, false, Const.EMPTY_ARRAY,
+ new UMDictionaryMap<String, String>(initparams),
+ new String[] {pattern}, serviceId, servletName);
+ }
+
+ public ServletRegistration addServletRegistration(
+ Servlet servlet, boolean asyncSupported, String[] errorPages,
+ Map<String, String> initparams, String[] patterns, long serviceId,
+ String servletName)
+ throws ServletException {
+
+ checkShutdown();
+
+ if (((patterns == null) || (patterns.length == 0)) &&
+ ((errorPages == null) || errorPages.length == 0)) {
+
+ throw new IllegalArgumentException(
+ "Either patterns or errorPages must contain a value.");
+ }
+
+ if (patterns != null) {
+ for (String pattern : patterns) {
+ checkPattern(pattern);
+ }
+ }
+
+ if (servlet == null) {
+ throw new IllegalArgumentException("Servlet cannot be null");
+ }
+
+ ServletDTO servletDTO = new ServletDTO();
+
+ servletDTO.asyncSupported = false;
+ servletDTO.initParams = initparams;
+ servletDTO.name = servletName;
+ servletDTO.patterns = sort(patterns);
+ servletDTO.serviceId = serviceId;
+ servletDTO.servletContextId = contextServiceId;
+ servletDTO.servletInfo = servlet.getServletInfo();
+
+ ErrorPageDTO errorPageDTO = null;
+
+ if ((errorPages != null) && (errorPages.length > 0)) {
+ errorPageDTO = new ErrorPageDTO();
+
+ errorPageDTO.asyncSupported = asyncSupported;
+ long[] errorCodes = new long[0];
+ List<String> exceptions = new ArrayList<String>();
+
+ for(String errorPage : errorPages) {
+ try {
+ long longValue = Long.parseLong(errorPage);
+
+ errorCodes = Arrays.copyOf(errorCodes, errorCodes.length + 1);
+
+ errorCodes[errorCodes.length - 1] = longValue;
+ }
+ catch (NumberFormatException nfe) {
+ exceptions.add(errorPage);
+ }
+ }
+
+ errorPageDTO.errorCodes = errorCodes;
+ errorPageDTO.exceptions = exceptions.toArray(new String[exceptions.size()]);
+ errorPageDTO.initParams = initparams;
+ errorPageDTO.name = servletName;
+ errorPageDTO.serviceId = serviceId;
+ errorPageDTO.servletContextId = contextServiceId;
+ errorPageDTO.servletInfo = servlet.getServletInfo();
+ }
+
+ ServletContextHelper curServletContextHelper = getServletContextHelper(
+ bundle);
+
+ ServletContext servletContext = createServletContext(
+ bundle, curServletContextHelper);
+ ServletRegistration servletRegistration = new ServletRegistration(
+ servlet, servletDTO, errorPageDTO, curServletContextHelper, this);
+ ServletConfig servletConfig = new ServletConfigImpl(
+ servletName, initparams, servletContext);
+
+ servletRegistration.init(servletConfig);
+
+ endpointRegistrations.add(servletRegistration);
+
+ registeredServlets.add(servlet);
+
+ return servletRegistration;
+ }
+
+ public void destroy() {
+ resourceServiceTracker.close();
+ servletServiceTracker.close();
+ filterServiceTracker.close();
+ listenerServiceTracker.close();
+
+ endpointRegistrations.clear();
+ filterRegistrations.clear();
+ listenerRegistrations.clear();
+ eventListeners.clear();
+ proxyContext.destroy();
+
+ eventListeners = null;
+ registeredServlets = null;
+ contextNames = null;
+ proxyContext = null;
+
+ shutdown = true;
+ }
+
+ public ClassLoader getClassLoader() {
+ return bundle.adapt(BundleWiring.class).getClassLoader();
+ }
+
+ public List<String> getContextNames() {
+ checkShutdown();
+
+ return contextNames;
+ }
+
+ public String getContextPath() {
+ checkShutdown();
+
+ return contextPath;
+ }
+
+ public DispatchTargets getDispatchTargets(
+ HttpServletRequest request, String servletName, String requestURI,
+ String servletPath, String pathInfo, String extension, Match match,
+ RequestInfoDTO requestInfoDTO) {
+
+ checkShutdown();
+
+ getProxyContext().initializeServletPath(request);
+
+ EndpointRegistration<?> endpointRegistration = null;
+ String pattern = null;
+
+ for (EndpointRegistration<?> curEndpointRegistration : endpointRegistrations) {
+ if ((pattern = curEndpointRegistration.match(
+ servletName, servletPath, pathInfo, extension, match)) != null) {
+
+ endpointRegistration = curEndpointRegistration;
+
+ break;
+ }
+ }
+
+ if (endpointRegistration == null) {
+ return null;
+ }
+
+ endpointRegistration.addReference();
+
+ addEnpointRegistrationsToRequestInfo(
+ endpointRegistration, requestInfoDTO);
+
+ if (filterRegistrations.isEmpty()) {
+ return new DispatchTargets(
+ this, endpointRegistration, servletPath, pathInfo, pattern);
+ }
+
+ String originalServletPath = servletPath;
+ String originalPathInfo = pathInfo;
+
+ List<FilterRegistration> matchingFilterRegistrations =
+ new ArrayList<FilterRegistration>();
+
+ for (Match curMatch : Match.values()) {
+ collectFilters(
+ matchingFilterRegistrations, servletName, requestURI, curMatch);
+ }
+
+ addFilterRegistrationsToRequestInfo(
+ matchingFilterRegistrations, requestInfoDTO);
+
+ return new DispatchTargets(
+ this, endpointRegistration, matchingFilterRegistrations,
+ originalServletPath, originalPathInfo, pattern);
+ }
+
+ private void collectFilters(
+ List<FilterRegistration> matchingFilterRegistrations,
+ String servletName, String requestURI, Match match) {
+
+ String servletPath = requestURI;
+ String pathInfo = "";
+ String extension = null;
+
+ int pos = -1;
+
+ if (requestURI != null) {
+ pos = requestURI.lastIndexOf('/');
+
+ if (match == Match.EXTENSION) {
+ int x = requestURI.lastIndexOf('.');
+
+ if (x != -1) {
+ extension = requestURI.substring(x + 1);
+ }
+
+ if (extension == null) {
+ return;
+ }
+ }
+ }
+
+ do {
+ for (FilterRegistration filterRegistration : filterRegistrations) {
+ if ((filterRegistration.match(
+ servletName, servletPath, pathInfo, extension, match) != null) &&
+ !matchingFilterRegistrations.contains(filterRegistration)) {
+
+ matchingFilterRegistrations.add(filterRegistration);
+
+ filterRegistration.addReference();
+ }
+ }
+
+ if (pos > -1) {
+ String newServletPath = requestURI.substring(0, pos);
+ pathInfo = requestURI.substring(pos);
+ servletPath = newServletPath;
+ pos = servletPath.lastIndexOf('/');
+
+ continue;
+ }
+
+ break;
+ }
+ while (true);
+ }
+
+ public Set<EndpointRegistration<?>> getEndpointRegistrations() {
+ checkShutdown();
+
+ return endpointRegistrations;
+ }
+
+ public EventListeners getEventListeners() {
+ checkShutdown();
+
+ return eventListeners;
+ }
+
+ public Set<FilterRegistration> getFilterRegistrations() {
+ checkShutdown();
+
+ return filterRegistrations;
+ }
+
+ public String getFullContextPath() {
+ List<String> endpoints = httpServiceRuntime.getHttpServiceEndpoints();
+
+ if (endpoints.isEmpty()) {
+ return proxyContext.getServletPath().concat(contextPath);
+ }
+
+ String defaultEndpoint = endpoints.get(0);
+
+ if ((defaultEndpoint.length() > 0) && defaultEndpoint.endsWith("/")) {
+ defaultEndpoint = defaultEndpoint.substring(
+ 0, defaultEndpoint.length() - 1);
+ }
+
+ return defaultEndpoint + contextPath;
+ }
+
+ public HttpServiceRuntimeImpl getHttpServiceRuntime() {
+ checkShutdown();
+
+ return httpServiceRuntime;
+ }
+
+ public Map<String, String> getInitParams() {
+ return initParams;
+ }
+
+ public Set<ListenerRegistration> getListenerRegistrations() {
+ checkShutdown();
+
+ return listenerRegistrations;
+ }
+
+ @Override
+ public ServletContextHelper getParentContext(ServletContextHelper context) {
+ //TODO
+ return null;
+ }
+
+ public ProxyContext getProxyContext() {
+ checkShutdown();
+
+ return proxyContext;
+ }
+
+ public Set<Servlet> getRegisteredServlets() {
+ checkShutdown();
+
+ return registeredServlets;
+ }
+
+ public long getServiceId() {
+ checkShutdown();
+
+ return contextServiceId;
+ }
+
+ public synchronized ServletContextDTO getServletContextDTO(){
+ checkShutdown();
+
+ ServletContextDTO servletContextDTO = new ServletContextDTO();
+
+ ServletContext servletContext = getProxyContext().getServletContext();
+
+ servletContextDTO.attributes = getAttributes(servletContext);
+ servletContextDTO.contextName = servletContext.getServletContextName();
+ servletContextDTO.contextPath = servletContext.getContextPath();
+ servletContextDTO.initParams = initParams;
+ servletContextDTO.names = getContextNames().toArray(new String[0]);
+ servletContextDTO.serviceId = getServiceId();
+
+ // TODO
+ servletContextDTO.errorPageDTOs = new ErrorPageDTO[0];
+
+ collectEndpointDTOs(servletContextDTO);
+ collectFilterDTOs(servletContextDTO);
+ collectListenerDTOs(servletContextDTO);
+
+ return servletContextDTO;
+ }
+
+ public ServletContextHelper getServletContextHelper() {
+ return servletContextHelper;
+ }
+
+ public boolean matches(String contextSelector) {
+ if (contextSelector == null) {
+ return true;
+ }
+
+ if (!contextSelector.startsWith(Const.OPEN_PAREN)) {
+ contextSelector = Const.OPEN_PAREN +
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME +
+ Const.EQUAL + contextSelector + Const.CLOSE_PAREN;
+ }
+
+ org.osgi.framework.Filter targetFilter;
+
+ try {
+ targetFilter = FrameworkUtil.createFilter(contextSelector);
+ }
+ catch (InvalidSyntaxException ise) {
+ throw new IllegalArgumentException(ise);
+ }
+
+ return matches(targetFilter);
+ }
+
+ public boolean matches(org.osgi.framework.Filter targetFilter) {
+ return targetFilter.matches(attributes);
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + '[' + getContextNames().get(0) + ']';
+ }
+
+ private void addEnpointRegistrationsToRequestInfo(
+ EndpointRegistration<?> endpointRegistration,
+ RequestInfoDTO requestInfoDTO) {
+
+ if (requestInfoDTO == null) {
+ return;
+ }
+
+ requestInfoDTO.servletContextId = getServiceId();
+
+ if (endpointRegistration instanceof ResourceRegistration) {
+ requestInfoDTO.resourceDTO =
+ (ResourceDTO)endpointRegistration.getD();
+ }
+ else {
+ requestInfoDTO.servletDTO =
+ (ServletDTO)endpointRegistration.getD();
+ }
+ }
+
+ private void addFilterRegistrationsToRequestInfo(
+ List<FilterRegistration> matchedFilterRegistrations,
+ RequestInfoDTO requestInfoDTO) {
+
+ if (requestInfoDTO == null) {
+ return;
+ }
+
+ FilterDTO[] filterDTOs =
+ new FilterDTO[matchedFilterRegistrations.size()];
+
+ for (int i = 0; i < filterDTOs.length ; i++) {
+ FilterRegistration filterRegistration =
+ matchedFilterRegistrations.get(i);
+
+ filterDTOs[i] = filterRegistration.getD();
+ }
+
+ requestInfoDTO.filterDTOs = filterDTOs;
+ }
+
+ private String[] asStringArray(
+ List<Class<? extends EventListener>> clazzes) {
+
+ String[] classesArray = new String[clazzes.size()];
+
+ for (int i = 0; i < classesArray.length; i++) {
+ classesArray[i] = clazzes.get(i).getName();
+ }
+
+ Arrays.sort(classesArray);
+
+ return classesArray;
+ }
+
+ private String[] checkDispatcher(String[] dispatcher) {
+ if ((dispatcher == null) || (dispatcher.length == 0)) {
+ return DISPATCHER;
+ }
+
+ for (String type : dispatcher) {
+ try {
+ Const.Dispatcher.valueOf(type);
+ }
+ catch (IllegalArgumentException iae) {
+ throw new IllegalArgumentException(
+ "Invalid dispatcher '" + type + "'", iae);
+ }
+ }
+
+ Arrays.sort(dispatcher);
+
+ return dispatcher;
+ }
+
+ private void checkPattern(String pattern) {
+ if (pattern == null) {
+ throw new IllegalArgumentException("Pattern cannot be null");
+ }
+
+ if (pattern.indexOf("*.") == 0) { //$NON-NLS-1$
+ return;
+ }
+
+ if (!pattern.startsWith(Const.SLASH) ||
+ (pattern.endsWith(Const.SLASH) && !pattern.equals(Const.SLASH))) {
+
+ throw new IllegalArgumentException(
+ "Invalid pattern '" + pattern + "'");
+ }
+ }
+
+ private void checkPrefix(String prefix) {
+ if (prefix == null) {
+ throw new IllegalArgumentException("Prefix cannot be null");
+ }
+
+ if (prefix.endsWith(Const.SLASH) && !prefix.equals(Const.SLASH)) {
+ throw new IllegalArgumentException("Invalid prefix '" + prefix + "'");
+ }
+ }
+
+ private void checkShutdown() {
+ if (shutdown) {
+ throw new IllegalStateException(
+ "Context is already shutdown"); //$NON-NLS-1$
+ }
+ }
+
+ private ServletContext createServletContext(
+ Bundle curBundle, ServletContextHelper curServletContextHelper) {
+
+ ServletContextAdaptor adaptor = new ServletContextAdaptor(
+ this, curBundle, curServletContextHelper, eventListeners,
+ AccessController.getContext());
+
+ return adaptor.createServletContext();
+ }
+
+ private void collectEndpointDTOs(
+ ServletContextDTO servletContextDTO) {
+
+ List<ResourceDTO> resourceDTOs = new ArrayList<ResourceDTO>();
+ List<ServletDTO> servletDTOs = new ArrayList<ServletDTO>();
+
+ for (EndpointRegistration<?> endpointRegistration : endpointRegistrations) {
+ if (endpointRegistration instanceof ResourceRegistration) {
+ resourceDTOs.add((ResourceDTO)endpointRegistration.getD());
+ }
+ else {
+ servletDTOs.add((ServletDTO)endpointRegistration.getD());
+ }
+ }
+
+ servletContextDTO.resourceDTOs = resourceDTOs.toArray(
+ new ResourceDTO[resourceDTOs.size()]);
+ servletContextDTO.servletDTOs = servletDTOs.toArray(
+ new ServletDTO[servletDTOs.size()]);
+ }
+
+ private void collectFilterDTOs(
+ ServletContextDTO servletContextDTO) {
+
+ List<FilterDTO> filterDTOs = new ArrayList<FilterDTO>();
+
+ for (FilterRegistration filterRegistration : filterRegistrations) {
+ filterDTOs.add(filterRegistration.getD());
+ }
+
+ servletContextDTO.filterDTOs = filterDTOs.toArray(
+ new FilterDTO[filterDTOs.size()]);
+ }
+
+ private void collectListenerDTOs(
+ ServletContextDTO servletContextDTO) {
+
+ List<ListenerDTO> listenerDTOs = new ArrayList<ListenerDTO>();
+
+ for (ListenerRegistration listenerRegistration : listenerRegistrations) {
+ listenerDTOs.add(listenerRegistration.getD());
+ }
+
+ servletContextDTO.listenerDTOs = listenerDTOs.toArray(
+ new ListenerDTO[listenerDTOs.size()]);
+ }
+
+ private int findFilterPriority(Dictionary<String, String> initparams) {
+ if (initparams == null) {
+ return 0;
+ }
+
+ String filterPriority = initparams.get(Const.FILTER_PRIORITY);
+
+ if (filterPriority == null) {
+ return 0;
+ }
+
+ try {
+ int result = Integer.parseInt(filterPriority);
+ if (result >= -1000 && result <= 1000) {
+ return result;
+ }
+ }
+ catch (NumberFormatException e) {
+ // fall through
+ }
+
+ throw new IllegalArgumentException(
+ "filter-priority must be an integer between -1000 and 1000 but " +
+ "was: " + filterPriority);
+ }
+
+ private Map<String, Object> getAttributes(ServletContext servletContext) {
+ Map<String, Object> map = new HashMap<String, Object>();
+
+ for (Enumeration<String> names = servletContext.getAttributeNames();
+ names.hasMoreElements();) {
+
+ String name = names.nextElement();
+
+ map.put(name, servletContext.getAttribute(name));
+ }
+
+ return Collections.unmodifiableMap(map);
+ }
+
+ private List<Class<? extends EventListener>> getListenerClasses(
+ EventListener eventListener) {
+
+ List<Class<? extends EventListener>> classes =
+ new ArrayList<Class<? extends EventListener>>();
+
+ if (ServletContextListener.class.isInstance(eventListener)) {
+ classes.add(ServletContextListener.class);
+ }
+ if (ServletContextAttributeListener.class.isInstance(eventListener)) {
+ classes.add(ServletContextAttributeListener.class);
+ }
+ if (ServletRequestListener.class.isInstance(eventListener)) {
+ classes.add(ServletRequestListener.class);
+ }
+ if (ServletRequestAttributeListener.class.isInstance(eventListener)) {
+ classes.add(ServletRequestAttributeListener.class);
+ }
+ if (HttpSessionListener.class.isInstance(eventListener)) {
+ classes.add(HttpSessionListener.class);
+ }
+ if (HttpSessionAttributeListener.class.isInstance(eventListener)) {
+ classes.add(HttpSessionAttributeListener.class);
+ }
+
+ return classes;
+ }
+
+ private ServletContextHelper getServletContextHelper(Bundle curBundle) {
+ if (curBundle == this.bundle) {
+ return servletContextHelper;
+ }
+
+ return new ServletContextHelper(curBundle) {
+
+ @Override
+ public String getMimeType(
+ ServletContextHelperContext context, String name) {
+
+ return servletContextHelper.getMimeType(context, name);
+ }
+
+ @Override
+ public boolean handleSecurity(
+ ServletContextHelperContext context,
+ HttpServletRequest request, HttpServletResponse response)
+ throws IOException {
+
+ return servletContextHelper.handleSecurity(
+ context, request, response);
+ }
+
+ };
+ }
+
+ private org.osgi.framework.Filter getFilteFilter() {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("(&(objectClass="); //$NON-NLS-1$
+ sb.append(Filter.class.getName());
+ sb.append(")(|("); //$NON-NLS-1$
+ sb.append(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN);
+ sb.append("=*)("); //$NON-NLS-1$
+ sb.append(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_REGEX);
+ sb.append("=*)("); //$NON-NLS-1$
+ sb.append(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_SERVLET);
+ sb.append("=*)))"); //$NON-NLS-1$
+
+ try {
+ return bundleContext.createFilter(sb.toString());
+ }
+ catch (InvalidSyntaxException ise) {
+ throw new IllegalArgumentException(ise);
+ }
+ }
+
+ private org.osgi.framework.Filter getResourceFilter() {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("(&(objectClass="); //$NON-NLS-1$
+ sb.append(Servlet.class.getName());
+ sb.append(")("); //$NON-NLS-1$
+ sb.append(HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PREFIX);
+ sb.append("=*)("); //$NON-NLS-1$
+ sb.append(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN);
+ sb.append("=*))"); //$NON-NLS-1$
+
+ try {
+ return bundleContext.createFilter(sb.toString());
+ }
+ catch (InvalidSyntaxException ise) {
+ throw new IllegalArgumentException(ise);
+ }
+ }
+
+ private org.osgi.framework.Filter getServletFilter() {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("(&(objectClass="); //$NON-NLS-1$
+ sb.append(Servlet.class.getName());
+ sb.append(")(|("); //$NON-NLS-1$
+ sb.append(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ERROR_PAGE);
+ sb.append("=*)("); //$NON-NLS-1$
+ sb.append(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN);
+ sb.append("=*))(!("); //$NON-NLS-1$
+ sb.append(HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PREFIX);
+ sb.append("=*)))"); //$NON-NLS-1$
+
+ try {
+ return bundleContext.createFilter(sb.toString());
+ }
+ catch (InvalidSyntaxException ise) {
+ throw new IllegalArgumentException(ise);
+ }
+ }
+
+ private String[] sort(String[] values) {
+ if (values == null) {
+ return null;
+ }
+
+ Arrays.sort(values);
+
+ return values;
+ }
+
+ private static final String[] DISPATCHER =
+ new String[] {Const.Dispatcher.REQUEST.toString()};
+
+ private Map<String, Object> attributes;
+ private Map<String, String> initParams;
+ private final Bundle bundle;
+ private final BundleContext bundleContext;
+ private List<String> contextNames;
+ private final String contextPath;
+ private final long contextServiceId;
+ private final Set<EndpointRegistration<?>> endpointRegistrations = new HashSet<EndpointRegistration<?>>();
+ private EventListeners eventListeners = new EventListeners();
+ private final Set<FilterRegistration> filterRegistrations = new HashSet<FilterRegistration>();
+ private ServiceTracker<Filter, FilterRegistration> filterServiceTracker;
+ private HttpServiceRuntimeImpl httpServiceRuntime;
+ private ServiceTracker<EventListener, ListenerRegistration> listenerServiceTracker;
+ private final Set<ListenerRegistration> listenerRegistrations = new HashSet<ListenerRegistration>();
+ private ProxyContext proxyContext;
+ private Set<Servlet> registeredServlets;
+ private ServiceTracker<Servlet, ServletRegistration> servletServiceTracker;
+ private ServiceTracker<Servlet, ResourceRegistration> resourceServiceTracker;
+ ServletContextHelper servletContextHelper;
+ private boolean shutdown;
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/DefaultServletContextHelper.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/DefaultServletContextHelper.java
new file mode 100644
index 00000000..be20a908
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/DefaultServletContextHelper.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2014 Cognos Incorporated, IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cognos Incorporated - initial API and implementation
+ * IBM Corporation - bug fixes and enhancements
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ *******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.context;
+
+import java.io.IOException;
+import java.net.URL;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.osgi.framework.Bundle;
+import org.osgi.service.http.HttpContext;
+import org.osgi.service.http.context.ServletContextHelper;
+import org.osgi.service.http.context.ServletContextHelperContext;
+
+public class DefaultServletContextHelper extends ServletContextHelper
+ implements HttpContext {
+
+ public DefaultServletContextHelper(Bundle bundle) {
+ super(bundle);
+
+ this.defaultContext = new ServletContextHelperContext() {
+
+ @Override
+ public ServletContextHelper getParentContext(
+ ServletContextHelper context) {
+
+ return null;
+ }
+
+ };
+ }
+
+ @Override
+ public boolean handleSecurity(
+ HttpServletRequest request, HttpServletResponse response)
+ throws IOException {
+
+ return handleSecurity(defaultContext, request, response);
+ }
+
+ @Override
+ public String getMimeType(String name) {
+ return getMimeType(defaultContext, name);
+ }
+
+ @Override
+ public URL getResource(String name) {
+ return getResource(defaultContext, name);
+ }
+
+ private final ServletContextHelperContext defaultContext;
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/DispatchTargets.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/DispatchTargets.java
new file mode 100644
index 00000000..2a2519c9
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/DispatchTargets.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.context;
+
+import java.util.Collections;
+import java.util.List;
+import org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration;
+import org.eclipse.equinox.http.servlet.internal.registration.FilterRegistration;
+
+/**
+ * @author Raymond Augé
+ */
+public class DispatchTargets {
+
+ public DispatchTargets(
+ ContextController contextController,
+ EndpointRegistration<?> endpointRegistration,
+ String servletPath, String pathInfo, String pattern) {
+
+ this(
+ contextController, endpointRegistration,
+ Collections.<FilterRegistration>emptyList(), servletPath, pathInfo,
+ pattern);
+ }
+
+ public DispatchTargets(
+ ContextController contextController,
+ EndpointRegistration<?> endpointRegistration,
+ List<FilterRegistration> matchingFilterRegistrations,
+ String servletPath, String pathInfo, String pattern) {
+
+ this.contextController = contextController;
+ this.endpointRegistration = endpointRegistration;
+ this.matchingFilterRegistrations = matchingFilterRegistrations;
+ this.servletPath = servletPath;
+ this.pathInfo = pathInfo;
+ }
+
+ public ContextController getContextController() {
+ return contextController;
+ }
+
+ public List<FilterRegistration> getMatchingFilterRegistrations() {
+ return matchingFilterRegistrations;
+ }
+
+ public String getPathInfo() {
+ return pathInfo;
+ }
+
+ public String getServletPath() {
+ return servletPath;
+ }
+
+ public EndpointRegistration<?> getServletRegistration() {
+ return endpointRegistration;
+ }
+
+ private final ContextController contextController;
+ private final EndpointRegistration<?> endpointRegistration;
+ private final List<FilterRegistration> matchingFilterRegistrations;
+ private final String pathInfo;
+ private final String servletPath;
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ProxyContext.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ProxyContext.java
index 9e2896e4..b89b7674 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ProxyContext.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ProxyContext.java
@@ -1,21 +1,24 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 Cognos Incorporated, IBM Corporation and others.
+ * Copyright (c) 2005, 2014 Cognos Incorporated, IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Cognos Incorporated - initial API and implementation
* IBM Corporation - bug fixes and enhancements
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
*******************************************************************************/
-package org.eclipse.equinox.http.servlet.internal;
+package org.eclipse.equinox.http.servlet.internal.context;
import java.io.File;
import java.util.*;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
-import org.osgi.service.http.HttpContext;
+import org.eclipse.equinox.http.servlet.internal.servlet.HttpServletRequestBuilder;
+import org.eclipse.equinox.http.servlet.internal.util.Const;
+import org.osgi.service.http.context.ServletContextHelper;
/**
* The ProxyContext provides something similar to a ServletContext for all servlets and resources under a particular ProxyServlet.
@@ -29,10 +32,13 @@ public class ProxyContext {
private static final String JAVAX_SERVLET_CONTEXT_TEMPDIR = "javax.servlet.context.tempdir"; //$NON-NLS-1$
private String servletPath;
- private HashMap attributesMap = new HashMap();
+ private HashMap<ServletContextHelper, ContextAttributes> attributesMap =
+ new HashMap<ServletContextHelper, ContextAttributes>();
File proxyContextTempDir;
+ private ServletContext servletContext;
public ProxyContext(ServletContext servletContext) {
+ this.servletContext = servletContext;
File tempDir = (File) servletContext.getAttribute(JAVAX_SERVLET_CONTEXT_TEMPDIR);
if (tempDir != null) {
proxyContextTempDir = new File(tempDir, "proxytemp"); //$NON-NLS-1$
@@ -48,33 +54,46 @@ public class ProxyContext {
synchronized void initializeServletPath(HttpServletRequest req) {
if (servletPath == null)
- servletPath = HttpServletRequestAdaptor.getDispatchServletPath(req);
+ servletPath = HttpServletRequestBuilder.getDispatchServletPath(req);
}
- synchronized String getServletPath() {
- return (servletPath == null ? "" : servletPath); //$NON-NLS-1$
+ public synchronized String getServletPath() {
+ return (servletPath == null ? Const.BLANK : servletPath);
}
- synchronized void createContextAttributes(HttpContext httpContext) {
- ContextAttributes attributes = (ContextAttributes) attributesMap.get(httpContext);
+ public synchronized void createContextAttributes(
+ ServletContextHelper servletContextHelper) {
+
+ ContextAttributes attributes = attributesMap.get(servletContextHelper);
if (attributes == null) {
- attributes = new ContextAttributes(httpContext);
- attributesMap.put(httpContext, attributes);
+ attributes = new ContextAttributes(servletContextHelper);
+ attributesMap.put(servletContextHelper, attributes);
}
attributes.addReference();
}
- synchronized void destroyContextAttributes(HttpContext httpContext) {
- ContextAttributes attributes = (ContextAttributes) attributesMap.get(httpContext);
+ public synchronized void destroyContextAttributes(
+ ServletContextHelper servletContextHelper) {
+
+ ContextAttributes attributes = attributesMap.get(servletContextHelper);
+ if (attributes == null) {
+ throw new IllegalStateException("too many calls");
+ }
attributes.removeReference();
if (attributes.referenceCount() == 0) {
- attributesMap.remove(httpContext);
+ attributesMap.remove(servletContextHelper);
attributes.destroy();
}
}
- synchronized Dictionary getContextAttributes(HttpContext httpContext) {
- return (Dictionary) attributesMap.get(httpContext);
+ public synchronized Dictionary<String, Object> getContextAttributes(
+ ServletContextHelper servletContextHelper) {
+
+ return attributesMap.get(servletContextHelper);
+ }
+
+ public ServletContext getServletContext() {
+ return servletContext;
}
/**
@@ -96,14 +115,18 @@ public class ProxyContext {
return directory.delete();
}
- public class ContextAttributes extends Hashtable {
+ public class ContextAttributes extends Hashtable<String, Object> {
private static final long serialVersionUID = 1916670423277243587L;
private int referenceCount;
- public ContextAttributes(HttpContext httpContext) {
+ public ContextAttributes(ServletContextHelper servletContextHelper) {
if (proxyContextTempDir != null) {
- File contextTempDir = new File(proxyContextTempDir, "hc_" + httpContext.hashCode()); //$NON-NLS-1$
+ File contextTempDir = new File(
+ proxyContextTempDir,
+ "hc_" + servletContextHelper.hashCode()); //$NON-NLS-1$
+
contextTempDir.mkdirs();
+
put(JAVAX_SERVLET_CONTEXT_TEMPDIR, contextTempDir);
}
}
@@ -126,4 +149,5 @@ public class ProxyContext {
return referenceCount;
}
}
+
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ServletContextHelperWrapper.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ServletContextHelperWrapper.java
new file mode 100644
index 00000000..5ed239b2
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/context/ServletContextHelperWrapper.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.context;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.osgi.framework.Bundle;
+import org.osgi.service.http.HttpContext;
+import org.osgi.service.http.context.ServletContextHelper;
+import org.osgi.service.http.context.ServletContextHelperContext;
+
+/**
+ * @author Raymond Augé
+ */
+public class ServletContextHelperWrapper
+ extends ServletContextHelper implements HttpContext {
+
+ public ServletContextHelperWrapper(
+ HttpContext httpContext, Bundle bundle) {
+
+ super(bundle);
+
+ _httpContext = httpContext;
+ _bundle = bundle;
+ }
+
+ @Override
+ public String getMimeType(String name) {
+ return _httpContext.getMimeType(name);
+ }
+
+ @Override
+ public String getMimeType(ServletContextHelperContext context, String name) {
+ return _httpContext.getMimeType(name);
+ }
+
+ @Override
+ public String getRealPath(ServletContextHelperContext context, String path) {
+ return null;
+ }
+
+ @Override
+ public URL getResource(String name) {
+ return _httpContext.getResource(name);
+ }
+
+ @Override
+ public URL getResource(ServletContextHelperContext context, String name) {
+ return _httpContext.getResource(name);
+ }
+
+ @Override
+ public Set<String> getResourcePaths(
+ ServletContextHelperContext context ,String path) {
+
+ if ((path == null) || (_bundle == null)) {
+ return null;
+ }
+
+ final Enumeration<URL> enumeration = _bundle.findEntries(
+ path, null, false);
+
+ if (enumeration == null) {
+ return null;
+ }
+
+ final Set<String> result = new HashSet<String>();
+
+ while (enumeration.hasMoreElements()) {
+ result.add(enumeration.nextElement().getPath());
+ }
+
+ return result;
+ }
+
+ @Override
+ public boolean handleSecurity(
+ HttpServletRequest request, HttpServletResponse response)
+ throws IOException {
+
+ return _httpContext.handleSecurity(request, response);
+ }
+
+ @Override
+ public boolean handleSecurity(
+ ServletContextHelperContext context, HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException {
+
+ return _httpContext.handleSecurity(request, response);
+ }
+
+ private final Bundle _bundle;
+ private final HttpContext _httpContext;
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextFilterTrackerCustomizer.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextFilterTrackerCustomizer.java
new file mode 100644
index 00000000..2b44ab9d
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextFilterTrackerCustomizer.java
@@ -0,0 +1,125 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.customizer;
+
+import java.util.List;
+import java.util.Map;
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+import org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl;
+import org.eclipse.equinox.http.servlet.internal.context.ContextController;
+import org.eclipse.equinox.http.servlet.internal.registration.FilterRegistration;
+import org.eclipse.equinox.http.servlet.internal.util.StringPlus;
+import org.osgi.framework.*;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+
+/**
+ * @author Raymond Augé
+ */
+public class ContextFilterTrackerCustomizer
+ extends RegistrationServiceTrackerCustomizer<Filter, FilterRegistration> {
+
+ public ContextFilterTrackerCustomizer(
+ BundleContext bundleContext, HttpServiceRuntimeImpl httpServiceRuntime,
+ ContextController contextController) {
+
+ super(bundleContext, httpServiceRuntime);
+
+ this.contextController = contextController;
+ }
+
+ @Override
+ public FilterRegistration addingService(
+ ServiceReference<Filter> serviceReference) {
+
+ if (!httpServiceRuntime.matches(serviceReference)) {
+ // TODO no match runtime
+
+ return null;
+ }
+
+ String contextSelector = (String)serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT);
+
+ if (!contextController.matches(contextSelector)) {
+ return null;
+ }
+
+ boolean asyncSupported = parseBoolean(
+ serviceReference,
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_ASYNC_SUPPORTED);
+ List<String> dispatcherList = StringPlus.from(
+ serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_DISPATCHER));
+ String[] dispatchers = dispatcherList.toArray(
+ new String[dispatcherList.size()]);
+ Long serviceId = (Long)serviceReference.getProperty(
+ Constants.SERVICE_ID);
+ Integer filterPriority = (Integer)serviceReference.getProperty(
+ Constants.SERVICE_RANKING);
+ if (filterPriority == null) {
+ filterPriority = Integer.valueOf(0);
+ }
+ Map<String, String> initParams = parseInitParams(
+ serviceReference, "filter.init."); //$NON-NLS-1$
+ List<String> patternList = StringPlus.from(
+ serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN));
+ String[] patterns = patternList.toArray(new String[patternList.size()]);
+ List<String> servletList = StringPlus.from(
+ serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_SERVLET));
+ String[] servlets = servletList.toArray(new String[servletList.size()]);
+ List<String> regexList = StringPlus.from(
+ serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_REGEX));
+
+ // TODO add this
+ String[] regex = regexList.toArray(new String[regexList.size()]);
+
+ Filter filter = bundleContext.getService(serviceReference);
+ String name = parseName(serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_NAME), filter);
+
+ try {
+ return contextController.addFilterRegistration(
+ filter, asyncSupported, dispatchers, filterPriority.intValue(),
+ initParams, name, patterns, serviceId.longValue(), servlets);
+ }
+ catch (ServletException se) {
+ httpServiceRuntime.log(se.getMessage(), se);
+ }
+
+ // TODO error?
+
+ return null;
+ }
+
+ @Override
+ public void modifiedService(
+ ServiceReference<Filter> serviceReference,
+ FilterRegistration filterRegistration) {
+ }
+
+ @Override
+ public void removedService(
+ ServiceReference<Filter> serviceReference,
+ FilterRegistration filterRegistration) {
+
+ bundleContext.ungetService(serviceReference);
+
+ filterRegistration.destroy();
+ }
+
+ private ContextController contextController;
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextListenerTrackerCustomizer.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextListenerTrackerCustomizer.java
new file mode 100644
index 00000000..b0a16b30
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextListenerTrackerCustomizer.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.customizer;
+
+import java.util.EventListener;
+import javax.servlet.ServletException;
+import org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl;
+import org.eclipse.equinox.http.servlet.internal.context.ContextController;
+import org.eclipse.equinox.http.servlet.internal.registration.ListenerRegistration;
+import org.osgi.framework.*;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+
+/**
+ * @author Raymond Augé
+ */
+public class ContextListenerTrackerCustomizer
+ extends RegistrationServiceTrackerCustomizer<EventListener, ListenerRegistration> {
+
+ public ContextListenerTrackerCustomizer(
+ BundleContext bundleContext, HttpServiceRuntimeImpl httpServiceRuntime,
+ ContextController contextController) {
+
+ super(bundleContext, httpServiceRuntime);
+
+ this.contextController = contextController;
+ }
+
+ @Override
+ public ListenerRegistration addingService(
+ ServiceReference<EventListener> serviceReference) {
+
+ if (!httpServiceRuntime.matches(serviceReference)) {
+ // TODO no match runtime
+
+ return null;
+ }
+
+ String contextSelector = (String)serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT);
+
+ if (!contextController.matches(contextSelector)) {
+ return null;
+ }
+
+ Long serviceId = (Long)serviceReference.getProperty(
+ Constants.SERVICE_ID);
+ EventListener eventListener = bundleContext.getService(
+ serviceReference);
+
+ try {
+ return contextController.addListenerRegistration(
+ eventListener, serviceId.longValue());
+ }
+ catch (ServletException se) {
+ httpServiceRuntime.log(se.getMessage(), se);
+ }
+
+ return null;
+ }
+
+ @Override
+ public void
+ modifiedService(
+ ServiceReference<EventListener> serviceReference,
+ ListenerRegistration listenerRegistration) {
+ }
+
+ @Override
+ public void
+ removedService(
+ ServiceReference<EventListener> serviceReference,
+ ListenerRegistration listenerRegistration) {
+
+ bundleContext.ungetService(serviceReference);
+
+ listenerRegistration.destroy();
+ }
+
+ private ContextController contextController;
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextResourceTrackerCustomizer.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextResourceTrackerCustomizer.java
new file mode 100644
index 00000000..93098771
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextResourceTrackerCustomizer.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.customizer;
+
+import java.util.List;
+import javax.servlet.Servlet;
+import org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl;
+import org.eclipse.equinox.http.servlet.internal.context.ContextController;
+import org.eclipse.equinox.http.servlet.internal.registration.ResourceRegistration;
+import org.eclipse.equinox.http.servlet.internal.util.StringPlus;
+import org.osgi.framework.*;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+
+/**
+ * @author Raymond Augé
+ */
+public class ContextResourceTrackerCustomizer
+ extends RegistrationServiceTrackerCustomizer<Servlet, ResourceRegistration> {
+
+ public ContextResourceTrackerCustomizer(
+ BundleContext bundleContext, HttpServiceRuntimeImpl httpServiceRuntime,
+ ContextController contextController) {
+
+ super(bundleContext, httpServiceRuntime);
+
+ this.contextController = contextController;
+ }
+
+ @Override
+ public ResourceRegistration addingService(
+ ServiceReference<Servlet> serviceReference) {
+
+ if (!httpServiceRuntime.matches(serviceReference)) {
+ // TODO no match runtime
+
+ return null;
+ }
+
+ String contextSelector = (String)serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT);
+
+ if (!contextController.matches(contextSelector)) {
+ // TODO no match context
+
+ return null;
+ }
+
+ List<String> patternList = StringPlus.from(
+ serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN));
+ String[] patterns = patternList.toArray(new String[patternList.size()]);
+ Long serviceId = (Long)serviceReference.getProperty(
+ Constants.SERVICE_ID);
+ String prefix = (String)serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PREFIX);
+
+ return contextController.addResourceRegistration(
+ patterns, prefix, serviceId.longValue());
+ }
+
+ @Override
+ public void modifiedService(
+ ServiceReference<Servlet> serviceReference,
+ ResourceRegistration resourceRegistration) {
+ }
+
+ @Override
+ public void removedService(
+ ServiceReference<Servlet> serviceReference,
+ ResourceRegistration resourceRegistration) {
+
+ bundleContext.ungetService(serviceReference);
+
+ resourceRegistration.destroy();
+ }
+
+ private ContextController contextController;
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextServletTrackerCustomizer.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextServletTrackerCustomizer.java
new file mode 100644
index 00000000..222ec3ad
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextServletTrackerCustomizer.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.customizer;
+
+import java.util.List;
+import java.util.Map;
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl;
+import org.eclipse.equinox.http.servlet.internal.context.ContextController;
+import org.eclipse.equinox.http.servlet.internal.registration.ServletRegistration;
+import org.eclipse.equinox.http.servlet.internal.util.StringPlus;
+import org.osgi.framework.*;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+
+/**
+ * @author Raymond Augé
+ */
+public class ContextServletTrackerCustomizer
+ extends RegistrationServiceTrackerCustomizer<Servlet, ServletRegistration> {
+
+ public ContextServletTrackerCustomizer(
+ BundleContext bundleContext, HttpServiceRuntimeImpl httpServiceRuntime,
+ ContextController contextController) {
+
+ super(bundleContext, httpServiceRuntime);
+
+ this.contextController = contextController;
+ }
+
+ @Override
+ public ServletRegistration addingService(
+ ServiceReference<Servlet> serviceReference) {
+
+ if (!httpServiceRuntime.matches(serviceReference)) {
+ // TODO no match runtime
+
+ return null;
+ }
+
+ String contextSelector = (String)serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT);
+
+ if (!contextController.matches(contextSelector)) {
+ // TODO no match context
+
+ return null;
+ }
+
+ Servlet servlet = bundleContext.getService(serviceReference);
+
+ if (httpServiceRuntime.getRegisteredServlets().contains(servlet)) {
+ return null;
+ }
+
+ boolean asyncSupported = parseBoolean(
+ serviceReference,
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED);
+ List<String> errorPageList = StringPlus.from(
+ serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ERROR_PAGE));
+ String[] errorPages = errorPageList.toArray(
+ new String[errorPageList.size()]);
+ Map<String, String> initParams = parseInitParams(
+ serviceReference, "servlet.init.");
+ List<String> patternList = StringPlus.from(
+ serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN));
+ String[] patterns = patternList.toArray(new String[patternList.size()]);
+ Long serviceId = (Long)serviceReference.getProperty(
+ Constants.SERVICE_ID);
+
+ String servletName = parseName(
+ serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME), servlet);
+
+ try {
+ return contextController.addServletRegistration(
+ servlet, asyncSupported, errorPages, initParams, patterns,
+ serviceId.longValue(), servletName);
+ }
+ catch (ServletException se) {
+ httpServiceRuntime.log(se.getMessage(), se);
+ }
+
+ // TODO error?
+
+ return null;
+ }
+
+ @Override
+ public void modifiedService(
+ ServiceReference<Servlet> serviceReference,
+ ServletRegistration servletRegistration) {
+ }
+
+ @Override
+ public void removedService(
+ ServiceReference<Servlet> serviceReference,
+ ServletRegistration servletRegistration) {
+
+ bundleContext.ungetService(serviceReference);
+
+ servletRegistration.destroy();
+ }
+
+ private ContextController contextController;
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/FilterTrackerCustomizer.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/FilterTrackerCustomizer.java
new file mode 100644
index 00000000..587ea512
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/FilterTrackerCustomizer.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.customizer;
+
+import javax.servlet.Filter;
+import org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl;
+import org.eclipse.equinox.http.servlet.internal.context.ContextController;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+
+/**
+ * @author Raymond Augé
+ */
+public class FilterTrackerCustomizer
+ extends RegistrationServiceTrackerCustomizer<Filter, Filter> {
+
+ public FilterTrackerCustomizer(
+ BundleContext bundleContext, HttpServiceRuntimeImpl httpServiceRuntime) {
+
+ super(bundleContext, httpServiceRuntime);
+ }
+
+ @Override
+ public Filter addingService(ServiceReference<Filter> serviceReference) {
+ if (!httpServiceRuntime.matches(serviceReference)) {
+ // TODO no match runtime
+
+ return null;
+ }
+
+ String contextSelector = (String)serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT);
+
+ ContextController contextController =
+ httpServiceRuntime.getOrAddContextController(
+ contextSelector,
+ serviceReference.getBundle().getBundleContext());
+
+ if (contextController == null) {
+ // TODO no match context
+
+ return null;
+ }
+
+ return bundleContext.getService(serviceReference);
+ }
+
+ @Override
+ public void modifiedService(
+ ServiceReference<Filter> serviceReference, Filter filter) {
+ }
+
+ @Override
+ public void removedService(
+ ServiceReference<Filter> serviceReference, Filter filter) {
+
+ bundleContext.ungetService(serviceReference);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ListenerTrackerCustomizer.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ListenerTrackerCustomizer.java
new file mode 100644
index 00000000..ea7a86dd
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ListenerTrackerCustomizer.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.customizer;
+
+import java.util.EventListener;
+import org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl;
+import org.eclipse.equinox.http.servlet.internal.context.ContextController;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+
+/**
+ * @author Raymond Augé
+ */
+public class ListenerTrackerCustomizer
+ extends RegistrationServiceTrackerCustomizer<EventListener, EventListener> {
+
+ public ListenerTrackerCustomizer(
+ BundleContext bundleContext, HttpServiceRuntimeImpl httpServiceRuntime) {
+
+ super(bundleContext, httpServiceRuntime);
+ }
+
+ @Override
+ public EventListener addingService(
+ ServiceReference<EventListener> serviceReference) {
+
+ if (!httpServiceRuntime.matches(serviceReference)) {
+ // TODO no match runtime
+
+ return null;
+ }
+
+ String contextSelector = (String)serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT);
+
+ ContextController contextController =
+ httpServiceRuntime.getOrAddContextController(
+ contextSelector,
+ serviceReference.getBundle().getBundleContext());
+
+ if (contextController == null) {
+ // TODO no match context
+
+ return null;
+ }
+
+ return bundleContext.getService(serviceReference);
+ }
+
+ @Override
+ public void
+ modifiedService(
+ ServiceReference<EventListener> serviceReference,
+ EventListener eventListener) {
+ }
+
+ @Override
+ public void
+ removedService(
+ ServiceReference<EventListener> serviceReference,
+ EventListener eventListener) {
+
+ bundleContext.ungetService(serviceReference);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/RegistrationServiceTrackerCustomizer.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/RegistrationServiceTrackerCustomizer.java
new file mode 100644
index 00000000..300e779b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/RegistrationServiceTrackerCustomizer.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.customizer;
+
+import org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+/**
+ * @author Raymond Augé
+ */
+public abstract class RegistrationServiceTrackerCustomizer<S, T>
+ implements ServiceTrackerCustomizer<S, T> {
+
+ public RegistrationServiceTrackerCustomizer(
+ BundleContext bundleContext, HttpServiceRuntimeImpl httpServiceRuntime) {
+
+ this.bundleContext = bundleContext;
+ this.httpServiceRuntime = httpServiceRuntime;
+ }
+
+ protected boolean parseBoolean(
+ ServiceReference<?> serviceReference, String property) {
+
+ Object value = serviceReference.getProperty(property);
+
+ if (Boolean.class.isInstance(value)) {
+ return ((Boolean)value).booleanValue();
+ }
+ if (String.class.isInstance(value)) {
+ return Boolean.valueOf((String)value);
+ }
+
+ return false;
+ }
+
+ protected Map<String, String> parseInitParams(
+ ServiceReference<?> serviceReference, String prefix) {
+
+ Map<String, String> initParams = new HashMap<String, String>();
+
+ for (String key : serviceReference.getPropertyKeys()) {
+ if (key.startsWith(prefix)) {
+ initParams.put(
+ key.substring(prefix.length()),
+ String.valueOf(serviceReference.getProperty(key)));
+ }
+ }
+
+ return initParams;
+ }
+
+ protected String parseName(Object property, Object object) {
+ if (property == null) {
+ return object.getClass().getName();
+ }
+
+ return String.valueOf(property);
+ }
+
+ protected BundleContext bundleContext;
+ protected HttpServiceRuntimeImpl httpServiceRuntime;
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ResourceTrackerCustomizer.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ResourceTrackerCustomizer.java
new file mode 100644
index 00000000..0721043b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ResourceTrackerCustomizer.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.customizer;
+
+import javax.servlet.Servlet;
+import org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl;
+import org.eclipse.equinox.http.servlet.internal.context.ContextController;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+
+/**
+ * @author Raymond Augé
+ */
+public class ResourceTrackerCustomizer
+ extends RegistrationServiceTrackerCustomizer<Servlet, Servlet> {
+
+ public ResourceTrackerCustomizer(
+ BundleContext bundleContext, HttpServiceRuntimeImpl httpServiceRuntime) {
+
+ super(bundleContext, httpServiceRuntime);
+ }
+
+ @Override
+ public Servlet addingService(ServiceReference<Servlet> serviceReference) {
+ if (!httpServiceRuntime.matches(serviceReference)) {
+ // TODO no match runtime
+
+ return null;
+ }
+
+ String contextSelector = (String)serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT);
+
+ ContextController contextController =
+ httpServiceRuntime.getOrAddContextController(
+ contextSelector,
+ serviceReference.getBundle().getBundleContext());
+
+ if (contextController == null) {
+ // TODO no match context
+
+ return null;
+ }
+
+ return bundleContext.getService(serviceReference);
+ }
+
+ @Override
+ public void modifiedService(
+ ServiceReference<Servlet> serviceReference, Servlet servlet) {
+ }
+
+ @Override
+ public void removedService(
+ ServiceReference<Servlet> serviceReference, Servlet servlet) {
+
+ bundleContext.ungetService(serviceReference);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ServletTrackerCustomizer.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ServletTrackerCustomizer.java
new file mode 100644
index 00000000..396d62f0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ServletTrackerCustomizer.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.customizer;
+
+import javax.servlet.Servlet;
+import org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl;
+import org.eclipse.equinox.http.servlet.internal.context.ContextController;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+
+/**
+ * @author Raymond Augé
+ */
+public class ServletTrackerCustomizer
+ extends RegistrationServiceTrackerCustomizer<Servlet, Servlet> {
+
+ public ServletTrackerCustomizer(
+ BundleContext bundleContext, HttpServiceRuntimeImpl httpServiceRuntime) {
+
+ super(bundleContext, httpServiceRuntime);
+ }
+
+ @Override
+ public Servlet addingService(
+ ServiceReference<Servlet> serviceReference) {
+
+ if (!httpServiceRuntime.matches(serviceReference)) {
+ // TODO no match runtime
+
+ return null;
+ }
+
+ String contextSelector = (String)serviceReference.getProperty(
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT);
+
+ ContextController contextController =
+ httpServiceRuntime.getOrAddContextController(
+ contextSelector,
+ serviceReference.getBundle().getBundleContext());
+
+ if (contextController == null) {
+ // TODO no match context
+
+ return null;
+ }
+
+ return bundleContext.getService(serviceReference);
+ }
+
+ @Override
+ public void modifiedService(
+ ServiceReference<Servlet> serviceReference, Servlet servlet) {
+ }
+
+ @Override
+ public void removedService(
+ ServiceReference<Servlet> serviceReference, Servlet servlet) {
+
+ bundleContext.ungetService(serviceReference);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/NullContextNamesException.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/NullContextNamesException.java
new file mode 100644
index 00000000..7db4b26d
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/NullContextNamesException.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.error;
+
+/**
+ * @author Raymond Augé
+ */
+public class NullContextNamesException extends IllegalArgumentException {
+
+ private static final long serialVersionUID = -2200377116055258609L;
+
+ public NullContextNamesException() {
+ super("ContextNames must contain a value.");
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/NullServletContextHelperException.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/NullServletContextHelperException.java
new file mode 100644
index 00000000..987d7285
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/NullServletContextHelperException.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.error;
+
+/**
+ * @author Raymond Augé
+ */
+public class NullServletContextHelperException extends IllegalArgumentException {
+
+ private static final long serialVersionUID = 8516340810740210836L;
+
+ public NullServletContextHelperException() {
+ super("ServletContexHelper cannot be null.");
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/PatternInUseException.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/PatternInUseException.java
new file mode 100644
index 00000000..a770a6a3
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/PatternInUseException.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.error;
+
+import org.osgi.service.http.NamespaceException;
+
+/**
+ * @author Raymond Augé
+ */
+public class PatternInUseException extends NamespaceException {
+
+ private static final long serialVersionUID = -4196149175131735927L;
+
+ public PatternInUseException(String pattern) {
+ super("Pattern already in use: " + pattern);
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/RegisteredFilterException.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/RegisteredFilterException.java
new file mode 100644
index 00000000..419e5a30
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/RegisteredFilterException.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.error;
+
+import javax.servlet.Filter;
+import javax.servlet.ServletException;
+
+/**
+ * @author Raymond Augé
+ */
+public class RegisteredFilterException extends ServletException {
+
+ private static final long serialVersionUID = 4321327145573490998L;
+
+ public RegisteredFilterException(Filter filter) {
+ super("Filter has already been registered: " + filter);
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/RegisteredServletContextHelperException.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/RegisteredServletContextHelperException.java
new file mode 100644
index 00000000..dafa00ba
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/RegisteredServletContextHelperException.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.error;
+
+import javax.servlet.ServletException;
+
+/**
+ * @author Raymond Augé
+ */
+public class RegisteredServletContextHelperException
+ extends ServletException {
+
+ private static final long serialVersionUID = 7301237379456486249L;
+
+ public RegisteredServletContextHelperException() {
+ super("ServletContextHelper has already been registered.");
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/ServletAlreadyRegisteredException.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/ServletAlreadyRegisteredException.java
new file mode 100644
index 00000000..91d657d2
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/ServletAlreadyRegisteredException.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.error;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+/**
+ * @author Raymond Augé
+ */
+public class ServletAlreadyRegisteredException extends ServletException {
+
+ private static final long serialVersionUID = 8838939310124336724L;
+
+ public ServletAlreadyRegisteredException(Servlet servlet) {
+ super("Servlet has already been registered: " + servlet);
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/EndpointRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/EndpointRegistration.java
new file mode 100644
index 00000000..10e46726
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/EndpointRegistration.java
@@ -0,0 +1,160 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.registration;
+
+import java.io.IOException;
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.eclipse.equinox.http.servlet.internal.context.ContextController;
+import org.eclipse.equinox.http.servlet.internal.servlet.Match;
+import org.osgi.dto.DTO;
+import org.osgi.service.http.context.ServletContextHelper;
+
+/**
+ * @author Raymond Augé
+ */
+public abstract class EndpointRegistration<D extends DTO>
+ extends MatchableRegistration<Servlet, D> {
+
+ private ServletContextHelper servletContextHelper; //The context used during the registration of the servlet
+ private ContextController contextController;
+ private ClassLoader classLoader;
+
+ public EndpointRegistration(
+ Servlet servlet, D d, ServletContextHelper servletContextHelper,
+ ContextController contextController) {
+
+ super(servlet, d);
+
+ this.servletContextHelper = servletContextHelper;
+ this.contextController = contextController;
+ classLoader = contextController.getClassLoader();
+ }
+
+ public void destroy() {
+ ClassLoader original = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(classLoader);
+
+ contextController.getEndpointRegistrations().remove(this);
+ contextController.getRegisteredServlets().remove(this);
+
+ super.destroy();
+ getT().destroy();
+ }
+ finally {
+ destroyContextAttributes();
+ Thread.currentThread().setContextClassLoader(original);
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof EndpointRegistration)) {
+ return false;
+ }
+
+ EndpointRegistration<?> endpointRegistration = (EndpointRegistration<?>)obj;
+
+ return getT().equals(endpointRegistration.getT());
+ }
+
+ @Override
+ public int hashCode() {
+ return Long.valueOf(getServiceId()).hashCode();
+ }
+
+ //Delegate the init call to the actual servlet
+ public void init(ServletConfig servletConfig) throws ServletException {
+ boolean initialized = false;
+ ClassLoader original = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(classLoader);
+
+ createContextAttributes();
+ getT().init(servletConfig);
+ initialized = true;
+ }
+ finally {
+ if (!initialized) {
+ destroyContextAttributes();
+ }
+ Thread.currentThread().setContextClassLoader(original);
+ }
+ }
+
+ public abstract String getName();
+
+ public abstract String[] getPatterns();
+
+ public abstract long getServiceId();
+
+ public ServletContext getServletContext() {
+ return getT().getServletConfig().getServletContext();
+ }
+
+ public ServletContextHelper getServletContextHelper() {
+ return servletContextHelper;
+ }
+
+ @Override
+ public String match(
+ String name, String servletPath, String pathInfo, String extension,
+ Match match) {
+
+ if (name != null) {
+ if (getName().equals(name)) {
+ return name;
+ }
+
+ return null;
+ }
+
+ String[] patterns = getPatterns();
+
+ if (patterns == null) {
+ return null;
+ }
+
+ for (String pattern : patterns) {
+ if (doMatch(pattern, servletPath, pathInfo, extension, match)) {
+ return pattern;
+ }
+ }
+
+ return null;
+ }
+
+ //Delegate the handling of the request to the actual servlet
+ public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
+ ClassLoader original = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ if (servletContextHelper.handleSecurity(contextController, req, resp))
+ getT().service(req, resp);
+ } finally {
+ Thread.currentThread().setContextClassLoader(original);
+ }
+ }
+
+ private void createContextAttributes() {
+ contextController.getProxyContext().createContextAttributes(
+ servletContextHelper);
+ }
+
+ private void destroyContextAttributes() {
+ contextController.getProxyContext().destroyContextAttributes(
+ servletContextHelper);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/FilterRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/FilterRegistration.java
new file mode 100644
index 00000000..7c0c3ea8
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/FilterRegistration.java
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ *******************************************************************************/
+package org.eclipse.equinox.http.servlet.internal.registration;
+
+import java.io.IOException;
+import java.util.Arrays;
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.eclipse.equinox.http.servlet.internal.context.ContextController;
+import org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl;
+import org.eclipse.equinox.http.servlet.internal.servlet.Match;
+import org.osgi.service.http.context.ServletContextHelper;
+import org.osgi.service.http.runtime.dto.FilterDTO;
+
+//This class wraps the filter object registered in the HttpService.registerFilter call, to manage the context classloader when handleRequests are being asked.
+public class FilterRegistration
+ extends MatchableRegistration<Filter, FilterDTO>
+ implements Comparable<FilterRegistration> {
+
+ private final ServletContextHelper servletContextHelper; //The context used during the registration of the filter
+ private final ClassLoader classLoader;
+ private final int priority;
+ private final ContextController contextController;
+
+ public FilterRegistration(
+ Filter filter, FilterDTO filterDTO, int priority,
+ ServletContextHelper servletContextHelper,
+ ContextController contextController) {
+
+ super(filter, filterDTO);
+
+ this.priority = priority;
+ this.servletContextHelper = servletContextHelper;
+ this.contextController = contextController;
+ classLoader = contextController.getClassLoader();
+ }
+
+ public int compareTo(FilterRegistration otherFilterRegistration) {
+ int priorityDifference = priority - otherFilterRegistration.priority;
+ if (priorityDifference != 0)
+ return -priorityDifference;
+
+ return (Math.abs(getD().serviceId) >
+ Math.abs(otherFilterRegistration.getD().serviceId)) ? 1 : -1;
+ }
+
+ public void destroy() {
+ ClassLoader original = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(classLoader);
+
+ contextController.getFilterRegistrations().remove(this);
+ super.destroy();
+ getT().destroy();
+ }
+ finally {
+ destroyContextAttributes();
+ Thread.currentThread().setContextClassLoader(original);
+ }
+ }
+
+ public boolean appliesTo(FilterChainImpl filterChainImpl) {
+ return (Arrays.binarySearch(
+ getD().dispatcher, filterChainImpl.getDispatcherType().name()) >= 0);
+ }
+
+ //Delegate the handling of the request to the actual filter
+ public void doFilter(
+ HttpServletRequest request, HttpServletResponse response,
+ FilterChain chain)
+ throws IOException, ServletException {
+
+ ClassLoader original = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(classLoader);
+
+ if (servletContextHelper.handleSecurity(contextController, request, response)) {
+ getT().doFilter(request, response, chain);
+ }
+ }
+ finally {
+ Thread.currentThread().setContextClassLoader(original);
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof FilterRegistration)) {
+ return false;
+ }
+
+ FilterRegistration filterRegistration = (FilterRegistration)obj;
+
+ return getT().equals(filterRegistration.getT());
+ }
+
+ @Override
+ public int hashCode() {
+ return Long.valueOf(getD().serviceId).hashCode();
+ }
+
+ public ServletContextHelper getServletContextHelper() {
+ return servletContextHelper;
+ }
+
+ //Delegate the init call to the actual filter
+ public void init(FilterConfig filterConfig) throws ServletException {
+ boolean initialized = false;
+ ClassLoader original = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(classLoader);
+
+ createContextAttributes();
+ getT().init(filterConfig);
+ initialized = true;
+ }
+ finally {
+ if (!initialized) {
+ destroyContextAttributes();
+ }
+ Thread.currentThread().setContextClassLoader(original);
+ }
+ }
+
+ @Override
+ public String match(
+ String name, String servletPath, String pathInfo, String extension,
+ Match match) {
+
+ if (name != null) {
+ if (getD().servletNames == null) {
+ return null;
+ }
+
+ for (String servletName : getD().servletNames) {
+ if (servletName.equals(name)) {
+ return name;
+ }
+ }
+
+ return null;
+ }
+
+ for (String pattern : getD().patterns) {
+ if (doMatch(pattern, servletPath, pathInfo, extension, match)) {
+ return pattern;
+ }
+ }
+
+ return null;
+ }
+
+ private void createContextAttributes() {
+ contextController.getProxyContext().createContextAttributes(
+ servletContextHelper);
+ }
+
+ private void destroyContextAttributes() {
+ contextController.getProxyContext().destroyContextAttributes(
+ servletContextHelper);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ListenerRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ListenerRegistration.java
new file mode 100644
index 00000000..e60bff8c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ListenerRegistration.java
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.registration;
+
+import java.lang.reflect.*;
+import java.util.EventListener;
+import java.util.List;
+import javax.servlet.*;
+import org.eclipse.equinox.http.servlet.internal.context.ContextController;
+import org.osgi.service.http.context.ServletContextHelper;
+import org.osgi.service.http.runtime.dto.ListenerDTO;
+
+/**
+ * @author Raymond Augé
+ */
+public class ListenerRegistration extends Registration<EventListener, ListenerDTO> {
+
+ private final List<Class<? extends EventListener>> classes;
+ private final EventListener proxy;
+ private final ServletContext servletContext;
+ private final ServletContextHelper servletContextHelper; //The context used during the registration of the servlet
+ private final ContextController contextController;
+ private ClassLoader classLoader;
+
+ public ListenerRegistration(
+ EventListener eventListener, List<Class<? extends EventListener>> classes,
+ ListenerDTO listenerDTO, ServletContext servletContext,
+ ServletContextHelper servletContextHelper,
+ ContextController contextController) {
+
+ super(eventListener, listenerDTO);
+
+ this.classes = classes;
+ this.servletContext = servletContext;
+ this.servletContextHelper = servletContextHelper;
+ this.contextController = contextController;
+
+ classLoader = contextController.getClassLoader();
+
+ createContextAttributes();
+
+ proxy = (EventListener)Proxy.newProxyInstance(
+ classLoader, classes.toArray(new Class[0]),
+ new EventListenerInvocationHandler());
+ }
+
+ @Override
+ public synchronized void destroy() {
+ ClassLoader original = Thread.currentThread().getContextClassLoader();
+
+ try {
+ Thread.currentThread().setContextClassLoader(classLoader);
+
+ contextController.getListenerRegistrations().remove(this);
+ contextController.getEventListeners().remove(classes, this);
+
+ super.destroy();
+
+ if (classes.contains(ServletContextListener.class)) {
+ ServletContextListener servletContextListener =
+ (ServletContextListener)super.getT();
+
+ servletContextListener.contextDestroyed(
+ new ServletContextEvent(servletContext));
+ }
+ }
+ finally {
+ destroyContextAttributes();
+ Thread.currentThread().setContextClassLoader(original);
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof ListenerRegistration)) {
+ return false;
+ }
+
+ ListenerRegistration listenerRegistration = (ListenerRegistration)obj;
+
+ return super.getT().equals(listenerRegistration.getT());
+ }
+
+ @Override
+ public int hashCode() {
+ return Long.valueOf(getD().serviceId).hashCode();
+ }
+
+ public ServletContext getServletContext() {
+ return servletContext;
+ }
+
+ public ServletContextHelper getServletContextHelper() {
+ return servletContextHelper;
+ }
+
+ @Override
+ public EventListener getT() {
+ return proxy;
+ }
+
+ private void createContextAttributes() {
+ contextController.getProxyContext().createContextAttributes(
+ servletContextHelper);
+ }
+
+ private void destroyContextAttributes() {
+ contextController.getProxyContext().destroyContextAttributes(
+ servletContextHelper);
+ }
+
+ private class EventListenerInvocationHandler implements InvocationHandler {
+
+ public EventListenerInvocationHandler() {
+ }
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+
+ ClassLoader original = Thread.currentThread().getContextClassLoader();
+
+ try {
+ Thread.currentThread().setContextClassLoader(classLoader);
+
+ return method.invoke(ListenerRegistration.super.getT(), args);
+ }
+ finally {
+ Thread.currentThread().setContextClassLoader(original);
+ }
+ }
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/MatchableRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/MatchableRegistration.java
new file mode 100644
index 00000000..7da78842
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/MatchableRegistration.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.registration;
+
+import org.eclipse.equinox.http.servlet.internal.servlet.Match;
+import org.osgi.dto.DTO;
+
+/**
+ * @author Raymond Augé
+ */
+public abstract class MatchableRegistration<T, D extends DTO>
+ extends Registration<T, D> {
+
+ public MatchableRegistration(T t, D d) {
+ super(t, d);
+ }
+
+ public abstract String match(
+ String name, String servletPath, String pathInfo, String extension,
+ Match match);
+
+ protected boolean isPathWildcardMatch(
+ String pattern, String servletPath, String pathInfo) {
+
+ int cpl = pattern.length() - 2;
+
+ if (pattern.endsWith("/*") && servletPath.regionMatches(0, pattern, 0, cpl)) { //$NON-NLS-1$
+ if ((pattern.length() > 2) && !pattern.startsWith(servletPath)) {
+ return false;
+ }
+
+ if (servletPath.length() == cpl) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ protected boolean doMatch(
+ String pattern, String servletPath, String pathInfo,
+ String extension, Match match)
+ throws IllegalArgumentException {
+
+ if (match == Match.EXACT) {
+ return pattern.equals(servletPath);
+ }
+
+ if (pattern.indexOf("/*.") == 0) { //$NON-NLS-1$
+ pattern = pattern.substring(1);
+ }
+
+ if (pattern.charAt(0) == '/') {
+ if ((match == Match.DEFAULT_SERVLET) && (pattern.length() == 1)) {
+ return true;
+ }
+
+ if ((match == Match.REGEX) && isPathWildcardMatch(
+ pattern, servletPath, pathInfo)) {
+
+ return true;
+ }
+ }
+
+ if ((match == Match.EXTENSION) && (pattern.indexOf("*.") == 0)) { //$NON-NLS-1$
+ return pattern.substring(2).equals(extension);
+ }
+
+ return false;
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Registration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/Registration.java
index 52ab0d58..0df5d73a 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/Registration.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/Registration.java
@@ -1,20 +1,31 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 Cognos Incorporated, IBM Corporation and others.
+ * Copyright (c) 2005, 2014 Cognos Incorporated, IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Cognos Incorporated - initial API and implementation
* IBM Corporation - bug fixes and enhancements
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
*******************************************************************************/
-package org.eclipse.equinox.http.servlet.internal;
+package org.eclipse.equinox.http.servlet.internal.registration;
-public abstract class Registration {
+import org.osgi.dto.DTO;
+
+public abstract class Registration<T, D extends DTO> {
+
+ private final D d;
+ private final T t;
protected int referenceCount;
+ public Registration(T t, D d) {
+ this.t = t;
+ this.d = d;
+ }
+
public synchronized void addReference() {
++referenceCount;
}
@@ -31,6 +42,7 @@ public abstract class Registration {
try {
while (referenceCount != 0) {
try {
+ (new Exception()).printStackTrace();
wait();
} catch (InterruptedException e) {
// wait until the servlet is inactive but save the interrupted status
@@ -42,4 +54,18 @@ public abstract class Registration {
Thread.currentThread().interrupt(); //restore the interrupted state
}
}
+
+ public D getD() {
+ return d;
+ }
+
+ public T getT() {
+ return t;
+ }
+
+ @Override
+ public String toString() {
+ return getD().toString();
+ }
+
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ResourceRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ResourceRegistration.java
new file mode 100644
index 00000000..91ea6f0f
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ResourceRegistration.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.registration;
+
+import org.eclipse.equinox.http.servlet.internal.context.ContextController;
+
+import javax.servlet.Servlet;
+import org.osgi.service.http.context.ServletContextHelper;
+import org.osgi.service.http.runtime.dto.ResourceDTO;
+/**
+ * @author Raymond Augé
+ */
+public class ResourceRegistration extends EndpointRegistration<ResourceDTO> {
+
+ public ResourceRegistration(
+ Servlet servlet, ResourceDTO resourceDTO,
+ ServletContextHelper servletContextHelper,
+ ContextController contextController) {
+
+ super(servlet, resourceDTO, servletContextHelper, contextController);
+
+ name = servlet.getClass().getName().concat("#").concat(getD().prefix); //$NON-NLS-1$
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String[] getPatterns() {
+ return getD().patterns;
+ }
+
+ @Override
+ public long getServiceId() {
+ return getD().serviceId;
+ }
+
+ private final String name;
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java
new file mode 100644
index 00000000..580a4f67
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/registration/ServletRegistration.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2014 Cognos Incorporated, IBM Corporation and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cognos Incorporated - initial API and implementation
+ * IBM Corporation - bug fixes and enhancements
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ *******************************************************************************/
+package org.eclipse.equinox.http.servlet.internal.registration;
+
+import javax.servlet.Servlet;
+import org.eclipse.equinox.http.servlet.internal.context.ContextController;
+import org.eclipse.equinox.http.servlet.internal.servlet.Match;
+import org.osgi.service.http.context.ServletContextHelper;
+import org.osgi.service.http.runtime.dto.ErrorPageDTO;
+import org.osgi.service.http.runtime.dto.ServletDTO;
+
+//This class wraps the servlet object registered in the HttpService.registerServlet call, to manage the context classloader when handleRequests are being asked.
+public class ServletRegistration extends EndpointRegistration<ServletDTO> {
+
+ public ServletRegistration(
+ Servlet servlet, ServletDTO servletDTO, ErrorPageDTO errorPageDTO,
+ ServletContextHelper servletContextHelper,
+ ContextController contextController) {
+
+ super(servlet, servletDTO, servletContextHelper, contextController);
+
+ this.errorPageDTO = errorPageDTO;
+ }
+
+ public ErrorPageDTO getErrorPageDTO() {
+ return errorPageDTO;
+ }
+
+ @Override
+ public String getName() {
+ return getD().name;
+ }
+
+ @Override
+ public String[] getPatterns() {
+ return getD().patterns;
+ }
+
+ @Override
+ public long getServiceId() {
+ return getD().serviceId;
+ }
+
+ @Override
+ public String match(
+ String name, String servletPath, String pathInfo, String extension,
+ Match match) {
+
+ if ((errorPageDTO != null) && (name != null)) {
+ for (long errorCode : errorPageDTO.errorCodes) {
+ if (String.valueOf(errorCode).equals(name)) {
+ return name;
+ }
+ }
+
+ for (String exception : errorPageDTO.exceptions) {
+ if (exception.equals(name)) {
+ return name;
+ }
+ }
+ }
+
+ return super.match(name, servletPath, pathInfo, extension, match);
+ }
+
+ private ErrorPageDTO errorPageDTO;
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/FilterChainImpl.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/FilterChainImpl.java
index 159fb2de..cbf15e79 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/FilterChainImpl.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/FilterChainImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation and others.
+ * Copyright (c) 2011, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,34 +7,51 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
*******************************************************************************/
-package org.eclipse.equinox.http.servlet.internal;
+package org.eclipse.equinox.http.servlet.internal.servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration;
+import org.eclipse.equinox.http.servlet.internal.registration.FilterRegistration;
public class FilterChainImpl implements FilterChain {
- private List matchingFilterRegistrations;
- private ServletRegistration registration;
+ private List<FilterRegistration> matchingFilterRegistrations;
+ private EndpointRegistration<?> registration;
+ private DispatcherType dispatcherType;
private int filterIndex = 0;
private int filterCount;
- public FilterChainImpl(List matchingFilterRegistrations, ServletRegistration registration) {
+ public FilterChainImpl(
+ List<FilterRegistration> matchingFilterRegistrations,
+ EndpointRegistration<?> registration, DispatcherType dispatcherType) {
+
this.matchingFilterRegistrations = matchingFilterRegistrations;
+ this.dispatcherType = dispatcherType;
this.registration = registration;
this.filterCount = matchingFilterRegistrations.size();
}
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
- if (filterIndex < filterCount) {
- FilterRegistration filterRegistration = (FilterRegistration) matchingFilterRegistrations.get(filterIndex++);
- filterRegistration.doFilter((HttpServletRequest) request, (HttpServletResponse) response, this);
- return;
+ while (filterIndex < filterCount) {
+ FilterRegistration filterRegistration = matchingFilterRegistrations.get(filterIndex++);
+
+ if (filterRegistration.appliesTo(this)) {
+ filterRegistration.doFilter((HttpServletRequest) request, (HttpServletResponse) response, this);
+
+ return;
+ }
}
registration.service((HttpServletRequest) request, (HttpServletResponse) response);
}
+
+ public DispatcherType getDispatcherType() {
+ return dispatcherType;
+ }
+
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/FilterConfigImpl.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/FilterConfigImpl.java
new file mode 100644
index 00000000..0a7b3c9c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/FilterConfigImpl.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2014 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ *******************************************************************************/
+package org.eclipse.equinox.http.servlet.internal.servlet;
+
+import java.util.*;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+
+public class FilterConfigImpl implements FilterConfig {
+
+ private final Map<String, String> initparams;
+ private final String filterName;
+ private final ServletContext servletContext;
+
+ public FilterConfigImpl(
+ String name, Map<String, String> initparams,
+ ServletContext servletContext) {
+
+ this.filterName = name;
+
+ if (initparams != null) {
+ this.initparams = initparams;
+ }
+ else {
+ this.initparams = Collections.emptyMap();
+ }
+
+ this.servletContext = servletContext;
+ }
+
+ public String getFilterName() {
+ return filterName;
+ }
+
+ public ServletContext getServletContext() {
+ return servletContext;
+ }
+
+ public String getInitParameter(String name) {
+ return initparams.get(name);
+ }
+
+ public Enumeration<String> getInitParameterNames() {
+ return Collections.enumeration(initparams.keySet());
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletRequestBuilder.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletRequestBuilder.java
new file mode 100644
index 00000000..f01d0b78
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletRequestBuilder.java
@@ -0,0 +1,291 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2014 Cognos Incorporated, IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cognos Incorporated - initial API and implementation
+ * IBM Corporation - bug fixes and enhancements
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ *******************************************************************************/
+package org.eclipse.equinox.http.servlet.internal.servlet;
+
+import java.lang.reflect.*;
+import java.util.*;
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import org.eclipse.equinox.http.servlet.internal.context.DispatchTargets;
+import org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration;
+import org.eclipse.equinox.http.servlet.internal.util.Const;
+import org.eclipse.equinox.http.servlet.internal.util.EventListeners;
+import org.osgi.service.http.HttpContext;
+
+public class HttpServletRequestBuilder {
+
+ private DispatchTargets dispatchTargets;
+ private EndpointRegistration<?> servletRegistration;
+ private final HttpServletRequest request;
+ private HttpServletRequest requestProxy;
+ private boolean isRequestDispatcherInclude;
+
+ static final String INCLUDE_REQUEST_URI_ATTRIBUTE = "javax.servlet.include.request_uri"; //$NON-NLS-1$
+ static final String INCLUDE_CONTEXT_PATH_ATTRIBUTE = "javax.servlet.include.context_path"; //$NON-NLS-1$
+ static final String INCLUDE_SERVLET_PATH_ATTRIBUTE = "javax.servlet.include.servlet_path"; //$NON-NLS-1$
+ static final String INCLUDE_PATH_INFO_ATTRIBUTE = "javax.servlet.include.path_info"; //$NON-NLS-1$
+
+ private final ThreadLocal<HttpServletRequest> requestTL = new ThreadLocal<HttpServletRequest>();
+
+ private final static Map<Method, Method> requestToHandlerMethods;
+
+ static {
+ requestToHandlerMethods = createContextToHandlerMethods();
+ }
+
+ private static Map<Method, Method> createContextToHandlerMethods() {
+ Map<Method, Method> methods = new HashMap<Method, Method>();
+ Method[] handlerMethods =
+ HttpServletRequestBuilder.class.getDeclaredMethods();
+
+ for (int i = 0; i < handlerMethods.length; i++) {
+ Method handlerMethod = handlerMethods[i];
+ String name = handlerMethod.getName();
+ Class<?>[] parameterTypes = handlerMethod.getParameterTypes();
+
+ try {
+ Method method = HttpServletRequest.class.getMethod(
+ name, parameterTypes);
+ methods.put(method, handlerMethod);
+ }
+ catch (NoSuchMethodException e) {
+ // do nothing
+ }
+ }
+
+ return methods;
+ }
+
+ public HttpServletRequestBuilder(HttpServletRequest request, DispatchTargets dispatchTargets) {
+ this.request = request;
+ this.dispatchTargets = dispatchTargets;
+ this.servletRegistration = dispatchTargets.getServletRegistration();
+
+ isRequestDispatcherInclude = request.getAttribute(HttpServletRequestBuilder.INCLUDE_REQUEST_URI_ATTRIBUTE) != null;
+
+ this.requestProxy = (HttpServletRequest)Proxy.newProxyInstance(
+ getClass().getClassLoader(), new Class[] {HttpServletRequest.class},
+ new InvocationHandler() {
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ return HttpServletRequestBuilder.this.invoke(proxy, method, args);
+ }
+
+ }
+ );
+ }
+
+ public HttpServletRequest build() {
+ return requestProxy;
+ }
+
+ Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ requestTL.set((HttpServletRequest)proxy);
+
+ try {
+ Method m = requestToHandlerMethods.get(method);
+ if (m != null) {
+ return m.invoke(this, args);
+ }
+ return method.invoke(request, args);
+ }
+ finally {
+ requestTL.remove();
+ }
+ }
+
+ public String getAuthType() {
+ String authType = (String)request.getAttribute(HttpContext.AUTHENTICATION_TYPE);
+ if (authType != null)
+ return authType;
+
+ return request.getAuthType();
+ }
+
+ public String getRemoteUser() {
+ String remoteUser = (String) request.getAttribute(HttpContext.REMOTE_USER);
+ if (remoteUser != null)
+ return remoteUser;
+
+ return request.getRemoteUser();
+ }
+
+ public HttpServletRequest getRequest() {
+ return request;
+ }
+
+ public String getPathInfo() {
+ if (isRequestDispatcherInclude)
+ return request.getPathInfo();
+
+ return dispatchTargets.getPathInfo();
+ }
+
+ public ServletContext getServletContext() {
+ return servletRegistration.getServletContext();
+ }
+
+ public String getServletPath() {
+ if (isRequestDispatcherInclude)
+ return request.getServletPath();
+
+ if (dispatchTargets.getServletPath().equals(Const.SLASH)) {
+ return Const.BLANK;
+ }
+ return dispatchTargets.getServletPath();
+ }
+
+ public String getContextPath() {
+ return dispatchTargets.getContextController().getFullContextPath();
+ }
+
+ public Object getAttribute(String attributeName) {
+ String servletPath = dispatchTargets.getServletPath();
+ if (isRequestDispatcherInclude) {
+ if (attributeName.equals(HttpServletRequestBuilder.INCLUDE_CONTEXT_PATH_ATTRIBUTE)) {
+ String contextPath = (String) request.getAttribute(HttpServletRequestBuilder.INCLUDE_CONTEXT_PATH_ATTRIBUTE);
+ if (contextPath == null || contextPath.equals(Const.SLASH))
+ contextPath = Const.BLANK;
+
+ String includeServletPath = (String) request.getAttribute(HttpServletRequestBuilder.INCLUDE_SERVLET_PATH_ATTRIBUTE);
+ if (includeServletPath == null || includeServletPath.equals(Const.SLASH))
+ includeServletPath = Const.BLANK;
+
+ return contextPath + includeServletPath;
+ } else if (attributeName.equals(HttpServletRequestBuilder.INCLUDE_SERVLET_PATH_ATTRIBUTE)) {
+ if (servletPath.equals(Const.SLASH)) {
+ return Const.BLANK;
+ }
+ return servletPath;
+ } else if (attributeName.equals(HttpServletRequestBuilder.INCLUDE_PATH_INFO_ATTRIBUTE)) {
+ String pathInfoAttribute = (String) request.getAttribute(HttpServletRequestBuilder.INCLUDE_PATH_INFO_ATTRIBUTE);
+ if (servletPath.equals(Const.SLASH)) {
+ return pathInfoAttribute;
+ }
+
+ if ((pathInfoAttribute == null) || (pathInfoAttribute.length() == 0)) {
+ return null;
+ }
+
+ pathInfoAttribute = pathInfoAttribute.substring(servletPath.length());
+ if (pathInfoAttribute.length() == 0)
+ return null;
+
+ return pathInfoAttribute;
+ }
+ }
+
+ return request.getAttribute(attributeName);
+ }
+
+ public RequestDispatcher getRequestDispatcher(String path) {
+ if (!path.startsWith(getContextPath())) {
+ path = getContextPath().substring(
+ request.getContextPath().length()).concat(path);
+ }
+
+ return new RequestDispatcherAdaptor(request.getRequestDispatcher(path));
+ }
+
+ public static String getDispatchPathInfo(HttpServletRequest req) {
+ if (req.getAttribute(INCLUDE_REQUEST_URI_ATTRIBUTE) != null)
+ return (String) req.getAttribute(INCLUDE_PATH_INFO_ATTRIBUTE);
+
+ return req.getPathInfo();
+ }
+
+ public static String getDispatchServletPath(HttpServletRequest req) {
+ if (req.getAttribute(INCLUDE_REQUEST_URI_ATTRIBUTE) != null) {
+ String servletPath = (String) req.getAttribute(INCLUDE_SERVLET_PATH_ATTRIBUTE);
+ return (servletPath == null) ? Const.BLANK : servletPath;
+ }
+ return req.getServletPath();
+ }
+
+ public HttpSession getSession() {
+ HttpSession session = request.getSession();
+ if (session != null) {
+ return new HttpSessionAdaptor(
+ session, servletRegistration.getT(),
+ dispatchTargets.getContextController().getEventListeners());
+ }
+
+ return null;
+ }
+
+ public HttpSession getSession(boolean create) {
+ HttpSession session = request.getSession(create);
+ if (session != null) {
+ return new HttpSessionAdaptor(
+ session, servletRegistration.getT(),
+ dispatchTargets.getContextController().getEventListeners());
+ }
+
+ return null;
+ }
+
+ public void removeAttribute(String name) {
+ request.removeAttribute(name);
+
+ EventListeners eventListeners = dispatchTargets.getContextController().getEventListeners();
+
+ List<ServletRequestAttributeListener> listeners = eventListeners.get(
+ ServletRequestAttributeListener.class);
+
+ if (listeners.isEmpty()) {
+ return;
+ }
+
+ ServletRequestAttributeEvent servletRequestAttributeEvent =
+ new ServletRequestAttributeEvent(
+ servletRegistration.getServletContext(), requestProxy, name, null);
+
+ for (ServletRequestAttributeListener servletRequestAttributeListener : listeners) {
+ servletRequestAttributeListener.attributeRemoved(
+ servletRequestAttributeEvent);
+ }
+ }
+
+ public void setAttribute(String name, Object value) {
+ boolean added = (request.getAttribute(name) == null);
+ request.setAttribute(name, value);
+
+ EventListeners eventListeners = dispatchTargets.getContextController().getEventListeners();
+
+ List<ServletRequestAttributeListener> listeners = eventListeners.get(
+ ServletRequestAttributeListener.class);
+
+ if (listeners.isEmpty()) {
+ return;
+ }
+
+ ServletRequestAttributeEvent servletRequestAttributeEvent =
+ new ServletRequestAttributeEvent(
+ servletRegistration.getServletContext(), requestProxy, name, value);
+
+ for (ServletRequestAttributeListener servletRequestAttributeListener : listeners) {
+ if (added) {
+ servletRequestAttributeListener.attributeAdded(
+ servletRequestAttributeEvent);
+ }
+ else {
+ servletRequestAttributeListener.attributeReplaced(
+ servletRequestAttributeEvent);
+ }
+ }
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletResponseWrapperImpl.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletResponseWrapperImpl.java
new file mode 100644
index 00000000..1b0de45f
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletResponseWrapperImpl.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.servlet;
+
+import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+
+/**
+ * @author Raymond Augé
+ */
+public class HttpServletResponseWrapperImpl extends HttpServletResponseWrapper {
+
+ public HttpServletResponseWrapperImpl(HttpServletResponse response) {
+ super(response);
+ }
+
+ @Override
+ public void sendError(int status) throws IOException {
+ this.status = status;
+ }
+
+ @Override
+ public void sendError(int status, String message) throws IOException {
+ this.status = status;
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ @Override
+ public int getStatus() {
+ return status;
+ }
+
+ private int status;
+ private String message;
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpSessionAdaptor.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpSessionAdaptor.java
index 1784a258..283fe7fa 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpSessionAdaptor.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpSessionAdaptor.java
@@ -1,30 +1,37 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Cognos Incorporated, IBM Corporation and others.
+ * Copyright (c) 2005, 2014 Cognos Incorporated, IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Cognos Incorporated - initial API and implementation
* IBM Corporation - bug fixes and enhancements
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
*******************************************************************************/
-package org.eclipse.equinox.http.servlet.internal;
+package org.eclipse.equinox.http.servlet.internal.servlet;
import java.util.Enumeration;
+import java.util.List;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
-import javax.servlet.http.HttpSession;
+import javax.servlet.http.*;
+import org.eclipse.equinox.http.servlet.internal.util.EventListeners;
// This class adapts HttpSessions in order to return the right ServletContext
public class HttpSessionAdaptor implements HttpSession {
+ private EventListeners eventListeners;
private HttpSession session;
private Servlet servlet;
- public HttpSessionAdaptor(HttpSession session, Servlet servlet) {
+ public HttpSessionAdaptor(
+ HttpSession session, Servlet servlet, EventListeners eventListeners) {
+
this.session = session;
this.servlet = servlet;
+ this.eventListeners = eventListeners;
}
public ServletContext getServletContext() {
@@ -35,7 +42,7 @@ public class HttpSessionAdaptor implements HttpSession {
return session.getAttribute(arg0);
}
- public Enumeration getAttributeNames() {
+ public Enumeration<String> getAttributeNames() {
return session.getAttributeNames();
}
@@ -85,15 +92,67 @@ public class HttpSessionAdaptor implements HttpSession {
public void removeAttribute(String arg0) {
session.removeAttribute(arg0);
+
+ List<HttpSessionAttributeListener> listeners = eventListeners.get(
+ HttpSessionAttributeListener.class);
+
+ if (listeners.isEmpty()) {
+ return;
+ }
+
+ HttpSessionBindingEvent httpSessionBindingEvent =
+ new HttpSessionBindingEvent(session, arg0);
+
+ for (HttpSessionAttributeListener httpSessionAttributeListener : listeners) {
+ httpSessionAttributeListener.attributeRemoved(
+ httpSessionBindingEvent);
+ }
}
/**@deprecated*/
public void removeValue(String arg0) {
session.removeValue(arg0);
+
+ List<HttpSessionAttributeListener> listeners = eventListeners.get(
+ HttpSessionAttributeListener.class);
+
+ if (listeners.isEmpty()) {
+ return;
+ }
+
+ HttpSessionBindingEvent httpSessionBindingEvent =
+ new HttpSessionBindingEvent(session, arg0);
+
+ for (HttpSessionAttributeListener httpSessionAttributeListener : listeners) {
+ httpSessionAttributeListener.attributeRemoved(
+ httpSessionBindingEvent);
+ }
}
public void setAttribute(String arg0, Object arg1) {
+ boolean added = (session.getAttribute(arg0) == null);
session.setAttribute(arg0, arg1);
+
+ List<HttpSessionAttributeListener> listeners = eventListeners.get(
+ HttpSessionAttributeListener.class);
+
+ if (listeners.isEmpty()) {
+ return;
+ }
+
+ HttpSessionBindingEvent httpSessionBindingEvent =
+ new HttpSessionBindingEvent(session, arg0, arg1);
+
+ for (HttpSessionAttributeListener httpSessionAttributeListener : listeners) {
+ if (added) {
+ httpSessionAttributeListener.attributeAdded(
+ httpSessionBindingEvent);
+ }
+ else {
+ httpSessionAttributeListener.attributeReplaced(
+ httpSessionBindingEvent);
+ }
+ }
}
public void setMaxInactiveInterval(int arg0) {
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/Match.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/Match.java
new file mode 100644
index 00000000..38f720bc
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/Match.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.servlet;
+
+/**
+ * @author Raymond Augé
+ */
+public enum Match {
+
+ EXACT, EXTENSION, REGEX, DEFAULT_SERVLET
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/NamedDispatcherAdaptor.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/NamedDispatcherAdaptor.java
new file mode 100644
index 00000000..c2431e7f
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/NamedDispatcherAdaptor.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2014 Cognos Incorporated, IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cognos Incorporated - initial API and implementation
+ * IBM Corporation - bug fixes and enhancements
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ *******************************************************************************/
+package org.eclipse.equinox.http.servlet.internal.servlet;
+
+import java.io.IOException;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import org.eclipse.equinox.http.servlet.internal.context.DispatchTargets;
+
+//This class unwraps the request so it can be processed by the underlying servlet container.
+public class NamedDispatcherAdaptor implements RequestDispatcher {
+
+ private final DispatchTargets dispatchTargets;
+
+ public NamedDispatcherAdaptor(DispatchTargets dispatchTargets) {
+ this.dispatchTargets = dispatchTargets;
+ }
+
+ public void forward(ServletRequest req, ServletResponse resp)
+ throws IOException, ServletException {
+
+ if (req instanceof HttpServletRequestBuilder)
+ req = ((HttpServletRequestBuilder) req).getRequest();
+
+ doDispatch((HttpServletRequest)req, (HttpServletResponse)resp);
+ }
+
+ public void include(ServletRequest req, ServletResponse resp)
+ throws IOException, ServletException {
+
+ if (req instanceof HttpServletRequestBuilder)
+ req = ((HttpServletRequestBuilder) req).getRequest();
+
+ doDispatch((HttpServletRequest)req, (HttpServletResponse)resp);
+ }
+
+ private void doDispatch(
+ HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+
+ DispatcherType dispatcherType = DispatcherType.REQUEST;
+
+ if (request.getAttribute("javax.servlet.include.request_uri") != null) {
+ request.setAttribute(
+ "javax.servlet.include.request_uri", request.getRequestURI());
+ request.setAttribute(
+ "javax.servlet.include.context_path",
+ dispatchTargets.getContextController().getContextPath());
+ request.setAttribute(
+ "javax.servlet.include.servlet_path",
+ dispatchTargets.getServletPath());
+ request.setAttribute(
+ "javax.servlet.include.path_info",
+ dispatchTargets.getPathInfo());
+
+ dispatcherType = DispatcherType.INCLUDE;
+ }
+
+ HttpServletRequest wrappedRequest = new HttpServletRequestBuilder(
+ request, dispatchTargets).build();
+ HttpServletResponseWrapper wrapperResponse =
+ new HttpServletResponseWrapperImpl(response);
+
+ ResponseStateHandler responseStateHandler = new ResponseStateHandler(
+ wrappedRequest, wrapperResponse, dispatchTargets, dispatcherType);
+
+ responseStateHandler.processRequest();
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ProxyServlet.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ProxyServlet.java
new file mode 100644
index 00000000..cd68ca8f
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ProxyServlet.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2014 Cognos Incorporated, IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cognos Incorporated - initial API and implementation
+ * IBM Corporation - bug fixes and enhancements
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ *******************************************************************************/
+package org.eclipse.equinox.http.servlet.internal.servlet;
+
+import java.io.IOException;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import org.eclipse.equinox.http.servlet.internal.Activator;
+import org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl;
+import org.eclipse.equinox.http.servlet.internal.util.Const;
+
+/**
+ * The ProxyServlet is the private side of a Servlet that when registered (and init() called) in a servlet container
+ * will in-turn register and provide an OSGi Http Service implementation.
+ * This class is not meant for extending or even using directly and is purely meant for registering
+ * in a servlet container.
+ */
+public class ProxyServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 4117456123807468871L;
+ private HttpServiceRuntimeImpl httpServiceRuntimeImpl;
+
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+
+ Activator.addProxyServlet(this);
+ }
+
+ public void destroy() {
+ Activator.unregisterHttpService(this);
+
+ super.destroy();
+ }
+
+ public void setHttpServiceRuntimeImpl(
+ HttpServiceRuntimeImpl httpServiceRuntimeImpl) {
+
+ this.httpServiceRuntimeImpl = httpServiceRuntimeImpl;
+ }
+
+ /**
+ * @see HttpServlet#service(ServletRequest, ServletResponse)
+ */
+ protected void service(
+ HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ checkRuntime();
+
+ String alias = HttpServletRequestBuilder.getDispatchPathInfo(request);
+
+ if (alias == null) {
+ alias = Const.SLASH;
+ }
+
+ if (processAlias(request, response, alias)) {
+ return;
+ }
+
+ response.sendError(
+ HttpServletResponse.SC_NOT_FOUND, "ProxyServlet: " + alias);
+ }
+
+ private void checkRuntime() {
+ if (httpServiceRuntimeImpl == null) {
+ throw new IllegalStateException(
+ "Proxy servlet not properly initialized. " +
+ "httpServiceRuntimeImpl is null");
+ }
+ }
+
+ private boolean processAlias(
+ HttpServletRequest request, HttpServletResponse response,
+ String alias)
+ throws ServletException, IOException {
+
+ return httpServiceRuntimeImpl.doDispatch(request, response, alias);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/RequestDispatcherAdaptor.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/RequestDispatcherAdaptor.java
index 4e48e403..22d1f6d9 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/RequestDispatcherAdaptor.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/RequestDispatcherAdaptor.java
@@ -1,20 +1,21 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Cognos Incorporated, IBM Corporation and others.
+ * Copyright (c) 2005, 2014 Cognos Incorporated, IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Cognos Incorporated - initial API and implementation
* IBM Corporation - bug fixes and enhancements
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
*******************************************************************************/
-package org.eclipse.equinox.http.servlet.internal;
+package org.eclipse.equinox.http.servlet.internal.servlet;
import java.io.IOException;
import javax.servlet.*;
-//This class unwraps the request so it can be processed by the underlying servlet container.
+//This class unwraps the request so it can be processed by the underlying servlet container.
public class RequestDispatcherAdaptor implements RequestDispatcher {
private RequestDispatcher requestDispatcher;
@@ -24,15 +25,15 @@ public class RequestDispatcherAdaptor implements RequestDispatcher {
}
public void forward(ServletRequest req, ServletResponse resp) throws ServletException, IOException {
- if (req instanceof HttpServletRequestAdaptor)
- req = ((HttpServletRequestAdaptor) req).getRequest();
+ if (req instanceof HttpServletRequestBuilder)
+ req = ((HttpServletRequestBuilder) req).getRequest();
requestDispatcher.forward(req, resp);
}
public void include(ServletRequest req, ServletResponse resp) throws ServletException, IOException {
- if (req instanceof HttpServletRequestAdaptor)
- req = ((HttpServletRequestAdaptor) req).getRequest();
+ if (req instanceof HttpServletRequestBuilder)
+ req = ((HttpServletRequestBuilder) req).getRequest();
requestDispatcher.include(req, resp);
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ResourceServlet.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ResourceServlet.java
index acb468af..4bfa0b21 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/ResourceServlet.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ResourceServlet.java
@@ -1,22 +1,25 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 Cognos Incorporated, IBM Corporation and others
+ * Copyright (c) 2005, 2014 Cognos Incorporated, IBM Corporation and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Cognos Incorporated - initial API and implementation
* IBM Corporation - bug fixes and enhancements
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
*******************************************************************************/
-package org.eclipse.equinox.http.servlet.internal;
+package org.eclipse.equinox.http.servlet.internal.servlet;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.security.*;
import javax.servlet.http.*;
-import org.osgi.service.http.HttpContext;
+import org.eclipse.equinox.http.servlet.internal.context.ContextController;
+import org.eclipse.equinox.http.servlet.internal.util.Const;
+import org.osgi.service.http.context.ServletContextHelper;
public class ResourceServlet extends HttpServlet {
private static final long serialVersionUID = 3586876493076122102L;
@@ -25,27 +28,29 @@ public class ResourceServlet extends HttpServlet {
private static final String IF_NONE_MATCH = "If-None-Match"; //$NON-NLS-1$
private static final String ETAG = "ETag"; //$NON-NLS-1$
+ private ContextController contextController;
private String internalName;
- HttpContext httpContext;
+ private ServletContextHelper servletContextHelper;
private AccessControlContext acc;
- public ResourceServlet(String internalName, HttpContext context, AccessControlContext acc) {
+ public ResourceServlet(String internalName, ContextController contextController, ServletContextHelper servletContextHelper, AccessControlContext acc) {
this.internalName = internalName;
- if (internalName.equals("/")) { //$NON-NLS-1$
- this.internalName = ""; //$NON-NLS-1$
+ if (internalName.equals(Const.SLASH)) {
+ this.internalName = Const.BLANK;
}
- this.httpContext = context;
+ this.contextController = contextController;
+ this.servletContextHelper = servletContextHelper;
this.acc = acc;
}
public void service(HttpServletRequest req, final HttpServletResponse resp) throws IOException {
String method = req.getMethod();
if (method.equals("GET") || method.equals("POST") || method.equals("HEAD")) { //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- String pathInfo = HttpServletRequestAdaptor.getDispatchPathInfo(req);
+ String pathInfo = HttpServletRequestBuilder.getDispatchPathInfo(req);
if (pathInfo == null)
- pathInfo = ""; //$NON-NLS-1$
+ pathInfo = Const.BLANK;
String resourcePath = internalName + pathInfo;
- URL resourceURL = httpContext.getResource(resourcePath);
+ URL resourceURL = servletContextHelper.getResource(contextController, resourcePath);
if (resourceURL != null)
writeResource(req, resp, resourcePath, resourceURL);
else
@@ -57,9 +62,9 @@ public class ResourceServlet extends HttpServlet {
private void writeResource(final HttpServletRequest req, final HttpServletResponse resp, final String resourcePath, final URL resourceURL) throws IOException {
try {
- AccessController.doPrivileged(new PrivilegedExceptionAction() {
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>() {
- public Object run() throws Exception {
+ public Boolean run() throws Exception {
URLConnection connection = resourceURL.openConnection();
long lastModified = connection.getLastModified();
int contentLength = connection.getContentLength();
@@ -88,7 +93,7 @@ public class ResourceServlet extends HttpServlet {
if (contentLength != -1)
resp.setContentLength(contentLength);
- String contentType = httpContext.getMimeType(resourcePath);
+ String contentType = servletContextHelper.getMimeType(contextController, resourcePath);
if (contentType == null)
contentType = getServletConfig().getServletContext().getMimeType(resourcePath);
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ResponseStateHandler.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ResponseStateHandler.java
new file mode 100644
index 00000000..6bfee6a1
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ResponseStateHandler.java
@@ -0,0 +1,212 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.servlet;
+
+import java.io.IOException;
+import java.util.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import org.eclipse.equinox.http.servlet.internal.context.ContextController;
+import org.eclipse.equinox.http.servlet.internal.context.DispatchTargets;
+import org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration;
+import org.eclipse.equinox.http.servlet.internal.registration.FilterRegistration;
+import org.eclipse.equinox.http.servlet.internal.util.EventListeners;
+
+/**
+ * @author Raymond Augé
+ */
+public class ResponseStateHandler {
+
+ public ResponseStateHandler(
+ HttpServletRequest request, HttpServletResponse response,
+ DispatchTargets dispatchTargets, DispatcherType dispatcherType) {
+
+ this.request = request;
+ this.response = response;
+ this.dispatchTargets = dispatchTargets;
+ this.dispatcherType = dispatcherType;
+ }
+
+ public void processRequest() throws IOException, ServletException {
+ ContextController contextController = dispatchTargets.getContextController();
+ EventListeners eventListeners = contextController.getEventListeners();
+ List<ServletRequestListener> servletRequestListeners = Collections.emptyList();
+ EndpointRegistration<?> registration = dispatchTargets.getServletRegistration();
+ List<FilterRegistration> matchingFilterRegistrations = dispatchTargets.getMatchingFilterRegistrations();
+
+ ServletRequestEvent servletRequestEvent = null;
+
+ if (dispatcherType == DispatcherType.REQUEST) {
+ servletRequestListeners = eventListeners.get(ServletRequestListener.class);
+
+ if (!servletRequestListeners.isEmpty()) {
+ servletRequestEvent = new ServletRequestEvent(registration.getServletContext(), request);
+ }
+ }
+
+ try {
+ for (ServletRequestListener servletRequestListener : servletRequestListeners) {
+ servletRequestListener.requestInitialized(servletRequestEvent);
+ }
+
+ if (matchingFilterRegistrations.isEmpty()) {
+ registration.service(request, response);
+ }
+ else {
+ Collections.sort(matchingFilterRegistrations);
+
+ FilterChain chain = new FilterChainImpl(
+ matchingFilterRegistrations, registration, dispatcherType);
+
+ chain.doFilter(request, response);
+ }
+ }
+ catch (IOException ioe) {
+ setException(ioe);
+
+ if (dispatcherType != DispatcherType.REQUEST) {
+ throw ioe;
+ }
+ }
+ catch (ServletException se) {
+ setException(se);
+
+ if (dispatcherType != DispatcherType.REQUEST) {
+ throw se;
+ }
+ }
+ finally {
+ registration.removeReference();
+
+ for (Iterator<FilterRegistration> it =
+ matchingFilterRegistrations.iterator(); it.hasNext();) {
+
+ FilterRegistration filterRegistration = it.next();
+ filterRegistration.removeReference();
+ }
+
+ handleErrors();
+
+ for (ServletRequestListener servletRequestListener : servletRequestListeners) {
+ servletRequestListener.requestDestroyed(servletRequestEvent);
+ }
+ }
+ }
+
+ public void setException(Exception exception) {
+ this.exception = exception;
+ }
+
+ private void handleErrors() throws IOException, ServletException {
+ if (dispatcherType != DispatcherType.REQUEST) {
+ return;
+ }
+
+ if (exception != null) {
+ handleException();
+ }
+ else {
+ handleResponseCode();
+ }
+ }
+
+ private void handleException() throws IOException, ServletException {
+ if (!(response instanceof HttpServletResponseWrapper)) {
+ return;
+ }
+
+ HttpServletResponseWrapper wrapper = (HttpServletResponseWrapper)response;
+
+ ContextController contextController = dispatchTargets.getContextController();
+ Class<? extends Exception> clazz = exception.getClass();
+ String className = clazz.getName();
+
+ DispatchTargets errorDispatchTargets = contextController.getDispatchTargets(
+ null, className, null, null, null, null, Match.EXACT, null);
+
+ if (errorDispatchTargets == null) {
+ if (exception instanceof ServletException) {
+ throw (ServletException)exception;
+ }
+
+ throw (IOException)exception;
+ }
+
+ request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, exception);
+ request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE, className);
+
+ if (request.getAttribute(RequestDispatcher.ERROR_MESSAGE) == null) {
+ request.setAttribute(RequestDispatcher.ERROR_MESSAGE, exception.getMessage());
+ }
+
+ request.setAttribute(
+ RequestDispatcher.ERROR_REQUEST_URI, request.getRequestURI());
+ request.setAttribute(
+ RequestDispatcher.ERROR_SERVLET_NAME,
+ errorDispatchTargets.getServletRegistration().getName());
+
+ ResponseStateHandler responseStateHandler = new ResponseStateHandler(
+ request, response, errorDispatchTargets, DispatcherType.ERROR);
+
+ responseStateHandler.processRequest();
+
+ HttpServletResponse wrappedResponse = (HttpServletResponse)wrapper.getResponse();
+
+ wrappedResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ private void handleResponseCode() throws IOException, ServletException {
+ if (!(response instanceof HttpServletResponseWrapper)) {
+ return;
+ }
+
+ HttpServletResponseWrapper wrapper = (HttpServletResponseWrapper)response;
+
+ int status = wrapper.getStatus();
+
+ if (status <= 400) {
+ return;
+ }
+
+ ContextController contextController = dispatchTargets.getContextController();
+
+ DispatchTargets errorDispatchTargets = contextController.getDispatchTargets(
+ null, String.valueOf(status), null, null, null, null, Match.EXACT, null);
+
+ if (errorDispatchTargets == null) {
+ return;
+ }
+
+ request.setAttribute(
+ RequestDispatcher.ERROR_REQUEST_URI, request.getRequestURI());
+ request.setAttribute(
+ RequestDispatcher.ERROR_SERVLET_NAME,
+ errorDispatchTargets.getServletRegistration().getName());
+ request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE, status);
+
+ ResponseStateHandler responseStateHandler = new ResponseStateHandler(
+ request, response, errorDispatchTargets, DispatcherType.ERROR);
+
+ responseStateHandler.processRequest();
+
+ HttpServletResponse wrappedResponse = (HttpServletResponse)wrapper.getResponse();
+
+ wrappedResponse.setStatus(status);
+ }
+
+ private DispatchTargets dispatchTargets;
+ private DispatcherType dispatcherType;
+ private Exception exception;
+ private HttpServletRequest request;
+ private HttpServletResponse response;
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ServletConfigImpl.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ServletConfigImpl.java
new file mode 100644
index 00000000..d5c95c08
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ServletConfigImpl.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2014 Cognos Incorporated, IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cognos Incorporated - initial API and implementation
+ * IBM Corporation - bug fixes and enhancements
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ *******************************************************************************/
+package org.eclipse.equinox.http.servlet.internal.servlet;
+
+import java.util.*;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+
+public class ServletConfigImpl implements ServletConfig {
+
+ private final Map<String, String> initparams;
+ private final ServletContext servletContext;
+ private final String servletName;
+
+ public ServletConfigImpl(
+ String servletName, Map<String, String> initparams,
+ ServletContext servletContext) {
+
+ this.servletName = servletName;
+
+ if (initparams != null) {
+ this.initparams = initparams;
+ }
+ else {
+ this.initparams = Collections.emptyMap();
+ }
+
+ this.servletContext = servletContext;
+ }
+
+ public String getServletName() {
+ return servletName;
+ }
+
+ public ServletContext getServletContext() {
+ return servletContext;
+ }
+
+ public String getInitParameter(String name) {
+ return initparams.get(name);
+ }
+
+ public Enumeration<String> getInitParameterNames() {
+ return Collections.enumeration(initparams.keySet());
+ }
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ServletContextAdaptor.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ServletContextAdaptor.java
new file mode 100644
index 00000000..3bc9444a
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/ServletContextAdaptor.java
@@ -0,0 +1,326 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2014 Cognos Incorporated, IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cognos Incorporated - initial API and implementation
+ * IBM Corporation - bug fixes and enhancements
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ *******************************************************************************/
+package org.eclipse.equinox.http.servlet.internal.servlet;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.*;
+import java.net.URL;
+import java.security.*;
+import java.util.*;
+import javax.servlet.*;
+import org.eclipse.equinox.http.servlet.internal.context.*;
+import org.eclipse.equinox.http.servlet.internal.util.Const;
+import org.eclipse.equinox.http.servlet.internal.util.EventListeners;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.wiring.BundleWiring;
+import org.osgi.service.http.context.ServletContextHelper;
+
+public class ServletContextAdaptor {
+
+ private final static Map<Method, Method> contextToHandlerMethods;
+
+ static {
+ contextToHandlerMethods = createContextToHandlerMethods();
+ }
+
+ private static Map<Method, Method> createContextToHandlerMethods() {
+ Map<Method, Method> methods = new HashMap<Method, Method>();
+ Method[] handlerMethods =
+ ServletContextAdaptor.class.getDeclaredMethods();
+
+ for (int i = 0; i < handlerMethods.length; i++) {
+ Method handlerMethod = handlerMethods[i];
+ String name = handlerMethod.getName();
+ Class<?>[] parameterTypes = handlerMethod.getParameterTypes();
+
+ try {
+ Method method = ServletContext.class.getMethod(
+ name, parameterTypes);
+ methods.put(method, handlerMethod);
+ }
+ catch (NoSuchMethodException e) {
+ // do nothing
+ }
+ }
+
+ return methods;
+ }
+
+ public ServletContextAdaptor(
+ ContextController contextController, Bundle bundle,
+ ServletContextHelper servletContextHelper,
+ EventListeners eventListeners, AccessControlContext acc) {
+
+ this.contextController = contextController;
+ this.proxyContext = contextController.getProxyContext();
+ this.servletContext = proxyContext.getServletContext();
+ this.contextName = contextController.getContextNames().get(0);
+ this.servletContextHelper = servletContextHelper;
+ this.eventListeners = eventListeners;
+ this.acc = acc;
+ this.bundle = bundle;
+
+ BundleWiring bundleWiring = this.bundle.adapt(BundleWiring.class);
+
+ this.classLoader = bundleWiring.getClassLoader();
+ }
+
+ public ServletContext createServletContext() {
+ Class<?> clazz = getClass();
+ ClassLoader curClassLoader = clazz.getClassLoader();
+ Class<?>[] interfaces = new Class[] {ServletContext.class};
+ InvocationHandler invocationHandler = createInvocationHandler();
+
+ return (ServletContext)Proxy.newProxyInstance(
+ curClassLoader, interfaces, invocationHandler);
+ }
+
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
+
+ public String getContextPath() {
+ return contextController.getFullContextPath();
+ }
+
+ public Object getAttribute(String attributeName) {
+ Dictionary<String, Object> attributes = getContextAttributes();
+
+ if (attributeName.equals("osgi-bundlecontext")) { //$NON-NLS-1$
+ return bundle.getBundleContext();
+ }
+
+ return attributes.get(attributeName);
+ }
+
+ public Enumeration<String> getAttributeNames() {
+ Dictionary<String, Object> attributes = getContextAttributes();
+ return attributes.keys();
+ }
+
+ public String getInitParameter(String name) {
+ return contextController.getInitParams().get(name);
+ }
+
+ public Enumeration<String> getInitParameterNames() {
+ return Collections.enumeration(
+ contextController.getInitParams().keySet());
+ }
+
+ public String getMimeType(final String name) {
+ String mimeType = null;
+
+ try {
+ mimeType = AccessController.doPrivileged(
+ new PrivilegedExceptionAction<String>() {
+ public String run() throws Exception {
+ return servletContextHelper.getMimeType(contextController, name);
+ }
+ }, acc
+ );
+ }
+ catch (PrivilegedActionException e) {
+ servletContext.log(e.getException().getMessage(), e.getException());
+ }
+
+ return (mimeType != null) ? mimeType : servletContext.getMimeType(name);
+ }
+
+ public RequestDispatcher getNamedDispatcher(String servletName) {
+ DispatchTargets dispatchTargets = contextController.getDispatchTargets(
+ null, servletName, null, null, null, null, Match.EXACT, null);
+
+ if (dispatchTargets == null) {
+ return null;
+ }
+
+ return new NamedDispatcherAdaptor(dispatchTargets);
+ }
+
+ public String getRealPath(final String path) {
+ try {
+ return AccessController.doPrivileged(
+ new PrivilegedExceptionAction<String>() {
+ public String run() throws Exception {
+ return servletContextHelper.getRealPath(contextController, path);
+ }
+ }, acc
+ );
+ }
+ catch (PrivilegedActionException e) {
+ servletContext.log(e.getException().getMessage(), e.getException());
+ }
+
+ return null;
+ }
+
+ public RequestDispatcher getRequestDispatcher(String path) {
+ if (!path.startsWith(getContextPath())) {
+ path = getContextPath().substring(
+ servletContext.getContextPath().length()).concat(path);
+ }
+
+ return new RequestDispatcherAdaptor(
+ servletContext.getRequestDispatcher(path));
+ }
+
+ public URL getResource(final String name) {
+ try {
+ return AccessController.doPrivileged(
+ new PrivilegedExceptionAction<URL>() {
+ public URL run() throws Exception {
+ return servletContextHelper.getResource(contextController, name);
+ }
+ }, acc
+ );
+ }
+ catch (PrivilegedActionException e) {
+ servletContext.log(e.getException().getMessage(), e.getException());
+ }
+
+ return null;
+ }
+
+ public InputStream getResourceAsStream(String name) {
+ URL url = getResource(name);
+
+ if (url != null) {
+ try {
+ return url.openStream();
+ }
+ catch (IOException ioe) {
+ servletContext.log(ioe.getMessage(), ioe);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @see javax.servlet.ServletContext#getResourcePaths(java.lang.String)
+ */
+ public Set<String> getResourcePaths(final String name) {
+ if (name == null || !name.startsWith(Const.SLASH))
+ return null;
+
+ try {
+ return AccessController.doPrivileged(
+ new PrivilegedExceptionAction<Set<String>>() {
+ public Set<String> run() throws Exception {
+ return servletContextHelper.getResourcePaths(contextController, name);
+ }
+ }, acc
+ );
+ }
+ catch (PrivilegedActionException e) {
+ servletContext.log(e.getException().getMessage(), e.getException());
+ }
+
+ return null;
+ }
+
+ public String getServletContextName() {
+ return contextName;
+ }
+
+ public void removeAttribute(String attributeName) {
+ Dictionary<String, Object> attributes = getContextAttributes();
+ Object attributeValue = attributes.remove(attributeName);
+
+ List<ServletContextAttributeListener> listeners =
+ eventListeners.get(ServletContextAttributeListener.class);
+
+ if (listeners.isEmpty()) {
+ return;
+ }
+
+ ServletContextAttributeEvent servletContextAttributeEvent =
+ new ServletContextAttributeEvent(
+ servletContextTL.get(), attributeName, attributeValue);
+
+ for (ServletContextAttributeListener servletContextAttributeListener : listeners) {
+ servletContextAttributeListener.attributeRemoved(
+ servletContextAttributeEvent);
+ }
+ }
+
+ public void setAttribute(String attributeName, Object attributeValue) {
+ Dictionary<String, Object> attributes = getContextAttributes();
+ boolean added = (attributes.get(attributeName) == null);
+ attributes.put(attributeName, attributeValue);
+
+ List<ServletContextAttributeListener> listeners =
+ eventListeners.get(ServletContextAttributeListener.class);
+
+ if (listeners.isEmpty()) {
+ return;
+ }
+
+ ServletContextAttributeEvent servletContextAttributeEvent =
+ new ServletContextAttributeEvent(
+ servletContextTL.get(), attributeName, attributeValue);
+
+ for (ServletContextAttributeListener servletContextAttributeListener : listeners) {
+ if (added) {
+ servletContextAttributeListener.attributeAdded(
+ servletContextAttributeEvent);
+ }
+ else {
+ servletContextAttributeListener.attributeReplaced(
+ servletContextAttributeEvent);
+ }
+ }
+ }
+
+ Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ servletContextTL.set((ServletContext)proxy);
+
+ try {
+ Method m = contextToHandlerMethods.get(method);
+ if (m != null) {
+ return m.invoke(this, args);
+ }
+ return method.invoke(servletContext, args);
+ }
+ finally {
+ servletContextTL.remove();
+ }
+ }
+
+ private InvocationHandler createInvocationHandler() {
+ return new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+
+ return ServletContextAdaptor.this.invoke(proxy, method, args);
+ }
+ };
+ }
+
+ private Dictionary<String, Object> getContextAttributes() {
+ return proxyContext.getContextAttributes(servletContextHelper);
+ }
+
+ private final AccessControlContext acc;
+ private final Bundle bundle;
+ private final ClassLoader classLoader;
+ private final ContextController contextController;
+ private final String contextName;
+ private final EventListeners eventListeners;
+ private final ProxyContext proxyContext;
+ private final ServletContext servletContext;
+ final ServletContextHelper servletContextHelper;
+ private final ThreadLocal<ServletContext> servletContextTL = new ThreadLocal<ServletContext>();
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/Const.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/Const.java
new file mode 100644
index 00000000..e749c5f5
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/Const.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.util;
+
+/**
+ * @author Raymond Augé
+ */
+public class Const {
+
+ public static final String BLANK = ""; //$NON-NLS-1$
+ public static final String CLOSE_PAREN = ")"; //$NON-NLS-1$
+ public static final String[] EMPTY_ARRAY = new String[0];
+ public static final String EQUAL = "="; //$NON-NLS-1$
+ public static final String FILTER_NAME = "filter-name"; //$NON-NLS-1$
+ public static final String FILTER_PRIORITY = "filter-priority"; //$NON-NLS-1$
+ public static final String OPEN_PAREN = "("; //$NON-NLS-1$
+ public static final String SERVLET_NAME = "servlet-name"; //$NON-NLS-1$
+ public static final String SLASH = "/"; //$NON-NLS-1$
+ public static final String SLASH_STAR = "/*"; //$NON-NLS-1$
+
+ public static enum Dispatcher {
+
+ ASYNC, ERROR, FORWARD, INCLUDE, REQUEST
+
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/EventListeners.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/EventListeners.java
new file mode 100644
index 00000000..1a74c7dc
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/EventListeners.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.util;
+
+import java.util.*;
+import java.util.concurrent.*;
+import org.eclipse.equinox.http.servlet.internal.registration.ListenerRegistration;
+
+public class EventListeners {
+
+ public void clear() {
+ map.clear();
+ }
+
+ public <E extends EventListener> List<E> get(Class<E> clazz) {
+ if (clazz == null) {
+ throw new NullPointerException("clazz can't be null");
+ }
+
+ List<ListenerRegistration> list = map.get(clazz);
+
+ if (list == null) {
+ return Collections.emptyList();
+ }
+
+ return new ListenerList<E>(list) ;
+ }
+
+ public <E extends EventListener> void put(
+ Class<E> clazz, ListenerRegistration listenerRegistration) {
+
+ if (clazz == null) {
+ throw new NullPointerException("clazz can't be null");
+ }
+
+ List<ListenerRegistration> list = map.get(clazz);
+
+ if (list == null) {
+ final List<ListenerRegistration> newList =
+ new CopyOnWriteArrayList<ListenerRegistration>();
+
+ list = map.putIfAbsent(clazz, newList);
+
+ if (list == null) {
+ list = newList;
+ }
+ }
+
+ list.add(listenerRegistration);
+ }
+
+ public void put(
+ List<Class<? extends EventListener>> classes,
+ ListenerRegistration listenerRegistration) {
+
+ for (Class<? extends EventListener> clazz : classes) {
+ put(clazz, listenerRegistration);
+ }
+ }
+
+ public <E extends EventListener> void remove(
+ Class<E> clazz, ListenerRegistration listenerRegistration) {
+
+ if (clazz == null) {
+ throw new NullPointerException("clazz can't be null");
+ }
+
+ List<ListenerRegistration> list = map.get(clazz);
+
+ if (list == null) {
+ return;
+ }
+
+ list.remove(listenerRegistration);
+ }
+
+ public void remove(
+ List<Class<? extends EventListener>> classes,
+ ListenerRegistration listenerRegistration) {
+
+ for (Class<? extends EventListener> clazz : classes) {
+ remove(clazz, listenerRegistration);
+ }
+ }
+
+ private ConcurrentMap<Class<? extends EventListener>, List<ListenerRegistration>> map =
+ new ConcurrentHashMap<Class<? extends EventListener>, List<ListenerRegistration>>();
+
+ class ListenerList<R extends EventListener> extends AbstractList<R> {
+
+ ListenerList(List<ListenerRegistration> list) {
+ this.list = list;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public R get(int index) {
+ return (R)list.get(index).getT();
+ }
+
+ @Override
+ public int size() {
+ return list.size();
+ }
+
+ private List<ListenerRegistration> list;
+
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/HttpTuple.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/HttpTuple.java
new file mode 100644
index 00000000..198b351d
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/HttpTuple.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.util;
+
+import org.eclipse.equinox.http.servlet.internal.HttpServiceFactory;
+import org.eclipse.equinox.http.servlet.internal.HttpServiceRuntimeImpl;
+import org.eclipse.equinox.http.servlet.internal.servlet.ProxyServlet;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.http.runtime.HttpServiceRuntime;
+
+public class HttpTuple {
+
+ public HttpTuple(
+ ProxyServlet proxyServlet,
+ HttpServiceFactory httpServiceFactory,
+ ServiceRegistration<?> hsfRegistration,
+ HttpServiceRuntimeImpl httpServiceRuntime,
+ ServiceRegistration<HttpServiceRuntime> hsrRegistration) {
+
+ this.proxyServlet = proxyServlet;
+ this.httpServiceFactory = httpServiceFactory;
+ this.hsfRegistration = hsfRegistration;
+ this.httpServiceRuntime = httpServiceRuntime;
+ this.hsrRegistration = hsrRegistration;
+ }
+
+ public void destroy() {
+ proxyServlet.setHttpServiceRuntimeImpl(null);
+ hsfRegistration.unregister();
+ hsrRegistration.unregister();
+ httpServiceRuntime.destroy();
+ }
+
+ final HttpServiceFactory httpServiceFactory;
+ final ServiceRegistration<?> hsfRegistration;
+ final HttpServiceRuntimeImpl httpServiceRuntime;
+ final ServiceRegistration<HttpServiceRuntime> hsrRegistration;
+ final ProxyServlet proxyServlet;
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/ServiceReferenceMap.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/ServiceReferenceMap.java
new file mode 100644
index 00000000..d71c606f
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/ServiceReferenceMap.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.util;
+
+import java.util.*;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * @author Raymond Augé
+ */
+public class ServiceReferenceMap extends AbstractMap<String, Object> {
+
+ public ServiceReferenceMap(ServiceReference<?> serviceReference) {
+ String[] propertyKeys = serviceReference.getPropertyKeys();
+
+ entries = new HashSet<Map.Entry<String,Object>>(propertyKeys.length);
+
+ for (String key : propertyKeys) {
+ Map.Entry<String,Object> entry = new ReferenceEntry(
+ key, serviceReference.getProperty(key));
+
+ entries.add(entry);
+ }
+ }
+
+ @Override
+ public Set<java.util.Map.Entry<String, Object>> entrySet() {
+ return entries;
+ }
+
+ private Set<java.util.Map.Entry<String, Object>> entries;
+
+ private class ReferenceEntry implements Map.Entry<String, Object> {
+
+ ReferenceEntry(String key, Object value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ @Override
+ public Object setValue(Object value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Object getValue() {
+ return value;
+ }
+
+ @Override
+ public String getKey() {
+ return key;
+ }
+
+ private String key;
+ private Object value;
+
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/StringPlus.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/StringPlus.java
new file mode 100644
index 00000000..79565119
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/StringPlus.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.util;
+
+import java.util.*;
+
+/**
+ * @author Raymond Augé
+ */
+public class StringPlus {
+
+ @SuppressWarnings("unchecked")
+ public static List<String> from(Object object) {
+ if (String.class.isInstance(object)) {
+ return Collections.singletonList((String)object);
+ }
+ else if (String[].class.isInstance(object)) {
+ return Arrays.asList((String[])object);
+ }
+ else if (Collection.class.isInstance(object)) {
+ Collection<?> collection = (Collection<?>)object;
+
+ if (!collection.isEmpty() &&
+ String.class.isInstance(collection.iterator().next())) {
+
+ return new ArrayList<String>((Collection<String>)object);
+ }
+ }
+
+ return Collections.emptyList();
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/UMDictionaryMap.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/UMDictionaryMap.java
new file mode 100644
index 00000000..ef76eae0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/UMDictionaryMap.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.util;
+
+import java.util.*;
+
+/**
+ * @author Raymond Augé
+ */
+public class UMDictionaryMap <K, V> implements Map<K, V> {
+
+ public UMDictionaryMap(Dictionary<K, V> dictionary) {
+ Map<K, V> map = new HashMap<K, V>();
+
+ if (dictionary != null) {
+ for (Enumeration<K> em = dictionary.keys(); em.hasMoreElements();) {
+ K key = em.nextElement();
+
+ map.put(key, dictionary.get(key));
+ }
+ }
+
+ _map = Collections.unmodifiableMap(map);
+ }
+
+ @Override
+ public int size() {
+ return _map.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return _map.isEmpty();
+ }
+
+ @Override
+ public boolean containsKey(Object key) {
+ return _map.containsKey(key);
+ }
+
+ @Override
+ public boolean containsValue(Object value) {
+ return _map.containsValue(value);
+ }
+
+ @Override
+ public V get(Object key) {
+ return _map.get(key);
+ }
+
+ @Override
+ public V put(K key, V value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public V remove(Object key) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void putAll(Map<? extends K, ? extends V> m) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void clear() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Set<K> keySet() {
+ return _map.keySet();
+ }
+
+ @Override
+ public Collection<V> values() {
+ return _map.values();
+ }
+
+ @Override
+ public Set<java.util.Map.Entry<K, V>> entrySet() {
+ return _map.entrySet();
+ }
+
+ private final Map<K, V> _map;
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/UMMapDictionary.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/UMMapDictionary.java
new file mode 100644
index 00000000..d4172f8d
--- /dev/null
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/util/UMMapDictionary.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Raymond Augé and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Raymond Augé <raymond.auge@liferay.com> - Bug 436698
+ ******************************************************************************/
+
+package org.eclipse.equinox.http.servlet.internal.util;
+
+import java.util.*;
+
+/**
+ * @author Raymond Augé
+ */
+public class UMMapDictionary <K, V> extends Dictionary<K, V> {
+
+ public UMMapDictionary(Map<K, V> map) {
+ if (map == null) {
+ _map = Collections.emptyMap();
+ }
+ else {
+ _map = Collections.unmodifiableMap(map);
+ }
+
+ _keys = Collections.enumeration(_map.keySet());
+ _elements = Collections.enumeration(_map.values());
+ }
+
+ @Override
+ public int size() {
+ return _map.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return _map.isEmpty();
+ }
+
+ @Override
+ public Enumeration<K> keys() {
+ return _keys;
+ }
+
+ @Override
+ public Enumeration<V> elements() {
+ return _elements;
+ }
+
+ @Override
+ public V get(Object key) {
+ return _map.get(key);
+ }
+
+ @Override
+ public V put(K key, V value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public V remove(Object key) {
+ throw new UnsupportedOperationException();
+ }
+
+ private final Enumeration<K> _keys;
+ private final Enumeration<V> _elements;
+ private final Map<K, V> _map;
+
+} \ No newline at end of file

Back to the top