diff --git a/bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF index e59feffb2d..9242cdf495 100644 --- a/bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF @@ -41,4 +41,10 @@ Import-Package: com.ibm.icu.text, jakarta.annotation;version="[2.1.0,3.0.0)", jakarta.inject;version="[2.0.0,3.0.0)", org.osgi.service.component.annotations;version="1.2.0";resolution:=optional, - org.osgi.service.event;version="1.3.0" + org.osgi.service.event;version="1.3.0", + org.osgi.service.servlet.context;version="[2.0.0,3.0.0)", + org.osgi.service.servlet.runtime;version="[2.0.0,3.0.0)", + org.osgi.service.servlet.runtime.dto;version="[2.0.0,3.0.0)", + org.osgi.service.servlet.whiteboard;version="[2.0.0,3.0.0)", + org.osgi.service.servlet.whiteboard.annotations;version="[2.0.0,3.0.0)", + org.osgi.service.servlet.whiteboard.propertytypes;version="[2.0.0,3.0.0)" diff --git a/bundles/org.eclipse.rap.rwt.osgi/META-INF/MANIFEST.MF b/bundles/org.eclipse.rap.rwt.osgi/META-INF/MANIFEST.MF index 8f1ddba28a..4b0899565b 100644 --- a/bundles/org.eclipse.rap.rwt.osgi/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.rap.rwt.osgi/META-INF/MANIFEST.MF @@ -14,9 +14,10 @@ Import-Package: jakarta.servlet;version="[5.0.0,7.0.0)", org.eclipse.rap.rwt.internal.application;version="[4.8.0,5.0.0)", org.eclipse.rap.rwt.internal.lifecycle;version="[4.8.0,5.0.0)", org.eclipse.rap.rwt.service;version="[4.8.0,5.0.0)", - org.eclipse.rap.service.http;version="[4.8.0,5.0.0)", org.osgi.framework;version="[1.3.0,2.0.0)", org.osgi.service.log;version="[1.3.0,2.0.0)", + org.osgi.service.servlet.runtime;version="[2.0.0,3.0.0)", + org.osgi.service.servlet.whiteboard;version="[2.0.0,3.0.0)", org.osgi.util.tracker;version="[1.4.0,2.0.0)" Bundle-Activator: org.eclipse.rap.rwt.osgi.internal.Activator Export-Package: org.eclipse.rap.rwt.osgi;version="4.8.0", diff --git a/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/ApplicationLauncher.java b/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/ApplicationLauncher.java index ac31b4c63e..95e88ce203 100644 --- a/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/ApplicationLauncher.java +++ b/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/ApplicationLauncher.java @@ -12,9 +12,7 @@ package org.eclipse.rap.rwt.osgi; import org.eclipse.rap.rwt.application.ApplicationConfiguration; -import org.eclipse.rap.service.http.HttpContext; -import org.eclipse.rap.service.http.HttpService; - +import org.osgi.service.servlet.runtime.HttpServiceRuntime; /** * A launcher for RWT applications in the OSGi environment. An instance of this interface will be @@ -45,11 +43,10 @@ public interface ApplicationLauncher { public static final String PROPERTY_CONTEXT_NAME = "contextName"; /** - * Launches an application with the given configuration at the given HTTPService. + * Launches an application with the given configuration at the given HttpServiceRuntime. * * @param configuration the configuration of the application to start - * @param httpService the http service to start the application at - * @param httpContext the http context to use, or null to use the default context + * @param httpService the HttpServiceRuntime * @param contextName the context name of the application, defines the first URL path segment to * the application * @param contextDirectory the name of a directory to store static web resources @@ -57,8 +54,7 @@ public interface ApplicationLauncher { * @since 4.0 */ ApplicationReference launch( ApplicationConfiguration configuration, - HttpService httpService, - HttpContext httpContext, + HttpServiceRuntime httpService, String contextName, String contextDirectory ); diff --git a/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/ApplicationLauncherImpl.java b/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/ApplicationLauncherImpl.java index 6af8340ac7..1e4376e558 100644 --- a/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/ApplicationLauncherImpl.java +++ b/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/ApplicationLauncherImpl.java @@ -19,18 +19,17 @@ import org.eclipse.rap.rwt.osgi.ApplicationLauncher; import org.eclipse.rap.rwt.osgi.ApplicationReference; import org.eclipse.rap.rwt.osgi.internal.ServiceContainer.ServiceHolder; -import org.eclipse.rap.service.http.HttpContext; -import org.eclipse.rap.service.http.HttpService; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogService; +import org.osgi.service.servlet.runtime.HttpServiceRuntime; public class ApplicationLauncherImpl implements ApplicationLauncher { private final Object lock; private final ServiceContainer configurations; - private final ServiceContainer httpServices; + private final ServiceContainer httpServices; private final HashSet applicationReferences; private BundleContext bundleContext; @@ -42,8 +41,8 @@ public ApplicationLauncherImpl( BundleContext bundleContext ) { this.bundleContext = bundleContext; } - public HttpService addHttpService( ServiceReference reference ) { - ServiceHolder httpServiceHolder; + public HttpServiceRuntime addHttpService( ServiceReference reference ) { + ServiceHolder httpServiceHolder; synchronized( lock ) { httpServiceHolder = httpServices.add( reference ); launchAtHttpService( httpServiceHolder ); @@ -51,7 +50,7 @@ public HttpService addHttpService( ServiceReference reference ) { return httpServiceHolder.getService(); } - public void removeHttpService( HttpService httpService ) { + public void removeHttpService( HttpServiceRuntime httpService ) { synchronized( lock ) { httpServices.remove( httpService ); stopApplicationReferences( httpService ); @@ -77,28 +76,25 @@ public void removeConfiguration( ApplicationConfiguration configuration ) { @Override public ApplicationReference launch( ApplicationConfiguration configuration, - HttpService httpService, - HttpContext httpContext, + HttpServiceRuntime httpService, String contextName, String contextDirectory ) { synchronized( lock ) { if( isAlive() ) { - return doLaunch( configuration, httpService, httpContext, contextName, contextDirectory ); + return doLaunch( configuration, httpService, contextName, contextDirectory ); } return null; } } private ApplicationReferenceImpl doLaunch( ApplicationConfiguration configuration, - HttpService httpService, - HttpContext httpContext, + HttpServiceRuntime httpService, String contextName, String contextDirectory ) { ApplicationReferenceImpl result = new ApplicationReferenceImpl( configuration, httpService, - httpContext, contextName, contextDirectory, this ); @@ -134,7 +130,7 @@ BundleContext getBundleContext() { return bundleContext; } - private void launchAtHttpService( ServiceHolder httpServiceHolder ) { + private void launchAtHttpService( ServiceHolder httpServiceHolder ) { ServiceHolder[] services = configurations.getServices(); for( ServiceHolder configurationHolder : services ) { if( matches( httpServiceHolder, configurationHolder ) ) { @@ -145,8 +141,8 @@ private void launchAtHttpService( ServiceHolder httpServiceHolder ) private void launchWithConfiguration( ServiceHolder configurationHolder ) { - ServiceHolder[] services = httpServices.getServices(); - for( ServiceHolder httpServiceHolder : services ) { + ServiceHolder[] services = httpServices.getServices(); + for( ServiceHolder httpServiceHolder : services ) { if( matches( httpServiceHolder, configurationHolder ) ) { launch( configurationHolder, httpServiceHolder ); } @@ -154,14 +150,14 @@ private void launchWithConfiguration( ServiceHolder co } private void launch( ServiceHolder configurationHolder, - ServiceHolder httpServiceHolder ) + ServiceHolder httpServiceHolder ) { ApplicationConfiguration configuration = configurationHolder.getService(); - HttpService httpService = httpServiceHolder.getService(); + HttpServiceRuntime httpService = httpServiceHolder.getService(); String contextName = getContextName( configurationHolder ); String contextLocation = getLocation( contextName, configuration, httpService ); try { - launch( configuration, httpService, null, contextName, contextLocation ); + launch( configuration, httpService, contextName, contextLocation ); } catch( RuntimeException rte ) { logProblem( "Unable to start RWT application.", rte ); } @@ -197,10 +193,10 @@ void stopApplicationReference( ApplicationReferenceImpl applicationReference ) { } } - private static boolean matches( ServiceHolder httpServiceHolder, + private static boolean matches( ServiceHolder httpServiceHolder, ServiceHolder configurationHolder ) { - ServiceReference httpServiceRef = httpServiceHolder.getReference(); + ServiceReference httpServiceRef = httpServiceHolder.getReference(); ServiceReference configurationRef = configurationHolder.getReference(); return new Matcher( httpServiceRef, configurationRef ).matches(); } @@ -219,7 +215,7 @@ private void logProblem( String failureMessage, Throwable failure ) { String getLocation( String contextName, ApplicationConfiguration configuration, - HttpService service ) + HttpServiceRuntime service ) { String pathToContext = getContextFileName( contextName, configuration, service ); File dataFile = bundleContext.getDataFile( pathToContext ); @@ -228,7 +224,7 @@ String getLocation( String contextName, static String getContextFileName( String name, ApplicationConfiguration configuration, - HttpService service ) + HttpServiceRuntime service ) { return new StringBuilder() .append( name == null ? "rwtcontext" : name ) diff --git a/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/ApplicationReferenceImpl.java b/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/ApplicationReferenceImpl.java index fa820b32e7..8171bf3d8c 100644 --- a/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/ApplicationReferenceImpl.java +++ b/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/ApplicationReferenceImpl.java @@ -12,17 +12,21 @@ package org.eclipse.rap.rwt.osgi.internal; import java.util.Collection; +import java.util.Dictionary; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; import org.eclipse.rap.rwt.application.ApplicationConfiguration; import org.eclipse.rap.rwt.application.ApplicationRunner; import org.eclipse.rap.rwt.engine.RWTServlet; import org.eclipse.rap.rwt.osgi.ApplicationReference; import org.eclipse.rap.rwt.service.ApplicationContext; -import org.eclipse.rap.service.http.HttpContext; -import org.eclipse.rap.service.http.HttpService; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; +import org.osgi.framework.*; +import org.osgi.service.servlet.runtime.HttpServiceRuntime; +import org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants; +import jakarta.servlet.Servlet; import jakarta.servlet.ServletContext; import jakarta.servlet.http.HttpServlet; @@ -34,8 +38,7 @@ class ApplicationReferenceImpl implements ApplicationReference { static final String RAP_HTTP_CONTEXT_CLASS_NAME = "org.eclipse.rap.ui.internal.RAPHttpContext"; private ApplicationConfiguration configuration; - private HttpService httpService; - private HttpContext httpContext; + private HttpServiceRuntime httpService; private String contextLocation; private String contextName; private ServletContext servletContextWrapper; @@ -43,20 +46,24 @@ class ApplicationReferenceImpl implements ApplicationReference { private ApplicationLauncherImpl applicationLauncher; private ServiceRegistration serviceRegistration; private volatile boolean alive; + private BundleContext bundleContext; + + // Whiteboard-Registrierungen, damit wir sie beim Stoppen wieder abmelden koennen. + private final Map> servletRegistrations = new HashMap<>(); + private ServiceRegistration resourceRegistration; ApplicationReferenceImpl( ApplicationConfiguration configuration, - HttpService httpService, - HttpContext httpContext, + HttpServiceRuntime httpService, String contextName, String contextLocation, ApplicationLauncherImpl applicationLauncher ) { this.configuration = configuration; this.httpService = httpService; - this.httpContext = isRAPContext( httpContext ) ? httpContext : wrapHttpContext( httpContext ); this.contextLocation = contextLocation; this.contextName = contextName; this.applicationLauncher = applicationLauncher; + this.bundleContext = FrameworkUtil.getBundle( getClass() ).getBundleContext(); } void start() { @@ -154,18 +161,6 @@ private void unregisterServletContextProviderServlet() { unregisterServlet( SERVLET_CONTEXT_FINDER_ALIAS ); } - private HttpContext wrapHttpContext( HttpContext context ) { - HttpContext wrapped = context != null ? context : httpService.createDefaultHttpContext(); - return new HttpContextWrapper( wrapped ); - } - - private static boolean isRAPContext( HttpContext context ) { - if( context != null ) { - return RAP_HTTP_CONTEXT_CLASS_NAME.equals( context.getClass().getName() ); - } - return false; - } - private HttpServlet registerServletContextProviderServlet() { HttpServlet result = new HttpServlet() { private static final long serialVersionUID = 1L; @@ -186,8 +181,17 @@ private BundleContext getBundleContext() { private void registerServlet( String alias, HttpServlet servlet ) { try { + String pattern = getContextSegment() + alias; HttpServlet wrapper = new CutOffContextPathWrapper( servlet, servletContextWrapper, alias ); - httpService.registerServlet( getContextSegment() + alias, wrapper, null, httpContext ); + Dictionary properties = new Hashtable<>(); + // Muster, unter dem das Servlet erreichbar ist (Whiteboard-Spec). + properties.put( HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, pattern ); + // Eindeutiger Name; optional, aber empfohlen. + properties.put( HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME, + "rwt-servlet" + pattern ); + ServiceRegistration registration + = bundleContext.registerService( Servlet.class, wrapper, properties ); + servletRegistrations.put( pattern, registration ); } catch( RuntimeException rte ) { throw rte; } catch( Exception shouldNotHappen ) { @@ -197,9 +201,16 @@ private void registerServlet( String alias, HttpServlet servlet ) { private void registerResourceDirectory() { String alias = ApplicationRunner.RESOURCES; - String location = contextLocation + "/" + alias; + String prefix = contextLocation + "/" + alias; + String pattern = getContextSegment() + "/" + alias + "/*"; try { - httpService.registerResources( getContextSegment() + "/" + alias, location, httpContext ); + Dictionary properties = new Hashtable<>(); + // Muster + Prefix fuer eine Whiteboard-Ressourcenregistrierung. + properties.put( HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PATTERN, pattern ); + properties.put( HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PREFIX, prefix ); + // Ein beliebiges Marker-Objekt genuegt als Service-Instanz. + resourceRegistration + = bundleContext.registerService( Object.class, new Object(), properties ); } catch( RuntimeException rte ) { throw rte; } catch( Exception shouldNotHappen ) { @@ -209,8 +220,6 @@ private void registerResourceDirectory() { private void clearFields() { applicationRunner = null; - httpService = null; - httpContext = null; configuration = null; contextName = null; contextLocation = null; @@ -219,11 +228,27 @@ private void clearFields() { } private void unregisterServlet( String alias ) { - httpService.unregister( getContextSegment() + alias ); + String pattern = getContextSegment() + alias; + ServiceRegistration registration = servletRegistrations.remove( pattern ); + if( registration != null ) { + try { + registration.unregister(); + } catch( IllegalStateException alreadyUnregistered ) { + // Registrierung wurde bereits abgemeldet - ignorieren. + } + } } private void unregisterResourcesDirectory() { - httpService.unregister( getContextSegment() + "/" + ApplicationRunner.RESOURCES ); + if( resourceRegistration != null ) { + try { + resourceRegistration.unregister(); + } catch( IllegalStateException alreadyUnregistered ) { + // bereits abgemeldet - ignorieren. + } finally { + resourceRegistration = null; + } + } } private void notifyAboutToStop() { @@ -249,5 +274,4 @@ private void markAlive() { private void markNotAlive() { alive = false; } - -} +} \ No newline at end of file diff --git a/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/HttpContextWrapper.java b/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/HttpContextWrapper.java deleted file mode 100644 index 01a36f4201..0000000000 --- a/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/HttpContextWrapper.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2024 Frank Appel 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: - * Frank Appel - initial API and implementation - * EclipseSource - ongoing development - ******************************************************************************/ -package org.eclipse.rap.rwt.osgi.internal; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; - -import org.eclipse.rap.service.http.HttpContext; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - - -class HttpContextWrapper implements HttpContext { - private final HttpContext context; - - HttpContextWrapper( HttpContext context ) { - this.context = context; - } - - @Override - public String getMimeType( String name ) { - return context.getMimeType( name ); - } - - @Override - public URL getResource( String name ) { - URL result = null; - try { - // Preliminary fix for bug 268759 - // 268759: ResourceManager handles non-existing resources incorrectly - File file = new File( name ); - if( file.exists() && !file.isDirectory() ) { - result = file.toURI().toURL(); - } - } catch( MalformedURLException shouldNotHappen ) { - throw new RuntimeException( shouldNotHappen ); - } - return result; - } - - @Override - public boolean handleSecurity( HttpServletRequest request, HttpServletResponse response ) - throws IOException - { - return context.handleSecurity( request, response ); - } - -} diff --git a/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/HttpTracker.java b/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/HttpTracker.java index 999a88ce57..1b75bfa799 100644 --- a/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/HttpTracker.java +++ b/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/HttpTracker.java @@ -10,28 +10,28 @@ ******************************************************************************/ package org.eclipse.rap.rwt.osgi.internal; -import org.eclipse.rap.service.http.HttpService; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; +import org.osgi.service.servlet.runtime.HttpServiceRuntime; import org.osgi.util.tracker.ServiceTracker; -class HttpTracker extends ServiceTracker { +class HttpTracker extends ServiceTracker { private final ApplicationLauncherImpl applicationLauncher; HttpTracker( BundleContext context, ApplicationLauncherImpl applicationLauncher ) { - super( context, HttpService.class.getName(), null ); + super( context, HttpServiceRuntime.class.getName(), null ); this.applicationLauncher = applicationLauncher; } @Override - public HttpService addingService( ServiceReference reference ) { + public HttpServiceRuntime addingService( ServiceReference reference ) { return applicationLauncher.addHttpService( reference ); } @Override - public void removedService( ServiceReference reference, HttpService service ) { + public void removedService( ServiceReference reference, HttpServiceRuntime service ) { applicationLauncher.removeHttpService( service ); } } diff --git a/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/Matcher.java b/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/Matcher.java index 24715cd17c..83dd6b62c4 100644 --- a/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/Matcher.java +++ b/bundles/org.eclipse.rap.rwt.osgi/src/org/eclipse/rap/rwt/osgi/internal/Matcher.java @@ -12,16 +12,16 @@ package org.eclipse.rap.rwt.osgi.internal; import org.eclipse.rap.rwt.application.ApplicationConfiguration; -import org.eclipse.rap.service.http.HttpService; import org.osgi.framework.*; +import org.osgi.service.servlet.runtime.HttpServiceRuntime; class Matcher { - private final ServiceReference httpServiceReference; + private final ServiceReference httpServiceReference; private final ServiceReference configurationReference; - Matcher( ServiceReference httpServiceReference, + Matcher( ServiceReference httpServiceReference, ServiceReference configurationReference ) { this.httpServiceReference = httpServiceReference; @@ -33,7 +33,7 @@ public boolean matches() { } private boolean matchesHttpService() { - return matchesTarget( configurationReference, httpServiceReference, HttpService.class ); + return matchesTarget( configurationReference, httpServiceReference, HttpServiceRuntime.class ); } private boolean matchesConfigurator() { diff --git a/bundles/org.eclipse.rap.ui.workbench/Eclipse UI/org/eclipse/rap/ui/internal/branding/BrandingExtension.java b/bundles/org.eclipse.rap.ui.workbench/Eclipse UI/org/eclipse/rap/ui/internal/branding/BrandingExtension.java index 84115bcf2e..91e0954fe3 100644 --- a/bundles/org.eclipse.rap.ui.workbench/Eclipse UI/org/eclipse/rap/ui/internal/branding/BrandingExtension.java +++ b/bundles/org.eclipse.rap.ui.workbench/Eclipse UI/org/eclipse/rap/ui/internal/branding/BrandingExtension.java @@ -26,10 +26,10 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.rap.rwt.application.Application; import org.eclipse.rap.rwt.service.ResourceLoader; -import org.eclipse.rap.service.http.HttpService; import org.osgi.framework.Bundle; import org.osgi.framework.Filter; import org.osgi.framework.ServiceReference; +import org.osgi.service.servlet.runtime.HttpServiceRuntime; public final class BrandingExtension { @@ -53,10 +53,10 @@ public final class BrandingExtension { private static final String ATT_CLASS = "class"; //$NON-NLS-1$ private final Application application; - private final ServiceReference httpServiceReference; + private final ServiceReference httpServiceReference; public BrandingExtension( Application configuration, - ServiceReference httpServiceReference ) + ServiceReference httpServiceReference ) { this.application = configuration; this.httpServiceReference = httpServiceReference; diff --git a/bundles/org.eclipse.rap.ui.workbench/Eclipse UI/org/eclipse/rap/ui/internal/servlet/HttpServiceTracker.java b/bundles/org.eclipse.rap.ui.workbench/Eclipse UI/org/eclipse/rap/ui/internal/servlet/HttpServiceTracker.java index 47bee71571..4aff3814fb 100644 --- a/bundles/org.eclipse.rap.ui.workbench/Eclipse UI/org/eclipse/rap/ui/internal/servlet/HttpServiceTracker.java +++ b/bundles/org.eclipse.rap.ui.workbench/Eclipse UI/org/eclipse/rap/ui/internal/servlet/HttpServiceTracker.java @@ -14,67 +14,51 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Platform; -import org.eclipse.rap.http.registry.HttpContextExtensionService; import org.eclipse.rap.rwt.application.ApplicationConfiguration; import org.eclipse.rap.rwt.osgi.ApplicationLauncher; import org.eclipse.rap.rwt.osgi.ApplicationReference; -import org.eclipse.rap.service.http.HttpContext; -import org.eclipse.rap.service.http.HttpService; + import org.eclipse.ui.PlatformUI; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.util.tracker.ServiceTracker; +import org.osgi.service.servlet.runtime.HttpServiceRuntime; -public class HttpServiceTracker extends ServiceTracker { - - public static final String ID_HTTP_CONTEXT = "org.eclipse.rap.httpcontext"; +public class HttpServiceTracker extends ServiceTracker { - private HttpContextExtensionService httpCtxExtService; - private HttpContextTracker httpContextTracker; private ApplicationLauncherTracker applicationLauncherTracker; private ApplicationLauncher applicationLauncher; private ApplicationReference applicationReference; public HttpServiceTracker( BundleContext context ) { - super( context, HttpService.class.getName(), null ); + super( context, HttpServiceRuntime.class.getName(), null ); } @Override - public HttpService addingService( ServiceReference reference ) { - HttpService result = context.getService( reference ); - HttpContext httpContext = httpCtxExtService.getHttpContext( reference, ID_HTTP_CONTEXT ); - applicationReference = startApplication( reference, result, httpContext ); + public HttpServiceRuntime addingService( ServiceReference reference ) { + HttpServiceRuntime result = context.getService( reference ); + applicationLauncherTracker = new ApplicationLauncherTracker( context ); + applicationLauncherTracker.open(); + applicationReference = startApplication( reference, result ); return result; } @Override - public void removedService( ServiceReference reference, HttpService service ) { + public void removedService( ServiceReference reference, HttpServiceRuntime service ) { applicationReference.stopApplication(); + applicationLauncherTracker.close(); super.removedService( reference, service ); } - @Override - public void open() { - httpContextTracker = new HttpContextTracker( context ); - httpContextTracker.open(); - } - - @Override - public void close() { - super.close(); - httpContextTracker.close(); - } - - private ApplicationReference startApplication( ServiceReference httpServiceReference, - HttpService service, - HttpContext context ) + private ApplicationReference startApplication( ServiceReference httpServiceReference, + HttpServiceRuntime service ) { ApplicationConfiguration configuration = new WorkbenchApplicationConfiguration( httpServiceReference ); String contextDirectory = findContextPath().toString(); - return applicationLauncher.launch( configuration, service, context, null, contextDirectory ); + return applicationLauncher.launch( configuration, service, null, contextDirectory ); } private static IPath findContextPath() { @@ -83,35 +67,6 @@ private static IPath findContextPath() { return stateLocation.append( "context" ); } - private class HttpContextTracker - extends ServiceTracker - { - - private HttpContextTracker( BundleContext context ) { - super( context, HttpContextExtensionService.class.getName(), null ); - } - - @Override - public HttpContextExtensionService - addingService( ServiceReference reference ) - { - HttpContextExtensionService result = super.addingService( reference ); - httpCtxExtService = context.getService( reference ); - applicationLauncherTracker = new ApplicationLauncherTracker( context ); - applicationLauncherTracker.open(); - return result; - } - - @Override - public void removedService( ServiceReference reference, - HttpContextExtensionService service ) - { - applicationLauncherTracker.close(); - httpCtxExtService = null; - super.removedService( reference, service ); - } - } - private class ApplicationLauncherTracker extends ServiceTracker { diff --git a/bundles/org.eclipse.rap.ui.workbench/Eclipse UI/org/eclipse/rap/ui/internal/servlet/WorkbenchApplicationConfiguration.java b/bundles/org.eclipse.rap.ui.workbench/Eclipse UI/org/eclipse/rap/ui/internal/servlet/WorkbenchApplicationConfiguration.java index 2c81d75253..d99082e918 100644 --- a/bundles/org.eclipse.rap.ui.workbench/Eclipse UI/org/eclipse/rap/ui/internal/servlet/WorkbenchApplicationConfiguration.java +++ b/bundles/org.eclipse.rap.ui.workbench/Eclipse UI/org/eclipse/rap/ui/internal/servlet/WorkbenchApplicationConfiguration.java @@ -42,7 +42,6 @@ import org.eclipse.rap.rwt.service.ResourceLoader; import org.eclipse.rap.rwt.service.ServiceHandler; import org.eclipse.rap.rwt.service.SettingStoreFactory; -import org.eclipse.rap.service.http.HttpService; import org.eclipse.rap.ui.internal.application.EntryPointApplicationWrapper; import org.eclipse.rap.ui.internal.branding.AbstractBranding; import org.eclipse.rap.ui.internal.branding.BrandingExtension; @@ -57,6 +56,7 @@ import org.osgi.framework.Constants; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; +import org.osgi.service.servlet.runtime.HttpServiceRuntime; public class WorkbenchApplicationConfiguration implements ApplicationConfiguration { @@ -76,7 +76,7 @@ public class WorkbenchApplicationConfiguration implements ApplicationConfigurati private static final String PT_APPLICATIONS = "applications"; //$NON-NLS-1$ private static final String PT_APP_VISIBLE = "visible"; //$NON-NLS-1$ - private final ServiceReference httpServiceReference; + private final ServiceReference httpServiceReference; // Default constructor to enable subclassing without adding a dependency to OSGi API public WorkbenchApplicationConfiguration() { @@ -86,7 +86,7 @@ public WorkbenchApplicationConfiguration() { /* * Note [rst]: public as per request in https://bugs.eclipse.org/bugs/show_bug.cgi?id=372183 */ - public WorkbenchApplicationConfiguration( ServiceReference httpServiceReference ) { + public WorkbenchApplicationConfiguration( ServiceReference httpServiceReference ) { this.httpServiceReference = httpServiceReference; } diff --git a/bundles/org.eclipse.rap.ui.workbench/META-INF/MANIFEST.MF b/bundles/org.eclipse.rap.ui.workbench/META-INF/MANIFEST.MF index 5dd34e8b2b..e9da727e66 100644 --- a/bundles/org.eclipse.rap.ui.workbench/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.rap.ui.workbench/META-INF/MANIFEST.MF @@ -102,7 +102,6 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)";visibili org.eclipse.rap.rwt;bundle-version="[4.8.0,5.0.0)", org.eclipse.help;bundle-version="[3.6.0,4.0.0)", org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)", - org.eclipse.rap.http.registry;bundle-version="[4.8.0,5.0.0)", org.eclipse.rap.jface.databinding;bundle-version="[4.8.0,5.0.0)", org.eclipse.core.databinding.property;bundle-version="[1.2.0,2.0.0)", org.eclipse.core.databinding.observable;bundle-version="[1.2.0,2.0.0)" @@ -113,7 +112,7 @@ Import-Package: com.ibm.icu.text, javax.xml.parsers, org.eclipse.rap.rwt.osgi;version="[4.8.0,5.0.0)", org.osgi.service.event;version="1.3.0", - org.eclipse.rap.service.http;version="[4.8.0,5.0.0)", + org.osgi.service.servlet.runtime;version="[2.0.0,3.0.0)", org.w3c.dom, org.xml.sax Bundle-RequiredExecutionEnvironment: JavaSE-21 diff --git a/bundles/org.eclipse.rap.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.rap.ui/META-INF/MANIFEST.MF index 60a5dd663e..28277627ca 100644 --- a/bundles/org.eclipse.rap.ui/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.rap.ui/META-INF/MANIFEST.MF @@ -10,7 +10,7 @@ Bundle-Vendor: %Plugin.providerName Bundle-Localization: plugin Import-Package: jakarta.servlet.http;version="[5.0.0,7.0.0)", org.osgi.service.event;version="1.3.0", - org.eclipse.rap.service.http;version="[4.8.0,5.0.0)" + org.osgi.service.servlet.context;version="[2.0.0,3.0.0)" Export-Package: org.eclipse.ui.internal;x-friends:="org.eclipse.rap.ui" Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)", org.eclipse.rap.rwt;bundle-version="[4.8.0,5.0.0)";visibility:=reexport, diff --git a/bundles/org.eclipse.rap.ui/src/org/eclipse/rap/ui/internal/RAPHttpContext.java b/bundles/org.eclipse.rap.ui/src/org/eclipse/rap/ui/internal/RAPHttpContext.java index 60f06d1053..0414b5f7dc 100644 --- a/bundles/org.eclipse.rap.ui/src/org/eclipse/rap/ui/internal/RAPHttpContext.java +++ b/bundles/org.eclipse.rap.ui/src/org/eclipse/rap/ui/internal/RAPHttpContext.java @@ -16,8 +16,8 @@ import java.net.URL; import org.eclipse.core.runtime.Platform; -import org.eclipse.rap.service.http.HttpContext; import org.osgi.framework.Bundle; +import org.osgi.service.servlet.context.ServletContextHelper; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @@ -25,7 +25,7 @@ // NOTE: This was added to org.eclipse.rap.ui to avoid starting // the workbench bundle before the context is established. The latter // uses the context already on startup -public final class RAPHttpContext implements HttpContext { +public final class RAPHttpContext extends ServletContextHelper { private final Bundle bundle; diff --git a/tests/org.eclipse.rap.rwt.jstest/META-INF/MANIFEST.MF b/tests/org.eclipse.rap.rwt.jstest/META-INF/MANIFEST.MF index 5c70fe6e75..e57f4d2599 100644 --- a/tests/org.eclipse.rap.rwt.jstest/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.rap.rwt.jstest/META-INF/MANIFEST.MF @@ -13,8 +13,10 @@ Require-Bundle: org.eclipse.rap.http.jetty;bundle-version="[4.8.0,5.0.0)", org.eclipse.rap.rwt;bundle-version="[4.8.0,5.0.0)" Import-Package: jakarta.servlet;version="6.0.0", jakarta.servlet.http;version="6.0.0", - org.eclipse.rap.service.http;version="[4.8.0,5.0.0)", org.osgi.framework;version="1.6.0", + org.osgi.service.servlet.runtime;version="[2.0.0,3.0.0)", + org.osgi.service.servlet.runtime.dto;version="[2.0.0,3.0.0)", + org.osgi.service.servlet.whiteboard;version="[2.0.0,3.0.0)", org.osgi.util.tracker;version="1.5.0" Bundle-Vendor: Eclipse.org - RAP Bundle-Activator: org.eclipse.rap.rwt.jstest.internal.Activator diff --git a/tests/org.eclipse.rap.rwt.jstest/src/org/eclipse/rap/rwt/jstest/internal/HttpServiceTracker.java b/tests/org.eclipse.rap.rwt.jstest/src/org/eclipse/rap/rwt/jstest/internal/HttpServiceTracker.java index c13cd7ce28..838859f723 100644 --- a/tests/org.eclipse.rap.rwt.jstest/src/org/eclipse/rap/rwt/jstest/internal/HttpServiceTracker.java +++ b/tests/org.eclipse.rap.rwt.jstest/src/org/eclipse/rap/rwt/jstest/internal/HttpServiceTracker.java @@ -10,47 +10,90 @@ ******************************************************************************/ package org.eclipse.rap.rwt.jstest.internal; -import org.eclipse.rap.service.http.HttpService; -import org.eclipse.rap.service.http.NamespaceException; +import java.util.Dictionary; +import java.util.Hashtable; + import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.servlet.runtime.HttpServiceRuntime; +import org.osgi.service.servlet.runtime.HttpServiceRuntimeConstants; +import org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants; import org.osgi.util.tracker.ServiceTracker; -public class HttpServiceTracker extends ServiceTracker { +public class HttpServiceTracker + extends ServiceTracker +{ + + private final BundleContext context; + + // Registrations for the whiteboard-based services + private ServiceRegistration resourceRegistration; public HttpServiceTracker( BundleContext context ) { - super( context, HttpService.class.getName(), null ); + super( context, HttpServiceRuntime.class.getName(), null ); + this.context = context; } @Override - public HttpService addingService( ServiceReference reference ) { - HttpService httpService = super.addingService( reference ); + public HttpServiceRuntime addingService( ServiceReference reference ) { + HttpServiceRuntime runtime = super.addingService( reference ); try { - register( httpService ); - String port = ( String )reference.getProperty( "http.port" ); - printUrl( port ); + registerWhiteboardResources(); + printUrl( reference ); } catch( Exception exception ) { - throw new RuntimeException( "Failed to add http service", exception ); + throw new RuntimeException( "Failed to add http service runtime", exception ); } - return httpService; + return runtime; } @Override - public void removedService( ServiceReference reference, HttpService service ) { - unregister( service ); + public void removedService( ServiceReference reference, + HttpServiceRuntime service ) + { + unregisterWhiteboardResources(); } - private void register( HttpService httpService ) throws NamespaceException { - httpService.registerResources( "/", "/htdocs", null ); + + private void registerWhiteboardResources() { + Dictionary properties = new Hashtable<>(); + // Maps requests under /resources to files under /htdocs in the bundle + properties.put( HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PATTERN, + "/resources/*" ); + properties.put( HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PREFIX, + "/htdocs" ); + // A resource service is registered as an arbitrary marker service. + resourceRegistration = + context.registerService( Object.class, new Object(), properties ); } - private void unregister( HttpService service ) { - service.unregister( "/" ); + private void unregisterWhiteboardResources() { + if( resourceRegistration != null ) { + resourceRegistration.unregister(); + resourceRegistration = null; + } } - private void printUrl( String port ) { + private void printUrl( ServiceReference reference ) { + // The runtime advertises its endpoints via the standard property + Object endpoints = + reference.getProperty( HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT ); System.out.println( "Open this URL to start the tests:" ); - System.out.println( "http://localhost:" + port + "/index.html" ); + if( endpoints instanceof String[] && ( ( String[] )endpoints ).length > 0 ) { + String base = ( ( String[] )endpoints )[ 0 ]; + if( !base.endsWith( "/" ) ) { + base = base + "/"; + } + System.out.println( base + "index.html" ); + } else if( endpoints instanceof String ) { + String base = ( String )endpoints; + if( !base.endsWith( "/" ) ) { + base = base + "/"; + } + System.out.println( base + "index.html" ); + } else { + System.out.println( "/index.html" ); + } } -} +} \ No newline at end of file