|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.apache.felix.webconsole.AbstractWebConsolePlugin
public abstract class AbstractWebConsolePlugin
The Web Console can be extended by registering an OSGi service for the interface
Servlet
with the service property
felix.webconsole.label
set to the label (last segment in the URL)
of the page. The respective service is called a Web Console Plugin or a plugin
for short.
To help rendering the response the Apache Felix Web Console bundle provides two
options. One of the options is to extend the AbstractWebConsolePlugin overwriting
the renderContent(HttpServletRequest, HttpServletResponse)
method.
Field Summary | |
---|---|
static String |
ATTR_FILEUPLOAD
The name of the request attribute containing the map of FileItems from the POST request |
static String |
GET_RESOURCE_METHOD_NAME
Web Console Plugin typically consists of servlet and resources such as images, scripts or style sheets. |
Constructor Summary | |
---|---|
AbstractWebConsolePlugin()
|
Method Summary | |
---|---|
void |
activate(BundleContext bundleContext)
This method is called from the Felix Web Console to ensure the AbstractWebConsolePlugin is correctly setup. |
void |
deactivate()
This method is called, by the Web Console to de-activate the plugin and release all used resources. |
protected void |
doGet(HttpServletRequest request,
HttpServletResponse response)
Renders the web console page for the request. |
protected void |
endResponse(PrintWriter pw)
This method is responsible for generating the footer of the page. |
static BrandingPlugin |
getBrandingPlugin()
Returns the BrandingPlugin currently used for web console
branding. |
Bundle |
getBundle()
Returns the Bundle pertaining to the
bundle context with which this plugin has
been activated. |
protected BundleContext |
getBundleContext()
Returns the BundleContext with which this plugin has been
activated. |
protected String[] |
getCssReferences()
Returns a list of CSS reference paths or null if no
additional CSS files are provided by the plugin. |
abstract String |
getLabel()
Retrieves the label. |
static String |
getParameter(HttpServletRequest request,
String name)
Deprecated. use WebConsoleUtil.getParameter(HttpServletRequest, String) |
protected Object |
getResourceProvider()
Returns the object which might provide resources. |
String |
getServletName()
Returns the title for this plugin as returned by getTitle() |
abstract String |
getTitle()
Retrieves the title of the plug-in. |
protected boolean |
isHtmlRequest(HttpServletRequest request)
Detects whether this request is intended to have the headers and footers of this plugin be rendered or not. |
void |
log(int level,
String message)
Calls the GenericServlet.log(String) method if the
configured log level is less than or equal to the given level . |
void |
log(int level,
String message,
Throwable t)
Calls the GenericServlet.log(String, Throwable) method if
the configured log level is less than or equal to the given
level . |
protected String |
readTemplateFile(String templateFile)
Reads the templateFile as a resource through the class
loader of this class converting the binary data into a string using
UTF-8 encoding. |
protected abstract void |
renderContent(HttpServletRequest req,
HttpServletResponse res)
This method is used to render the content of the plug-in. |
protected void |
renderTopNavigation(HttpServletRequest request,
PrintWriter pw)
This method is called to generate the top level links with the available plug-ins. |
protected void |
sendRedirect(HttpServletRequest request,
HttpServletResponse response,
String redirectUrl)
Deprecated. use WebConsoleUtil.sendRedirect(HttpServletRequest, HttpServletResponse, String) |
static void |
setBrandingPlugin(BrandingPlugin brandingPlugin)
Sets the BrandingPlugin to use globally by all extensions of
this class for branding. |
static void |
setLogLevel(int logLevel)
Sets the log level to be applied for calls to the log(int, String)
and log(int, String, Throwable) methods. |
protected PrintWriter |
startResponse(HttpServletRequest request,
HttpServletResponse response)
This method is responsible for generating the top heading of the page. |
Methods inherited from class javax.servlet.http.HttpServlet |
---|
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service |
Methods inherited from class javax.servlet.GenericServlet |
---|
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, init, init, log, log |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String ATTR_FILEUPLOAD
public static final String GET_RESOURCE_METHOD_NAME
getResourceProvider()
,
Constant Field ValuesConstructor Detail |
---|
public AbstractWebConsolePlugin()
Method Detail |
---|
public String getServletName()
getTitle()
javax.servlet.GenericServlet#getServletName()
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
startResponse(HttpServletRequest, HttpServletResponse)
renderTopNavigation(HttpServletRequest, PrintWriter)
renderContent(HttpServletRequest, HttpServletResponse)
endResponse(PrintWriter)
Note: If a resource is sent back for the request only the first step is executed. Otherwise the first step is a null-operation actually and the latter four steps are executed in order.
doGet
in class HttpServlet
request
- an HttpServletRequest
object that
contains the request the client has made
of the servletresponse
- an HttpServletResponse
object that
contains the response the servlet sends
to the client
ServletException
- if the request for the GET
could not be handled
IOException
- if an input or output error is
detected when the servlet handles
the GET requestHttpServlet.doGet(
javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
protected boolean isHtmlRequest(HttpServletRequest request)
true but has been overwritten in the
WebConsolePluginAdapter
for the plugins.
- Parameters:
request
- the original request passed from the HTTP server
- Returns:
true
if the page should have headers and footers rendered
public void activate(BundleContext bundleContext)
bundleContext
- the context of the plugin bundlepublic void deactivate()
protected abstract void renderContent(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
req
- the HTTP request send from the userres
- the HTTP response object, where to render the plugin data.
IOException
- if an input or output error is
detected when the servlet handles the request
ServletException
- if the request for the GET
could not be handledpublic abstract String getLabel()
AbstractWebConsolePlugin()
constructor is used.
public abstract String getTitle()
AbstractWebConsolePlugin()
constructor is used.
protected String[] getCssReferences()
null
if no
additional CSS files are provided by the plugin.
The result is an array of strings which are used as the value of
the href
attribute of the <link>
elements
placed in the head section of the HTML generated. If the reference is
a relative path, it is turned into an absolute path by prepending the
value of the WebConsoleConstants.ATTR_APP_ROOT
request attribute.
null
if no such CSS files are required.protected BundleContext getBundleContext()
BundleContext
with which this plugin has been
activated. If the plugin has not be activated by calling the
activate(BundleContext)
method, this method returns
null
.
null
if the bundle is not activated.public final Bundle getBundle()
Bundle
pertaining to the
bundle context
with which this plugin has
been activated. If the plugin has not be activated by calling the
activate(BundleContext)
method, this method returns
null
.
null
if the plugin is not activated.protected Object getResourceProvider()
getResource
method.
This method may be overwritten by extensions. This base class implementation returns this instance.
null
if no
resources will be provided by this plugin.public void log(int level, String message)
GenericServlet.log(String)
method if the
configured log level is less than or equal to the given level
.
Note, that the level
paramter is only used to decide whether
the GenericServlet.log(String)
method is called or not. The
actual implementation of the GenericServlet.log
method is
outside of the control of this method.
level
- The log level at which to log the messagemessage
- The message to logpublic void log(int level, String message, Throwable t)
GenericServlet.log(String, Throwable)
method if
the configured log level is less than or equal to the given
level
.
Note, that the level
paramter is only used to decide whether
the GenericServlet.log(String, Throwable)
method is called
or not. The actual implementation of the GenericServlet.log
method is outside of the control of this method.
level
- The log level at which to log the messagemessage
- The message to logt
- The Throwable
to log with the messageprotected PrintWriter startResponse(HttpServletRequest request, HttpServletResponse response) throws IOException
request
- the HTTP request coming from the userresponse
- the HTTP response, where data is rendered
IOException
- on I/O errorendResponse(PrintWriter)
protected void renderTopNavigation(HttpServletRequest request, PrintWriter pw)
request
- the HTTP request coming from the userpw
- the writer, where the HTML data is renderedprotected void endResponse(PrintWriter pw)
pw
- the writer, where the HTML data is renderedstartResponse(HttpServletRequest, HttpServletResponse)
public static final String getParameter(HttpServletRequest request, String name)
WebConsoleUtil.getParameter(HttpServletRequest, String)
ATTR_FILEUPLOAD
. The attribute value is a Map
where the key is a String specifying the field name and the value
is a FileItem
.
request
- the HTTP request coming from the username
- the name of the parameter
null
if not set. If multipart is used,
and the specified parameter is field - then the value of the parameter
is returned.protected void sendRedirect(HttpServletRequest request, HttpServletResponse response, String redirectUrl) throws IOException
WebConsoleUtil.sendRedirect(HttpServletRequest, HttpServletResponse, String)
request
- the HTTP request coming from the userresponse
- the HTTP response, where data is renderedredirectUrl
- the redirect URI.
IOException
- If an input or output exception occurs
IllegalStateException
- If the response was committed or if a partial
URL is given and cannot be converted into a valid URLpublic static BrandingPlugin getBrandingPlugin()
BrandingPlugin
currently used for web console
branding.
public static final void setBrandingPlugin(BrandingPlugin brandingPlugin)
BrandingPlugin
to use globally by all extensions of
this class for branding.
Note: This method is intended to be used internally by the Web Console to update the branding plugin to use.
brandingPlugin
- the brandingPlugin to setpublic static final void setLogLevel(int logLevel)
log(int, String)
and log(int, String, Throwable)
methods.
Note: This method is intended to be used internally by the Web Console to update the log level according to the Web Console configuration.
logLevel
- the maximum allowed log level. If message is logged with
lower level it will not be forwarded to the logger.protected final String readTemplateFile(String templateFile)
templateFile
as a resource through the class
loader of this class converting the binary data into a string using
UTF-8 encoding.
If the template file cannot read into a string and an exception is caused, the exception is logged and an empty string returned.
templateFile
- The absolute path to the template file to read.
NullPointerException
- if templateFile
is
null
RuntimeException
- if an IOException
is thrown reading
the template file into a string. The exception provides the
exception thrown as its cause.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |