This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new ff62218214 FELIX-6631 : Migrate webconsole plugins to jakarta.servlet 
api
ff62218214 is described below

commit ff62218214cf5431a3c3fd85930de3934d6f95ca
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Tue Aug 22 06:47:26 2023 +0200

    FELIX-6631 : Migrate webconsole plugins to jakarta.servlet api
---
 webconsole-plugins/gogo/pom.xml                    | 33 ++++++++------------
 .../webconsole/plugins/gogo/impl/Activator.java    | 14 ++++++---
 .../webconsole/plugins/gogo/impl/GogoPlugin.java   | 35 ++++++++++------------
 .../plugins/gogo/impl/SessionTerminalManager.java  |  8 ++---
 4 files changed, 42 insertions(+), 48 deletions(-)

diff --git a/webconsole-plugins/gogo/pom.xml b/webconsole-plugins/gogo/pom.xml
index d4a4a3fa9a..c23350ccb3 100644
--- a/webconsole-plugins/gogo/pom.xml
+++ b/webconsole-plugins/gogo/pom.xml
@@ -57,18 +57,10 @@
                                </executions>
                        </plugin>
             
-            <plugin>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <configuration>
-                    <source>1.5</source>
-                    <target>1.5</target>
-                </configuration>
-            </plugin>
-
                        <plugin>
                                <groupId>org.apache.felix</groupId>
                                <artifactId>maven-bundle-plugin</artifactId>
-                               <version>2.3.6</version>
+                               <version>5.1.9</version>
                                <extensions>true</extensions>
                                <configuration>
                                        <instructions>
@@ -78,6 +70,11 @@
                                                <Bundle-Activator>
                                                        
org.apache.felix.webconsole.plugins.gogo.impl.Activator
                         </Bundle-Activator>
+                                               <Import-Package>
+                                                   
jakarta.servlet;version="[5,7)",
+                                                       
jakarta.servlet.http;version="[5,7)",
+                                                       *
+                                               </Import-Package>
                                        </instructions>
                                </configuration>
                        </plugin>
@@ -93,26 +90,20 @@
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
-            <version>4.0.0</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
-            <version>4.0.0</version>
+            <artifactId>osgi.core</artifactId>
+            <version>6.0.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.webconsole</artifactId>
-            <version>3.0.0</version>
+            <version>4.8.13-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>javax.servlet</groupId>
-            <artifactId>servlet-api</artifactId>
-            <version>2.3</version>
+            <groupId>jakarta.servlet</groupId>
+            <artifactId>jakarta.servlet-api</artifactId>
+            <version>5.0.0</version>
             <scope>provided</scope>
         </dependency>
        </dependencies>
diff --git 
a/webconsole-plugins/gogo/src/main/java/org/apache/felix/webconsole/plugins/gogo/impl/Activator.java
 
