You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2023/08/21 13:51:44 UTC
[felix-dev] branch jakarta-servlet-6 updated (7462920294 -> a0621b6f95)
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a change to branch jakarta-servlet-6
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
from 7462920294 No need to branch webconsole l18n modules
new 60fbd5ea70 No need to branch depback plugin
new 1d5b52db1c Port changes from main branch
new a0621b6f95 Port changes from main branch
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
webconsole-plugins/deppack/changelog.txt | 6 -
webconsole-plugins/deppack/pom.xml | 154 -----------
.../plugins/deppack/internal/Activator.java | 98 -------
.../plugins/deppack/internal/WebConsolePlugin.java | 260 ------------------
.../main/resources/OSGI-INF/l10n/bundle.properties | 40 ---
.../resources/OSGI-INF/l10n/bundle_bg.properties | 40 ---
.../resources/OSGI-INF/l10n/bundle_de.properties | 40 ---
.../resources/OSGI-INF/l10n/bundle_ru.properties | 40 ---
.../deppack/src/main/resources/res/plugin.css | 19 --
.../deppack/src/main/resources/res/plugin.html | 55 ----
.../deppack/src/main/resources/res/plugin.js | 172 ------------
webconsole/pom.xml | 7 +
.../felix/webconsole/DefaultVariableResolver.java | 2 +
.../apache/felix/webconsole/VariableResolver.java | 1 +
.../felix/webconsole/WebConsoleConstants.java | 3 +
.../apache/felix/webconsole/WebConsoleUtil.java | 302 ---------------------
.../felix/webconsole/i18n/LocalizationHelper.java | 10 +-
.../internal/WebConsolePluginAdapter.java | 16 +-
.../webconsole/internal/compendium/LogServlet.java | 8 +-
.../internal/configuration/ConfigManager.java | 43 +--
.../internal/core/BaseUpdateInstallHelper.java | 2 +-
.../webconsole/internal/core/BundlesServlet.java | 57 ++--
.../webconsole/internal/core/InstallHelper.java | 2 +-
.../core/PermissionsConfigurationPrinter.java | 6 +-
.../core/ServicesConfigurationPrinter.java | 64 +----
.../webconsole/internal/core/ServicesServlet.java | 50 ++--
.../internal/core/ServicesUsedInfoProvider.java | 9 +-
.../webconsole/internal/core/UpdateHelper.java | 2 +-
.../internal/filter/FilteringResponseWrapper.java | 41 +--
.../internal/filter/ResourceFilteringWriter.java | 9 +-
.../internal/i18n/CombinedEnumeration.java | 26 +-
.../internal/i18n/CombinedResourceBundle.java | 2 +-
.../i18n/ConsolePropertyResourceBundle.java | 26 +-
.../internal/i18n/ResourceBundleCache.java | 87 +++---
.../internal/misc/ConfigurationRender.java | 2 +-
.../webconsole/internal/misc/LicenseServlet.java | 13 +-
.../internal/misc/SystemPropertiesPrinter.java | 9 +-
.../servlet}/AbstractWebConsolePlugin.java | 95 ++++---
.../JakartaServletAdapter.java} | 202 ++++++--------
.../webconsole/internal/servlet/OsgiManager.java | 12 +-
.../felix/webconsole/internal/servlet/Plugin.java | 11 +-
.../webconsole/internal/servlet/PluginHolder.java | 25 +-
.../servlet}/SimpleWebConsolePlugin.java | 19 +-
.../internal/servlet/WebConsoleUtil.java | 169 ++++++++++++
.../webconsole/internal/system/VMStatPlugin.java | 12 +-
.../felix/webconsole/servlet/AbstractServlet.java | 201 ++++++++++++++
.../servlet/RequestVariableResolver.java | 62 +++++
.../felix/webconsole/servlet/ServletConstants.java | 75 +++++
.../webconsole/{i18n => servlet}/package-info.java | 2 +-
.../servlet}/AbstractWebConsolePluginTest.java | 8 +-
.../internal/servlet/OsgiManagerTest.java | 4 +-
51 files changed, 908 insertions(+), 1712 deletions(-)
delete mode 100755 webconsole-plugins/deppack/changelog.txt
delete mode 100644 webconsole-plugins/deppack/pom.xml
delete mode 100644 webconsole-plugins/deppack/src/main/java/org/apache/felix/webconsole/plugins/deppack/internal/Activator.java
delete mode 100644 webconsole-plugins/deppack/src/main/java/org/apache/felix/webconsole/plugins/deppack/internal/WebConsolePlugin.java
delete mode 100644 webconsole-plugins/deppack/src/main/resources/OSGI-INF/l10n/bundle.properties
delete mode 100644 webconsole-plugins/deppack/src/main/resources/OSGI-INF/l10n/bundle_bg.properties
delete mode 100644 webconsole-plugins/deppack/src/main/resources/OSGI-INF/l10n/bundle_de.properties
delete mode 100644 webconsole-plugins/deppack/src/main/resources/OSGI-INF/l10n/bundle_ru.properties
delete mode 100644 webconsole-plugins/deppack/src/main/resources/res/plugin.css
delete mode 100644 webconsole-plugins/deppack/src/main/resources/res/plugin.html
delete mode 100644 webconsole-plugins/deppack/src/main/resources/res/plugin.js
delete mode 100755 webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
rename webconsole/src/main/java/org/apache/felix/webconsole/{ => internal/servlet}/AbstractWebConsolePlugin.java (93%)
copy webconsole/src/main/java/org/apache/felix/webconsole/internal/{WebConsolePluginAdapter.java => servlet/JakartaServletAdapter.java} (52%)
rename webconsole/src/main/java/org/apache/felix/webconsole/{ => internal/servlet}/SimpleWebConsolePlugin.java (92%)
create mode 100755 webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/WebConsoleUtil.java
create mode 100755 webconsole/src/main/java/org/apache/felix/webconsole/servlet/AbstractServlet.java
create mode 100755 webconsole/src/main/java/org/apache/felix/webconsole/servlet/RequestVariableResolver.java
create mode 100755 webconsole/src/main/java/org/apache/felix/webconsole/servlet/ServletConstants.java
copy webconsole/src/main/java/org/apache/felix/webconsole/{i18n => servlet}/package-info.java (95%)
rename webconsole/src/test/java/org/apache/felix/webconsole/{ => internal/servlet}/AbstractWebConsolePluginTest.java (95%)
[felix-dev] 03/03: Port changes from main branch
Posted by cz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch jakarta-servlet-6
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
commit a0621b6f959002f04cab23672112d21bec4267fb
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Aug 21 15:51:37 2023 +0200
Port changes from main branch
---
.../felix/webconsole/DefaultVariableResolver.java | 2 +
.../apache/felix/webconsole/VariableResolver.java | 1 +
.../felix/webconsole/WebConsoleConstants.java | 3 +
.../apache/felix/webconsole/WebConsoleUtil.java | 302 ---------------------
.../internal/WebConsolePluginAdapter.java | 15 +-
.../webconsole/internal/compendium/LogServlet.java | 8 +-
.../internal/configuration/ConfigManager.java | 12 +-
.../internal/core/BaseUpdateInstallHelper.java | 2 +-
.../webconsole/internal/core/BundlesServlet.java | 12 +-
.../webconsole/internal/core/InstallHelper.java | 2 +-
.../webconsole/internal/core/ServicesServlet.java | 8 +-
.../webconsole/internal/core/UpdateHelper.java | 2 +-
.../internal/filter/FilteringResponseWrapper.java | 2 +-
.../internal/misc/ConfigurationRender.java | 2 +-
.../webconsole/internal/misc/LicenseServlet.java | 8 +-
.../servlet}/AbstractWebConsolePlugin.java | 95 ++++---
.../internal/servlet/JakartaServletAdapter.java | 45 +--
.../internal/servlet/JakartaServletTracker.java | 106 --------
.../webconsole/internal/servlet/OsgiManager.java | 2 -
.../felix/webconsole/internal/servlet/Plugin.java | 7 +-
.../webconsole/internal/servlet/PluginHolder.java | 20 --
.../servlet}/SimpleWebConsolePlugin.java | 19 +-
.../internal/servlet/WebConsoleUtil.java | 169 ++++++++++++
.../webconsole/internal/system/VMStatPlugin.java | 6 +-
.../servlet}/AbstractWebConsolePluginTest.java | 4 +-
25 files changed, 294 insertions(+), 560 deletions(-)
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/DefaultVariableResolver.java b/webconsole/src/main/java/org/apache/felix/webconsole/DefaultVariableResolver.java
index b6885262c1..40fe2a6207 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/DefaultVariableResolver.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/DefaultVariableResolver.java
@@ -22,6 +22,8 @@ package org.apache.felix.webconsole;
import java.util.HashMap;
import java.util.Map;
+import org.apache.felix.webconsole.internal.servlet.WebConsoleUtil;
+
/**
* The <code>DefaultVariableResolver</code> is a <code>HashMap</code> based
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/VariableResolver.java b/webconsole/src/main/java/org/apache/felix/webconsole/VariableResolver.java
index 23ffc49a65..47bd0cf12d 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/VariableResolver.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/VariableResolver.java
@@ -18,6 +18,7 @@
*/
package org.apache.felix.webconsole;
+import org.apache.felix.webconsole.internal.servlet.WebConsoleUtil;
/**
* The <code>VariableResolver</code> interface defines the API for an object
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java
index bc09cf4d1c..fb2b52cb69 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleConstants.java
@@ -18,6 +18,9 @@
*/
package org.apache.felix.webconsole;
+import org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin;
+import org.apache.felix.webconsole.internal.servlet.WebConsoleUtil;
+
/**
* WebConsoleConstants provides some common constants that are used by plugin
* developers.
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
deleted file mode 100755
index 447d0ccd5b..0000000000
--- a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.webconsole;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.Array;
-import java.net.URLDecoder;
-
-import jakarta.servlet.ServletRequest;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-
-
-/**
- * The <code>WebConsoleUtil</code> provides various utility methods for use
- * by Web Console plugins.
- */
-public final class WebConsoleUtil
-{
-
- private WebConsoleUtil()
- {
- /* no instantiation */
- }
-
- /**
- * Returns the {@link VariableResolver} for the given request.
- * <p>
- * If no resolver has yet be created for the requests, an instance of the
- * {@link DefaultVariableResolver} is created with preset properties,
- * placed into the request and returned. The preset properties are
- * <code>appRoot</code> set to the value of the
- * {@link WebConsoleConstants#ATTR_APP_ROOT} request attribute and
- * <code>pluginRoot</code> set to the value of the
- * {@link WebConsoleConstants#ATTR_PLUGIN_ROOT} request attribute.
- * <p>
- * <b>Note</b>: An object not implementing the {@link VariableResolver}
- * interface already stored as the
- * {@link WebConsoleConstants#ATTR_CONSOLE_VARIABLE_RESOLVER} attribute
- * will silently be replaced by the {@link DefaultVariableResolver}
- * instance.
- *
- * @param request The request whose attribute is returned (or set)
- *
- * @return The {@link VariableResolver} for the given request.
- */
- @SuppressWarnings("unchecked")
- public static VariableResolver getVariableResolver( final ServletRequest request )
- {
- final Object resolverObj = request.getAttribute( WebConsoleConstants.ATTR_CONSOLE_VARIABLE_RESOLVER );
- if ( resolverObj instanceof VariableResolver )
- {
- return ( VariableResolver ) resolverObj;
- }
-
- final DefaultVariableResolver resolver = new DefaultVariableResolver();
- resolver.put( "appRoot", request.getAttribute( WebConsoleConstants.ATTR_APP_ROOT ) );
- resolver.put( "pluginRoot", request.getAttribute( WebConsoleConstants.ATTR_PLUGIN_ROOT ) );
- setVariableResolver( request, resolver );
- return resolver;
- }
-
-
- /**
- * Sets the {@link VariableResolver} as the
- * {@link WebConsoleConstants#ATTR_CONSOLE_VARIABLE_RESOLVER}
- * attribute in the given request. An attribute of that name already
- * existing is silently replaced.
- *
- * @param request The request whose attribute is set
- * @param resolver The {@link VariableResolver} to place into the request
- */
- public static void setVariableResolver( final ServletRequest request, final VariableResolver resolver )
- {
- request.setAttribute( WebConsoleConstants.ATTR_CONSOLE_VARIABLE_RESOLVER, resolver );
- }
-
- /**
- * Utility method to handle relative redirects.
- * Some application servers like Web Sphere handle relative redirects differently
- * therefore we should make an absolute URL before invoking send redirect.
- *
- * @param request the HTTP request coming from the user
- * @param response the HTTP response, where data is rendered
- * @param redirectUrl the redirect URI.
- * @throws IOException If an input or output exception occurs
- * @throws IllegalStateException If the response was committed or if a partial
- * URL is given and cannot be converted into a valid URL
- */
- public static final void sendRedirect(final HttpServletRequest request,
- final HttpServletResponse response,
- String redirectUrl) throws IOException {
- // check for relative URL
- if ( !redirectUrl.startsWith("/") ) { //$NON-NLS-1$
- String base = request.getContextPath() + request.getServletPath() + request.getPathInfo();
- int i = base.lastIndexOf('/');
- if (i > -1) {
- base = base.substring(0, i);
- } else {
- i = base.indexOf(':');
- base = (i > -1) ? base.substring(i + 1, base.length()) : ""; //$NON-NLS-1$
- }
- if (!base.startsWith("/")) { //$NON-NLS-1$
- base = '/' + base;
- }
- redirectUrl = base + '/' + redirectUrl;
-
- }
- response.sendRedirect(redirectUrl);
- }
-
- /**
- * Sets response headers to force the client to not cache the response
- * sent back. This method must be called before the response is committed
- * otherwise it will have no effect.
- * <p>
- * This method sets the <code>Cache-Control</code>, <code>Expires</code>,
- * and <code>Pragma</code> headers.
- *
- * @param response The response for which to set the cache prevention
- */
- public static final void setNoCache(final HttpServletResponse response) {
- response.setHeader("Cache-Control", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$
- response.addHeader("Cache-Control", "no-store"); //$NON-NLS-1$ //$NON-NLS-2$
- response.addHeader("Cache-Control", "must-revalidate"); //$NON-NLS-1$ //$NON-NLS-2$
- response.addHeader("Cache-Control", "max-age=0"); //$NON-NLS-1$ //$NON-NLS-2$
- response.setHeader("Expires", "Thu, 01 Jan 1970 01:00:00 GMT"); //$NON-NLS-1$ //$NON-NLS-2$
- response.setHeader("Pragma", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Escapes HTML special chars like: <>&\r\n and space
- *
- *
- * @param text the text to escape
- * @return the escaped text
- */
- public static final String escapeHtml(String text)
- {
- StringBuilder sb = new StringBuilder(text.length() * 4 / 3);
- char ch, oldch = '_';
- for (int i = 0; i < text.length(); i++)
- {
- switch (ch = text.charAt(i))
- {
- case '<':
- sb.append("<"); //$NON-NLS-1$
- break;
- case '>':
- sb.append(">"); //$NON-NLS-1$
- break;
- case '&':
- sb.append("&"); //$NON-NLS-1$
- break;
- case ' ':
- sb.append(" "); //$NON-NLS-1$
- break;
- case '\'':
- sb.append("'"); //$NON-NLS-1$
- break;
- case '"':
- sb.append("""); //$NON-NLS-1$
- break;
- case '\r':
- case '\n':
- if (oldch != '\r' && oldch != '\n') // don't add twice <br>
- sb.append("<br/>\n"); //$NON-NLS-1$
- break;
- default:
- sb.append(ch);
- }
- oldch = ch;
- }
-
- return sb.toString();
- }
-
- /**
- * Retrieves a request parameter and converts it to int.
- *
- * @param request the HTTP request
- * @param name the name of the request parameter
- * @param _default the default value returned if the parameter is not set or is not a valid integer.
- * @return the request parameter if set and is valid integer, or the default value
- */
- public static final int getParameterInt(HttpServletRequest request, String name,
- int _default)
- {
- int ret = _default;
- String param = request.getParameter(name);
- try
- {
- if (param != null)
- ret = Integer.parseInt(param);
- }
- catch (NumberFormatException nfe)
- {
- // don't care, will return default
- }
-
- return ret;
- }
-
- /**
- * Decode the given value expected to be URL encoded.
- * <p>
- * This method first tries to use the Java 1.4 method
- * <code>URLDecoder.decode(String, String)</code> method and falls back to
- * the now deprecated <code>URLDecoder.decode(String, String)</code>
- * which uses the platform character set to decode the string. This is
- * because the platforms before 1.4 and most notably some OSGi Execution
- * Environments (such as Minimum EE) do not provide the newer method.
- *
- * @param value the value to decode
- * @return the decoded string
- */
- @SuppressWarnings("deprecation")
- public static String urlDecode( final String value )
- {
- // shortcut for empty or missing values
- if ( value == null || value.length() == 0 )
- {
- return value;
- }
-
- try {
- return URLDecoder.decode( value, "UTF-8" );
- } catch (UnsupportedEncodingException e) {
- return URLDecoder.decode( value );
- }
- }
-
- /**
- * This method will stringify a Java object. It is mostly used to print the values
- * of unknown properties. This method will correctly handle if the passed object
- * is array and will property display it.
- *
- * If the value is byte[] the elements are shown as Hex
- *
- * @param value the value to convert
- * @return the string representation of the value
- */
- public static final String toString(Object value)
- {
- if (value == null)
- {
- return "n/a"; //$NON-NLS-1$
- }
- else if (value.getClass().isArray())
- {
- final StringBuilder sb = new StringBuilder();
- final int len = Array.getLength(value);
- sb.append('[');
- for (int i = 0; i < len; i++)
- {
- final Object element = Array.get(value, i);
- if (element instanceof Byte)
- {
- // convert byte[] to hex string
- sb.append("0x"); //$NON-NLS-1$
- final String x = Integer.toHexString(((Byte) element).intValue() & 0xff);
- if (1 == x.length())
- {
- sb.append('0');
- }
- sb.append(x);
- }
- else
- {
- sb.append(toString(element));
- }
-
- if (i < len - 1)
- {
- sb.append(", "); //$NON-NLS-1$
- }
- }
- return sb.append(']').toString();
- }
- else
- {
- return value.toString();
- }
- }
-}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/WebConsolePluginAdapter.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/WebConsolePluginAdapter.java
index 4eb6742585..ef2c37ff90 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/WebConsolePluginAdapter.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/WebConsolePluginAdapter.java
@@ -21,8 +21,9 @@ package org.apache.felix.webconsole.internal;
import java.io.IOException;
import java.util.*;
-import org.apache.felix.webconsole.AbstractWebConsolePlugin;
+
import org.apache.felix.webconsole.WebConsoleConstants;
+import org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin;
import org.osgi.framework.ServiceReference;
import jakarta.servlet.Servlet;
@@ -78,7 +79,7 @@ public class WebConsolePluginAdapter extends AbstractWebConsolePlugin
/**
* Returns the label of this plugin page as defined in the constructor.
*
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#getLabel()
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#getLabel()
*/
public String getLabel()
{
@@ -91,7 +92,7 @@ public class WebConsolePluginAdapter extends AbstractWebConsolePlugin
* {@link WebConsoleConstants#PLUGIN_TITLE} service registration attribute
* which is exposed as the servlet name in the servlet configuration.
*
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#getTitle()
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#getTitle()
*/
public String getTitle()
{
@@ -106,7 +107,7 @@ public class WebConsolePluginAdapter extends AbstractWebConsolePlugin
* {@link WebConsoleConstants#PLUGIN_CSS_REFERENCES felix.webconsole.css}
* service registration property of the plugin.
*
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#getCssReferences()
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#getCssReferences()
*/
protected String[] getCssReferences()
{
@@ -118,7 +119,7 @@ public class WebConsolePluginAdapter extends AbstractWebConsolePlugin
* Call the plugin servlet's service method to render the content of this
* page.
*
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
*/
protected void renderContent( HttpServletRequest req, HttpServletResponse res ) throws ServletException,
IOException
@@ -132,7 +133,7 @@ public class WebConsolePluginAdapter extends AbstractWebConsolePlugin
* <code>getResource()</code> method on that object for this plugin to
* provide additional resources.
*
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#getResourceProvider()
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#getResourceProvider()
*/
protected Object getResourceProvider()
{
@@ -182,7 +183,7 @@ public class WebConsolePluginAdapter extends AbstractWebConsolePlugin
* method is called without any decorations and without setting any
* response headers.
*
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#isHtmlRequest(jakarta.servlet.http.HttpServletRequest)
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#isHtmlRequest(jakarta.servlet.http.HttpServletRequest)
*/
protected boolean isHtmlRequest( final HttpServletRequest request )
{
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/LogServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/LogServlet.java
index e3a2e147a8..ef2d216fe8 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/LogServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/LogServlet.java
@@ -28,9 +28,9 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.felix.utils.json.JSONWriter;
-import org.apache.felix.webconsole.SimpleWebConsolePlugin;
-import org.apache.felix.webconsole.WebConsoleUtil;
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
+import org.apache.felix.webconsole.internal.servlet.SimpleWebConsolePlugin;
+import org.apache.felix.webconsole.internal.servlet.WebConsoleUtil;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
@@ -120,7 +120,7 @@ public class LogServlet extends SimpleWebConsolePlugin implements OsgiManagerPlu
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#doGet(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#doGet(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
*/
protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException,
IOException
@@ -141,7 +141,7 @@ public class LogServlet extends SimpleWebConsolePlugin implements OsgiManagerPlu
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
*/
protected void renderContent( HttpServletRequest request, HttpServletResponse response ) throws IOException
{
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
index efed40249b..cef84138a3 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
@@ -19,6 +19,8 @@ package org.apache.felix.webconsole.internal.configuration;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@@ -29,12 +31,12 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.felix.utils.json.JSONWriter;
-import org.apache.felix.webconsole.SimpleWebConsolePlugin;
import org.apache.felix.webconsole.WebConsoleConstants;
-import org.apache.felix.webconsole.WebConsoleUtil;
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
import org.apache.felix.webconsole.internal.Util;
import org.apache.felix.webconsole.internal.misc.ServletSupport;
+import org.apache.felix.webconsole.internal.servlet.SimpleWebConsolePlugin;
+import org.apache.felix.webconsole.internal.servlet.WebConsoleUtil;
import org.apache.felix.webconsole.servlet.RequestVariableResolver;
import org.apache.felix.webconsole.spi.ConfigurationHandler;
import org.apache.felix.webconsole.spi.ValidationException;
@@ -145,7 +147,7 @@ public class ConfigManager extends SimpleWebConsolePlugin implements OsgiManager
String pid = request.getParameter( ConfigManager.PID );
if ( pid == null ) {
String info = request.getPathInfo();
- pid = WebConsoleUtil.urlDecode( info.substring( info.lastIndexOf( '/' ) + 1 ) );
+ pid = URLDecoder.decode( info.substring( info.lastIndexOf( '/' ) + 1 ), StandardCharsets.UTF_8 );
}
// ignore this request if the PID is invalid / not provided
if ( pid == null || pid.length() == 0 || !ConfigurationUtil.isAllowedPid(pid)) {
@@ -224,7 +226,7 @@ public class ConfigManager extends SimpleWebConsolePlugin implements OsgiManager
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#doGet(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#doGet(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
*/
@Override
protected void doGet( HttpServletRequest request, HttpServletResponse response )
@@ -351,7 +353,7 @@ public class ConfigManager extends SimpleWebConsolePlugin implements OsgiManager
}
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
*/
@Override
protected void renderContent( HttpServletRequest request, HttpServletResponse response ) throws IOException
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BaseUpdateInstallHelper.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BaseUpdateInstallHelper.java
index f3ae105e90..bb24b49500 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BaseUpdateInstallHelper.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BaseUpdateInstallHelper.java
@@ -28,7 +28,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-import org.apache.felix.webconsole.SimpleWebConsolePlugin;
+import org.apache.felix.webconsole.internal.servlet.SimpleWebConsolePlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
index 7c585b58e6..206e8c47a4 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
@@ -52,13 +52,13 @@ import org.apache.felix.utils.json.JSONWriter;
import org.apache.felix.utils.manifest.Clause;
import org.apache.felix.utils.manifest.Parser;
import org.apache.felix.webconsole.ConfigurationPrinter;
-import org.apache.felix.webconsole.SimpleWebConsolePlugin;
import org.apache.felix.webconsole.WebConsoleConstants;
-import org.apache.felix.webconsole.WebConsoleUtil;
import org.apache.felix.webconsole.bundleinfo.BundleInfo;
import org.apache.felix.webconsole.bundleinfo.BundleInfoProvider;
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
import org.apache.felix.webconsole.internal.Util;
+import org.apache.felix.webconsole.internal.servlet.SimpleWebConsolePlugin;
+import org.apache.felix.webconsole.internal.servlet.WebConsoleUtil;
import org.apache.felix.webconsole.servlet.RequestVariableResolver;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -147,7 +147,7 @@ public class BundlesServlet extends SimpleWebConsolePlugin implements OsgiManage
}
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#activate(org.osgi.framework.BundleContext)
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#activate(org.osgi.framework.BundleContext)
*/
@Override
public void activate( BundleContext bundleContext ) {
@@ -203,7 +203,7 @@ public class BundlesServlet extends SimpleWebConsolePlugin implements OsgiManage
/**
- * @see org.apache.felix.webconsole.SimpleWebConsolePlugin#deactivate()
+ * @see org.apache.felix.webconsole.internal.servlet.SimpleWebConsolePlugin#deactivate()
*/
@Override
public void deactivate()
@@ -322,7 +322,7 @@ public class BundlesServlet extends SimpleWebConsolePlugin implements OsgiManage
//---------- BaseWebConsolePlugin
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#doGet(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#doGet(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
*/
@Override
protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException,
@@ -516,7 +516,7 @@ public class BundlesServlet extends SimpleWebConsolePlugin implements OsgiManage
}
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
*/
@Override
protected void renderContent( HttpServletRequest request, HttpServletResponse response ) throws IOException
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/InstallHelper.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/InstallHelper.java
index 6801df2f6c..fb5a135349 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/InstallHelper.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/InstallHelper.java
@@ -22,7 +22,7 @@ package org.apache.felix.webconsole.internal.core;
import java.io.File;
import java.io.InputStream;
-import org.apache.felix.webconsole.SimpleWebConsolePlugin;
+import org.apache.felix.webconsole.internal.servlet.SimpleWebConsolePlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
index 284f3bcda1..e5aa362dff 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
@@ -30,12 +30,12 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.felix.utils.json.JSONWriter;
-import org.apache.felix.webconsole.SimpleWebConsolePlugin;
import org.apache.felix.webconsole.WebConsoleConstants;
-import org.apache.felix.webconsole.WebConsoleUtil;
import org.apache.felix.webconsole.bundleinfo.BundleInfoProvider;
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
import org.apache.felix.webconsole.internal.Util;
+import org.apache.felix.webconsole.internal.servlet.SimpleWebConsolePlugin;
+import org.apache.felix.webconsole.internal.servlet.WebConsoleUtil;
import org.apache.felix.webconsole.servlet.RequestVariableResolver;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -377,7 +377,7 @@ public class ServicesServlet extends SimpleWebConsolePlugin implements OsgiManag
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#doGet(jakarta.servlet.http.HttpServletRequest, jalarta.servlet.http.HttpServletResponse)
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#doGet(jakarta.servlet.http.HttpServletRequest, jalarta.servlet.http.HttpServletResponse)
*/
protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException,
IOException
@@ -404,7 +404,7 @@ public class ServicesServlet extends SimpleWebConsolePlugin implements OsgiManag
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
*/
protected void renderContent( HttpServletRequest request, HttpServletResponse response ) throws IOException
{
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/UpdateHelper.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/UpdateHelper.java
index c9616a4dd6..7d052a751d 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/UpdateHelper.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/UpdateHelper.java
@@ -23,7 +23,7 @@ import java.io.File;
import java.io.InputStream;
import org.apache.felix.bundlerepository.Reason;
-import org.apache.felix.webconsole.SimpleWebConsolePlugin;
+import org.apache.felix.webconsole.internal.servlet.SimpleWebConsolePlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/filter/FilteringResponseWrapper.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/filter/FilteringResponseWrapper.java
index e262be2954..899ddef4dc 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/filter/FilteringResponseWrapper.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/filter/FilteringResponseWrapper.java
@@ -27,7 +27,7 @@ import jakarta.servlet.ServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponseWrapper;
-import org.apache.felix.webconsole.WebConsoleUtil;
+import org.apache.felix.webconsole.internal.servlet.WebConsoleUtil;
import org.apache.felix.webconsole.servlet.RequestVariableResolver;
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
index ac3aed49ed..9cdb380c8d 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
@@ -19,7 +19,7 @@ package org.apache.felix.webconsole.internal.misc;
import java.io.PrintWriter;
-import org.apache.felix.webconsole.WebConsoleUtil;
+import org.apache.felix.webconsole.internal.servlet.WebConsoleUtil;
public class ConfigurationRender
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
index 639abf2c3d..869ae3b782 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
@@ -42,10 +42,10 @@ import jakarta.servlet.http.HttpServletResponse;
import org.apache.felix.utils.json.JSONWriter;
import org.apache.felix.utils.manifest.Clause;
import org.apache.felix.utils.manifest.Parser;
-import org.apache.felix.webconsole.SimpleWebConsolePlugin;
-import org.apache.felix.webconsole.WebConsoleUtil;
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
import org.apache.felix.webconsole.internal.Util;
+import org.apache.felix.webconsole.internal.servlet.SimpleWebConsolePlugin;
+import org.apache.felix.webconsole.internal.servlet.WebConsoleUtil;
import org.apache.felix.webconsole.servlet.RequestVariableResolver;
import org.osgi.framework.Bundle;
@@ -86,7 +86,7 @@ public final class LicenseServlet extends SimpleWebConsolePlugin implements Osgi
}
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#doGet(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#doGet(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
@@ -107,7 +107,7 @@ public final class LicenseServlet extends SimpleWebConsolePlugin implements Osgi
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
*/
protected void renderContent( HttpServletRequest request, HttpServletResponse res ) throws IOException
{
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/AbstractWebConsolePlugin.java
similarity index 93%
rename from webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
rename to webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/AbstractWebConsolePlugin.java
index 097cf31625..fffdf69d08 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/AbstractWebConsolePlugin.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.felix.webconsole;
+package org.apache.felix.webconsole.internal.servlet;
import java.io.IOException;
@@ -44,7 +44,10 @@ import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
-import org.apache.felix.webconsole.internal.servlet.OsgiManager;
+import org.apache.felix.webconsole.BrandingPlugin;
+import org.apache.felix.webconsole.DefaultBrandingPlugin;
+import org.apache.felix.webconsole.WebConsoleConstants;
+import org.apache.felix.webconsole.servlet.RequestVariableResolver;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.service.log.LogService;
@@ -77,7 +80,7 @@ public abstract class AbstractWebConsolePlugin extends HttpServlet
*
* @see #getResourceProvider()
*/
- public static final String GET_RESOURCE_METHOD_NAME = "getResource"; //$NON-NLS-1$
+ public static final String GET_RESOURCE_METHOD_NAME = "getResource";
/**
* The header fragment read from the templates/main_header.html file
@@ -182,9 +185,9 @@ public abstract class AbstractWebConsolePlugin extends HttpServlet
renderTopNavigation( request, pw );
// wrap content in a separate div
- pw.println( "<div id='content'>" ); //$NON-NLS-1$
+ pw.println( "<div id='content'>" );
renderContent( request, response );
- pw.println( "</div>" ); //$NON-NLS-1$
+ pw.println( "</div>" );
// close the main div, body, and html
endResponse( pw );
@@ -565,7 +568,7 @@ public abstract class AbstractWebConsolePlugin extends HttpServlet
long lastModified = connection.getLastModified();
if ( lastModified > 0 )
{
- long ifModifiedSince = request.getDateHeader( "If-Modified-Since" ); //$NON-NLS-1$
+ long ifModifiedSince = request.getDateHeader( "If-Modified-Since" );
if ( ifModifiedSince >= ( lastModified / 1000 * 1000 ) )
{
// Round down to the nearest second for a proper compare
@@ -576,12 +579,12 @@ public abstract class AbstractWebConsolePlugin extends HttpServlet
}
// have to send, so set the last modified header now
- response.setDateHeader( "Last-Modified", lastModified ); //$NON-NLS-1$
+ response.setDateHeader( "Last-Modified", lastModified );
}
// describe the contents
response.setContentType( getServletContext().getMimeType( pi ) );
- response.setIntHeader( "Content-Length", connection.getContentLength() ); //$NON-NLS-1$
+ response.setIntHeader( "Content-Length", connection.getContentLength() );
// spool the actual contents
OutputStream out = response.getOutputStream();
@@ -613,11 +616,10 @@ public abstract class AbstractWebConsolePlugin extends HttpServlet
* @throws IOException on I/O error
* @see #endResponse(PrintWriter)
*/
- @SuppressWarnings({ "unchecked" })
protected PrintWriter startResponse( HttpServletRequest request, HttpServletResponse response ) throws IOException
{
- response.setCharacterEncoding( "utf-8" ); //$NON-NLS-1$
- response.setContentType( "text/html" ); //$NON-NLS-1$
+ response.setCharacterEncoding( "utf-8" );
+ response.setContentType( "text/html" );
final PrintWriter pw = response.getWriter();
@@ -625,24 +627,21 @@ public abstract class AbstractWebConsolePlugin extends HttpServlet
// support localization of the plugin title
String title = getTitle();
- if ( title.startsWith( "%" ) ) //$NON-NLS-1$
+ if ( title.startsWith( "%" ) )
{
- title = "${" + title.substring( 1 ) + "}"; //$NON-NLS-1$ //$NON-NLS-2$
+ title = "${" + title.substring( 1 ) + "}";
}
- VariableResolver resolver = WebConsoleUtil.getVariableResolver(request);
- if (resolver instanceof DefaultVariableResolver) {
- DefaultVariableResolver r = (DefaultVariableResolver) resolver;
- r.put("head.title", title); //$NON-NLS-1$
- r.put("head.label", getLabel()); //$NON-NLS-1$
- r.put("head.cssLinks", getCssLinks(appRoot)); //$NON-NLS-1$
- r.put("brand.name", brandingPlugin.getBrandName()); //$NON-NLS-1$
- r.put("brand.product.url", brandingPlugin.getProductURL()); //$NON-NLS-1$
- r.put("brand.product.name", brandingPlugin.getProductName()); //$NON-NLS-1$
- r.put("brand.product.img", toUrl( brandingPlugin.getProductImage(), appRoot )); //$NON-NLS-1$
- r.put("brand.favicon", toUrl( brandingPlugin.getFavIcon(), appRoot )); //$NON-NLS-1$
- r.put("brand.css", toUrl( brandingPlugin.getMainStyleSheet(), appRoot )); //$NON-NLS-1$
- }
+ RequestVariableResolver r = WebConsoleUtil.getRequestVariableResolver(request);
+ r.put("head.title", title);
+ r.put("head.label", getLabel());
+ r.put("head.cssLinks", getCssLinks(appRoot));
+ r.put("brand.name", brandingPlugin.getBrandName());
+ r.put("brand.product.url", brandingPlugin.getProductURL());
+ r.put("brand.product.name", brandingPlugin.getProductName());
+ r.put("brand.product.img", toUrl( brandingPlugin.getProductImage(), appRoot ));
+ r.put("brand.favicon", toUrl( brandingPlugin.getFavIcon(), appRoot ));
+ r.put("brand.css", toUrl( brandingPlugin.getMainStyleSheet(), appRoot ));
pw.println( getHeader() );
return pw;
@@ -660,7 +659,7 @@ public abstract class AbstractWebConsolePlugin extends HttpServlet
{
// assume pathInfo to not be null, else this would not be called
String current = request.getPathInfo();
- int slash = current.indexOf( "/", 1 ); //$NON-NLS-1$
+ int slash = current.indexOf( "/", 1 );
if ( slash < 0 )
{
slash = current.length();
@@ -688,14 +687,14 @@ public abstract class AbstractWebConsolePlugin extends HttpServlet
}
if (!langMap.containsKey(locale))
{
- locale = "en"; //$NON-NLS-1$
+ locale = "en";
}
- pw.println("<div id='langSelect'>"); //$NON-NLS-1$
- pw.println(" <span>"); //$NON-NLS-1$
+ pw.println("<div id='langSelect'>");
+ pw.println(" <span>");
printLocaleElement(pw, appRoot, locale, langMap.get(locale));
- pw.println(" </span>"); //$NON-NLS-1$
- pw.println(" <span class='flags ui-helper-hidden'>"); //$NON-NLS-1$
+ pw.println(" </span>");
+ pw.println(" <span class='flags ui-helper-hidden'>");
for (Iterator li = langMap.keySet().iterator(); li.hasNext();)
{
// <img src="us.gif" alt="en" title="English"/>
@@ -706,8 +705,8 @@ public abstract class AbstractWebConsolePlugin extends HttpServlet
}
}
- pw.println(" </span>"); //$NON-NLS-1$
- pw.println("</div>"); //$NON-NLS-1$
+ pw.println(" </span>");
+ pw.println("</div>");
}
}
@@ -759,15 +758,15 @@ public abstract class AbstractWebConsolePlugin extends HttpServlet
private static final void printLocaleElement( PrintWriter pw, String appRoot, Object langCode, Object langName )
{
- pw.print(" <img src='"); //$NON-NLS-1$
+ pw.print(" <img src='");
pw.print(appRoot);
- pw.print("/res/flags/"); //$NON-NLS-1$
+ pw.print("/res/flags/");
pw.print(langCode);
- pw.print(".gif' alt='"); //$NON-NLS-1$
+ pw.print(".gif' alt='");
pw.print(langCode);
- pw.print("' title='"); //$NON-NLS-1$
+ pw.print("' title='");
pw.print(langName);
- pw.println("'/>"); //$NON-NLS-1$
+ pw.println("'/>");
}
/**
@@ -841,7 +840,7 @@ public abstract class AbstractWebConsolePlugin extends HttpServlet
// (for example plugin provided CSS links)
if ( HEADER == null )
{
- HEADER = readTemplateFile( AbstractWebConsolePlugin.class, "/templates/main_header.html" ); //$NON-NLS-1$
+ HEADER = readTemplateFile( AbstractWebConsolePlugin.class, "/templates/main_header.html" );
}
return HEADER;
}
@@ -851,7 +850,7 @@ public abstract class AbstractWebConsolePlugin extends HttpServlet
{
if ( FOOTER == null )
{
- FOOTER = readTemplateFile( AbstractWebConsolePlugin.class, "/templates/main_footer.html" ); //$NON-NLS-1$
+ FOOTER = readTemplateFile( AbstractWebConsolePlugin.class, "/templates/main_footer.html" );
}
return FOOTER;
}
@@ -903,12 +902,12 @@ public abstract class AbstractWebConsolePlugin extends HttpServlet
catch ( IOException e )
{
// don't use new Exception(message, cause) because cause is 1.4+
- throw new RuntimeException( "readTemplateFile: Error loading " + templateFile + ": " + e ); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new RuntimeException( "readTemplateFile: Error loading " + templateFile + ": " + e ); //$NON-NLS-2$
}
// template file does not exist, return an empty string
- log( LogService.LOG_ERROR, "readTemplateFile: File '" + templateFile + "' not found through class " + clazz ); //$NON-NLS-1$ //$NON-NLS-2$
- return ""; //$NON-NLS-1$
+ log( LogService.LOG_ERROR, "readTemplateFile: File '" + templateFile + "' not found through class " + clazz ); //$NON-NLS-2$
+ return "";
}
@@ -918,16 +917,16 @@ public abstract class AbstractWebConsolePlugin extends HttpServlet
final String[] cssRefs = getCssReferences();
if ( cssRefs == null )
{
- return ""; //$NON-NLS-1$
+ return "";
}
// build the CSS links from the references
final StringBuilder buf = new StringBuilder();
for ( int i = 0; i < cssRefs.length; i++ )
{
- buf.append( "<link href='" ); //$NON-NLS-1$
+ buf.append( "<link href='" );
buf.append( toUrl( cssRefs[i], appRoot ) );
- buf.append( "' rel='stylesheet' type='text/css' />" ); //$NON-NLS-1$
+ buf.append( "' rel='stylesheet' type='text/css' />" );
}
return buf.toString();
@@ -948,7 +947,7 @@ public abstract class AbstractWebConsolePlugin extends HttpServlet
*/
private static final String toUrl( final String url, final String appRoot )
{
- if ( url.startsWith( "/" ) ) //$NON-NLS-1$
+ if ( url.startsWith( "/" ) )
{
return appRoot + url;
}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/JakartaServletAdapter.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/JakartaServletAdapter.java
index a4c1d1d86d..73dc625749 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/JakartaServletAdapter.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/JakartaServletAdapter.java
@@ -22,21 +22,17 @@ package org.apache.felix.webconsole.internal.servlet;
import java.io.IOException;
import java.util.*;
-import javax.servlet.Servlet;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.felix.http.jakartawrappers.HttpServletRequestWrapper;
-import org.apache.felix.http.jakartawrappers.HttpServletResponseWrapper;
-import org.apache.felix.http.jakartawrappers.ServletConfigWrapper;
-import org.apache.felix.http.javaxwrappers.ServletExceptionUtil;
-import org.apache.felix.webconsole.AbstractWebConsolePlugin;
import org.apache.felix.webconsole.servlet.AbstractServlet;
import org.apache.felix.webconsole.servlet.ServletConstants;
import org.osgi.framework.ServiceReference;
+import jakarta.servlet.Servlet;
+import jakarta.servlet.ServletConfig;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.servlet.http.HttpServletResponseWrapper;
+
/**
* The <code>JakartaServletAdapter</code> is an adapter to the
* {@link AbstractWebConsolePlugin} for regular servlets registered with the
@@ -98,12 +94,7 @@ public class JakartaServletAdapter extends AbstractWebConsolePlugin {
@Override
protected void renderContent( final HttpServletRequest req, final HttpServletResponse res )
throws ServletException, IOException {
- try {
- plugin.renderContent( (jakarta.servlet.http.HttpServletRequest)HttpServletRequestWrapper.getWrapper(req),
- (jakarta.servlet.http.HttpServletResponse)HttpServletResponseWrapper.getWrapper(res) );
- } catch (final jakarta.servlet.ServletException s) {
- throw ServletExceptionUtil.getServletException(s);
- }
+ plugin.renderContent(req, res);
}
/**
@@ -111,9 +102,9 @@ public class JakartaServletAdapter extends AbstractWebConsolePlugin {
* <code>getResource()</code> method on that object for this plugin to
* provide additional resources.
*
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#getResourceProvider()
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#getResourceProvider()
*/
- protected Object getResourceProvider() {
+ public Object getResourceProvider() {
return plugin;
}
@@ -133,11 +124,7 @@ public class JakartaServletAdapter extends AbstractWebConsolePlugin {
super.init( config );
// plugin initialization
- try {
- plugin.init( new ServletConfigWrapper(config) );
- } catch ( final jakarta.servlet.ServletException s) {
- throw ServletExceptionUtil.getServletException(s);
- }
+ plugin.init( config );
} catch ( ServletException se ) {
// if init fails, the plugin will not be destroyed and thus
// the plugin not deactivated. Do it here
@@ -189,10 +176,9 @@ public class JakartaServletAdapter extends AbstractWebConsolePlugin {
super.setStatus(sc);
}
- @Override
public void setStatus(final int sc, final String sm) {
this.done = true;
- super.setStatus(sc, sm);
+ super.setStatus(sc);
}
}
@@ -209,12 +195,7 @@ public class JakartaServletAdapter extends AbstractWebConsolePlugin {
throws ServletException, IOException {
final CheckHttpServletResponse checkResponse = new CheckHttpServletResponse(resp);
// call plugin first
- try {
- plugin.service( (jakarta.servlet.http.HttpServletRequest)HttpServletRequestWrapper.getWrapper(req),
- (jakarta.servlet.http.HttpServletResponse)HttpServletResponseWrapper.getWrapper(resp) );
- } catch (final jakarta.servlet.ServletException s) {
- throw ServletExceptionUtil.getServletException(s);
- }
+ plugin.service(req, resp);
// if a GET request and plugin did not create a response yet, call super to get full HTML response
if ( !checkResponse.isDone() && req.getMethod().equals( "GET" ) ) {
// handle the GET request here and call into plugin on renderContent
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/JakartaServletTracker.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/JakartaServletTracker.java
deleted file mode 100755
index b0e1a140a1..0000000000
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/JakartaServletTracker.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.felix.webconsole.internal.servlet;
-
-
-import java.io.Closeable;
-
-import org.apache.felix.http.javaxwrappers.ServletWrapper;
-import org.apache.felix.webconsole.WebConsoleConstants;
-import org.apache.felix.webconsole.internal.Util;
-import org.apache.felix.webconsole.internal.servlet.Plugin.ServletPlugin;
-import org.apache.felix.webconsole.servlet.AbstractServlet;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
-
-import jakarta.servlet.Servlet;
-
-public class JakartaServletTracker implements Closeable, ServiceTrackerCustomizer<Servlet, JakartaServletTracker.JakartaServletPlugin> {
-
- private final ServiceTracker<Servlet, JakartaServletPlugin> servletTracker;
-
- private final PluginHolder pluginHolder;
-
- public JakartaServletTracker( final PluginHolder pluginHolder, final BundleContext context ) {
- this.pluginHolder = pluginHolder;
- Filter filter = null;
- try {
- filter = context.createFilter("(&(" + Constants.OBJECTCLASS + "=" + Servlet.class.getName() +
- ")(" + WebConsoleConstants.PLUGIN_LABEL + "=*))");
- } catch (final InvalidSyntaxException e) {
- // not expected, thus fail hard
- throw new InternalError( "Failed creating filter: " + e.getMessage() );
- }
- this.servletTracker = new ServiceTracker<>(context, filter, this);
- servletTracker.open();
- }
-
- @Override
- public void close() {
- servletTracker.close();
- }
-
- @Override
- public JakartaServletPlugin addingService( final org.osgi.framework.ServiceReference<Servlet> reference ) {
- final String label = Util.getStringProperty( reference, WebConsoleConstants.PLUGIN_LABEL );
- if ( label != null ) {
- final JakartaServletPlugin plugin = new JakartaServletPlugin(this.pluginHolder, reference, label);
- pluginHolder.addPlugin(plugin);
- return plugin;
- }
- return null;
- }
-
- @Override
- public void modifiedService( final org.osgi.framework.ServiceReference<Servlet> reference, final JakartaServletPlugin service ) {
- this.removedService(reference, service);
- this.addingService(reference);
- }
-
- @Override
- public void removedService( final org.osgi.framework.ServiceReference<Servlet> reference, final JakartaServletPlugin service ) {
- this.pluginHolder.removePlugin(service);
- }
-
- public static class JakartaServletPlugin extends ServletPlugin {
-
- @SuppressWarnings({"unchecked", "rawtypes"})
- public JakartaServletPlugin(PluginHolder holder, ServiceReference<jakarta.servlet.Servlet> serviceReference,
- String label) {
- super(holder, (ServiceReference)serviceReference, label);
- }
-
- @SuppressWarnings({"unchecked", "rawtypes"})
- protected javax.servlet.Servlet getService() {
- final Servlet servlet = (Servlet) getHolder().getBundleContext().getService( (ServiceReference)this.getServiceReference() );
- if (servlet != null) {
- if ( servlet instanceof AbstractServlet ) {
- return new JakartaServletAdapter((AbstractServlet)servlet, this.getServiceReference());
- }
- return new ServletWrapper(servlet);
- }
- return null;
- }
- }
-}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
index ea763fe8e1..522dc9b38c 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
@@ -39,14 +39,12 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
-import org.apache.felix.webconsole.AbstractWebConsolePlugin;
import org.apache.felix.webconsole.BrandingPlugin;
import org.apache.felix.webconsole.User;
import org.apache.felix.webconsole.WebConsoleConstants;
import org.apache.felix.webconsole.WebConsoleSecurityProvider;
import org.apache.felix.webconsole.WebConsoleSecurityProvider2;
import org.apache.felix.webconsole.WebConsoleSecurityProvider3;
-import org.apache.felix.webconsole.WebConsoleUtil;
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
import org.apache.felix.webconsole.internal.Util;
import org.apache.felix.webconsole.internal.core.BundlesServlet;
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/Plugin.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/Plugin.java
index c9c5e32ef7..815c557b28 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/Plugin.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/Plugin.java
@@ -22,11 +22,11 @@ import java.util.Collections;
import java.util.Enumeration;
import java.util.NoSuchElementException;
-import org.apache.felix.webconsole.AbstractWebConsolePlugin;
import org.apache.felix.webconsole.WebConsoleConstants;
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
import org.apache.felix.webconsole.internal.Util;
import org.apache.felix.webconsole.internal.WebConsolePluginAdapter;
+import org.apache.felix.webconsole.servlet.AbstractServlet;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
@@ -199,10 +199,13 @@ public abstract class Plugin implements ServletConfig, Comparable<Plugin> {
}
protected AbstractWebConsolePlugin doGetConsolePlugin() {
- final Servlet service = getService();
+ Servlet service = getService();
if ( service != null ) {
this.title = Util.getStringProperty( this.getServiceReference(), WebConsoleConstants.PLUGIN_TITLE );
this.category = Util.getStringProperty( this.getServiceReference(), WebConsoleConstants.PLUGIN_CATEGORY );
+ if ( service instanceof AbstractServlet ) {
+ service = new JakartaServletAdapter((AbstractServlet)service, this.getServiceReference());
+ }
final AbstractWebConsolePlugin servlet;
if ( service instanceof AbstractWebConsolePlugin ) {
servlet = ( AbstractWebConsolePlugin ) service;
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/PluginHolder.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/PluginHolder.java
index f4671525c9..0e22c614f1 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/PluginHolder.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/PluginHolder.java
@@ -18,8 +18,6 @@
*/
package org.apache.felix.webconsole.internal.servlet;
-import java.io.Closeable;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -28,7 +26,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
-import org.apache.felix.webconsole.AbstractWebConsolePlugin;
import org.apache.felix.webconsole.WebConsoleConstants;
import org.apache.felix.webconsole.internal.Util;
import org.apache.felix.webconsole.internal.i18n.ResourceBundleManager;
@@ -69,8 +66,6 @@ class PluginHolder implements ServiceTrackerCustomizer<Servlet, Plugin> {
private final ServiceTracker<Servlet, Plugin> servletTracker;
- private volatile Closeable jakartaTracker;
-
PluginHolder( final OsgiManager osgiManager, final BundleContext context ) {
this.osgiManager = osgiManager;
this.bundleContext = context;
@@ -95,13 +90,6 @@ class PluginHolder implements ServiceTrackerCustomizer<Servlet, Plugin> {
*/
void open() {
this.servletTracker.open();
- try {
- this.jakartaTracker = new JakartaServletTracker(this, this.getBundleContext());
- this.osgiManager.log(LogService.LOG_INFO, "Jakarta Servlet bridge enabled");
- } catch ( final Throwable t) {
- // ignore
- this.osgiManager.log(LogService.LOG_INFO, "Jakarta Servlet bridge not enabled");
- }
}
/**
@@ -110,14 +98,6 @@ class PluginHolder implements ServiceTrackerCustomizer<Servlet, Plugin> {
* held plugin services.
*/
void close() {
- if (this.jakartaTracker != null) {
- try {
- this.jakartaTracker.close();
- } catch (final IOException e) {
- // ignore
- }
- this.jakartaTracker = null;
- }
this.servletTracker.close();
this.plugins.clear();
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/SimpleWebConsolePlugin.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/SimpleWebConsolePlugin.java
similarity index 92%
rename from webconsole/src/main/java/org/apache/felix/webconsole/SimpleWebConsolePlugin.java
rename to webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/SimpleWebConsolePlugin.java
index ead43171a3..fc3be5b0eb 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/SimpleWebConsolePlugin.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/SimpleWebConsolePlugin.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.webconsole;
+package org.apache.felix.webconsole.internal.servlet;
import java.net.URL;
@@ -29,6 +29,7 @@ import java.util.Map;
import java.util.ResourceBundle;
import org.apache.felix.webconsole.i18n.LocalizationHelper;
+import org.apache.felix.webconsole.servlet.ServletConstants;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@@ -155,7 +156,7 @@ public abstract class SimpleWebConsolePlugin extends AbstractWebConsolePlugin
}
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#getLabel()
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#getLabel()
*/
public final String getLabel()
{
@@ -164,7 +165,7 @@ public abstract class SimpleWebConsolePlugin extends AbstractWebConsolePlugin
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#getTitle()
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#getTitle()
*/
public final String getTitle()
{
@@ -173,7 +174,7 @@ public abstract class SimpleWebConsolePlugin extends AbstractWebConsolePlugin
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#getCategory()
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#getCategory()
*/
public String getCategory()
{
@@ -182,7 +183,7 @@ public abstract class SimpleWebConsolePlugin extends AbstractWebConsolePlugin
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#getCssReferences()
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#getCssReferences()
*/
protected final String[] getCssReferences()
{
@@ -225,10 +226,10 @@ public abstract class SimpleWebConsolePlugin extends AbstractWebConsolePlugin
activate( bc ); // don't know why this is needed!
final Dictionary<String, Object> props = new Hashtable<>();
- props.put( WebConsoleConstants.PLUGIN_LABEL, getLabel() );
- props.put( WebConsoleConstants.PLUGIN_TITLE, getTitle() );
+ props.put( ServletConstants.PLUGIN_LABEL, getLabel() );
+ props.put( ServletConstants.PLUGIN_TITLE, getTitle() );
if ( getCategory() != null ) {
- props.put( WebConsoleConstants.PLUGIN_CATEGORY, getCategory() );
+ props.put( ServletConstants.PLUGIN_CATEGORY, getCategory() );
}
reg = bc.registerService( Servlet.class, this, props ); //$NON-NLS-1$
}
@@ -302,7 +303,7 @@ public abstract class SimpleWebConsolePlugin extends AbstractWebConsolePlugin
* {@link #getService(String)} method. If you override this method, don't
* forget to call the super.
*
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#deactivate()
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#deactivate()
*/
public void deactivate() {
for ( Iterator<ServiceTracker<?, ?>> ti = services.values().iterator(); ti.hasNext(); ) {
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/WebConsoleUtil.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/WebConsoleUtil.java
new file mode 100755
index 0000000000..60a8e25aaf
--- /dev/null
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/WebConsoleUtil.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.webconsole.internal.servlet;
+
+import java.io.IOException;
+import java.lang.reflect.Array;
+
+import org.apache.felix.webconsole.servlet.RequestVariableResolver;
+
+import jakarta.servlet.ServletRequest;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+
+
+/**
+ * The <code>WebConsoleUtil</code> provides various utility methods for use
+ * by Web Console plugins.
+ */
+public final class WebConsoleUtil
+{
+
+ private WebConsoleUtil()
+ {
+ /* no instantiation */
+ }
+
+ /**
+ * Utility method to handle relative redirects.
+ * Some application servers like Web Sphere handle relative redirects differently
+ * therefore we should make an absolute URL before invoking send redirect.
+ *
+ * @param request the HTTP request coming from the user
+ * @param response the HTTP response, where data is rendered
+ * @param redirectUrl the redirect URI.
+ * @throws IOException If an input or output exception occurs
+ * @throws IllegalStateException If the response was committed or if a partial
+ * URL is given and cannot be converted into a valid URL
+ */
+ public static final void sendRedirect(final HttpServletRequest request,
+ final HttpServletResponse response,
+ String redirectUrl) throws IOException {
+ // check for relative URL
+ if ( !redirectUrl.startsWith("/") ) { //$NON-NLS-1$
+ String base = request.getContextPath() + request.getServletPath() + request.getPathInfo();
+ int i = base.lastIndexOf('/');
+ if (i > -1) {
+ base = base.substring(0, i);
+ } else {
+ i = base.indexOf(':');
+ base = (i > -1) ? base.substring(i + 1, base.length()) : ""; //$NON-NLS-1$
+ }
+ if (!base.startsWith("/")) { //$NON-NLS-1$
+ base = '/' + base;
+ }
+ redirectUrl = base + '/' + redirectUrl;
+
+ }
+ response.sendRedirect(redirectUrl);
+ }
+
+ /**
+ * Sets response headers to force the client to not cache the response
+ * sent back. This method must be called before the response is committed
+ * otherwise it will have no effect.
+ * <p>
+ * This method sets the <code>Cache-Control</code>, <code>Expires</code>,
+ * and <code>Pragma</code> headers.
+ *
+ * @param response The response for which to set the cache prevention
+ */
+ public static final void setNoCache(final HttpServletResponse response) {
+ response.setHeader("Cache-Control", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$
+ response.addHeader("Cache-Control", "no-store"); //$NON-NLS-1$ //$NON-NLS-2$
+ response.addHeader("Cache-Control", "must-revalidate"); //$NON-NLS-1$ //$NON-NLS-2$
+ response.addHeader("Cache-Control", "max-age=0"); //$NON-NLS-1$ //$NON-NLS-2$
+ response.setHeader("Expires", "Thu, 01 Jan 1970 01:00:00 GMT"); //$NON-NLS-1$ //$NON-NLS-2$
+ response.setHeader("Pragma", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Retrieves a request parameter and converts it to int.
+ *
+ * @param request the HTTP request
+ * @param name the name of the request parameter
+ * @param _default the default value returned if the parameter is not set or is not a valid integer.
+ * @return the request parameter if set and is valid integer, or the default value
+ */
+ public static final int getParameterInt(HttpServletRequest request, String name,
+ int _default)
+ {
+ int ret = _default;
+ String param = request.getParameter(name);
+ try
+ {
+ if (param != null)
+ ret = Integer.parseInt(param);
+ }
+ catch (NumberFormatException nfe)
+ {
+ // don't care, will return default
+ }
+
+ return ret;
+ }
+
+ public static RequestVariableResolver getRequestVariableResolver( final ServletRequest request) {
+ return (RequestVariableResolver) request.getAttribute(RequestVariableResolver.REQUEST_ATTRIBUTE);
+ }
+
+
+ /**
+ * This method will stringify a Java object. It is mostly used to print the values
+ * of unknown properties. This method will correctly handle if the passed object
+ * is array and will property display it.
+ *
+ * If the value is byte[] the elements are shown as Hex
+ *
+ * @param value the value to convert
+ * @return the string representation of the value
+ */
+ public static final String toString(Object value) {
+ if (value == null) {
+ return "n/a";
+ } else if (value.getClass().isArray()) {
+ final StringBuilder sb = new StringBuilder();
+ int len = Array.getLength(value);
+ sb.append('[');
+
+ for(int i = 0; i < len; ++i) {
+ final Object element = Array.get(value, i);
+ if (element instanceof Byte) {
+ sb.append("0x");
+ final String x = Integer.toHexString(((Byte)element).intValue() & 255);
+ if (1 == x.length()) {
+ sb.append('0');
+ }
+
+ sb.append(x);
+ } else {
+ sb.append(toString(element));
+ }
+
+ if (i < len - 1) {
+ sb.append(", ");
+ }
+ }
+
+ return sb.append(']').toString();
+ } else {
+ return value.toString();
+ }
+ }
+}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
index 2f48a2c7d6..25929bfd0a 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
@@ -31,11 +31,11 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.felix.utils.json.JSONWriter;
-import org.apache.felix.webconsole.SimpleWebConsolePlugin;
import org.apache.felix.webconsole.WebConsoleConstants;
-import org.apache.felix.webconsole.WebConsoleUtil;
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
import org.apache.felix.webconsole.internal.servlet.OsgiManager;
+import org.apache.felix.webconsole.internal.servlet.SimpleWebConsolePlugin;
+import org.apache.felix.webconsole.internal.servlet.WebConsoleUtil;
import org.apache.felix.webconsole.servlet.RequestVariableResolver;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
@@ -169,7 +169,7 @@ public class VMStatPlugin extends SimpleWebConsolePlugin implements OsgiManagerP
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
+ * @see org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
*/
protected void renderContent( HttpServletRequest request, HttpServletResponse response ) throws IOException
{
diff --git a/webconsole/src/test/java/org/apache/felix/webconsole/AbstractWebConsolePluginTest.java b/webconsole/src/test/java/org/apache/felix/webconsole/internal/servlet/AbstractWebConsolePluginTest.java
similarity index 97%
rename from webconsole/src/test/java/org/apache/felix/webconsole/AbstractWebConsolePluginTest.java
rename to webconsole/src/test/java/org/apache/felix/webconsole/internal/servlet/AbstractWebConsolePluginTest.java
index f69505e82e..b29c370b65 100755
--- a/webconsole/src/test/java/org/apache/felix/webconsole/AbstractWebConsolePluginTest.java
+++ b/webconsole/src/test/java/org/apache/felix/webconsole/internal/servlet/AbstractWebConsolePluginTest.java
@@ -16,12 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.webconsole;
+package org.apache.felix.webconsole.internal.servlet;
import java.lang.reflect.Method;
import java.net.URL;
+import org.apache.felix.webconsole.internal.servlet.AbstractWebConsolePlugin;
+
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
[felix-dev] 02/03: Port changes from main branch
Posted by cz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch jakarta-servlet-6
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
commit 1d5b52db1c64aee0de3e7d16bcff64373f10a822
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Aug 21 15:25:10 2023 +0200
Port changes from main branch
---
webconsole/pom.xml | 7 +
.../felix/webconsole/i18n/LocalizationHelper.java | 10 +-
.../internal/WebConsolePluginAdapter.java | 1 +
.../internal/configuration/ConfigManager.java | 31 +--
.../webconsole/internal/core/BundlesServlet.java | 45 ++--
.../core/PermissionsConfigurationPrinter.java | 6 +-
.../core/ServicesConfigurationPrinter.java | 64 +-----
.../webconsole/internal/core/ServicesServlet.java | 44 ++--
.../internal/core/ServicesUsedInfoProvider.java | 9 +-
.../internal/filter/FilteringResponseWrapper.java | 39 ++--
.../internal/filter/ResourceFilteringWriter.java | 9 +-
.../internal/i18n/CombinedEnumeration.java | 26 +--
.../internal/i18n/CombinedResourceBundle.java | 2 +-
.../i18n/ConsolePropertyResourceBundle.java | 26 +--
.../internal/i18n/ResourceBundleCache.java | 87 +++-----
.../webconsole/internal/misc/LicenseServlet.java | 5 +-
.../internal/misc/SystemPropertiesPrinter.java | 9 +-
.../JakartaServletAdapter.java} | 231 ++++++++++-----------
.../internal/servlet/JakartaServletTracker.java | 106 ++++++++++
.../webconsole/internal/servlet/OsgiManager.java | 12 ++
.../felix/webconsole/internal/servlet/Plugin.java | 6 +-
.../webconsole/internal/servlet/PluginHolder.java | 43 ++--
.../webconsole/internal/system/VMStatPlugin.java | 6 +-
.../felix/webconsole/servlet/AbstractServlet.java | 201 ++++++++++++++++++
.../servlet/RequestVariableResolver.java | 62 ++++++
.../felix/webconsole/servlet/ServletConstants.java | 75 +++++++
.../felix/webconsole/servlet/package-info.java | 21 ++
.../webconsole/AbstractWebConsolePluginTest.java | 4 +
.../internal/servlet/OsgiManagerTest.java | 4 +-
29 files changed, 799 insertions(+), 392 deletions(-)
diff --git a/webconsole/pom.xml b/webconsole/pom.xml
index 6e76474344..3026269816 100644
--- a/webconsole/pom.xml
+++ b/webconsole/pom.xml
@@ -42,6 +42,7 @@
org.apache.felix.webconsole;provide:=true,
org.apache.felix.webconsole.bundleinfo;provide:=true,
org.apache.felix.webconsole.i18n;provide:=true,
+ org.apache.felix.webconsole.servlet,
org.apache.felix.webconsole.spi
</webconsole.exports>
<felix.java.version>11</felix.java.version>
@@ -384,6 +385,12 @@
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.owasp.encoder</groupId>
+ <artifactId>encoder</artifactId>
+ <version>1.2.3</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/i18n/LocalizationHelper.java b/webconsole/src/main/java/org/apache/felix/webconsole/i18n/LocalizationHelper.java
index a29b6c1c04..b830e38caa 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/i18n/LocalizationHelper.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/i18n/LocalizationHelper.java
@@ -40,10 +40,10 @@ public class LocalizationHelper {
* the bundle that provides the localization resources. See the
* standard OSGi-type localization support.
*/
- public LocalizationHelper(Bundle bundle) {
- if (null == bundle)
- throw new NullPointerException();
- this.cache = new ResourceBundleCache(bundle);
+ public LocalizationHelper(final Bundle bundle) {
+ if (null == bundle)
+ throw new NullPointerException();
+ this.cache = new ResourceBundleCache(bundle);
}
/**
@@ -54,6 +54,6 @@ public class LocalizationHelper {
* @return the resource bundle (could be empty, but never <code>null</code>)
*/
public ResourceBundle getResourceBundle(final Locale locale) {
- return cache.getResourceBundle(locale);
+ return cache.getResourceBundle(locale);
}
}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/WebConsolePluginAdapter.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/WebConsolePluginAdapter.java
index 362453a571..4eb6742585 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/WebConsolePluginAdapter.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/WebConsolePluginAdapter.java
@@ -239,6 +239,7 @@ public class WebConsolePluginAdapter extends AbstractWebConsolePlugin
}
}
+
//---------- internal
@SuppressWarnings("rawtypes")
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
index b9a82702bc..efed40249b 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigManager.java
@@ -35,6 +35,7 @@ import org.apache.felix.webconsole.WebConsoleUtil;
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
import org.apache.felix.webconsole.internal.Util;
import org.apache.felix.webconsole.internal.misc.ServletSupport;
+import org.apache.felix.webconsole.servlet.RequestVariableResolver;
import org.apache.felix.webconsole.spi.ConfigurationHandler;
import org.apache.felix.webconsole.spi.ValidationException;
import org.osgi.framework.BundleContext;
@@ -423,9 +424,9 @@ public class ConfigManager extends SimpleWebConsolePlugin implements OsgiManager
cas.getJsonSupport().listFactoryConfigurations( jw, pidFilter, locale );
}
if ( !hasConfigs && !hasMetatype && cas != null ) {
- jw.key("noconfigs").value(true); //$NON-NLS-1$
+ jw.key("noconfigs").value(true);
} else {
- jw.key("noconfigs").value(false); //$NON-NLS-1$
+ jw.key("noconfigs").value(false);
}
jw.endObject();
@@ -438,19 +439,19 @@ public class ConfigManager extends SimpleWebConsolePlugin implements OsgiManager
// prepare variables
final String referer = request.getParameter( REFERER );
- final boolean factoryCreate = "true".equals( request.getParameter(FACTORY_CREATE) ); //$NON-NLS-1$
- @SuppressWarnings("unchecked")
- final Map<String, Object> vars = ( ( Map<String, Object> ) WebConsoleUtil.getVariableResolver( request ) );
- vars.put( "__data__", json.toString() ); //$NON-NLS-1$
- vars.put( "selectedPid", pid != null ? pid : "" ); //$NON-NLS-1$ //$NON-NLS-2$
- vars.put( "configurationReferer", referer != null ? referer : "" ); //$NON-NLS-1$ //$NON-NLS-2$
- vars.put( "factoryCreate", Boolean.valueOf(factoryCreate) ); //$NON-NLS-1$
- vars.put( "param.apply", ACTION_APPLY ); //$NON-NLS-1$
- vars.put( "param.create", ACTION_CREATE ); //$NON-NLS-1$
- vars.put( "param.unbind", ACTION_UNBIND ); //$NON-NLS-1$
- vars.put( "param.delete", ACTION_DELETE ); //$NON-NLS-1$
- vars.put( "param.propertylist", PROPERTY_LIST ); //$NON-NLS-1$
- vars.put( "param.pidFilter", PID_FILTER ); //$NON-NLS-1$
+ final boolean factoryCreate = "true".equals( request.getParameter(FACTORY_CREATE) );
+
+ final RequestVariableResolver vars = WebConsoleUtil.getRequestVariableResolver(request);
+ vars.put( "__data__", json.toString() );
+ vars.put( "selectedPid", pid != null ? pid : "" );
+ vars.put( "configurationReferer", referer != null ? referer : "" );
+ vars.put( "factoryCreate", Boolean.valueOf(factoryCreate) );
+ vars.put( "param.apply", ACTION_APPLY );
+ vars.put( "param.create", ACTION_CREATE );
+ vars.put( "param.unbind", ACTION_UNBIND );
+ vars.put( "param.delete", ACTION_DELETE );
+ vars.put( "param.propertylist", PROPERTY_LIST );
+ vars.put( "param.pidFilter", PID_FILTER );
response.getWriter().print(TEMPLATE);
}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
index 85d1089348..7c585b58e6 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
@@ -52,7 +52,6 @@ import org.apache.felix.utils.json.JSONWriter;
import org.apache.felix.utils.manifest.Clause;
import org.apache.felix.utils.manifest.Parser;
import org.apache.felix.webconsole.ConfigurationPrinter;
-import org.apache.felix.webconsole.DefaultVariableResolver;
import org.apache.felix.webconsole.SimpleWebConsolePlugin;
import org.apache.felix.webconsole.WebConsoleConstants;
import org.apache.felix.webconsole.WebConsoleUtil;
@@ -60,6 +59,7 @@ import org.apache.felix.webconsole.bundleinfo.BundleInfo;
import org.apache.felix.webconsole.bundleinfo.BundleInfoProvider;
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
import org.apache.felix.webconsole.internal.Util;
+import org.apache.felix.webconsole.servlet.RequestVariableResolver;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -70,12 +70,14 @@ import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;
+import org.osgi.framework.startlevel.BundleStartLevel;
+import org.osgi.framework.startlevel.FrameworkStartLevel;
+import org.osgi.framework.wiring.BundleRevision;
import org.osgi.framework.wiring.FrameworkWiring;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.log.LogService;
import org.osgi.service.packageadmin.ExportedPackage;
import org.osgi.service.packageadmin.PackageAdmin;
-import org.osgi.service.startlevel.StartLevel;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
@@ -517,16 +519,17 @@ public class BundlesServlet extends SimpleWebConsolePlugin implements OsgiManage
* @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
*/
@Override
- @SuppressWarnings("unchecked")
protected void renderContent( HttpServletRequest request, HttpServletResponse response ) throws IOException
{
// get request info from request attribute
final RequestInfo reqInfo = getRequestInfo(request);
- final int startLevel = getStartLevel().getInitialBundleStartLevel();
+ final Bundle systemBundle = this.getBundleContext().getBundle(Constants.SYSTEM_BUNDLE_LOCATION);
+ final FrameworkStartLevel fsl = systemBundle.adapt(FrameworkStartLevel.class);
+ final int startLevel = fsl.getInitialBundleStartLevel();
// prepare variables
- DefaultVariableResolver vars = ( ( DefaultVariableResolver ) WebConsoleUtil.getVariableResolver( request ) );
+ final RequestVariableResolver vars = WebConsoleUtil.getRequestVariableResolver(request);
vars.put( "startLevel", String.valueOf(startLevel));
vars.put( "drawDetails", reqInfo.bundleRequested ? Boolean.TRUE : Boolean.FALSE );
vars.put( "currentBundle", (reqInfo.bundleRequested && reqInfo.bundle != null ? String.valueOf(reqInfo.bundle.getBundleId()) : "null"));
@@ -754,15 +757,13 @@ public class BundlesServlet extends SimpleWebConsolePlugin implements OsgiManage
}
- private final boolean isFragmentBundle( Bundle bundle )
- {
+ private final boolean isFragmentBundle(final Bundle bundle ) {
// Workaround for FELIX-3670
- if ( bundle.getState() == Bundle.UNINSTALLED )
- {
+ if ( bundle.getState() == Bundle.UNINSTALLED ) {
return bundle.getHeaders().get( Constants.FRAGMENT_HOST ) != null;
}
-
- return getPackageAdmin().getBundleType( bundle ) == PackageAdmin.BUNDLE_TYPE_FRAGMENT;
+ final BundleRevision rev = bundle.adapt(BundleRevision.class);
+ return rev != null && (rev.getTypes() & BundleRevision.TYPE_FRAGMENT) == BundleRevision.TYPE_FRAGMENT;
}
private void keyVal(final List<Map<String, Object>> props, final String key, final Object val)
@@ -864,14 +865,11 @@ public class BundlesServlet extends SimpleWebConsolePlugin implements OsgiManage
}
- private final Integer getStartLevel( Bundle bundle )
- {
- if ( bundle.getState() != Bundle.UNINSTALLED )
- {
- StartLevel sl = getStartLevel();
- if ( sl != null )
- {
- return sl.getBundleStartLevel( bundle );
+ private final Integer getStartLevel( Bundle bundle ) {
+ if ( bundle.getState() != Bundle.UNINSTALLED ){
+ final BundleStartLevel bsl = bundle.adapt( BundleStartLevel.class );
+ if (bsl != null ) {
+ return bsl.getStartLevel();
}
}
@@ -880,8 +878,7 @@ public class BundlesServlet extends SimpleWebConsolePlugin implements OsgiManage
}
- private void listImportExport( List<Map<String, Object>> props, Bundle bundle, final String pluginRoot )
- {
+ private void listImportExport( List<Map<String, Object>> props, Bundle bundle, final String pluginRoot ) {
PackageAdmin packageAdmin = getPackageAdmin();
if ( packageAdmin == null )
{
@@ -1466,12 +1463,6 @@ public class BundlesServlet extends SimpleWebConsolePlugin implements OsgiManage
return ( PackageAdmin ) getService( PackageAdmin.class.getName() );
}
- private final StartLevel getStartLevel()
- {
- return ( StartLevel ) getService( StartLevel.class.getName() );
- }
-
-
//---------- Bundle Installation handler (former InstallAction)
private void installBundles( final HttpServletRequest request )
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/PermissionsConfigurationPrinter.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/PermissionsConfigurationPrinter.java
index 1701350edb..f1083874e0 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/PermissionsConfigurationPrinter.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/PermissionsConfigurationPrinter.java
@@ -59,8 +59,8 @@ public final class PermissionsConfigurationPrinter extends AbstractConfiguration
public final void printConfiguration(PrintWriter pw)
{
final BundleContext bc = getBundleContext();
- final ServiceReference paRef = bc.getServiceReference( PERMISSION_ADMIN_NAME );
- final ServiceReference cpaRef = bc.getServiceReference( CONDITIONAL_PERMISSION_ADMIN_NAME );
+ final ServiceReference<?> paRef = bc.getServiceReference( PERMISSION_ADMIN_NAME );
+ final ServiceReference<?> cpaRef = bc.getServiceReference( CONDITIONAL_PERMISSION_ADMIN_NAME );
final Object paSvc = paRef != null ? bc.getService(paRef) : null;
final Object cpaSvc = cpaRef != null ? bc.getService(cpaRef) : null;
@@ -112,7 +112,7 @@ public final class PermissionsConfigurationPrinter extends AbstractConfiguration
boolean hasPermissions = false;
//final java.util.List list = cpa.newConditionalPermissionUpdate().getConditionalPermissionInfos();
//for (int i = 0; list != null && i < list.size(); i++)
- for (Enumeration e = cpa.getConditionalPermissionInfos(); e.hasMoreElements();)
+ for (Enumeration<ConditionalPermissionInfo> e = cpa.getConditionalPermissionInfos(); e.hasMoreElements();)
{
hasPermissions = true;
//final ConditionalPermissionInfo info = (ConditionalPermissionInfo) list.get(i);
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesConfigurationPrinter.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesConfigurationPrinter.java
index 56d11870d4..11af2fcc19 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesConfigurationPrinter.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesConfigurationPrinter.java
@@ -47,7 +47,7 @@ public class ServicesConfigurationPrinter extends AbstractConfigurationPrinter
" Using Bundle {0} - {1} ({2}), version {3}");
// don't create empty reference array all the time, create it only once - it is immutable
- private static final ServiceReference[] NO_REFS = new ServiceReference[0];
+ private static final ServiceReference<?>[] NO_REFS = new ServiceReference[0];
/**
* @see org.apache.felix.webconsole.ConfigurationPrinter#getTitle()
@@ -65,7 +65,7 @@ public class ServicesConfigurationPrinter extends AbstractConfigurationPrinter
public final void printConfiguration(PrintWriter pw)
{
final Object[] data = new Object[4]; // used as message formatter parameters
- final ServiceReference refs[] = getServices();
+ final ServiceReference<?> refs[] = getServices();
pw.print("Status: ");
pw.println(ServicesServlet.getStatusLine(refs));
@@ -118,7 +118,7 @@ public class ServicesConfigurationPrinter extends AbstractConfigurationPrinter
return data;
}
- private static final Object[] params(ServiceReference ref, Object[] data)
+ private static final Object[] params(ServiceReference<?> ref, Object[] data)
{
data[0] = ServicesServlet.propertyAsString(ref, Constants.SERVICE_ID);
data[1] = ServicesServlet.propertyAsString(ref, Constants.OBJECTCLASS);
@@ -127,64 +127,20 @@ public class ServicesConfigurationPrinter extends AbstractConfigurationPrinter
return data;
}
- private final ServiceReference[] getServices()
- {
- ServiceReference[] refs = null;
- try
- {
+ private final ServiceReference<?>[] getServices() {
+ ServiceReference<?>[] refs = null;
+ try {
refs = BundleContextUtil.getWorkingBundleContext(getBundleContext()).getAllServiceReferences(null, null);
- }
- catch (InvalidSyntaxException e)
- {
+ } catch (InvalidSyntaxException e) {
// ignore
}
// no services or invalid filter syntax (unlikely)
- if (refs != null)
- {
- Arrays.sort(refs, new ServiceReferenceComparator());
- }
- else
- {
+ if (refs != null) {
+ Arrays.sort(refs);
+ } else {
refs = NO_REFS;
}
return refs;
}
-
-}
-
-class ServiceReferenceComparator implements Comparator
-{
- private static final Long ZERO = new Long(0);
-
- public int compare(ServiceReference p1, ServiceReference p2)
- {
- Long id1 = null;
- if (p1 != null)
- {
- id1 = (Long) p1.getProperty(Constants.SERVICE_ID);
- }
- if (id1 == null)
- {
- id1 = ZERO;
- }
-
- Long id2 = null;
- if (p2 != null)
- {
- id2 = (Long) p2.getProperty(Constants.SERVICE_ID);
- }
- if (id2 == null)
- {
- id2 = ZERO;
- }
-
- return id1.compareTo(id2);
- }
-
- @Override
- public int compare(Object o1, Object o2)
- {
- return compare((ServiceReference) o1, (ServiceReference) o2);
- }
}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
index a8fd5e205b..284f3bcda1 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
@@ -30,18 +30,20 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.felix.utils.json.JSONWriter;
-import org.apache.felix.webconsole.DefaultVariableResolver;
import org.apache.felix.webconsole.SimpleWebConsolePlugin;
import org.apache.felix.webconsole.WebConsoleConstants;
import org.apache.felix.webconsole.WebConsoleUtil;
+import org.apache.felix.webconsole.bundleinfo.BundleInfoProvider;
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
import org.apache.felix.webconsole.internal.Util;
+import org.apache.felix.webconsole.servlet.RequestVariableResolver;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
+import org.owasp.encoder.Encode;
/**
@@ -50,12 +52,12 @@ import org.osgi.framework.ServiceRegistration;
public class ServicesServlet extends SimpleWebConsolePlugin implements OsgiManagerPlugin
{
// don't create empty reference array all the time, create it only once - it is immutable
- private static final ServiceReference[] NO_REFS = new ServiceReference[0];
+ private static final ServiceReference<?>[] NO_REFS = new ServiceReference[0];
private final class RequestInfo
{
public final String extension;
- public final ServiceReference service;
+ public final ServiceReference<?> service;
public final boolean serviceRequested;
@@ -122,7 +124,7 @@ public class ServicesServlet extends SimpleWebConsolePlugin implements OsgiManag
TEMPLATE = readTemplateFile( "/templates/services.html" ); //$NON-NLS-1$
}
- private ServiceRegistration bipReg;
+ private ServiceRegistration<BundleInfoProvider> bipReg;
public void activate(BundleContext bundleContext)
{
@@ -140,7 +142,7 @@ public class ServicesServlet extends SimpleWebConsolePlugin implements OsgiManag
}
- final ServiceReference getServiceById( String pathInfo )
+ final ServiceReference<?> getServiceById( String pathInfo )
{
// only use last part of the pathInfo
pathInfo = pathInfo.substring( pathInfo.lastIndexOf( '/' ) + 1 );
@@ -151,7 +153,7 @@ public class ServicesServlet extends SimpleWebConsolePlugin implements OsgiManag
String filterStr = filter.toString();
try
{
- ServiceReference[] refs = BundleContextUtil.getWorkingBundleContext(this.getBundleContext()).getAllServiceReferences( null, filterStr );
+ ServiceReference<?>[] refs = BundleContextUtil.getWorkingBundleContext(this.getBundleContext()).getAllServiceReferences( null, filterStr );
if ( refs == null || refs.length != 1 )
{
return null;
@@ -167,7 +169,7 @@ public class ServicesServlet extends SimpleWebConsolePlugin implements OsgiManag
}
- private final ServiceReference[] getServices(String filter)
+ private final ServiceReference<?>[] getServices(String filter)
{
// empty filter string will return nothing, must set it to null to return all services
if (filter != null && filter.trim().length() == 0) {
@@ -175,7 +177,7 @@ public class ServicesServlet extends SimpleWebConsolePlugin implements OsgiManag
}
try
{
- final ServiceReference[] refs = BundleContextUtil.getWorkingBundleContext(this.getBundleContext()).getAllServiceReferences( null, filter );
+ final ServiceReference<?>[] refs = BundleContextUtil.getWorkingBundleContext(this.getBundleContext()).getAllServiceReferences( null, filter );
if ( refs != null )
{
return refs;
@@ -191,7 +193,7 @@ public class ServicesServlet extends SimpleWebConsolePlugin implements OsgiManag
}
- static final String getStatusLine( final ServiceReference[] services )
+ static final String getStatusLine( final ServiceReference<?>[] services )
{
final int count = services.length;
final StringBuilder buffer = new StringBuilder();
@@ -204,14 +206,14 @@ public class ServicesServlet extends SimpleWebConsolePlugin implements OsgiManag
}
- static final String propertyAsString( ServiceReference ref, String name )
+ static final String propertyAsString( ServiceReference<?> ref, String name )
{
final Object value = ref.getProperty( name );
return WebConsoleUtil.toString( value );
}
- private void renderJSON( final HttpServletResponse response, final ServiceReference service, final Locale locale )
+ private void renderJSON( final HttpServletResponse response, final ServiceReference<?> service, final Locale locale )
throws IOException
{
response.setContentType( "application/json" );
@@ -232,7 +234,7 @@ public class ServicesServlet extends SimpleWebConsolePlugin implements OsgiManag
}
}
- private void serviceDetails( JSONWriter jw, ServiceReference service ) throws IOException
+ private void serviceDetails( JSONWriter jw, ServiceReference<?> service ) throws IOException
{
String[] keys = service.getPropertyKeys();
@@ -266,7 +268,7 @@ public class ServicesServlet extends SimpleWebConsolePlugin implements OsgiManag
}
- private void usingBundles( JSONWriter jw, ServiceReference service, Locale locale ) throws IOException
+ private void usingBundles( JSONWriter jw, ServiceReference<?> service, Locale locale ) throws IOException
{
jw.key( "usingBundles" );
jw.array();
@@ -287,7 +289,7 @@ public class ServicesServlet extends SimpleWebConsolePlugin implements OsgiManag
}
- private void serviceInfo( JSONWriter jw, ServiceReference service, boolean details, final Locale locale )
+ private void serviceInfo( JSONWriter jw, ServiceReference<?> service, boolean details, final Locale locale )
throws IOException
{
jw.object();
@@ -333,19 +335,19 @@ public class ServicesServlet extends SimpleWebConsolePlugin implements OsgiManag
}
- private void writeJSON(final Writer pw, final ServiceReference service, final Locale locale, final String filter) throws IOException
+ private void writeJSON(final Writer pw, final ServiceReference<?> service, final Locale locale, final String filter) throws IOException
{
writeJSON( pw, service, false, locale, filter );
}
- private void writeJSON( final Writer pw, final ServiceReference service, final boolean fullDetails, final Locale locale, final String filter )
+ private void writeJSON( final Writer pw, final ServiceReference<?> service, final boolean fullDetails, final Locale locale, final String filter )
throws IOException
{
- final ServiceReference[] allServices = this.getServices(filter);
+ final ServiceReference<?>[] allServices = this.getServices(filter);
final String statusLine = getStatusLine( allServices );
- final ServiceReference[] services = ( service != null ) ? new ServiceReference[]
+ final ServiceReference<?>[] services = ( service != null ) ? new ServiceReference[]
{ service } : allServices;
final JSONWriter jw = new JSONWriter( pw );
@@ -375,7 +377,7 @@ public class ServicesServlet extends SimpleWebConsolePlugin implements OsgiManag
/**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#doGet(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
+ * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#doGet(jakarta.servlet.http.HttpServletRequest, jalarta.servlet.http.HttpServletResponse)
*/
protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException,
IOException
@@ -415,11 +417,11 @@ public class ServicesServlet extends SimpleWebConsolePlugin implements OsgiManag
writeJSON(w, reqInfo.service, request.getLocale(), filter);
// prepare variables
- DefaultVariableResolver vars = ( ( DefaultVariableResolver ) WebConsoleUtil.getVariableResolver( request ) );
+ final RequestVariableResolver vars = WebConsoleUtil.getRequestVariableResolver(request);
vars.put( "bundlePath", appRoot + "/" + BundlesServlet.NAME + "/" );
vars.put( "drawDetails", String.valueOf(reqInfo.serviceRequested));
vars.put( "__data__", w.toString() );
- vars.put( "filter", filter == null ? "" : WebConsoleUtil.escapeHtml(filter));
+ vars.put( "filter", filter == null ? "" : Encode.forHtmlContent(filter) );
response.getWriter().print( TEMPLATE );
}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesUsedInfoProvider.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesUsedInfoProvider.java
index 8ab35886d9..2139a6117c 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesUsedInfoProvider.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesUsedInfoProvider.java
@@ -61,7 +61,7 @@ final class ServicesUsedInfoProvider implements BundleInfoProvider
public BundleInfo[] getBundleInfo( Bundle bundle, String webConsoleRoot, Locale locale )
{
- final ServiceReference[] refs = bundle.getServicesInUse();
+ final ServiceReference<?>[] refs = bundle.getServicesInUse();
if ( null == refs || refs.length == 0 )
return NO_INFO;
@@ -74,7 +74,7 @@ final class ServicesUsedInfoProvider implements BundleInfoProvider
}
- private BundleInfo toInfo( ServiceReference ref, String webConsoleRoot, Locale locale )
+ private BundleInfo toInfo( ServiceReference<?> ref, String webConsoleRoot, Locale locale )
{
final String[] classes = ( String[] ) ref.getProperty( Constants.OBJECTCLASS );
final Object id = ref.getProperty( Constants.SERVICE_ID );
@@ -91,9 +91,8 @@ final class ServicesUsedInfoProvider implements BundleInfoProvider
}
- ServiceRegistration register( BundleContext context )
- {
- return context.registerService( BundleInfoProvider.class.getName(), this, null );
+ ServiceRegistration<BundleInfoProvider> register( BundleContext context ) {
+ return context.registerService( BundleInfoProvider.class, this, null );
}
}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/filter/FilteringResponseWrapper.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/filter/FilteringResponseWrapper.java
index ab4610e74d..e262be2954 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/filter/FilteringResponseWrapper.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/filter/FilteringResponseWrapper.java
@@ -27,8 +27,8 @@ import jakarta.servlet.ServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponseWrapper;
-import org.apache.felix.webconsole.VariableResolver;
import org.apache.felix.webconsole.WebConsoleUtil;
+import org.apache.felix.webconsole.servlet.RequestVariableResolver;
/**
@@ -40,8 +40,7 @@ import org.apache.felix.webconsole.WebConsoleUtil;
* exists in the resource bundle, the text is written unmodifed (except the
* wrapping <code>${}</code> characters are removed.
*/
-public class FilteringResponseWrapper extends HttpServletResponseWrapper
-{
+public class FilteringResponseWrapper extends HttpServletResponseWrapper {
// the resource bundle providing translations for the output
private final ResourceBundle locale;
@@ -62,36 +61,30 @@ public class FilteringResponseWrapper extends HttpServletResponseWrapper
* @param locale a resource bundle, that will be used for translation of the strings
* @param request the original request - used to obtain the variable resolver
*/
- public FilteringResponseWrapper( final HttpServletResponse response, final ResourceBundle locale,
- final ServletRequest request )
- {
+ public FilteringResponseWrapper( final HttpServletResponse response,
+ final ResourceBundle locale,
+ final ServletRequest request ) {
super( response );
this.locale = locale;
this.request = request;
}
-
/**
* Returns a <code>PrintWriter</code> for the response. If <code>text/html</code>
* is being generated a filtering writer is returned which translates
* strings enclosed in <code>${}</code> according to the resource bundle
* configured for this response.
*
- * @see jakarta.servlet.ServletResponseWrapper#getWriter()
+ * @see javax.servlet.ServletResponseWrapper#getWriter()
*/
- public PrintWriter getWriter() throws IOException
- {
- if ( writer == null )
- {
+ public PrintWriter getWriter() throws IOException {
+ if ( writer == null ) {
final PrintWriter base = super.getWriter();
- if ( doWrap() )
- {
- final VariableResolver resolver = WebConsoleUtil.getVariableResolver( request );
- final ResourceFilteringWriter filter = new ResourceFilteringWriter( base, locale, resolver );
+ if ( doWrap() ) {
+ final RequestVariableResolver vars = WebConsoleUtil.getRequestVariableResolver(request);
+ final ResourceFilteringWriter filter = new ResourceFilteringWriter( base, locale, vars );
writer = new PrintWriter( filter );
- }
- else
- {
+ } else {
writer = base;
}
}
@@ -99,11 +92,7 @@ public class FilteringResponseWrapper extends HttpServletResponseWrapper
return writer;
}
-
- private final boolean doWrap()
- {
- boolean doWrap = getContentType() != null && getContentType().indexOf( "text/html" ) >= 0;
- return doWrap;
+ private final boolean doWrap() {
+ return getContentType() != null && getContentType().indexOf( "text/html" ) >= 0;
}
-
}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/filter/ResourceFilteringWriter.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/filter/ResourceFilteringWriter.java
index e201dd03b0..1379114707 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/filter/ResourceFilteringWriter.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/filter/ResourceFilteringWriter.java
@@ -25,8 +25,7 @@ import java.io.Writer;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
-import org.apache.felix.webconsole.DefaultVariableResolver;
-import org.apache.felix.webconsole.VariableResolver;
+import org.apache.felix.webconsole.servlet.RequestVariableResolver;
/**
@@ -75,7 +74,7 @@ class ResourceFilteringWriter extends FilterWriter
*/
private final ResourceBundle locale;
- private final VariableResolver variables;
+ private final RequestVariableResolver variables;
/**
* The buffer to gather the text to be translated
@@ -88,11 +87,11 @@ class ResourceFilteringWriter extends FilterWriter
private int state = STATE_NULL;
- ResourceFilteringWriter( final Writer out, final ResourceBundle locale, final VariableResolver variables )
+ ResourceFilteringWriter( final Writer out, final ResourceBundle locale, final RequestVariableResolver variables )
{
super( out );
this.locale = locale;
- this.variables = ( variables != null ) ? variables : new DefaultVariableResolver();
+ this.variables = variables;
}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/CombinedEnumeration.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/CombinedEnumeration.java
index 5d0441b1c9..c23db58f45 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/CombinedEnumeration.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/CombinedEnumeration.java
@@ -32,28 +32,28 @@ import java.util.Set;
* So if both enumerations would produce the same result, say "123", only the
* first would be returned.
*/
-class CombinedEnumeration implements Enumeration
+class CombinedEnumeration implements Enumeration<String>
{
// the first enumeration to iterate
- private final Enumeration first;
+ private final Enumeration<String> first;
// the second enumeration to iterate once the first is exhausted
- private final Enumeration second;
+ private final Enumeration<String> second;
// the set of values already returned to prevent duplicate entries
- private final Set seenKeys;
+ private final Set<String> seenKeys;
// preview to the next return value for nextElement(), null at the end
- private Object nextKey;
+ private String nextKey;
- CombinedEnumeration( final Enumeration first, final Enumeration second )
+ CombinedEnumeration( final Enumeration<String> first, final Enumeration<String> second )
{
this.first = first;
this.second = second;
- this.seenKeys = new HashSet();
+ this.seenKeys = new HashSet<>();
this.nextKey = seek();
}
@@ -64,14 +64,14 @@ class CombinedEnumeration implements Enumeration
}
- public Object nextElement()
+ public String nextElement()
{
if ( !hasMoreElements() )
{
throw new NoSuchElementException();
}
- Object result = nextKey;
+ String result = nextKey;
nextKey = seek();
return result;
}
@@ -82,11 +82,11 @@ class CombinedEnumeration implements Enumeration
* (unique) element is available, null is returned. The element returned
* is also added to the set of seen elements to prevent duplicate provision
*/
- private Object seek()
+ private String seek()
{
while ( first.hasMoreElements() )
{
- final Object next = first.nextElement();
+ final String next = first.nextElement();
if ( !seenKeys.contains( next ) )
{
seenKeys.add( next );
@@ -95,7 +95,7 @@ class CombinedEnumeration implements Enumeration
}
while ( second.hasMoreElements() )
{
- final Object next = second.nextElement();
+ final String next = second.nextElement();
if ( !seenKeys.contains( next ) )
{
seenKeys.add( next );
@@ -104,4 +104,4 @@ class CombinedEnumeration implements Enumeration
}
return null;
}
-}
\ No newline at end of file
+}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/CombinedResourceBundle.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/CombinedResourceBundle.java
index eafc68eecf..19130c6fc5 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/CombinedResourceBundle.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/CombinedResourceBundle.java
@@ -48,7 +48,7 @@ class CombinedResourceBundle extends ResourceBundle
}
- public Enumeration getKeys()
+ public Enumeration<String> getKeys()
{
return new CombinedEnumeration( resourceBundle.getKeys(), defaultResourceBundle.getKeys() );
}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/ConsolePropertyResourceBundle.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/ConsolePropertyResourceBundle.java
index c1d389b3e6..82d028bfd3 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/ConsolePropertyResourceBundle.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/ConsolePropertyResourceBundle.java
@@ -27,14 +27,11 @@ import java.util.Properties;
import java.util.ResourceBundle;
-class ConsolePropertyResourceBundle extends ResourceBundle
-{
+class ConsolePropertyResourceBundle extends ResourceBundle {
private final Properties props;
-
- ConsolePropertyResourceBundle( final ResourceBundle parent, final URL source )
- {
+ ConsolePropertyResourceBundle( final ResourceBundle parent, final URL source ) {
setParent( parent );
props = new Properties();
@@ -47,21 +44,18 @@ class ConsolePropertyResourceBundle extends ResourceBundle
}
}
-
- public Enumeration getKeys()
- {
- Enumeration keysEnum = null;
- if (parent == null) {
- keysEnum = props.keys();
- } else {
- keysEnum = new CombinedEnumeration( props.keys(), parent.getKeys() );
+ @Override
+ public Enumeration<String> getKeys() {
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ Enumeration<String> keysEnum = (Enumeration) props.keys();
+ if (parent != null) {
+ keysEnum = new CombinedEnumeration( keysEnum, parent.getKeys() );
}
return keysEnum;
}
-
- protected Object handleGetObject( String key )
- {
+ @Override
+ protected Object handleGetObject( String key ) {
return props.get( key );
}
}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/ResourceBundleCache.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/ResourceBundleCache.java
index 9962d209c5..19bb78d1c4 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/ResourceBundleCache.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/i18n/ResourceBundleCache.java
@@ -33,8 +33,7 @@ import org.osgi.framework.Constants;
/**
* The <code>ResourceBundleCache</code> caches resource bundles per OSGi bundle.
*/
-public class ResourceBundleCache
-{
+public class ResourceBundleCache {
/**
* The default locale corresponding to the default language in the
@@ -46,9 +45,9 @@ public class ResourceBundleCache
private final Bundle bundle;
- private final Map resourceBundles;
+ private final Map<Locale, ResourceBundle> resourceBundles;
- private Map resourceBundleEntries;
+ private volatile Map<String, URL> resourceBundleEntries;
/**
@@ -56,10 +55,9 @@ public class ResourceBundleCache
*
* @param bundle the bundle which resources should be loaded.
*/
- public ResourceBundleCache( final Bundle bundle )
- {
+ public ResourceBundleCache( final Bundle bundle ) {
this.bundle = bundle;
- this.resourceBundles = new HashMap();
+ this.resourceBundles = new HashMap<>();
}
@@ -69,10 +67,8 @@ public class ResourceBundleCache
* @param locale the requested locale
* @return the resource bundle for the requested locale
*/
- public ResourceBundle getResourceBundle( final Locale locale )
- {
- if ( locale == null )
- {
+ public ResourceBundle getResourceBundle( final Locale locale ) {
+ if ( locale == null ) {
return getResourceBundleInternal( DEFAULT_LOCALE );
}
@@ -80,26 +76,21 @@ public class ResourceBundleCache
}
- ResourceBundle getResourceBundleInternal( final Locale locale )
- {
- if ( locale == null )
- {
+ ResourceBundle getResourceBundleInternal( final Locale locale ) {
+ if ( locale == null ) {
return null;
}
- synchronized ( resourceBundles )
- {
- ResourceBundle bundle = ( ResourceBundle ) resourceBundles.get( locale );
- if ( bundle != null )
- {
+ synchronized ( resourceBundles ) {
+ ResourceBundle bundle = resourceBundles.get( locale );
+ if ( bundle != null ) {
return bundle;
}
}
ResourceBundle parent = getResourceBundleInternal( getParentLocale( locale ) );
ResourceBundle bundle = loadResourceBundle( parent, locale );
- synchronized ( resourceBundles )
- {
+ synchronized ( resourceBundles ) {
resourceBundles.put( locale, bundle );
}
@@ -107,43 +98,36 @@ public class ResourceBundleCache
}
- private ResourceBundle loadResourceBundle( final ResourceBundle parent, final Locale locale )
- {
- final String path = "_" + locale.toString(); //$NON-NLS-1$
- final URL source = ( URL ) getResourceBundleEntries().get( path );
+ private ResourceBundle loadResourceBundle( final ResourceBundle parent, final Locale locale ) {
+ final String path = "_" + locale.toString();
+ final URL source = getResourceBundleEntries().get( path );
return new ConsolePropertyResourceBundle( parent, source );
}
- private synchronized Map getResourceBundleEntries()
- {
- if ( this.resourceBundleEntries == null )
- {
+ private synchronized Map<String, URL> getResourceBundleEntries() {
+ if ( this.resourceBundleEntries == null ) {
String file = ( String ) bundle.getHeaders().get( Constants.BUNDLE_LOCALIZATION );
- if ( file == null )
- {
+ if ( file == null ) {
file = Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;
}
// remove leading slash
- if ( file.startsWith( "/" ) ) //$NON-NLS-1$
- {
+ if ( file.startsWith( "/" ) ) {
file = file.substring( 1 );
}
// split path and base name
int slash = file.lastIndexOf( '/' );
String fileName = file.substring( slash + 1 );
- String path = ( slash <= 0 ) ? "/" : file.substring( 0, slash ); //$NON-NLS-1$
+ String path = ( slash <= 0 ) ? "/" : file.substring( 0, slash );
- HashMap resourceBundleEntries = new HashMap();
+ HashMap<String, URL> resourceBundleEntries = new HashMap<>();
- Enumeration locales = bundle.findEntries( path, fileName + "*.properties", false ); //$NON-NLS-1$
- if ( locales != null )
- {
- while ( locales.hasMoreElements() )
- {
- URL entry = ( URL ) locales.nextElement();
+ Enumeration<URL> locales = bundle.findEntries( path, fileName + "*.properties", false );
+ if ( locales != null ) {
+ while ( locales.hasMoreElements() ) {
+ URL entry = locales.nextElement();
// calculate the key
String entryPath = entry.getPath();
@@ -154,7 +138,7 @@ public class ResourceBundleCache
// the default language is "name.properties" thus the entry
// path is empty and must default to "_"+DEFAULT_LOCALE
if (entryPath.length() == 0) {
- entryPath = "_" + DEFAULT_LOCALE; //$NON-NLS-1$
+ entryPath = "_" + DEFAULT_LOCALE;
}
// only add this entry, if the "language" is not provided
@@ -172,23 +156,16 @@ public class ResourceBundleCache
}
- private static final Locale getParentLocale( Locale locale )
- {
- if ( locale.getVariant().length() != 0 )
- {
+ private static final Locale getParentLocale( Locale locale ) {
+ if ( locale.getVariant().length() != 0 ) {
return new Locale( locale.getLanguage(), locale.getCountry() );
- }
- else if ( locale.getCountry().length() != 0 )
- {
- return new Locale( locale.getLanguage(), "" ); //$NON-NLS-1$
- }
- else if ( !locale.getLanguage().equals( DEFAULT_LOCALE.getLanguage() ) )
- {
+ } else if ( locale.getCountry().length() != 0 ) {
+ return new Locale( locale.getLanguage(), "" );
+ } else if ( !locale.getLanguage().equals( DEFAULT_LOCALE.getLanguage() ) ) {
return DEFAULT_LOCALE;
}
// no more parents
return null;
}
-
}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
index 826cf18aa3..639abf2c3d 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/LicenseServlet.java
@@ -42,11 +42,11 @@ import jakarta.servlet.http.HttpServletResponse;
import org.apache.felix.utils.json.JSONWriter;
import org.apache.felix.utils.manifest.Clause;
import org.apache.felix.utils.manifest.Parser;
-import org.apache.felix.webconsole.DefaultVariableResolver;
import org.apache.felix.webconsole.SimpleWebConsolePlugin;
import org.apache.felix.webconsole.WebConsoleUtil;
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
import org.apache.felix.webconsole.internal.Util;
+import org.apache.felix.webconsole.servlet.RequestVariableResolver;
import org.osgi.framework.Bundle;
@@ -109,14 +109,13 @@ public final class LicenseServlet extends SimpleWebConsolePlugin implements Osgi
/**
* @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
*/
- @SuppressWarnings("unchecked")
protected void renderContent( HttpServletRequest request, HttpServletResponse res ) throws IOException
{
Bundle[] bundles = getBundleContext().getBundles();
Util.sort( bundles, request.getLocale() );
// prepare variables
- DefaultVariableResolver vars = ( ( DefaultVariableResolver ) WebConsoleUtil.getVariableResolver( request ) );
+ final RequestVariableResolver vars = WebConsoleUtil.getRequestVariableResolver(request);
vars.put( "__data__", getBundleData( bundles, request.getLocale() ));
res.getWriter().print(TEMPLATE);
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/SystemPropertiesPrinter.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/SystemPropertiesPrinter.java
index dbd71c6963..5279eb9df7 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/SystemPropertiesPrinter.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/SystemPropertiesPrinter.java
@@ -28,11 +28,11 @@ import java.util.TreeSet;
import org.apache.felix.webconsole.internal.AbstractConfigurationPrinter;
-public class SystemPropertiesPrinter extends AbstractConfigurationPrinter
-{
+public class SystemPropertiesPrinter extends AbstractConfigurationPrinter {
private static final String TITLE = "System Properties";
+ @SuppressWarnings("unused")
private static final String LABEL = "_systemproperties";
@@ -42,8 +42,7 @@ public class SystemPropertiesPrinter extends AbstractConfigurationPrinter
}
- public void printConfiguration( PrintWriter printWriter )
- {
+ public void printConfiguration( PrintWriter printWriter ) {
Properties props = System.getProperties();
SortedSet keys = new TreeSet( props.keySet() );
for ( Iterator ki = keys.iterator(); ki.hasNext(); )
@@ -54,4 +53,4 @@ public class SystemPropertiesPrinter extends AbstractConfigurationPrinter
}
-}
\ No newline at end of file
+}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/WebConsolePluginAdapter.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/JakartaServletAdapter.java
similarity index 50%
copy from webconsole/src/main/java/org/apache/felix/webconsole/internal/WebConsolePluginAdapter.java
copy to webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/JakartaServletAdapter.java
index 362453a571..a4c1d1d86d 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/WebConsolePluginAdapter.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/JakartaServletAdapter.java
@@ -16,32 +16,34 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.felix.webconsole.internal;
+package org.apache.felix.webconsole.internal.servlet;
import java.io.IOException;
import java.util.*;
-import org.apache.felix.webconsole.AbstractWebConsolePlugin;
-import org.apache.felix.webconsole.WebConsoleConstants;
-import org.osgi.framework.ServiceReference;
-import jakarta.servlet.Servlet;
-import jakarta.servlet.ServletConfig;
-import jakarta.servlet.ServletException;
-import jakarta.servlet.ServletRequest;
-import jakarta.servlet.ServletResponse;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.felix.http.jakartawrappers.HttpServletRequestWrapper;
+import org.apache.felix.http.jakartawrappers.HttpServletResponseWrapper;
+import org.apache.felix.http.jakartawrappers.ServletConfigWrapper;
+import org.apache.felix.http.javaxwrappers.ServletExceptionUtil;
+import org.apache.felix.webconsole.AbstractWebConsolePlugin;
+import org.apache.felix.webconsole.servlet.AbstractServlet;
+import org.apache.felix.webconsole.servlet.ServletConstants;
+import org.osgi.framework.ServiceReference;
/**
- * The <code>WebConsolePluginAdapter</code> is an adapter to the
+ * The <code>JakartaServletAdapter</code> is an adapter to the
* {@link AbstractWebConsolePlugin} for regular servlets registered with the
* {@link org.apache.felix.webconsole.WebConsoleConstants#PLUGIN_TITLE}
- * service attribute.
+ * service attribute using jakarta.servlet.Servlet
*/
-public class WebConsolePluginAdapter extends AbstractWebConsolePlugin
-{
+public class JakartaServletAdapter extends AbstractWebConsolePlugin {
/** serial UID */
private static final long serialVersionUID = 1L;
@@ -49,8 +51,11 @@ public class WebConsolePluginAdapter extends AbstractWebConsolePlugin
// the plugin label (aka address)
private final String label;
+ // the plugin title
+ private final String title;
+
// the actual plugin to forward rendering requests to
- private final Servlet plugin;
+ private final AbstractServlet plugin;
// the CSS references (null if none)
private final String[] cssReferences;
@@ -62,11 +67,11 @@ public class WebConsolePluginAdapter extends AbstractWebConsolePlugin
* @param plugin the plugin itself
* @param serviceReference reference to the plugin
*/
- public WebConsolePluginAdapter( String label, Servlet plugin, ServiceReference<Servlet> serviceReference )
- {
- this.label = label;
+ public JakartaServletAdapter( final AbstractServlet plugin, ServiceReference<Servlet> serviceReference ) {
+ this.label = (String) serviceReference.getProperty( ServletConstants.PLUGIN_LABEL );
+ this.title = (String) serviceReference.getProperty( ServletConstants.PLUGIN_TITLE );
this.plugin = plugin;
- this.cssReferences = toStringArray( serviceReference.getProperty( WebConsoleConstants.PLUGIN_CSS_REFERENCES ) );
+ this.cssReferences = toStringArray( serviceReference.getProperty( ServletConstants.PLUGIN_CSS_REFERENCES ) );
// activate this abstract plugin (mainly to set the bundle context)
activate( serviceReference.getBundle().getBundleContext() );
@@ -75,58 +80,32 @@ public class WebConsolePluginAdapter extends AbstractWebConsolePlugin
//---------- AbstractWebConsolePlugin API
- /**
- * Returns the label of this plugin page as defined in the constructor.
- *
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#getLabel()
- */
- public String getLabel()
- {
+ @Override
+ public String getLabel() {
return label;
}
-
- /**
- * Returns the title of this plugin page as defined by the
- * {@link WebConsoleConstants#PLUGIN_TITLE} service registration attribute
- * which is exposed as the servlet name in the servlet configuration.
- *
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#getTitle()
- */
- public String getTitle()
- {
- // return the servlet name from the configuration but don't call
- // the base class implementation, which calls getTitle()
- return getServletConfig().getServletName();
+ @Override
+ public String getTitle() {
+ return this.title;
}
-
- /**
- * Returns the CSS references from the
- * {@link WebConsoleConstants#PLUGIN_CSS_REFERENCES felix.webconsole.css}
- * service registration property of the plugin.
- *
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#getCssReferences()
- */
- protected String[] getCssReferences()
- {
+ @Override
+ protected String[] getCssReferences() {
return cssReferences;
}
-
- /**
- * Call the plugin servlet's service method to render the content of this
- * page.
- *
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
- */
- protected void renderContent( HttpServletRequest req, HttpServletResponse res ) throws ServletException,
- IOException
- {
- plugin.service( req, res );
+ @Override
+ protected void renderContent( final HttpServletRequest req, final HttpServletResponse res )
+ throws ServletException, IOException {
+ try {
+ plugin.renderContent( (jakarta.servlet.http.HttpServletRequest)HttpServletRequestWrapper.getWrapper(req),
+ (jakarta.servlet.http.HttpServletResponse)HttpServletResponseWrapper.getWrapper(res) );
+ } catch (final jakarta.servlet.ServletException s) {
+ throw ServletExceptionUtil.getServletException(s);
+ }
}
-
/**
* Returns the registered plugin class to be able to call the
* <code>getResource()</code> method on that object for this plugin to
@@ -134,8 +113,7 @@ public class WebConsolePluginAdapter extends AbstractWebConsolePlugin
*
* @see org.apache.felix.webconsole.AbstractWebConsolePlugin#getResourceProvider()
*/
- protected Object getResourceProvider()
- {
+ protected Object getResourceProvider() {
return plugin;
}
@@ -145,22 +123,22 @@ public class WebConsolePluginAdapter extends AbstractWebConsolePlugin
/**
* Initializes this servlet as well as the plugin servlet.
*
- * @see jakarta.servlet.GenericServlet#init(jakarta.servlet.ServletConfig)
+ * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
*/
- public void init( ServletConfig config ) throws ServletException
- {
+ public void init( ServletConfig config ) throws ServletException {
// no need to activate the plugin, this has already been done
// when the instance was setup
- try
- {
+ try {
// base classe initialization
super.init( config );
// plugin initialization
- plugin.init( config );
- }
- catch ( ServletException se )
- {
+ try {
+ plugin.init( new ServletConfigWrapper(config) );
+ } catch ( final jakarta.servlet.ServletException s) {
+ throw ServletExceptionUtil.getServletException(s);
+ }
+ } catch ( ServletException se ) {
// if init fails, the plugin will not be destroyed and thus
// the plugin not deactivated. Do it here
deactivate();
@@ -170,32 +148,53 @@ public class WebConsolePluginAdapter extends AbstractWebConsolePlugin
}
}
+ private static final class CheckHttpServletResponse extends HttpServletResponseWrapper {
- /**
- * Detects whether this request is intended to have the headers and
- * footers of this plugin be rendered or not. The decision is taken based
- * on whether and what extension the request URI has: If the request URI
- * has no extension or the the extension is <code>.html</code>, the request
- * is assumed to be rendered with header and footer. Otherwise the
- * headers and footers are omitted and the
- * {@link #renderContent(HttpServletRequest, HttpServletResponse)}
- * method is called without any decorations and without setting any
- * response headers.
- *
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#isHtmlRequest(jakarta.servlet.http.HttpServletRequest)
- */
- protected boolean isHtmlRequest( final HttpServletRequest request )
- {
- final String requestUri = request.getRequestURI();
- if ( requestUri.endsWith( ".html" ) ) {
- return true;
+ private boolean done = false;
+ public CheckHttpServletResponse(HttpServletResponse response) {
+ super(response);
+ }
+
+ public boolean isDone() {
+ return this.done;
+ }
+
+ @Override
+ public void reset() {
+ this.done = false;
+ super.reset();
+ }
+
+ @Override
+ public void sendError(final int sc) throws IOException {
+ this.done = true;
+ super.sendError(sc);
+ }
+
+ @Override
+ public void sendError(final int sc, final String msg) throws IOException {
+ this.done = true;
+ super.sendError(sc, msg);
+ }
+
+ @Override
+ public void sendRedirect(final String location) throws IOException {
+ this.done = true;
+ super.sendRedirect(location);
+ }
+
+ @Override
+ public void setStatus(final int sc) {
+ this.done = true;
+ super.setStatus(sc);
}
- // check if there is an extension
- final int lastSlash = requestUri.lastIndexOf('/');
- final int lastDot = requestUri.indexOf('.', lastSlash + 1);
- return lastDot < 0;
- }
+ @Override
+ public void setStatus(final int sc, final String sm) {
+ this.done = true;
+ super.setStatus(sc, sm);
+ }
+ }
/**
* Directly refer to the plugin's service method unless the request method
@@ -204,46 +203,44 @@ public class WebConsolePluginAdapter extends AbstractWebConsolePlugin
* {@link #renderContent(HttpServletRequest, HttpServletResponse)}
* method.
*
- * @see jakarta.servlet.http.HttpServlet#service(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)
+ * @see javax.servlet.http.HttpServlet#service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
*/
- public void service( ServletRequest req, ServletResponse resp ) throws ServletException, IOException
- {
- if ( ( req instanceof HttpServletRequest ) && ( ( HttpServletRequest ) req ).getMethod().equals( "GET" ) )
- {
+ public void service( HttpServletRequest req, HttpServletResponse resp )
+ throws ServletException, IOException {
+ final CheckHttpServletResponse checkResponse = new CheckHttpServletResponse(resp);
+ // call plugin first
+ try {
+ plugin.service( (jakarta.servlet.http.HttpServletRequest)HttpServletRequestWrapper.getWrapper(req),
+ (jakarta.servlet.http.HttpServletResponse)HttpServletResponseWrapper.getWrapper(resp) );
+ } catch (final jakarta.servlet.ServletException s) {
+ throw ServletExceptionUtil.getServletException(s);
+ }
+ // if a GET request and plugin did not create a response yet, call super to get full HTML response
+ if ( !checkResponse.isDone() && req.getMethod().equals( "GET" ) ) {
// handle the GET request here and call into plugin on renderContent
super.service( req, resp );
}
- else
- {
- // not a GET request, have the plugin handle it directly
- plugin.service( req, resp );
- }
}
-
/**
* Destroys this servlet as well as the plugin servlet.
*
- * @see jakarta.servlet.GenericServlet#destroy()
+ * @see javax.servlet.GenericServlet#destroy()
*/
- public void destroy()
- {
- try
- {
+ public void destroy() {
+ try {
plugin.destroy();
super.destroy();
- }
- finally
- {
+ } finally {
deactivate();
}
}
+
//---------- internal
@SuppressWarnings("rawtypes")
- private String[] toStringArray( final Object value )
- {
+ private String[] toStringArray( final Object value ) {
if ( value instanceof String )
{
return new String[]
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/JakartaServletTracker.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/JakartaServletTracker.java
new file mode 100755
index 0000000000..b0e1a140a1
--- /dev/null
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/JakartaServletTracker.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.webconsole.internal.servlet;
+
+
+import java.io.Closeable;
+
+import org.apache.felix.http.javaxwrappers.ServletWrapper;
+import org.apache.felix.webconsole.WebConsoleConstants;
+import org.apache.felix.webconsole.internal.Util;
+import org.apache.felix.webconsole.internal.servlet.Plugin.ServletPlugin;
+import org.apache.felix.webconsole.servlet.AbstractServlet;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+import jakarta.servlet.Servlet;
+
+public class JakartaServletTracker implements Closeable, ServiceTrackerCustomizer<Servlet, JakartaServletTracker.JakartaServletPlugin> {
+
+ private final ServiceTracker<Servlet, JakartaServletPlugin> servletTracker;
+
+ private final PluginHolder pluginHolder;
+
+ public JakartaServletTracker( final PluginHolder pluginHolder, final BundleContext context ) {
+ this.pluginHolder = pluginHolder;
+ Filter filter = null;
+ try {
+ filter = context.createFilter("(&(" + Constants.OBJECTCLASS + "=" + Servlet.class.getName() +
+ ")(" + WebConsoleConstants.PLUGIN_LABEL + "=*))");
+ } catch (final InvalidSyntaxException e) {
+ // not expected, thus fail hard
+ throw new InternalError( "Failed creating filter: " + e.getMessage() );
+ }
+ this.servletTracker = new ServiceTracker<>(context, filter, this);
+ servletTracker.open();
+ }
+
+ @Override
+ public void close() {
+ servletTracker.close();
+ }
+
+ @Override
+ public JakartaServletPlugin addingService( final org.osgi.framework.ServiceReference<Servlet> reference ) {
+ final String label = Util.getStringProperty( reference, WebConsoleConstants.PLUGIN_LABEL );
+ if ( label != null ) {
+ final JakartaServletPlugin plugin = new JakartaServletPlugin(this.pluginHolder, reference, label);
+ pluginHolder.addPlugin(plugin);
+ return plugin;
+ }
+ return null;
+ }
+
+ @Override
+ public void modifiedService( final org.osgi.framework.ServiceReference<Servlet> reference, final JakartaServletPlugin service ) {
+ this.removedService(reference, service);
+ this.addingService(reference);
+ }
+
+ @Override
+ public void removedService( final org.osgi.framework.ServiceReference<Servlet> reference, final JakartaServletPlugin service ) {
+ this.pluginHolder.removePlugin(service);
+ }
+
+ public static class JakartaServletPlugin extends ServletPlugin {
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public JakartaServletPlugin(PluginHolder holder, ServiceReference<jakarta.servlet.Servlet> serviceReference,
+ String label) {
+ super(holder, (ServiceReference)serviceReference, label);
+ }
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ protected javax.servlet.Servlet getService() {
+ final Servlet servlet = (Servlet) getHolder().getBundleContext().getService( (ServiceReference)this.getServiceReference() );
+ if (servlet != null) {
+ if ( servlet instanceof AbstractServlet ) {
+ return new JakartaServletAdapter((AbstractServlet)servlet, this.getServiceReference());
+ }
+ return new ServletWrapper(servlet);
+ }
+ return null;
+ }
+ }
+}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
index 758935eb3d..ea763fe8e1 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
@@ -46,12 +46,14 @@ import org.apache.felix.webconsole.WebConsoleConstants;
import org.apache.felix.webconsole.WebConsoleSecurityProvider;
import org.apache.felix.webconsole.WebConsoleSecurityProvider2;
import org.apache.felix.webconsole.WebConsoleSecurityProvider3;
+import org.apache.felix.webconsole.WebConsoleUtil;
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
import org.apache.felix.webconsole.internal.Util;
import org.apache.felix.webconsole.internal.core.BundlesServlet;
import org.apache.felix.webconsole.internal.filter.FilteringResponseWrapper;
import org.apache.felix.webconsole.internal.i18n.ResourceBundleManager;
import org.apache.felix.webconsole.internal.servlet.Plugin.InternalPlugin;
+import org.apache.felix.webconsole.servlet.RequestVariableResolver;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -628,9 +630,19 @@ public class OsgiManager extends GenericServlet {
request = wrapRequest(request, locale);
response = wrapResponse(request, response, plugin);
+ // make sure to set the variable resolver
+ initRequestVariableResolver(request);
+
plugin.service(request, response);
}
+ private void initRequestVariableResolver(final HttpServletRequest request) {
+ final RequestVariableResolver resolver = new RequestVariableResolver();
+ request.setAttribute(RequestVariableResolver.REQUEST_ATTRIBUTE, resolver);
+ resolver.put( "appRoot", (String) request.getAttribute( WebConsoleConstants.ATTR_APP_ROOT ) );
+ resolver.put( "pluginRoot", (String) request.getAttribute( WebConsoleConstants.ATTR_PLUGIN_ROOT ) );
+ }
+
private final void logout(HttpServletRequest request, HttpServletResponse response)
throws IOException {
final Object securityProvider = securityProviderTracker.getService();
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/Plugin.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/Plugin.java
index 67c181c4ef..c9c5e32ef7 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/Plugin.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/Plugin.java
@@ -194,8 +194,12 @@ public abstract class Plugin implements ServletConfig, Comparable<Plugin> {
return this.getServiceReference().toString();
}
+ protected Servlet getService() {
+ return getHolder().getBundleContext().getService( this.getServiceReference() );
+ }
+
protected AbstractWebConsolePlugin doGetConsolePlugin() {
- final Servlet service = getHolder().getBundleContext().getService( this.getServiceReference() );
+ final Servlet service = getService();
if ( service != null ) {
this.title = Util.getStringProperty( this.getServiceReference(), WebConsoleConstants.PLUGIN_TITLE );
this.category = Util.getStringProperty( this.getServiceReference(), WebConsoleConstants.PLUGIN_CATEGORY );
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/PluginHolder.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/PluginHolder.java
index 5a30de010c..f4671525c9 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/PluginHolder.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/PluginHolder.java
@@ -18,6 +18,8 @@
*/
package org.apache.felix.webconsole.internal.servlet;
+import java.io.Closeable;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -67,6 +69,8 @@ class PluginHolder implements ServiceTrackerCustomizer<Servlet, Plugin> {
private final ServiceTracker<Servlet, Plugin> servletTracker;
+ private volatile Closeable jakartaTracker;
+
PluginHolder( final OsgiManager osgiManager, final BundleContext context ) {
this.osgiManager = osgiManager;
this.bundleContext = context;
@@ -91,6 +95,13 @@ class PluginHolder implements ServiceTrackerCustomizer<Servlet, Plugin> {
*/
void open() {
this.servletTracker.open();
+ try {
+ this.jakartaTracker = new JakartaServletTracker(this, this.getBundleContext());
+ this.osgiManager.log(LogService.LOG_INFO, "Jakarta Servlet bridge enabled");
+ } catch ( final Throwable t) {
+ // ignore
+ this.osgiManager.log(LogService.LOG_INFO, "Jakarta Servlet bridge not enabled");
+ }
}
/**
@@ -99,6 +110,14 @@ class PluginHolder implements ServiceTrackerCustomizer<Servlet, Plugin> {
* held plugin services.
*/
void close() {
+ if (this.jakartaTracker != null) {
+ try {
+ this.jakartaTracker.close();
+ } catch (final IOException e) {
+ // ignore
+ }
+ this.jakartaTracker = null;
+ }
this.servletTracker.close();
this.plugins.clear();
@@ -223,29 +242,21 @@ class PluginHolder implements ServiceTrackerCustomizer<Servlet, Plugin> {
// support only one level for now
Map categoryMap = null;
String category = plugin.getCategory();
- if ( category == null || category.trim().length() == 0 )
- {
+ if ( category == null || category.trim().length() == 0 ) {
// FELIX-3798 configured default category
category = defaultCategory;
}
- // TODO: FELIX-3769; translate the Category
-
categoryMap = findCategoryMap( map, category );
final String label = plugin.getLabel();
String title = plugin.getTitle();
- if ( title.startsWith( "%" ) )
- {
- try
- {
- final ResourceBundle resourceBundle = resourceBundleManager.getResourceBundle( plugin.getBundle(),
- locale );
+ if ( title.startsWith( "%" ) ) {
+ try {
+ final ResourceBundle resourceBundle = resourceBundleManager.getResourceBundle( plugin.getBundle(), locale );
title = resourceBundle.getString( title.substring( 1 ) );
- }
- catch ( Throwable e )
- {
- /* ignore missing resource - use default title */
+ } catch ( Throwable e ) {
+ // ignore missing resource - use default title
}
}
@@ -350,7 +361,7 @@ class PluginHolder implements ServiceTrackerCustomizer<Servlet, Plugin> {
removePlugin( plugin );
}
- private void addPlugin( final Plugin plugin ) {
+ void addPlugin( final Plugin plugin ) {
synchronized ( plugins ) {
final List<Plugin> list = plugins.computeIfAbsent(plugin.getLabel(), k -> new ArrayList<>());
final Plugin oldPlugin = list.isEmpty() ? null : list.get(0);
@@ -375,7 +386,7 @@ class PluginHolder implements ServiceTrackerCustomizer<Servlet, Plugin> {
}
}
- private void removePlugin( final Plugin plugin ) {
+ void removePlugin( final Plugin plugin ) {
synchronized ( plugins ) {
final List<Plugin> list = plugins.get( plugin.getLabel() );
if ( list != null ) {
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
index 195266ec0e..2f48a2c7d6 100755
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
@@ -31,12 +31,12 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.felix.utils.json.JSONWriter;
-import org.apache.felix.webconsole.DefaultVariableResolver;
import org.apache.felix.webconsole.SimpleWebConsolePlugin;
import org.apache.felix.webconsole.WebConsoleConstants;
import org.apache.felix.webconsole.WebConsoleUtil;
import org.apache.felix.webconsole.internal.OsgiManagerPlugin;
import org.apache.felix.webconsole.internal.servlet.OsgiManager;
+import org.apache.felix.webconsole.servlet.RequestVariableResolver;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.service.startlevel.StartLevel;
@@ -190,7 +190,7 @@ public class VMStatPlugin extends SimpleWebConsolePlugin implements OsgiManagerP
jw.endObject();
jw.flush();
- DefaultVariableResolver vars = ( ( DefaultVariableResolver ) WebConsoleUtil.getVariableResolver( request ) );
+ final RequestVariableResolver vars = WebConsoleUtil.getRequestVariableResolver(request);
vars.put( "data", json.toString() );
body = TPL_VM_RESTART;
@@ -250,7 +250,7 @@ public class VMStatPlugin extends SimpleWebConsolePlugin implements OsgiManagerP
jw.flush();
- DefaultVariableResolver vars = ( ( DefaultVariableResolver ) WebConsoleUtil.getVariableResolver( request ) );
+ final RequestVariableResolver vars = WebConsoleUtil.getRequestVariableResolver(request);
vars.put( "startData", json.toString() );
response.getWriter().print( body );
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/servlet/AbstractServlet.java b/webconsole/src/main/java/org/apache/felix/webconsole/servlet/AbstractServlet.java
new file mode 100755
index 0000000000..031ad59cdc
--- /dev/null
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/servlet/AbstractServlet.java
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.webconsole.servlet;
+
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.StringWriter;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.charset.StandardCharsets;
+
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+
+
+/**
+ * This class can be used as a base class for a web console plugin.
+ * The plugin (servlet) needs to be registered as a servlet service
+ * with at least the label property.
+ *
+ * @see ServletConstants#PLUGIN_LABEL
+ * @see ServletConstants#PLUGIN_TITLE
+ * @see ServletConstants#PLUGIN_CATEGORY
+ */
+public abstract class AbstractServlet extends HttpServlet {
+
+ /**
+ * Called to identify resources.
+ * By default, if the path starts with "/res/" this is treated as a resource
+ * and the URL to the resource is tried to be loaded via the class loader.
+ * @param path the path
+ * @return the URL of the resource or <code>null</code> if not found.
+ */
+ protected URL getResource( final String path ) {
+ final int index = path.indexOf( '/', 1 );
+ if (index != -1) {
+ if (path.substring(index).startsWith("/res/") ) {
+ return getClass().getResource( path.substring(index) );
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Handle get requests. This method can be used to return resources, like JSON responses etc.
+ * If the plugin is serving a resource, this method call {@link HttpServletResponse#setStatus(int)}.
+ * This method is also allowed to send a redirect or an error.
+ * If none of the three applies, the webconsole will call {@link #renderContent(HttpServletRequest, HttpServletResponse)}
+ */
+ @Override
+ protected void doGet( final HttpServletRequest request, final HttpServletResponse response )
+ throws ServletException, IOException {
+ this.spoolResource( request, response );
+ }
+
+ /**
+ * This method is used to render the main contents of the plugin
+ * @param request The request
+ * @param response The response
+ * @throws ServletException If an error occurs
+ * @throws IOException If writing the response fails
+ */
+ public void renderContent( final HttpServletRequest request, final HttpServletResponse response)
+ throws ServletException, IOException {
+ throw new ServletException("Render method not implemented");
+ }
+
+ /**
+ * If the request addresses a resource , this method serves it
+ * and returns <code>true</code>. Otherwise <code>false</code> is returned.
+ * <p>
+ * If <code>true</code> is returned, the request is considered complete and
+ * request processing terminates. Otherwise request processing continues
+ * with normal plugin rendering.
+ *
+ * @param request The request object
+ * @param response The response object
+ * @return <code>true</code> if the request causes a resource to be sent back.
+ *
+ * @throws IOException If an error occurs accessing or spooling the resource.
+ */
+ protected final void spoolResource(final HttpServletRequest request, final HttpServletResponse response)
+ throws IOException {
+ // check for a resource, fail if none
+ final URL url = this.getResource(request.getPathInfo());
+ if ( url == null ) {
+ return;
+ }
+
+ // open the connection and the stream (we use the stream to be able
+ // to at least hint to close the connection because there is no
+ // method to explicitly close the conneciton, unfortunately)
+ final URLConnection connection = url.openConnection();
+ try ( final InputStream ins = connection.getInputStream()) {
+ // FELIX-2017 Equinox may return an URL for a non-existing
+ // resource but then (instead of throwing) return null on
+ // getInputStream. We should account for this situation and
+ // just assume a non-existing resource in this case.
+ if (ins == null) {
+ return;
+ }
+
+ // check whether we may return 304/UNMODIFIED
+ long lastModified = connection.getLastModified();
+ if ( lastModified > 0 ) {
+ long ifModifiedSince = request.getDateHeader( "If-Modified-Since" );
+ if ( ifModifiedSince >= ( lastModified / 1000 * 1000 ) ) {
+ // Round down to the nearest second for a proper compare
+ // A ifModifiedSince of -1 will always be less
+ response.setStatus( HttpServletResponse.SC_NOT_MODIFIED );
+
+ return;
+ }
+
+ // have to send, so set the last modified header now
+ response.setDateHeader( "Last-Modified", lastModified ); //$NON-NLS-1$
+ }
+
+ // describe the contents
+ response.setContentType( getServletContext().getMimeType( request.getPathInfo() ) );
+ if (connection.getContentLength() != -1) {
+ response.setContentLength( connection.getContentLength() );
+ }
+ response.setStatus( HttpServletResponse.SC_OK);
+
+ // spool the actual contents
+ final OutputStream out = response.getOutputStream();
+ final byte[] buf = new byte[2048];
+ int rd;
+ while ( ( rd = ins.read( buf ) ) >= 0 ) {
+ out.write( buf, 0, rd );
+ }
+ }
+ }
+
+ /**
+ * Reads the <code>templateFile</code> as a resource through the class
+ * loader of this class converting the binary data into a string using
+ * UTF-8 encoding.
+ *
+ * @param templateFile The absolute path to the template file to read.
+ * @return The contents of the template file as a string
+ *
+ * @throws NullPointerException if <code>templateFile</code> is
+ * <code>null</code>
+ * @throws FileNotFoundException If template file cannot be found
+ * @throws IOException On any other error reading the template file
+ */
+ protected final String readTemplateFile( final String templateFile ) throws IOException {
+ return readTemplateFile( getClass(), templateFile );
+ }
+
+ private final String readTemplateFile( final Class<?> clazz, final String templateFile) throws IOException {
+ try(final InputStream templateStream = clazz.getResourceAsStream( templateFile )) {
+ if ( templateStream != null ) {
+ try ( final StringWriter w = new StringWriter()) {
+ final byte[] buf = new byte[2048];
+ int l;
+ while ( ( l = templateStream.read(buf)) > 0 ) {
+ w.write(new String(buf, 0, l, StandardCharsets.UTF_8));
+ }
+ String str = w.toString();
+ switch ( str.charAt(0) ) { // skip BOM
+ case 0xFEFF: // UTF-16/UTF-32, big-endian
+ case 0xFFFE: // UTF-16, little-endian
+ case 0xEFBB: // UTF-8
+ return str.substring(1);
+ }
+ return str;
+ }
+ }
+ }
+
+ throw new FileNotFoundException("Template " + templateFile + " not found");
+ }
+
+ protected RequestVariableResolver getVariableResolver(final HttpServletRequest request) {
+ return (RequestVariableResolver) request.getAttribute(RequestVariableResolver.REQUEST_ATTRIBUTE);
+ }
+}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/servlet/RequestVariableResolver.java b/webconsole/src/main/java/org/apache/felix/webconsole/servlet/RequestVariableResolver.java
new file mode 100755
index 0000000000..4efdc3aacd
--- /dev/null
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/servlet/RequestVariableResolver.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.webconsole.servlet;
+
+import java.util.HashMap;
+
+/**
+ * The <code>RequestVariableResolver</code> is a <code>HashMap</code> that
+ * is used by the webconsole to process variables in the template.
+ * The resolver is stored as a request attribute with the name
+ * {@link #REQUEST_ATTRIBUTE}.
+ */
+public class RequestVariableResolver extends HashMap<String, Object> {
+
+ /**
+ * The name of the request attribute holding the {@link RequestVariableResolver}
+ * for the request (value is "felix.webconsole.variable.resolver").
+ *
+ * @since 3.0
+ */
+ public static final String REQUEST_ATTRIBUTE = "felix.webconsole.variable.resolver";
+
+ /**
+ * Creates a new variable resolver with default capacity.
+ */
+ public RequestVariableResolver() {
+ super();
+ }
+
+ /**
+ * Returns the string representation of the value stored under the variable
+ * name in this map. If no value is stored under the variable name,
+ * <code>null</code> is returned.
+ *
+ * @param variable The name of the variable whose value is to be returned.
+ * @return The variable value or <code>null</code> if there is no entry
+ * with the given name in this map.
+ */
+ public String resolve( final String variable ) {
+ final Object value = this.get(variable);
+ if ( value != null ) {
+ return value.toString();
+ }
+ return null;
+ }
+}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/servlet/ServletConstants.java b/webconsole/src/main/java/org/apache/felix/webconsole/servlet/ServletConstants.java
new file mode 100755
index 0000000000..7b5f2f1431
--- /dev/null
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/servlet/ServletConstants.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.webconsole.servlet;
+
+/**
+ * Constants for servlets registered with the web console.
+ */
+public abstract class ServletConstants {
+
+ /**
+ * The URI address label under which the servlet is called by
+ * the web console (value is "felix.webconsole.label").
+ * <p>
+ * This service registration property must be set to a single non-empty
+ * String value. Otherwise the Servlet services will
+ * be ignored by the web console and not be used as a plugin.
+ */
+ public static final String PLUGIN_LABEL = "felix.webconsole.label";
+
+ /**
+ * The title under which the servlet is called by
+ * the web console (value is "felix.webconsole.title").
+ * <p>
+ * This property is required for the service to be used as a plugin.
+ * Otherwise the service is just ignored by the web console.
+ * <p>
+ */
+ public static final String PLUGIN_TITLE = "felix.webconsole.title";
+
+ /**
+ * The category under which the servlet is listed in the top
+ * navigation by the web console (value is "felix.webconsole.category").
+ * <p>
+ * If not specified, the servlet is put into the default category.
+ */
+ public static final String PLUGIN_CATEGORY = "felix.webconsole.category";
+
+ /**
+ * The name of the service registration properties providing references
+ * to addition CSS files that should be loaded when rendering the header
+ * for a registered plugin.
+ * <p>
+ * This property is expected to be a single string value, array of string
+ * values or a Collection (or Vector) of string values.
+ */
+ public static final String PLUGIN_CSS_REFERENCES = "felix.webconsole.css";
+
+ /**
+ * The name of the request attribute providing the absolute path of the
+ * Web Console root (value is "felix.webconsole.appRoot"). This consists of
+ * the servlet context path (from <code>HttpServletRequest.getContextPath()</code>)
+ * and the Web Console servlet path (from
+ * <code>HttpServletRequest.getServletPath()</code>,
+ * <code>/system/console</code> by default).
+ * <p>
+ * The type of this request attribute is <code>String</code>.
+ */
+ public static final String ATTR_APP_ROOT = "felix.webconsole.appRoot";
+}
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/servlet/package-info.java b/webconsole/src/main/java/org/apache/felix/webconsole/servlet/package-info.java
new file mode 100755
index 0000000000..6792c7703b
--- /dev/null
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/servlet/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+@org.osgi.annotation.versioning.Version("1.0.0")
+package org.apache.felix.webconsole.servlet;
+
diff --git a/webconsole/src/test/java/org/apache/felix/webconsole/AbstractWebConsolePluginTest.java b/webconsole/src/test/java/org/apache/felix/webconsole/AbstractWebConsolePluginTest.java
index 93cc070ae2..f69505e82e 100755
--- a/webconsole/src/test/java/org/apache/felix/webconsole/AbstractWebConsolePluginTest.java
+++ b/webconsole/src/test/java/org/apache/felix/webconsole/AbstractWebConsolePluginTest.java
@@ -122,6 +122,7 @@ public class AbstractWebConsolePluginTest extends TestCase
private static class PrivateTestPlugin extends TestPlugin
{
+ @SuppressWarnings("unused")
private URL getResource( String name )
{
return null;
@@ -130,6 +131,7 @@ public class AbstractWebConsolePluginTest extends TestCase
private static class ProtectedTestPlugin extends TestPlugin
{
+ @SuppressWarnings("unused")
protected URL getResource( String name )
{
return null;
@@ -138,6 +140,7 @@ public class AbstractWebConsolePluginTest extends TestCase
private static class PackageTestPlugin extends TestPlugin
{
+ @SuppressWarnings("unused")
URL getResource( String name )
{
return null;
@@ -146,6 +149,7 @@ public class AbstractWebConsolePluginTest extends TestCase
private static class PublicTestPlugin extends TestPlugin
{
+ @SuppressWarnings("unused")
public URL getResource( String name )
{
return null;
diff --git a/webconsole/src/test/java/org/apache/felix/webconsole/internal/servlet/OsgiManagerTest.java b/webconsole/src/test/java/org/apache/felix/webconsole/internal/servlet/OsgiManagerTest.java
index f3e243b336..248bc172e0 100755
--- a/webconsole/src/test/java/org/apache/felix/webconsole/internal/servlet/OsgiManagerTest.java
+++ b/webconsole/src/test/java/org/apache/felix/webconsole/internal/servlet/OsgiManagerTest.java
@@ -69,7 +69,7 @@ public class OsgiManagerTest {
OsgiManager.splitCommaSeparatedString(" abc , x.y.z,123"));
}
- @SuppressWarnings({ "unchecked", "rawtypes", "serial" })
+ @SuppressWarnings({ "unchecked", "rawtypes"})
@Test
public void testUpdateDependenciesCustomizerAdd() throws Exception {
BundleContext bc = mockBundleContext();
@@ -97,7 +97,7 @@ public class OsgiManagerTest {
assertEquals(1, updateCalled.size());
}
- @SuppressWarnings({ "unchecked", "rawtypes", "serial" })
+ @SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testUpdateDependenciesCustomzerRemove() throws Exception {
BundleContext bc = mockBundleContext();
[felix-dev] 01/03: No need to branch depback plugin
Posted by cz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch jakarta-servlet-6
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
commit 60fbd5ea7050abc5940b73148ebbf5fb5a4ddd31
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Aug 21 14:43:11 2023 +0200
No need to branch depback plugin
---
webconsole-plugins/deppack/changelog.txt | 6 -
webconsole-plugins/deppack/pom.xml | 154 ------------
.../plugins/deppack/internal/Activator.java | 98 --------
.../plugins/deppack/internal/WebConsolePlugin.java | 260 ---------------------
.../main/resources/OSGI-INF/l10n/bundle.properties | 40 ----
.../resources/OSGI-INF/l10n/bundle_bg.properties | 40 ----
.../resources/OSGI-INF/l10n/bundle_de.properties | 40 ----
.../resources/OSGI-INF/l10n/bundle_ru.properties | 40 ----
.../deppack/src/main/resources/res/plugin.css | 19 --
.../deppack/src/main/resources/res/plugin.html | 55 -----
.../deppack/src/main/resources/res/plugin.js | 172 --------------
11 files changed, 924 deletions(-)
diff --git a/webconsole-plugins/deppack/changelog.txt b/webconsole-plugins/deppack/changelog.txt
deleted file mode 100755
index b1b34642b2..0000000000
--- a/webconsole-plugins/deppack/changelog.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-Initial Release 1.0.0
----------------------
-
-** Improvement
- * [FELIX-3861] - Set felix.webconsole.category on Web Console plugins
- * [FELIX-5510] - Remove usage of org.json form web console plugins
\ No newline at end of file
diff --git a/webconsole-plugins/deppack/pom.xml b/webconsole-plugins/deppack/pom.xml
deleted file mode 100644
index 424dd9f343..0000000000
--- a/webconsole-plugins/deppack/pom.xml
+++ /dev/null
@@ -1,154 +0,0 @@
-<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
- license agreements. See the NOTICE file distributed with this work for additional
- information regarding copyright ownership. The ASF licenses this file to
- you under the Apache License, Version 2.0 (the "License"); you may not use
- this file except in compliance with the License. You may obtain a copy of
- the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
- by applicable law or agreed to in writing, software distributed under the
- License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
- OF ANY KIND, either express or implied. See the License for the specific
- language governing permissions and limitations under the License. -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.felix</groupId>
- <artifactId>felix-parent</artifactId>
- <version>8-SNAPSHOT</version>
- <relativePath>../../../pom/pom.xml</relativePath>
- </parent>
-
- <artifactId>org.apache.felix.webconsole.plugins.deppack</artifactId>
- <packaging>bundle</packaging>
- <version>3.0.0-SNAPSHOT</version>
-
- <name>Apache Felix Web Console Deployment Packages Plugin</name>
- <description>
- This is a plugin for the Apache Felix OSGi web console for displaying Deployment Packages.
- </description>
-
- <scm>
- <connection>scm:git:https://github.com/apache/felix-dev.git</connection>
- <developerConnection>scm:git:https://github.com/apache/felix-dev.git</developerConnection>
- <url>https://gitbox.apache.org/repos/asf?p=felix-dev.git</url>
- </scm>
-
- <properties>
- <felix.java.version>17</felix.java.version>
- </properties>
-
- <build>
- <!-- add UTF-8-to-ISO translated resources -->
- <resources>
- <resource>
- <directory>${basedir}/src/main/resources</directory>
- </resource>
- <resource>
- <directory>target/classes</directory>
- <includes>
- <include>OSGI-INF/**</include>
- </includes>
- <filtering>false</filtering>
- </resource>
- </resources>
-
- <plugins>
- <!-- translate UTF-8 encoded properties files to ISO-8859-1 -->
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>native2ascii-maven-plugin</artifactId>
- <version>1.0-beta-1</version>
- <executions>
- <execution>
- <goals>
- <goal>native2ascii</goal>
- </goals>
- <configuration>
- <encoding>UTF-8</encoding>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.rat</groupId>
- <artifactId>apache-rat-plugin</artifactId>
- <configuration>
- <includes>
- <include>src/**</include>
- </includes>
- <excludes>
- <exclude>src/main/resources/res/*.html</exclude>
- </excludes>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>5.1.8</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-SymbolicName>
- ${artifactId}
- </Bundle-SymbolicName>
- <Bundle-Activator>
- org.apache.felix.webconsole.plugins.deppack.internal.Activator
- </Bundle-Activator>
- <Embed-Dependency>
- org.apache.felix.utils;inline=org/apache/felix/utils/json/JSONWriter**
- </Embed-Dependency>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>jakarta.servlet</groupId>
- <artifactId>jakarta.servlet-api</artifactId>
- <version>6.0.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-fileupload2-core</artifactId>
- <version>2.0.0-M3-SNAPSHOT</version>
- <scope>provided</scope>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-fileupload2-jakarta-servlet6</artifactId>
- <version>2.0.0-M3-SNAPSHOT</version>
- <scope>provided</scope>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>osgi.core</artifactId>
- <version>8.0.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.deploymentadmin</artifactId>
- <version>1.1.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.webconsole</artifactId>
- <version>6.0.0-SNAPSHOT</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.utils</artifactId>
- <version>1.11.8</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-</project>
diff --git a/webconsole-plugins/deppack/src/main/java/org/apache/felix/webconsole/plugins/deppack/internal/Activator.java b/webconsole-plugins/deppack/src/main/java/org/apache/felix/webconsole/plugins/deppack/internal/Activator.java
deleted file mode 100644
index 5bf71d4359..0000000000
--- a/webconsole-plugins/deppack/src/main/java/org/apache/felix/webconsole/plugins/deppack/internal/Activator.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.felix.webconsole.plugins.deppack.internal;
-
-import org.apache.felix.webconsole.SimpleWebConsolePlugin;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.deploymentadmin.DeploymentAdmin;
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
-
-/**
- * Activator is the main starting class.
- */
-public class Activator implements BundleActivator, ServiceTrackerCustomizer
-{
-
- private ServiceTracker tracker;
- private BundleContext context;
-
- private SimpleWebConsolePlugin plugin;
-
- /**
- * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
- */
- public final void start(BundleContext context) throws Exception
- {
- this.context = context;
- this.tracker = new ServiceTracker(context, DeploymentAdmin.class.getName(), this);
- this.tracker.open();
- }
-
- /**
- * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- public final void stop(BundleContext context) throws Exception
- {
- if (tracker != null)
- {
- tracker.close();
- tracker = null;
- }
- }
-
- // - begin tracker
- /**
- * @see org.osgi.util.tracker.ServiceTrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference,
- * java.lang.Object)
- */
- public final void modifiedService(ServiceReference reference, Object service)
- {/* unused */
- }
-
- /**
- * @see org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
- */
- public final Object addingService(ServiceReference reference)
- {
- SimpleWebConsolePlugin plugin = this.plugin;
- if (plugin == null)
- {
- this.plugin = plugin = new WebConsolePlugin(tracker).register(context);
- }
-
- return context.getService(reference);
- }
-
- /**
- * @see org.osgi.util.tracker.ServiceTrackerCustomizer#removedService(org.osgi.framework.ServiceReference,
- * java.lang.Object)
- */
- public final void removedService(ServiceReference reference, Object service)
- {
- SimpleWebConsolePlugin plugin = this.plugin;
-
- if (tracker.getTrackingCount() == 0 && plugin != null)
- {
- plugin.unregister();
- this.plugin = null;
- }
-
- }
-}
diff --git a/webconsole-plugins/deppack/src/main/java/org/apache/felix/webconsole/plugins/deppack/internal/WebConsolePlugin.java b/webconsole-plugins/deppack/src/main/java/org/apache/felix/webconsole/plugins/deppack/internal/WebConsolePlugin.java
deleted file mode 100644
index c8fd45b45f..0000000000
--- a/webconsole-plugins/deppack/src/main/java/org/apache/felix/webconsole/plugins/deppack/internal/WebConsolePlugin.java
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.felix.webconsole.plugins.deppack.internal;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.Map;
-
-import jakarta.servlet.ServletException;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-
-import org.apache.commons.fileupload2.core.FileItem;
-import org.apache.felix.webconsole.AbstractWebConsolePlugin;
-import org.apache.felix.webconsole.DefaultVariableResolver;
-import org.apache.felix.webconsole.SimpleWebConsolePlugin;
-import org.apache.felix.webconsole.WebConsoleUtil;
-import org.apache.felix.webconsole.internal.Util;
-import org.apache.felix.utils.json.JSONWriter;
-import org.osgi.service.deploymentadmin.DeploymentAdmin;
-import org.osgi.service.deploymentadmin.DeploymentPackage;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * DepPackServlet provides a plugin for managing deployment admin packages.
- */
-class WebConsolePlugin extends SimpleWebConsolePlugin
-{
-
- private static final String LABEL = "deppack"; //$NON-NLS-1$
- private static final String TITLE = "%deppack.pluginTitle"; //$NON-NLS-1$
- private static final String CSS[] = { "/" + LABEL + "/res/plugin.css" }; //$NON-NLS-1$ //$NON-NLS-2$
- private static final String CATEGORY = "OSGi"; //$NON-NLS-1$
-
- //
- private static final String ACTION_DEPLOY = "deploydp"; //$NON-NLS-1$
- private static final String ACTION_UNINSTALL = "uninstalldp"; //$NON-NLS-1$
- private static final String PARAMETER_PCK_FILE = "pckfile"; //$NON-NLS-1$
-
- // templates
- private final String TEMPLATE;
-
- private final ServiceTracker adminTracker;
-
- /** Default constructor */
- WebConsolePlugin(ServiceTracker adminTracker)
- {
- super(LABEL, TITLE, CSS);
-
- // load templates
- TEMPLATE = readTemplateFile("/res/plugin.html"); //$NON-NLS-1$
- this.adminTracker = adminTracker;
- }
-
- public String getCategory()
- {
- return CATEGORY;
- }
-
- /**
- * @see jakarta.servlet.http.HttpServlet#doPost(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
- */
- protected void doPost(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException
- {
- // get the uploaded data
- final String action = WebConsoleUtil.getParameter(req, Util.PARAM_ACTION);
- if (ACTION_DEPLOY.equals(action))
- {
- Map params = (Map) req.getAttribute(AbstractWebConsolePlugin.ATTR_FILEUPLOAD);
- if (params != null)
- {
- final FileItem pck = getFileItem(params, PARAMETER_PCK_FILE, false);
- final DeploymentAdmin admin = (DeploymentAdmin) adminTracker.getService();
- if (admin != null)
- {
- try
- {
- admin.installDeploymentPackage(pck.getInputStream());
-
- final String uri = req.getRequestURI();
- resp.sendRedirect(uri);
- return;
- }
- catch ( /*Deployment*/Exception e)
- {
- throw new ServletException("Unable to deploy package.", e);
- }
- }
- }
- throw new ServletException("Upload file or deployment admin missing.");
- }
- else if (ACTION_UNINSTALL.equals(action))
- {
- final String pckId = req.getPathInfo().substring(
- req.getPathInfo().lastIndexOf('/') + 1);
- if (pckId != null && pckId.length() > 0)
- {
- final DeploymentAdmin admin = (DeploymentAdmin) adminTracker.getService();
- if (admin != null)
- {
- try
- {
- final DeploymentPackage pck = admin.getDeploymentPackage(pckId);
- if (pck != null)
- {
- pck.uninstall();
- }
- }
- catch ( /*Deployment*/Exception e)
- {
- throw new ServletException("Unable to undeploy package.", e);
- }
- }
-
- }
-
- final PrintWriter pw = resp.getWriter();
- pw.println("{ \"reload\":true }");
- return;
- }
- throw new ServletException("Unknown action: " + action);
- }
-
- private static final FileItem getFileItem(Map params, String name, boolean isFormField)
- {
- FileItem[] items = (FileItem[]) params.get(name);
- if (items != null)
- {
- for (int i = 0; i < items.length; i++)
- {
- if (items[i].isFormField() == isFormField)
- {
- return items[i];
- }
- }
- }
-
- // nothing found, fail
- return null;
- }
-
- /**
- * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)
- */
- protected void renderContent(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException
- {
-
- final DeploymentAdmin admin = (DeploymentAdmin) adminTracker.getService();
-
- StringWriter w = new StringWriter();
- PrintWriter w2 = new PrintWriter(w);
- JSONWriter jw = new JSONWriter(w2);
- jw.object();
- if (null == admin)
- {
- jw.key("error"); //$NON-NLS-1$
- jw.value(true);
- }
- else
- {
- final DeploymentPackage[] packages = admin.listDeploymentPackages();
- jw.key("data"); //$NON-NLS-1$
-
- jw.array();
- for (int i = 0; i < packages.length; i++)
- {
- packageInfoJson(jw, packages[i]);
- }
- jw.endArray();
-
- }
- jw.endObject();
-
-
- // prepare variables
- DefaultVariableResolver vars = ((DefaultVariableResolver) WebConsoleUtil.getVariableResolver(request));
- vars.put("__data__", w.toString()); //$NON-NLS-1$
-
- response.getWriter().print(TEMPLATE);
- }
-
- private static final void packageInfoJson(JSONWriter jw, DeploymentPackage pack)
- throws IOException
- {
- jw.object();
- jw.key("id"); //$NON-NLS-1$
- jw.value(pack.getName());
- jw.key("name"); //$NON-NLS-1$
- jw.value(pack.getName());
- jw.key("state"); //$NON-NLS-1$
- jw.value(pack.getVersion());
-
- jw.key("actions"); //$NON-NLS-1$
- jw.array();
-
- jw.object();
- jw.key("enabled"); //$NON-NLS-1$
- jw.value(true);
- jw.key("name"); //$NON-NLS-1$
- jw.value("Uninstall");
- jw.key("link"); //$NON-NLS-1$
- jw.value(ACTION_UNINSTALL);
- jw.endObject();
-
- jw.endArray();
-
- jw.key("props"); //$NON-NLS-1$
- jw.array();
- jw.object();
- jw.key("key");
- jw.value("Package Name");
- jw.key("value");
- jw.value(pack.getName());
- jw.endObject();
-
- jw.object();
- jw.key("key");
- jw.value("Version");
- jw.key("value");
- jw.value(pack.getVersion());
- jw.endObject();
-
- final StringBuilder buffer = new StringBuilder();
- for (int i = 0; i < pack.getBundleInfos().length; i++)
- {
- buffer.append(pack.getBundleInfos()[i].getSymbolicName());
- buffer.append(" - "); //$NON-NLS-1$
- buffer.append(pack.getBundleInfos()[i].getVersion());
- buffer.append("<br/>"); //$NON-NLS-1$
- }
- jw.object();
- jw.key("key");
- jw.value("Bundles");
- jw.key("value");
- jw.value(buffer.toString());
- jw.endObject();
-
- jw.endArray();
-
- jw.endObject();
- }
-
-}
diff --git a/webconsole-plugins/deppack/src/main/resources/OSGI-INF/l10n/bundle.properties b/webconsole-plugins/deppack/src/main/resources/OSGI-INF/l10n/bundle.properties
deleted file mode 100644
index 1a0f302576..0000000000
--- a/webconsole-plugins/deppack/src/main/resources/OSGI-INF/l10n/bundle.properties
+++ /dev/null
@@ -1,40 +0,0 @@
-#Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-#
-# Web Console strings for reference all strings here are commented.
-# This file may be used to produce a translation of the strings
-#
-# Note that properties files are ISO-8859-1 encoded. To provide translations
-# for languages requiring different character encodings, you may use the
-# native2ascii Maven Plugin from http://mojo.codehaus.org/native2ascii-maven-plugin/
-# to translate the natively encoded files to ISO-8859-1 during bundle build
-#
-# Translations requiring non-ISO-8859-1 encoding are placed in the
-# src/main/native2ascii/OSGI-INF/l10n folder and are converted using said
-# plugin while building the bundle
-#
-
-# Deployment Admin plugin
-deppack.pluginTitle=Deployment Packages
-deppack.status.no_data=No deployment packages installed!
-deppack.status.no_service=Deployment Admin is not installed/running!
-deppack.status.ok=Deployment Admin service is running
-deppack.details=Details
-deppack.actions=Actions
-deppack.install_update=Install or Update
-deppack.package.name=Package Name
-deppack.bundles=Bundles
-deppack.uninstall=Uninstall
diff --git a/webconsole-plugins/deppack/src/main/resources/OSGI-INF/l10n/bundle_bg.properties b/webconsole-plugins/deppack/src/main/resources/OSGI-INF/l10n/bundle_bg.properties
deleted file mode 100644
index 89c20a2114..0000000000
--- a/webconsole-plugins/deppack/src/main/resources/OSGI-INF/l10n/bundle_bg.properties
+++ /dev/null
@@ -1,40 +0,0 @@
-#Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-#
-# Web Console strings for reference all strings here are commented.
-# This file may be used to produce a translation of the strings
-#
-# Note that properties files are ISO-8859-1 encoded. To provide translations
-# for languages requiring different character encodings, you may use the
-# native2ascii Maven Plugin from http://mojo.codehaus.org/native2ascii-maven-plugin/
-# to translate the natively encoded files to ISO-8859-1 during bundle build
-#
-# Translations requiring non-ISO-8859-1 encoding are placed in the
-# src/main/native2ascii/OSGI-INF/l10n folder and are converted using said
-# plugin while building the bundle
-# native2ascii -encoding utf-8 bundle_bg.raw_properties bundle_bg.properties
-
-# Deployment Admin plugin
-deppack.pluginTitle=Управление на пакети
-deppack.status.no_data=Няма инсталирани пакети!
-deppack.status.no_service=Услугата Deployment Admin не е налична в момента!
-deppack.status.ok=Deployment Admin е наличен и по-долу е показан списъка с пакет
-deppack.details=Детайли
-deppack.actions=Действия
-deppack.install_update=Инсталиране/обновяване
-deppack.package.name=Име на пакет
-deppack.bundles=Бъндъли
-deppack.uninstall=Премахване
diff --git a/webconsole-plugins/deppack/src/main/resources/OSGI-INF/l10n/bundle_de.properties b/webconsole-plugins/deppack/src/main/resources/OSGI-INF/l10n/bundle_de.properties
deleted file mode 100644
index 864181f56e..0000000000
--- a/webconsole-plugins/deppack/src/main/resources/OSGI-INF/l10n/bundle_de.properties
+++ /dev/null
@@ -1,40 +0,0 @@
-#Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-#
-# Web Console strings for reference all strings here are commented.
-# This file may be used to produce a translation of the strings
-#
-# Note that properties files are ISO-8859-1 encoded. To provide translations
-# for languages requiring different character encodings, you may use the
-# native2ascii Maven Plugin from http://mojo.codehaus.org/native2ascii-maven-plugin/
-# to translate the natively encoded files to ISO-8859-1 during bundle build
-#
-# Translations requiring non-ISO-8859-1 encoding are placed in the
-# src/main/native2ascii/OSGI-INF/l10n folder and are converted using said
-# plugin while building the bundle
-#
-
-# Deployment Admin plugin
-deppack.pluginTitle=Deployment Packages
-deppack.status.no_data=Kein Deployment Package ist installiert!
-deppack.status.no_service=Deployment Admin Dienst ist nicht instaliert/aktiv!
-deppack.status.ok=Deployment Admin Dienst ist aktiv
-deppack.details=Details
-deppack.actions=Aktionen
-deppack.install_update=Installieren oder Aktualisieren
-deppack.package.name=Package Name
-deppack.bundles=Bundles
-deppack.uninstall=Deinstallieren
diff --git a/webconsole-plugins/deppack/src/main/resources/OSGI-INF/l10n/bundle_ru.properties b/webconsole-plugins/deppack/src/main/resources/OSGI-INF/l10n/bundle_ru.properties
deleted file mode 100644
index 6895031828..0000000000
--- a/webconsole-plugins/deppack/src/main/resources/OSGI-INF/l10n/bundle_ru.properties
+++ /dev/null
@@ -1,40 +0,0 @@
-#Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-#
-# Web Console strings for reference all strings here are commented.
-# This file may be used to produce a translation of the strings
-#
-# Note that properties files are ISO-8859-1 encoded. To provide translations
-# for languages requiring different character encodings, you may use the
-# native2ascii Maven Plugin from http://mojo.codehaus.org/native2ascii-maven-plugin/
-# to translate the natively encoded files to ISO-8859-1 during bundle build
-#
-# Translations requiring non-ISO-8859-1 encoding are placed in the
-# src/main/native2ascii/OSGI-INF/l10n folder and are converted using said
-# plugin while building the bundle
-#
-
-# Deployment Admin plugin
-deppack.pluginTitle=Управление пакетами
-deppack.status.no_data=Нет установочных пакетов!
-deppack.status.no_service=Сервис Deployment Admin не установлен или не запущен.
-deppack.status.ok=Сервис Deployment Admin работает
-deppack.details=Подробно
-deppack.actions=Действия
-deppack.install_update=Установить/обновить
-deppack.package.name=Имя пакета
-deppack.bundles=Модули
-deppack.uninstall=Удалить
diff --git a/webconsole-plugins/deppack/src/main/resources/res/plugin.css b/webconsole-plugins/deppack/src/main/resources/res/plugin.css
deleted file mode 100644
index c767846deb..0000000000
--- a/webconsole-plugins/deppack/src/main/resources/res/plugin.css
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-.pkgname { cursor:pointer }
-.pkgname span { float:left }
diff --git a/webconsole-plugins/deppack/src/main/resources/res/plugin.html b/webconsole-plugins/deppack/src/main/resources/res/plugin.html
deleted file mode 100644
index ba16fcdb29..0000000000
--- a/webconsole-plugins/deppack/src/main/resources/res/plugin.html
+++ /dev/null
@@ -1,55 +0,0 @@
-<script type="text/javascript" src="${pluginRoot}/res/plugin.js"></script>
-<script type="text/javascript">
-// <![CDATA[
-var i18n = {
- status_no_data : "${deppack.status.no_data}",
- status_no_serv : "${deppack.status.no_service}",
- status_ok : "${deppack.status.ok}",
- package_name : "${deppack.package.name}",
- version : "${version}",
- bundles : "${deppack.bundles}",
- uninstall : "${deppack.uninstall}"
-}
-var packageListData = ${__data__};
-// ]]>
-</script>
-
-<p class="statline"> </p>
-
-<div id="dps1"> <!-- will be hidden if no DP service available -->
-<!-- top header -->
-<form method="post" enctype="multipart/form-data" action="${pluginRoot}">
- <div class="ui-widget-header ui-corner-top buttonGroup" style="text-align: right">
- <input name="action" type="hidden" value="deploydp" />
- <input name="pckfile" type="file" size="50" />
- <input type="submit" value="${deppack.install_update}" />
- </div>
-</form>
-
-<div id="dps2"> <!-- will be hidden if no data available -->
- <table id="plugin_table" class="nicetable">
- <thead>
- <tr>
- <th>${id}</th>
- <th style="width:100%">${deppack.details}</th>
- <th>${version}</th>
- <th colspan="1">${deppack.actions}</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td colspan="5"> </td>
- </tr>
- </tbody>
- </table>
-
- <!-- bottom header -->
- <form method="post" enctype="multipart/form-data" action="${pluginRoot}">
- <div class="ui-widget-header ui-corner-bottom buttonGroup" style="text-align: right">
- <input name="action" type="hidden" value="deploydp" />
- <input name="pckfile" type="file" size="50" />
- <input type="submit" value="${deppack.install_update}" />
- </div>
- </form>
-</div><!--dps2-->
-</div><!--dps1-->
diff --git a/webconsole-plugins/deppack/src/main/resources/res/plugin.js b/webconsole-plugins/deppack/src/main/resources/res/plugin.js
deleted file mode 100644
index 149590e91e..0000000000
--- a/webconsole-plugins/deppack/src/main/resources/res/plugin.js
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-function fixId(id) { return id.replace('.', '_'); }
-
-function data( /* Array of Object */ dataArray ) { // render components
- plugin_table.find('tbody').empty();
- if (dataArray.length == 1) {
- entry( dataArray[0], true );
- } else {
- for ( var idx in dataArray ) {
- entry( dataArray[idx] );
- }
- }
-}
-
-function entry( /* Object */ dataEntry, /* boolean */ singleEntry ) {
- var id = fixId(dataEntry.id);
- var trElement = tr( 'ui-state-active', { 'id': 'entry' + id });
-
- // entry brief
- entryInternal( trElement, dataEntry, singleEntry );
- plugin_table.append(trElement);
-
- // dataEntry detailed properties
- trElement = tr( 'ui-helper-hidden', {
- 'id' : 'entry' + id + '_details'
- });
- if (dataEntry.props) {
- getDataEntryDetails( trElement, dataEntry.props );
- }
- plugin_table.append(trElement);
-}
-
-function entryInternal( /* Element */ parent, /* Object */ dataEntry, /* boolean */ singleEntry ) {
- var id = dataEntry.id;
- var _id = fixId(id);
-
- parent.appendChild( td( null, null, [ text( id ) ] ) );
- parent.appendChild( td( null,
- {
- 'onclick': 'toggleDetails("#entry' + _id + '")',
- 'class': 'pkgname'
- },
- [
- createElement( 'span', 'ui-icon ui-icon-triangle-1-e', { id: 'entry' + _id + '_icon'} ),
- text(dataEntry.name)
- ]
- )
- );
- parent.appendChild( td( null, null, [ text( dataEntry.state ) ] ) );
-
- for ( var aidx in dataEntry.actions ) {
- var action = dataEntry.actions[aidx];
- parent.appendChild( actionButton( action.enabled, id, action.link, action.name ) );
- }
-}
-
-
-/* Element */ function actionButton( /* boolean */ enabled, /* long */ id, /* String */ op, /* String */ opLabel ) {
- var buttonTd = td( "content", { align: "right" } );
- if ( op ) {
- switch (opLabel) {
- case "Uninstall" : opLabel = i18n.uninstall; break;
- }
- var input = createElement( "input", null, {
- type: 'button',
- value: opLabel,
- onclick: 'changeDataEntryState("' + id + '", "' + op + '");'
- });
- if (!enabled) {
- input.setAttribute( "disabled", true );
- $(input).addClass('ui-state-disabled');
- }
- buttonTd.appendChild( input );
- } else {
- addText( buttonTd, "\u00a0" );
- }
- return buttonTd;
-}
-
-
-function getDataEntryDetails( /* Element */ parent, /* Array of Object */ details )
-{
- parent.appendChild( addText( td( "content"), "\u00a0" ) );
-
- var tdEl = td( null, { colspan: 4 } );
- parent.appendChild( tdEl );
-
- var tableEl = createElement( "table", null, { border: 0 } );
- tdEl.appendChild( tableEl );
-
- var tbody = createElement( "tbody" );
- tableEl.appendChild( tbody );
- for (var idx in details) {
- var prop = details[idx];
- var trEl = tr();
- var key = prop.key;
- switch (key) {
- case 'Package Name': key = i18n.package_name; break;
- case 'Version' : key = i18n.version; break;
- case 'Bundles' : key = i18n.bundles; break;
- }
- trEl.appendChild( addText( td( null, { noWrap: true } ), key ) );
-
- var proptd = td();
- trEl.appendChild( proptd );
- $(proptd).html( prop.value ? prop.value : "\u00a0");
-
- tbody.appendChild( trEl );
- }
- }
-
-
-function changeDataEntryState(/* long */ id, /* String */ action) {
- var parm = pluginRoot + "/" + id + "?action=" + action;
- $.post(parm, null, function() { // always reload
- document.location.reload();
- }, "text");
-}
-
-
-function toggleDetails(name) {
- var icon = $(name + '_icon');
- var details = $(name + '_details');
- var show = icon.attr('show');
- if (typeof show == 'undefined') show = '';
- icon.attr('show', show ? '' : 'true');
-
- if (show == 'true') {
- icon.removeClass('ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-e');
- details.addClass('ui-helper-hidden');
- } else {
- icon.removeClass('ui-icon-triangle-1-e').addClass('ui-icon-triangle-1-s');
- details.removeClass('ui-helper-hidden');
- }
-}
-
-var plugin_table = false;
-$(document).ready(function() {
- plugin_table = $('#plugin_table');
- var /* Array of Data Objects */ bundleData = packageListData;
- if (bundleData.error) {
- $('.statline').text(i18n.status_no_serv);
- $('#dps1').addClass('ui-helper-hidden');
- } else if (!bundleData.data || bundleData.data.length == 0) {
- $('.statline').text(i18n.status_no_data);
- $('#dps1').removeClass('ui-helper-hidden');
- $('#dps2').addClass('ui-helper-hidden');
- } else {
- data( bundleData.data );
- $('.statline').text(i18n.status_ok);
- $('#dps1').removeClass('ui-helper-hidden');
- $('#dps2').removeClass('ui-helper-hidden');
- initStaticWidgets(plugin_table);
- }
-});
-