This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new 02ca43b4ef FELIX-6623 : Use Http Whiteboard for Web Console
registration
02ca43b4ef is described below
commit 02ca43b4ef06da9c14204ea33a4a778236aac871
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Wed Aug 16 07:42:56 2023 +0200
FELIX-6623 : Use Http Whiteboard for Web Console registration
---
webconsole/pom.xml | 7 +-
.../felix/webconsole/AbstractWebConsolePlugin.java | 14 +-
.../felix/webconsole/DefaultBrandingPlugin.java | 5 +-
.../apache/felix/webconsole/WebConsoleUtil.java | 47 +--
.../internal/core/BundleContextUtil.java | 6 +-
.../webconsole/internal/core/BundlesServlet.java | 405 +++++++--------------
.../webconsole/internal/servlet/OsgiManager.java | 18 +-
.../felix/webconsole/internal/servlet/Plugin.java | 9 +-
8 files changed, 183 insertions(+), 328 deletions(-)
diff --git a/webconsole/pom.xml b/webconsole/pom.xml
index 1a6f58f147..7f044c4fd7 100644
--- a/webconsole/pom.xml
+++ b/webconsole/pom.xml
@@ -115,7 +115,7 @@
</Export-Package>
<!-- Import-Package header is also used for the all
bundle -->
<Import-Package>
- javax.servlet.*;version="[2.4,5)",
+ javax.servlet.*;version="[3,5)",
!javax.portlet,
!org.apache.felix.bundlerepository,
!org.osgi.service.obr,
@@ -350,8 +350,8 @@
<dependency>
<groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.4</version>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.0.1</version>
<scope>provided</scope>
</dependency>
@@ -442,7 +442,6 @@
<scope>provided</scope>
<optional>true</optional>
</dependency>
-
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
b/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
index 4bb2563c07..25932644a5 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
@@ -61,13 +61,16 @@ import org.osgi.service.log.LogService;
* options. One of the options is to extend the AbstractWebConsolePlugin
overwriting
* the {@link #renderContent(HttpServletRequest, HttpServletResponse)} method.
*/
-public abstract class AbstractWebConsolePlugin extends HttpServlet
-{
+public abstract class AbstractWebConsolePlugin extends HttpServlet {
/** Pseudo class version ID to keep the IDE quite. */
private static final long serialVersionUID = 1L;
- /** The name of the request attribute containing the map of FileItems from
the POST request */
+ /**
+ * The name of the request attribute containing the map of FileItems from
the POST request.
+ * @deprecated Use the Servlet API for uploads
+ */
+ @Deprecated
public static final String ATTR_FILEUPLOAD =
"org.apache.felix.webconsole.fileupload"; //$NON-NLS-1$
/**
@@ -84,7 +87,9 @@ public abstract class AbstractWebConsolePlugin extends
HttpServlet
* Without setting this attribute, your plugin will not work if there is a
security manager enabled.
* It is guaranteed, that your plugin has permissions to read/write/delete
files to the location,
* provided by the bundle context.
+ * @deprecated Use the Servlet API for uploads
*/
+ @Deprecated
public static final String ATTR_FILEUPLOAD_REPO =
"org.apache.felix.webconsole.fileupload.repo"; //$NON-NLS-1$
/**
@@ -817,8 +822,9 @@ public abstract class AbstractWebConsolePlugin extends
HttpServlet
* parameter value or <code>null</code> if not set. If multipart is used,
* and the specified parameter is field - then the value of the parameter
* is returned.
- * @deprecated use {@link WebConsoleUtil#getParameter(HttpServletRequest,
String)}
+ * @deprecated Use the Servlet API for uploads
*/
+ @Deprecated
public static final String getParameter( HttpServletRequest request,
String name )
{
return WebConsoleUtil.getParameter(request, name);
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/DefaultBrandingPlugin.java
b/webconsole/src/main/java/org/apache/felix/webconsole/DefaultBrandingPlugin.java
index 0a0a897f99..0da020b530 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/DefaultBrandingPlugin.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/DefaultBrandingPlugin.java
@@ -32,7 +32,8 @@ import java.util.Properties;
* <p>
* This default implementation provides Apache Felix based default branding
* as follows:
- * <table summary="Web Console Branding Properties">
+ * <table>
+ * <caption>Web Console Branding Properties</caption>
* <tr><th>Name</th><th>Property Name</th><th>Default Value</th></tr>
* <tr>
* <td>Brand Name</td>
@@ -47,7 +48,7 @@ import java.util.Properties;
* <tr>
* <td>Product URL</td>
* <td>webconsole.product.url</td>
- * <td>http://felix.apache.org</td>
+ * <td>https://felix.apache.org</td>
* </tr>
* <tr>
* <td>Product Image</td>
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
index 040e21211d..e48421e589 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
@@ -25,7 +25,6 @@ import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.net.URLDecoder;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -121,28 +120,26 @@ public final class WebConsoleUtil
* parameter value or <code>null</code> if not set. If multipart is used,
* and the specified parameter is field - then the value of the parameter
* is returned.
+ * @deprecated Use the Servlet API for uploads
*/
- public static final String getParameter( HttpServletRequest request,
String name )
- {
+ @Deprecated
+ public static final String getParameter( final HttpServletRequest request,
final String name ) {
// just get the parameter if not a multipart/form-data POST
- if ( !FileUploadBase.isMultipartContent( new ServletRequestContext(
request ) ) )
- {
+ if ( !FileUploadBase.isMultipartContent( new ServletRequestContext(
request ) ) ) {
return request.getParameter( name );
}
// check, whether we already have the parameters
@SuppressWarnings("unchecked")
Map<String, FileItem[]> params = ( Map<String, FileItem[]> )
request.getAttribute( AbstractWebConsolePlugin.ATTR_FILEUPLOAD );
- if ( params == null )
- {
+ if ( params == null ) {
// parameters not read yet, read now
// Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold( 256000 );
// See https://issues.apache.org/jira/browse/FELIX-4660
final Object repo = request.getAttribute(
AbstractWebConsolePlugin.ATTR_FILEUPLOAD_REPO );
- if ( repo instanceof File )
- {
+ if ( repo instanceof File ) {
factory.setRepository( (File) repo );
}
@@ -153,20 +150,13 @@ public final class WebConsoleUtil
// Parse the request
params = new HashMap<>();
- try
- {
+ try {
final List<FileItem> items = upload.parseRequest( request );
- for ( final Iterator<FileItem> fiter = items.iterator();
fiter.hasNext(); )
- {
- final FileItem fi = fiter.next();
+ for(final FileItem fi : items) {
FileItem[] current = ( FileItem[] ) params.get(
fi.getFieldName() );
- if ( current == null )
- {
- current = new FileItem[]
- { fi };
- }
- else
- {
+ if ( current == null ) {
+ current = new FileItem[] { fi };
+ } else {
FileItem[] newCurrent = new FileItem[current.length +
1];
System.arraycopy( current, 0, newCurrent, 0,
current.length );
newCurrent[current.length] = fi;
@@ -174,22 +164,17 @@ public final class WebConsoleUtil
}
params.put( fi.getFieldName(), current );
}
- }
- catch ( FileUploadException fue )
- {
+ } catch ( FileUploadException fue ) {
// fail
return null;
}
request.setAttribute( AbstractWebConsolePlugin.ATTR_FILEUPLOAD,
params );
}
- FileItem[] param = ( FileItem[] ) params.get( name );
- if ( param != null )
- {
- for ( int i = 0; i < param.length; i++ )
- {
- if ( param[i].isFormField() )
- {
+ final FileItem[] param = ( FileItem[] ) params.get( name );
+ if ( param != null ) {
+ for ( int i = 0; i < param.length; i++ ) {
+ if ( param[i].isFormField() ) {
return param[i].getString();
}
}
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleContextUtil.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleContextUtil.java
index 4148fe2e18..bf78905532 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleContextUtil.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleContextUtil.java
@@ -24,8 +24,8 @@ import org.osgi.framework.Constants;
/**
* The <code>BundleContextUtil</code> class.
*/
-public class BundleContextUtil
-{
+public class BundleContextUtil {
+
/**
* This property defines which bundle context the web console plugins use
to
* get the list of bundles and services. It defaults to {@link
#WORK_CTX_OWN}.
@@ -44,6 +44,8 @@ public class BundleContextUtil
/**
* Get the working bundle context: the bundle context to lookup bundles and
* services.
+ * @param bc the bundle context of the web console plugin
+ * @return the bundle context to use
*/
public static BundleContext getWorkingBundleContext( final BundleContext
bc)
{
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 130419e02e..80afee3d06 100644
---
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
@@ -18,7 +18,10 @@ package org.apache.felix.webconsole.internal.core;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
@@ -27,6 +30,7 @@ import java.text.MessageFormat;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.Dictionary;
@@ -46,12 +50,12 @@ import java.util.jar.Manifest;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.Part;
-import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.io.IOUtils;
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.AbstractWebConsolePlugin;
import org.apache.felix.webconsole.ConfigurationPrinter;
import org.apache.felix.webconsole.DefaultVariableResolver;
import org.apache.felix.webconsole.SimpleWebConsolePlugin;
@@ -143,8 +147,7 @@ public class BundlesServlet extends SimpleWebConsolePlugin
implements OsgiManage
* @see
org.apache.felix.webconsole.AbstractWebConsolePlugin#activate(org.osgi.framework.BundleContext)
*/
@Override
- public void activate( BundleContext bundleContext )
- {
+ public void activate( BundleContext bundleContext ) {
super.activate( bundleContext );
bundleInfoTracker = new ServiceTracker<>( bundleContext,
BundleInfoProvider.class, new
ServiceTrackerCustomizer<BundleInfoProvider,BundleInfoProvider>() {
@@ -357,20 +360,23 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
* @see
javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
*/
@Override
- protected void doPost( HttpServletRequest req, HttpServletResponse resp )
throws ServletException, IOException
- {
+ protected void doPost( HttpServletRequest req, HttpServletResponse resp )
+ throws ServletException, IOException {
boolean success = false;
BundleException bundleException = null;
- final String action = WebConsoleUtil.getParameter( req, "action" );
- if ( "refreshPackages".equals( action ) )
- {
+ final String action;
+ if (req.getParts().isEmpty()) {
+ action = req.getParameter( "action" );
+ } else {
+ action = getValue(req, "action");
+ }
+
+ if ( "refreshPackages".equals( action ) ) {
// refresh packages and give it most 15 seconds to finish
final FrameworkWiring fw =
getBundleContext().getBundle(Constants.SYSTEM_BUNDLE_LOCATION).adapt(FrameworkWiring.class);
BaseUpdateInstallHelper.refreshPackages( fw, getBundleContext(),
15000L, null );
success = true;
- }
- else if ( "install".equals( action ) )
- {
+ } else if ( "install".equals( action ) ) {
installBundles( req );
if (req.getRequestURI().endsWith( "/install" )) {
@@ -382,65 +388,43 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
}
return;
- }
- else
- {
+ } else {
final RequestInfo reqInfo = new RequestInfo( req );
- if ( reqInfo.bundle == null && reqInfo.bundleRequested )
- {
+ if ( reqInfo.bundle == null && reqInfo.bundleRequested ) {
resp.sendError( 404 );
return;
}
final Bundle bundle = reqInfo.bundle;
- if ( bundle != null )
- {
- if ( "start".equals( action ) )
- {
+ if ( bundle != null ) {
+ if ( "start".equals( action ) ) {
// start bundle
- try
- {
+ try {
bundle.start();
- }
- catch ( BundleException be )
- {
+ } catch ( BundleException be ) {
bundleException = be;
log( "Cannot start", be );
}
- }
- else if ( "stop".equals( action ) )
- {
+ } else if ( "stop".equals( action ) ) {
// stop bundle
- try
- {
+ try {
bundle.stop();
- }
- catch ( BundleException be )
- {
+ } catch ( BundleException be ) {
bundleException = be;
log( "Cannot stop", be );
}
- }
- else if ( "refresh".equals( action ) )
- {
+ } else if ( "refresh".equals( action ) ) {
// refresh bundle wiring and give at most 5 seconds to
finish
final FrameworkWiring fw =
getBundleContext().getBundle(Constants.SYSTEM_BUNDLE_LOCATION).adapt(FrameworkWiring.class);
BaseUpdateInstallHelper.refreshPackages( fw,
getBundleContext(), 5000L, bundle );
- }
- else if ( "update".equals( action ) )
- {
+ } else if ( "update".equals( action ) ) {
// update the bundle
update( bundle );
- }
- else if ( "uninstall".equals( action ) )
- {
+ } else if ( "uninstall".equals( action ) ) {
// uninstall bundle
- try
- {
+ try {
bundle.uninstall();
- }
- catch ( BundleException be )
- {
+ } catch ( BundleException be ) {
bundleException = be;
log( "Cannot uninstall", be );
}
@@ -449,13 +433,10 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
// write the state only
resp.setContentType( "application/json" ); //$NON-NLS-1$
resp.setCharacterEncoding( "UTF-8" ); //$NON-NLS-1$
- if ( null == getBundleContext() )
- {
+ if ( null == getBundleContext() ) {
// refresh package on the web console itself or some of
it's dependencies
resp.getWriter().print("false"); //$NON-NLS-1$
- }
- else
- {
+ } else {
resp.getWriter().print( "{\"fragment\":" +
isFragmentBundle( bundle ) //$NON-NLS-1$
+ ",\"stateRaw\":" + bundle.getState() + "}" );
//$NON-NLS-1$ //$NON-NLS-2$
}
@@ -463,27 +444,20 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
}
}
- if ( success && null != getBundleContext() )
- {
+ if ( success && null != getBundleContext() ) {
final String pluginRoot = ( String ) req.getAttribute(
WebConsoleConstants.ATTR_PLUGIN_ROOT );
final String servicesRoot = getServicesRoot( req );
- try
- {
+ try {
this.renderJSON( resp, null, pluginRoot, servicesRoot,
req.getLocale(), req.getParameter(FILTER_PARAM), bundleException );
- }
- catch (InvalidSyntaxException e)
- {
+ } catch (InvalidSyntaxException e) {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Invalid LDAP filter specified");
}
- }
- else
- {
+ } else {
super.doPost( req, resp );
}
}
- private String getServicesRoot(HttpServletRequest request)
- {
+ private String getServicesRoot(HttpServletRequest request) {
return ( ( String ) request.getAttribute(
WebConsoleConstants.ATTR_APP_ROOT ) ) +
"/" + ServicesServlet.LABEL + "/";
}
@@ -518,14 +492,11 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
// search
final Bundle[] bundles =
BundleContextUtil.getWorkingBundleContext(this.getBundleContext()).getBundles();
- for(int i=0; i<bundles.length; i++)
- {
+ for(int i=0; i<bundles.length; i++) {
final Bundle bundle = bundles[i];
// check symbolic name first
- if ( symbolicName.equals(bundle.getSymbolicName()) )
- {
- if ( version == null ||
version.equals(bundle.getHeaders().get(Constants.BUNDLE_VERSION)) )
- {
+ if ( symbolicName.equals(bundle.getSymbolicName()) ) {
+ if ( version == null ||
version.equals(bundle.getHeaders().get(Constants.BUNDLE_VERSION)) ) {
return bundle;
}
}
@@ -537,8 +508,7 @@ public class BundlesServlet extends SimpleWebConsolePlugin
implements OsgiManage
}
- private void appendBundleInfoCount( final StringBuilder buf, String msg,
int count )
- {
+ private void appendBundleInfoCount( final StringBuilder buf, String msg,
int count ) {
buf.append(count);
buf.append(" bundle");
if ( count != 1 )
@@ -551,6 +521,7 @@ public class BundlesServlet extends SimpleWebConsolePlugin
implements OsgiManage
* @see
org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
*/
@Override
+ @SuppressWarnings("unchecked")
protected void renderContent( HttpServletRequest request,
HttpServletResponse response ) throws IOException
{
// get request info from request attribute
@@ -904,7 +875,7 @@ public class BundlesServlet extends SimpleWebConsolePlugin
implements OsgiManage
StartLevel sl = getStartLevel();
if ( sl != null )
{
- return new Integer( sl.getBundleStartLevel( bundle ) );
+ return sl.getBundleStartLevel( bundle );
}
}
@@ -913,7 +884,7 @@ public class BundlesServlet extends SimpleWebConsolePlugin
implements OsgiManage
}
- private void listImportExport( List 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 )
@@ -921,24 +892,15 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
return;
}
- Map usingBundles = new TreeMap();
+ Map<String, Bundle> usingBundles = new TreeMap<>();
ExportedPackage[] exports = packageAdmin.getExportedPackages( bundle );
- if ( exports != null && exports.length > 0 )
- {
+ if ( exports != null && exports.length > 0 ) {
// do alphabetical sort
- Arrays.sort( exports, new Comparator()
- {
- public int compare( ExportedPackage p1, ExportedPackage p2 )
- {
- return p1.getName().compareTo( p2.getName() );
- }
-
-
+ Arrays.sort( exports, new Comparator<ExportedPackage>() {
@Override
- public int compare( Object o1, Object o2 )
- {
- return compare( ( ExportedPackage ) o1, ( ExportedPackage
) o2 );
+ public int compare( ExportedPackage p1, ExportedPackage p2 ) {
+ return p1.getName().compareTo( p2.getName() );
}
} );
@@ -970,7 +932,7 @@ public class BundlesServlet extends SimpleWebConsolePlugin
implements OsgiManage
if ( exports != null && exports.length > 0 )
{
// collect import packages first
- final List imports = new ArrayList();
+ final List<ExportedPackage> imports = new ArrayList<>();
for ( int i = 0; i < exports.length; i++ )
{
final ExportedPackage ep = exports[i];
@@ -987,34 +949,21 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
}
// now sort
Object[] val;
- if ( imports.size() > 0 )
- {
- final ExportedPackage[] packages = ( ExportedPackage[] )
imports.toArray( new ExportedPackage[imports
-
.size()] );
- Arrays.sort( packages, new Comparator()
- {
- public int compare( ExportedPackage p1, ExportedPackage p2
)
- {
- return p1.getName().compareTo( p2.getName() );
- }
-
-
+ if ( imports.size() > 0 ) {
+ final ExportedPackage[] packages = ( ExportedPackage[] )
imports.toArray( new ExportedPackage[imports.size()] );
+ Arrays.sort( packages, new Comparator<ExportedPackage>() {
@Override
- public int compare( Object o1, Object o2 )
- {
- return compare( ( ExportedPackage ) o1, (
ExportedPackage ) o2 );
+ public int compare( ExportedPackage p1, ExportedPackage p2
) {
+ return p1.getName().compareTo( p2.getName() );
}
} );
// and finally print out
val = new Object[packages.length];
- for ( int i = 0; i < packages.length; i++ )
- {
+ for ( int i = 0; i < packages.length; i++ ) {
ExportedPackage ep = packages[i];
val[i] = collectImport( ep.getName(), ep.getVersion(),
false, ep, pluginRoot );
}
- }
- else
- {
+ } else {
// add description if there are no imports
val = new Object[1];
val[0] = "None";
@@ -1023,13 +972,10 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
keyVal( props, "Imported Packages", val );
}
- if ( !usingBundles.isEmpty() )
- {
+ if ( !usingBundles.isEmpty() ) {
Object[] val = new Object[usingBundles.size()];
int index = 0;
- for ( Iterator ui = usingBundles.values().iterator();
ui.hasNext(); )
- {
- Bundle usingBundle = ( Bundle ) ui.next();
+ for(final Bundle usingBundle : usingBundles.values()) {
val[index] = getBundleDescriptor( usingBundle, pluginRoot );
index++;
}
@@ -1038,30 +984,20 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
}
- private void listImportExportsUnresolved( final List props, Bundle bundle,
final String pluginRoot )
- {
- Dictionary dict = bundle.getHeaders();
+ private void listImportExportsUnresolved( final List<Map<String, Object>>
props, Bundle bundle, final String pluginRoot ) {
+ final Dictionary<String, String> dict = bundle.getHeaders();
String target = ( String ) dict.get( Constants.EXPORT_PACKAGE );
- if ( target != null )
- {
+ if ( target != null ) {
Clause[] pkgs = Parser.parseHeader( target );
- if ( pkgs != null && pkgs.length > 0 )
- {
+ if ( pkgs != null && pkgs.length > 0 ) {
// do alphabetical sort
- Arrays.sort( pkgs, new Comparator()
- {
+ Arrays.sort( pkgs, new Comparator<Clause>() {
+ @Override
public int compare( Clause p1, Clause p2 )
{
return p1.getName().compareTo( p2.getName() );
}
-
-
- @Override
- public int compare( Object o1, Object o2 )
- {
- return compare( ( Clause) o1, ( Clause ) o2 );
- }
} );
Object[] val = new Object[pkgs.length];
@@ -1084,7 +1020,7 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
Clause[] pkgs = Parser.parseHeader( target );
if ( pkgs != null && pkgs.length > 0 )
{
- Map imports = new TreeMap();
+ Map<String, Clause> imports = new TreeMap<>();
for ( int i = 0; i < pkgs.length; i++ )
{
Clause pkg = pkgs[i];
@@ -1092,7 +1028,7 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
}
// collect import packages first
- final Map candidates = new HashMap();
+ final Map<String, ExportedPackage> candidates = new
HashMap<>();
PackageAdmin packageAdmin = getPackageAdmin();
if ( packageAdmin != null )
{
@@ -1152,7 +1088,7 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
}
}
- private String getServiceID(ServiceReference ref, final String
servicesRoot)
+ private String getServiceID(ServiceReference<?> ref, final String
servicesRoot)
{
String id = ref.getProperty( Constants.SERVICE_ID ).toString();
@@ -1169,9 +1105,9 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
}
- private void listServices( List props, Bundle bundle, final String
servicesRoot )
+ private void listServices( List<Map<String, Object>> props, Bundle bundle,
final String servicesRoot )
{
- ServiceReference[] refs = bundle.getRegisteredServices();
+ ServiceReference<?>[] refs = bundle.getRegisteredServices();
if ( refs == null || refs.length == 0 )
{
return;
@@ -1183,7 +1119,7 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
String key = "Service ID " + getServiceID( refs[i], servicesRoot );
- List val = new ArrayList();
+ List<String> val = new ArrayList<>();
appendProperty( val, refs[i], Constants.OBJECTCLASS, "Types" );
appendProperty( val, refs[i], Constants.SERVICE_PID, "Service PID"
);
@@ -1195,28 +1131,27 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
appendProperty( val, refs[i], Constants.SERVICE_DESCRIPTION,
"Description" );
appendProperty( val, refs[i], Constants.SERVICE_VENDOR, "Vendor" );
- keyVal( props, key, val.toArray(new Object[val.size()]));
+ keyVal( props, key, val.toArray(new String[val.size()]));
}
}
- private void listHeaders( List props, Bundle bundle )
+ private void listHeaders( List<Map<String, Object>> props, Bundle bundle )
{
- List val = new ArrayList();
+ final List<String> val = new ArrayList<>();
- Dictionary headers = bundle.getHeaders(""); // don't localize at all -
raw headers
- Enumeration he = headers.keys();
- while ( he.hasMoreElements() )
- {
- Object header = he.nextElement();
- String value = String.valueOf(headers.get( header ));
+ final Dictionary<String, String> headers = bundle.getHeaders(""); //
don't localize at all - raw headers
+ final Enumeration<String> he = headers.keys();
+ while ( he.hasMoreElements() ) {
+ final String header = he.nextElement();
+ String value = headers.get( header );
// Package headers may be long, support line breaking by
// ensuring blanks after comma and semicolon.
value = enableLineWrapping(value);
val.add( header + ": " + value );
}
- keyVal( props, "Manifest Headers", val.toArray(new Object[val.size()])
);
+ keyVal( props, "Manifest Headers", val.toArray(new String[val.size()])
);
}
private static final String enableLineWrapping(final String value)
@@ -1234,7 +1169,7 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
return sb.toString();
}
- private void listFragmentInfo( final List props, final Bundle bundle,
final String pluginRoot )
+ private void listFragmentInfo( final List<Map<String, Object>> props,
final Bundle bundle, final String pluginRoot )
{
if ( isFragmentBundle( bundle ) )
@@ -1267,7 +1202,7 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
}
- private void appendProperty( final List props, ServiceReference ref,
String name, String label )
+ private void appendProperty( final List<String> props, ServiceReference<?>
ref, String name, String label )
{
StringBuilder dest = new StringBuilder();
Object value = ref.getProperty( name );
@@ -1543,35 +1478,33 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
//---------- Bundle Installation handler (former InstallAction)
- private void installBundles( HttpServletRequest request ) throws
IOException
- {
-
- // get the uploaded data
- final Map params = ( Map ) request.getAttribute(
AbstractWebConsolePlugin.ATTR_FILEUPLOAD );
- if ( params == null )
- {
+ private String getValue(final HttpServletRequest request, final String
fieldName) throws ServletException, IOException {
+ final Part part = request.getPart(fieldName);
+ if ( part != null ) {
+ return IOUtils.toString(part.getInputStream(), "UTF-8");
+ }
+ return null;
+ }
+
+ private void installBundles( final HttpServletRequest request )
+ throws IOException, ServletException {
+ final Collection<Part> bundleItems = request.getParts();
+ if ( bundleItems.isEmpty() ) {
return;
}
final long uploadId;
- final String uidVal = WebConsoleUtil.getParameter( request, "uploadid"
);
+ final String uidVal = this.getValue(request, "uploadid");
if ( uidVal != null ) {
uploadId = Long.valueOf(uidVal);
} else {
uploadId = -1;
}
- final FileItem startItem = getParameter( params, FIELD_START );
- final FileItem startLevelItem = getParameter( params, FIELD_STARTLEVEL
);
- final FileItem[] bundleItems = getFileItems( params, FIELD_BUNDLEFILE
);
- final FileItem refreshPackagesItem = getParameter( params,
FIELD_REFRESH_PACKAGES );
- final FileItem parallelVersionItem = getParameter( params,
FIELD_PARALLEL_VERSION );
-
- // don't care any more if no bundle item
- if ( bundleItems.length == 0 )
- {
- return;
- }
+ final String startItem = this.getValue(request, FIELD_START);
+ final String startLevelItem = this.getValue(request, FIELD_STARTLEVEL);
+ final String refreshPackagesItem = this.getValue(request,
FIELD_REFRESH_PACKAGES);
+ final String parallelVersionItem = this.getValue(request,
FIELD_PARALLEL_VERSION);
// default values
// it exists
@@ -1579,96 +1512,51 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
String bundleLocation = "inputstream:";
// convert the start level value
- if ( startLevelItem != null )
- {
- try
- {
- startLevel = Integer.parseInt( startLevelItem.getString() );
- }
- catch ( NumberFormatException nfe )
- {
+ if ( startLevelItem != null ) {
+ try {
+ startLevel = Integer.parseInt( startLevelItem );
+ } catch ( NumberFormatException nfe ) {
log( LogService.LOG_INFO, "Cannot parse start level parameter
" + startLevelItem
+ " to a number, not setting start level" );
}
}
- for ( int i = 0; i < bundleItems.length; i++ )
- {
- final FileItem bundleItem = bundleItems[i];
+ for(final Part part : bundleItems) {
+ if (!FIELD_BUNDLEFILE.equals(part.getName())) {
+ continue;
+ }
// write the bundle data to a temporary file to ease processing
File tmpFile = null;
- try
- {
+ try {
// copy the data to a file for better processing
tmpFile = File.createTempFile( "install", ".tmp" );
- tmpFile.delete(); // FIX for FILEUPLOAD-293
- bundleItem.write( tmpFile );
- }
- catch ( Exception e )
- {
- log( LogService.LOG_ERROR, "Problem accessing uploaded bundle
file: " + bundleItem.getName(), e );
+ try (final InputStream bundleStream = part.getInputStream();
+ final OutputStream out = new FileOutputStream(tmpFile)) {
+ IOUtils.copy(bundleStream, out);
+ }
+ } catch ( final Exception e ) {
+ log( LogService.LOG_ERROR, "Problem accessing uploaded bundle
file: " + part.getName(), e );
// remove the tmporary file
- if ( tmpFile != null )
- {
+ if ( tmpFile != null && tmpFile.exists()) {
tmpFile.delete();
tmpFile = null;
}
}
// install or update the bundle now
- if ( tmpFile != null )
- {
+ if ( tmpFile != null ) {
// start, refreshPackages just needs to exist, don't care for
value
final boolean start = startItem != null;
final boolean refreshPackages = refreshPackagesItem != null;
final boolean parallelVersion = parallelVersionItem != null;
- bundleLocation = "inputstream:" + bundleItem.getName();
+ bundleLocation = "inputstream:".concat(part.getName());
installBundle( bundleLocation, tmpFile, startLevel, start,
refreshPackages, parallelVersion, uploadId);
}
}
}
-
- private FileItem getParameter( Map params, String name )
- {
- FileItem[] items = ( FileItem[] ) params.get( name );
- if ( items != null )
- {
- for ( int i = 0; i < items.length; i++ )
- {
- if ( items[i].isFormField() )
- {
- return items[i];
- }
- }
- }
-
- // nothing found, fail
- return null;
- }
-
-
- private FileItem[] getFileItems( Map params, String name )
- {
- final List files = new ArrayList();
- FileItem[] items = ( FileItem[] ) params.get( name );
- if ( items != null )
- {
- for ( int i = 0; i < items.length; i++ )
- {
- if ( !items[i].isFormField() && items[i].getSize() > 0 )
- {
- files.add( items[i] );
- }
- }
- }
-
- return ( FileItem[] ) files.toArray( new FileItem[files.size()] );
- }
-
-
private void installBundle( String location, File bundleFile, int
startLevel, boolean start, boolean refreshPackages, boolean parallelVersion,
final long uploadId)
throws IOException
{
@@ -1721,48 +1609,29 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
}
}
-
- private String getSymbolicName( File bundleFile )
- {
- return getSymbolicNameVersion(bundleFile).getKey();
- }
-
- private Map.Entry<String, String> getSymbolicNameVersion( File bundleFile )
- {
+ private Map.Entry<String, String> getSymbolicNameVersion( File bundleFile
) {
JarFile jar = null;
- try
- {
+ try {
jar = new JarFile( bundleFile );
- Manifest m = jar.getManifest();
- if ( m != null )
- {
+ final Manifest m = jar.getManifest();
+ if ( m != null ) {
String sn = m.getMainAttributes().getValue(
Constants.BUNDLE_SYMBOLICNAME );
- if ( sn != null )
- {
+ if ( sn != null ) {
final int paramPos = sn.indexOf(';');
- if ( paramPos != -1 )
- {
+ if ( paramPos != -1 ) {
sn = sn.substring(0, paramPos);
}
}
- String v = m.getMainAttributes().getValue(
Constants.BUNDLE_VERSION );
- return new AbstractMap.SimpleImmutableEntry(sn, v);
+ final String v = m.getMainAttributes().getValue(
Constants.BUNDLE_VERSION );
+ return new AbstractMap.SimpleImmutableEntry<>(sn, v);
}
- }
- catch ( IOException ioe )
- {
+ } catch ( final IOException ioe ) {
log( LogService.LOG_WARNING, "Cannot extract symbolic name and
version of bundle file " + bundleFile, ioe );
- }
- finally
- {
- if ( jar != null )
- {
- try
- {
+ } finally {
+ if ( jar != null ) {
+ try {
jar.close();
- }
- catch ( IOException ioe )
- {
+ } catch ( IOException ioe ) {
// ignore
}
}
@@ -1772,21 +1641,15 @@ public class BundlesServlet extends
SimpleWebConsolePlugin implements OsgiManage
return null;
}
-
-
-
private void installBackground( final File bundleFile, final String
location, final int startlevel,
- final boolean doStart, final boolean refreshPackages )
- {
+ final boolean doStart, final boolean refreshPackages ) {
InstallHelper t = new InstallHelper( this, getBundleContext(),
bundleFile, location, startlevel, doStart,
refreshPackages );
t.start();
}
-
- private void updateBackground( final Bundle bundle, final File bundleFile,
final boolean refreshPackages )
- {
+ private void updateBackground( final Bundle bundle, final File bundleFile,
final boolean refreshPackages ) {
UpdateHelper t = new UpdateHelper( this, bundle, bundleFile,
refreshPackages );
t.start();
}
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 b898fd7bab..eff053801c 100644
---
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
@@ -265,19 +265,19 @@ public class OsgiManager extends GenericServlet {
private volatile Map<String, Object> configuration;
// See https://issues.apache.org/jira/browse/FELIX-2267
- private Locale configuredLocale;
+ private volatile Locale configuredLocale;
- private Set<String> enabledPlugins;
+ private volatile Set<String> enabledPlugins;
final ConcurrentSkipListSet<String> registeredSecurityProviders = new
ConcurrentSkipListSet<String>();
final Set<String> requiredSecurityProviders;
- ResourceBundleManager resourceBundleManager;
+ final ResourceBundleManager resourceBundleManager;
- private int logLevel = DEFAULT_LOG_LEVEL;
+ private volatile int logLevel = DEFAULT_LOG_LEVEL;
- private String defaultCategory = DEFAULT_CATEGORY;
+ private volatile String defaultCategory = DEFAULT_CATEGORY;
public OsgiManager(BundleContext bundleContext)
{
@@ -437,11 +437,7 @@ public class OsgiManager extends GenericServlet {
holder.close();
// dispose off the resource bundle manager
- if (resourceBundleManager != null)
- {
- resourceBundleManager.dispose();
- resourceBundleManager = null;
- }
+ resourceBundleManager.dispose();
// stop listening for brandings
if (brandingTracker != null)
@@ -934,6 +930,8 @@ public class OsgiManager extends GenericServlet {
props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_TARGET,
httpServiceSelector);
}
+
props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_MULTIPART_ENABLED,
Boolean.TRUE);
+
props.put("osgi.http.whiteboard.servlet.multipart.maxFileCount", 50);
props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/");
props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, "(" +
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=" +
SERVLEXT_CONTEXT_NAME + ")");
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 9ea34a5adf..65f0366c2b 100644
---
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
@@ -69,6 +69,7 @@ public abstract class Plugin implements ServletConfig,
Comparable<Plugin> {
/**
* Initialize everything including title and category
+ * @return {@code true} if the plugin is initialized, {@code false}
otherwise
*/
public boolean init() {
final AbstractWebConsolePlugin plugin = this.doGetConsolePlugin();
@@ -169,7 +170,7 @@ public abstract class Plugin implements ServletConfig,
Comparable<Plugin> {
}
@Override
- public Enumeration<?> getInitParameterNames() {
+ public Enumeration<String> getInitParameterNames() {
return Collections.emptyEnumeration();
}
@@ -236,16 +237,16 @@ public abstract class Plugin implements ServletConfig,
Comparable<Plugin> {
}
@Override
- public Enumeration<?> getInitParameterNames() {
+ public Enumeration<String> getInitParameterNames() {
final String[] keys = this.getServiceReference().getPropertyKeys();
- return new Enumeration<Object>() {
+ return new Enumeration<String>() {
int idx = 0;
public boolean hasMoreElements() {
return idx < keys.length;
}
- public Object nextElement() {
+ public String nextElement() {
if ( hasMoreElements() ) {
return keys[idx++];
}