b/webconsole-plugins/gogo/src/main/java/org/apache/felix/webconsole/plugins/gogo/impl/Activator.java
index 5f6072164d..183fbe331a 100644
--- 
a/webconsole-plugins/gogo/src/main/java/org/apache/felix/webconsole/plugins/gogo/impl/Activator.java
+++ 
b/webconsole-plugins/gogo/src/main/java/org/apache/felix/webconsole/plugins/gogo/impl/Activator.java
@@ -20,22 +20,28 @@ package org.apache.felix.webconsole.plugins.gogo.impl;
 
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+import jakarta.servlet.Servlet;
 
 public class Activator implements BundleActivator {
 
     private SessionTerminalManager terminalManager;
 
-    private GogoPlugin plugin;
+    private ServiceRegistration<Servlet> plugin;
 
     public void start(BundleContext context) throws Exception {
         this.terminalManager = new SessionTerminalManager(context);
-        this.plugin = new GogoPlugin(this.terminalManager);
-        this.plugin.register(context);
+        this.plugin = new GogoPlugin(this.terminalManager).register(context);
     }
 
     public void stop(BundleContext context) throws Exception {
         if (this.plugin != null) {
-            this.plugin.unregister();
+            try {
+                this.plugin.unregister();
+            } catch (IllegalStateException ignore) {
+                // ignore
+            }
             this.plugin = null;
         }
         if (this.terminalManager != null) {
diff --git 
a/webconsole-plugins/gogo/src/main/java/org/apache/felix/webconsole/plugins/gogo/impl/GogoPlugin.java
 
b/webconsole-plugins/gogo/src/main/java/org/apache/felix/webconsole/plugins/gogo/impl/GogoPlugin.java
index 1f29ba0ed5..bdba2bb799 100644
--- 
a/webconsole-plugins/gogo/src/main/java/org/apache/felix/webconsole/plugins/gogo/impl/GogoPlugin.java
+++ 
b/webconsole-plugins/gogo/src/main/java/org/apache/felix/webconsole/plugins/gogo/impl/GogoPlugin.java
@@ -24,17 +24,22 @@ package org.apache.felix.webconsole.plugins.gogo.impl;
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.zip.GZIPOutputStream;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.apache.felix.webconsole.SimpleWebConsolePlugin;
+import jakarta.servlet.Servlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import org.apache.felix.webconsole.servlet.AbstractServlet;
+import org.apache.felix.webconsole.servlet.ServletConstants;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
 
 /**
  * The <code>GogoPlugin</code>
  */
-public class GogoPlugin extends SimpleWebConsolePlugin {
+public class GogoPlugin extends AbstractServlet {
 
     /** Pseudo class version ID to keep the IDE quite. */
     private static final long serialVersionUID = 1L;
@@ -52,26 +57,18 @@ public class GogoPlugin extends SimpleWebConsolePlugin {
     private final SessionTerminalManager terminalManager;
 
     public GogoPlugin(final SessionTerminalManager terminalManager) {
-        super(LABEL, TITLE, null);
         this.terminalManager = terminalManager;
     }
 
-    @Override
-    public void activate(BundleContext bundleContext) {
-        super.activate(bundleContext);
-    }
-
-    @Override
-    public void deactivate() {
-        super.deactivate();
-    }
-
-    public String getCategory()
-    {
-        return CATEGORY;
+    public ServiceRegistration<Servlet> register(final BundleContext 
bundleContext) {
+        final Dictionary<String, Object> props = new Hashtable<>();
+        props.put(ServletConstants.PLUGIN_LABEL, LABEL); 
+        props.put(ServletConstants.PLUGIN_TITLE, TITLE);
+        props.put(ServletConstants.PLUGIN_CATEGORY, CATEGORY);
+        return bundleContext.registerService(Servlet.class, this, props);
     }
 
-    protected void renderContent(HttpServletRequest request, 
HttpServletResponse response) throws IOException {
+    public void renderContent(HttpServletRequest request, HttpServletResponse 
response) throws IOException {
         PrintWriter pw = response.getWriter();
 
         String appRoot = request.getContextPath() + request.getServletPath();
diff --git 
a/webconsole-plugins/gogo/src/main/java/org/apache/felix/webconsole/plugins/gogo/impl/SessionTerminalManager.java
 
b/webconsole-plugins/gogo/src/main/java/org/apache/felix/webconsole/plugins/gogo/impl/SessionTerminalManager.java
index a539ed5088..3c74601773 100644
--- 
a/webconsole-plugins/gogo/src/main/java/org/apache/felix/webconsole/plugins/gogo/impl/SessionTerminalManager.java
+++ 
b/webconsole-plugins/gogo/src/main/java/org/apache/felix/webconsole/plugins/gogo/impl/SessionTerminalManager.java
@@ -23,10 +23,10 @@ import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Set;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import javax.servlet.http.HttpSessionEvent;
-import javax.servlet.http.HttpSessionListener;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpSession;
+import jakarta.servlet.http.HttpSessionEvent;
+import jakarta.servlet.http.HttpSessionListener;
 
 import org.apache.felix.service.command.CommandProcessor;
 import org.osgi.framework.BundleContext;

Reply via email to