You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2020/01/28 20:34:15 UTC
[jspwiki] 14/32: JSPWIKI-120: remove WikiEngine#getRedirectURL(..)
use same method on WikiContext
This is an automated email from the ASF dual-hosted git repository.
juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit d3f4bd334217df532ae0a32de64ede59dcb28b11
Author: juanpablo <ju...@apache.org>
AuthorDate: Mon Jan 20 22:10:16 2020 +0100
JSPWIKI-120: remove WikiEngine#getRedirectURL(..) use same method on WikiContext
Also, moved WikiEngine#createContext as proper Constructor on WikiContext, and propagate the change
---
.../src/main/java/org/apache/wiki/WikiContext.java | 19 +++
.../src/main/java/org/apache/wiki/WikiEngine.java | 45 ++-----
.../apache/wiki/attachment/AttachmentServlet.java | 127 +++++++-------------
.../java/org/apache/wiki/search/SearchManager.java | 71 +++++------
.../java/org/apache/wiki/xmlrpc/RPCServlet.java | 132 ++++++++-------------
.../org/apache/wiki/search/SearchManagerTest.java | 6 +-
6 files changed, 154 insertions(+), 246 deletions(-)
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java
index 150cb6f..939a843 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java
@@ -194,6 +194,9 @@ public class WikiContext implements Cloneable, Command {
if ( engine == null || command == null ) {
throw new IllegalArgumentException( "Parameter engine and command must not be null." );
}
+ if( !engine.isConfigured() ) {
+ throw new InternalWikiException( "WikiEngine has not been properly started. It is likely that the configuration is faulty. Please check all logs for the possible reason." );
+ }
m_engine = engine;
m_request = request;
@@ -247,6 +250,22 @@ public class WikiContext implements Cloneable, Command {
}
/**
+ * Creates a new WikiContext from a supplied HTTP request, using a default wiki context.
+ *
+ * @param engine The WikiEngine that is handling the request
+ * @param request the HTTP request
+ * @param requestContext the default context to use
+ * @return a new WikiContext object.
+ *
+ * @see org.apache.wiki.ui.CommandResolver
+ * @see org.apache.wiki.ui.Command
+ * @since 2.1.15.
+ */
+ public WikiContext( final WikiEngine engine, final HttpServletRequest request, final String requestContext ) {
+ this( engine, request, engine.getCommandResolver().findCommand( request, requestContext ) );
+ }
+
+ /**
* {@inheritDoc}
* @see org.apache.wiki.ui.Command#getContentTemplate()
*/
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
index e3c6dd7..a2846ac 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
@@ -46,7 +46,6 @@ import org.apache.wiki.rss.RSSGenerator;
import org.apache.wiki.rss.RSSThread;
import org.apache.wiki.search.SearchManager;
import org.apache.wiki.tasks.TasksManager;
-import org.apache.wiki.ui.Command;
import org.apache.wiki.ui.CommandResolver;
import org.apache.wiki.ui.EditorManager;
import org.apache.wiki.ui.TemplateManager;
@@ -60,7 +59,6 @@ import org.apache.wiki.workflow.WorkflowManager;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
@@ -563,6 +561,15 @@ public class WikiEngine {
}
/**
+ * check if the WikiEngine has been configured.
+ *
+ * @return {@code true} if it has, {@code false} otherwise.
+ */
+ public boolean isConfigured() {
+ return m_isConfigured;
+ }
+
+ /**
* Checks if the template directory specified in the wiki's properties actually exists. If it doesn't, then {@code m_templateDir} is
* set to {@link #DEFAULT_TEMPLATE_NAME}.
* <p>
@@ -1007,40 +1014,6 @@ public class WikiEngine {
}
/**
- * Figure out to which page we are really going to. Considers special page names from the jspwiki.properties, and possible aliases.
- * This method delgates requests to {@link org.apache.wiki.WikiContext#getRedirectURL()}.
- *
- * @param context The Wiki Context in which the request is being made.
- * @return A complete URL to the new page to redirect to
- * @since 2.2
- */
- public String getRedirectURL( final WikiContext context ) {
- return context.getRedirectURL();
- }
-
- /**
- * Shortcut to create a WikiContext from a supplied HTTP request, using a default wiki context.
- *
- * @param request the HTTP request
- * @param requestContext the default context to use
- * @return a new WikiContext object.
- *
- * @see org.apache.wiki.ui.CommandResolver
- * @see org.apache.wiki.ui.Command
- * @since 2.1.15.
- */
- // FIXME: We need to have a version which takes a fixed page name as well, or check it elsewhere.
- public WikiContext createContext( final HttpServletRequest request, final String requestContext ) {
- if( !m_isConfigured ) {
- throw new InternalWikiException( "WikiEngine has not been properly started. It is likely that the configuration is faulty. Please check all logs for the possible reason." );
- }
-
- // Build the wiki context
- final Command command = m_commandResolver.findCommand( request, requestContext );
- return new WikiContext( this, request, command );
- }
-
- /**
* Returns the root path. The root path is where the WikiEngine is located in the file system.
*
* @since 2.2
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/attachment/AttachmentServlet.java b/jspwiki-main/src/main/java/org/apache/wiki/attachment/AttachmentServlet.java
index 7c449d8..2bb0053 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/attachment/AttachmentServlet.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/attachment/AttachmentServlet.java
@@ -194,7 +194,7 @@ public class AttachmentServlet extends HttpServlet {
*/
// FIXME: Messages would need to be localized somehow.
public void doGet( final HttpServletRequest req, final HttpServletResponse res ) throws IOException {
- final WikiContext context = m_engine.createContext( req, WikiContext.ATTACH );
+ final WikiContext context = new WikiContext( m_engine, req, WikiContext.ATTACH );
final AttachmentManager mgr = m_engine.getAttachmentManager();
final AuthorizationManager authmgr = m_engine.getAuthorizationManager();
@@ -373,15 +373,12 @@ public class AttachmentServlet extends HttpServlet {
* content of the file.
*
*/
- public void doPost( HttpServletRequest req, HttpServletResponse res ) throws IOException {
- try
- {
- String nextPage = upload( req );
+ public void doPost( final HttpServletRequest req, final HttpServletResponse res ) throws IOException {
+ try {
+ final String nextPage = upload( req );
req.getSession().removeAttribute("msg");
res.sendRedirect( nextPage );
- }
- catch( RedirectException e )
- {
+ } catch( final RedirectException e ) {
WikiSession session = WikiSession.getWikiSession( m_engine, req );
session.addMessage( e.getMessage() );
@@ -420,12 +417,12 @@ public class AttachmentServlet extends HttpServlet {
* @throws IOException If upload fails
* @throws FileUploadException
*/
- protected String upload( HttpServletRequest req ) throws RedirectException, IOException {
+ protected String upload( final HttpServletRequest req ) throws RedirectException, IOException {
String msg = "";
- String attName = "(unknown)";
- String errorPage = m_engine.getURL( WikiContext.ERROR, "", null, false ); // If something bad happened, Upload should be able to take care of most stuff
+ final String attName = "(unknown)";
+ final String errorPage = m_engine.getURL( WikiContext.ERROR, "", null, false ); // If something bad happened, Upload should be able to take care of most stuff
String nextPage = errorPage;
- String progressId = req.getParameter( "progressid" );
+ final String progressId = req.getParameter( "progressid" );
// Check that we have a file upload request
if( !ServletFileUpload.isMultipartContent(req) ) {
@@ -433,18 +430,16 @@ public class AttachmentServlet extends HttpServlet {
}
try {
- FileItemFactory factory = new DiskFileItemFactory();
+ final FileItemFactory factory = new DiskFileItemFactory();
- // Create the context _before_ Multipart operations, otherwise
- // strict servlet containers may fail when setting encoding.
- WikiContext context = m_engine.createContext( req, WikiContext.ATTACH );
-
- UploadListener pl = new UploadListener();
+ // Create the context _before_ Multipart operations, otherwise strict servlet containers may fail when setting encoding.
+ final WikiContext context = new WikiContext( m_engine, req, WikiContext.ATTACH );
+ final UploadListener pl = new UploadListener();
m_engine.getProgressManager().startProgress( pl, progressId );
- ServletFileUpload upload = new ServletFileUpload(factory);
- upload.setHeaderEncoding("UTF-8");
+ final ServletFileUpload upload = new ServletFileUpload( factory );
+ upload.setHeaderEncoding( "UTF-8" );
if( !context.hasAdminPermissions() ) {
upload.setFileSizeMax( m_maxSize );
}
@@ -456,12 +451,11 @@ public class AttachmentServlet extends HttpServlet {
//FileItem actualFile = null;
List<FileItem> fileItems = new ArrayList<>();
- for( FileItem item : items ) {
+ for( final FileItem item : items ) {
if( item.isFormField() ) {
if( item.getFieldName().equals("page") ) {
//
- // FIXME: Kludge alert. We must end up with the parent page name,
- // if this is an upload of a new revision
+ // FIXME: Kludge alert. We must end up with the parent page name, if this is an upload of a new revision
//
wikipage = item.getString("UTF-8");
@@ -494,18 +488,18 @@ public class AttachmentServlet extends HttpServlet {
}
}
- } catch( ProviderException e ) {
+ } catch( final ProviderException e ) {
msg = "Upload failed because the provider failed: "+e.getMessage();
log.warn( msg + " (attachment: " + attName + ")", e );
- throw new IOException(msg);
- } catch( IOException e ) {
+ throw new IOException( msg );
+ } catch( final IOException e ) {
// Show the submit page again, but with a bit more intimidating output.
msg = "Upload failure: " + e.getMessage();
log.warn( msg + " (attachment: " + attName + ")", e );
throw e;
- } catch (FileUploadException e) {
+ } catch( final FileUploadException e ) {
// Show the submit page again, but with a bit more intimidating output.
msg = "Upload failure: " + e.getMessage();
log.warn( msg + " (attachment: " + attName + ")", e );
@@ -543,12 +537,9 @@ public class AttachmentServlet extends HttpServlet {
{
boolean created = false;
- try
- {
+ try {
filename = AttachmentManager.validateFileName( filename );
- }
- catch( WikiException e )
- {
+ } catch( final WikiException e ) {
// this is a kludge, the exception that is caught here contains the i18n key
// here we have the context available, so we can internationalize it properly :
throw new RedirectException (Preferences.getBundle( context, InternationalizationManager.CORE_BUNDLE )
@@ -561,34 +552,25 @@ public class AttachmentServlet extends HttpServlet {
// before we receive the file, due to the stupid constructor of MultipartRequest.
//
- if( !context.hasAdminPermissions() )
- {
- if( contentLength > m_maxSize )
- {
+ if( !context.hasAdminPermissions() ) {
+ if( contentLength > m_maxSize ) {
// FIXME: Does not delete the received files.
- throw new RedirectException( "File exceeds maximum size ("+m_maxSize+" bytes)",
- errorPage );
+ throw new RedirectException( "File exceeds maximum size ("+m_maxSize+" bytes)", errorPage );
}
- if( !isTypeAllowed(filename) )
- {
- throw new RedirectException( "Files of this type may not be uploaded to this wiki",
- errorPage );
+ if( !isTypeAllowed(filename) ) {
+ throw new RedirectException( "Files of this type may not be uploaded to this wiki", errorPage );
}
}
- Principal user = context.getCurrentUser();
-
- AttachmentManager mgr = m_engine.getAttachmentManager();
+ final Principal user = context.getCurrentUser();
+ final AttachmentManager mgr = m_engine.getAttachmentManager();
log.debug("file="+filename);
- if( data == null )
- {
+ if( data == null ) {
log.error("File could not be opened.");
-
- throw new RedirectException("File could not be opened.",
- errorPage);
+ throw new RedirectException("File could not be opened.", errorPage);
}
//
@@ -604,8 +586,7 @@ public class AttachmentServlet extends HttpServlet {
Attachment att = mgr.getAttachmentInfo( context.getPage().getName() );
- if( att == null )
- {
+ if( att == null ) {
att = new Attachment( m_engine, parentPage, filename );
created = true;
}
@@ -615,37 +596,26 @@ public class AttachmentServlet extends HttpServlet {
// Check if we're allowed to do this?
//
- Permission permission = PermissionFactory.getPagePermission( att, "upload" );
- if( m_engine.getAuthorizationManager().checkPermission( context.getWikiSession(),
- permission ) )
- {
- if( user != null )
- {
+ final Permission permission = PermissionFactory.getPagePermission( att, "upload" );
+ if( m_engine.getAuthorizationManager().checkPermission( context.getWikiSession(), permission ) ) {
+ if( user != null ) {
att.setAuthor( user.getName() );
}
- if( changenote != null && changenote.length() > 0 )
- {
+ if( changenote != null && changenote.length() > 0 ) {
att.setAttribute( WikiPage.CHANGENOTE, changenote );
}
- try
- {
+ try {
m_engine.getAttachmentManager().storeAttachment( att, data );
- }
- catch( ProviderException pe )
- {
+ } catch( final ProviderException pe ) {
// this is a kludge, the exception that is caught here contains the i18n key
// here we have the context available, so we can internationalize it properly :
- throw new ProviderException( Preferences.getBundle( context, InternationalizationManager.CORE_BUNDLE )
- .getString( pe.getMessage() ) );
+ throw new ProviderException( Preferences.getBundle( context, InternationalizationManager.CORE_BUNDLE ).getString( pe.getMessage() ) );
}
- log.info( "User " + user + " uploaded attachment to " + parentPage +
- " called "+filename+", size " + att.getSize() );
- }
- else
- {
+ log.info( "User " + user + " uploaded attachment to " + parentPage + " called "+filename+", size " + att.getSize() );
+ } else {
throw new RedirectException( "No permission to upload a file", errorPage );
}
@@ -656,22 +626,17 @@ public class AttachmentServlet extends HttpServlet {
* Provides tracking for upload progress.
*
*/
- private static class UploadListener
- extends ProgressItem
- implements ProgressListener
- {
+ private static class UploadListener extends ProgressItem implements ProgressListener {
public long m_currentBytes;
public long m_totalBytes;
- public void update(long recvdBytes, long totalBytes, int item)
- {
+ public void update( final long recvdBytes, final long totalBytes, final int item) {
m_currentBytes = recvdBytes;
m_totalBytes = totalBytes;
}
- public int getProgress()
- {
- return (int) (((float)m_currentBytes / m_totalBytes) * 100 + 0.5);
+ public int getProgress() {
+ return ( int )( ( ( float )m_currentBytes / m_totalBytes ) * 100 + 0.5 );
}
}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/search/SearchManager.java b/jspwiki-main/src/main/java/org/apache/wiki/search/SearchManager.java
index 247d08d..ac256fe 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/search/SearchManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/search/SearchManager.java
@@ -132,11 +132,11 @@ public class SearchManager extends BasicPageFilter implements InternalModule, Wi
log.debug("Calling getSuggestions() DONE. "+callResults.size());
result = AjaxUtil.toJson(callResults);
} else if (actionName.equals(AJAX_ACTION_PAGES)) {
- List<Map<String,Object>> callResults = new ArrayList<>();
+ final List< Map< String, Object > > callResults;
log.debug("Calling findPages() START");
- WikiContext wikiContext = m_engine.createContext(req, WikiContext.VIEW);
- if (wikiContext == null) {
- throw new ServletException("Could not create a WikiContext from the request "+req);
+ final WikiContext wikiContext = new WikiContext( m_engine, req, WikiContext.VIEW );
+ if( wikiContext == null ) {
+ throw new ServletException( "Could not create a WikiContext from the request " + req );
}
callResults = findPages(itemId, maxResults, wikiContext);
log.debug("Calling findPages() DONE. "+callResults.size());
@@ -148,45 +148,37 @@ public class SearchManager extends BasicPageFilter implements InternalModule, Wi
}
/**
- * Provides a list of suggestions to use for a page name.
- * Currently the algorithm just looks into the value parameter,
+ * Provides a list of suggestions to use for a page name. Currently the algorithm just looks into the value parameter,
* and returns all page names from that.
*
* @param wikiName the page name
* @param maxLength maximum number of suggestions
* @return the suggestions
*/
- public List<String> getSuggestions( String wikiName, int maxLength )
- {
- StopWatch sw = new StopWatch();
+ public List<String> getSuggestions( String wikiName, final int maxLength ) {
+ final StopWatch sw = new StopWatch();
sw.start();
- List<String> list = new ArrayList<>(maxLength);
+ final List< String > list = new ArrayList<>( maxLength );
- if( wikiName.length() > 0 )
- {
+ if( wikiName.length() > 0 ) {
// split pagename and attachment filename
String filename = "";
int pos = wikiName.indexOf("/");
- if( pos >= 0 )
- {
+ if( pos >= 0 ) {
filename = wikiName.substring( pos ).toLowerCase();
wikiName = wikiName.substring( 0, pos );
}
- String cleanWikiName = MarkupParser.cleanLink(wikiName).toLowerCase() + filename;
-
- String oldStyleName = MarkupParser.wikifyLink(wikiName).toLowerCase() + filename;
-
- Set< String > allPages = m_engine.getReferenceManager().findCreated();
+ final String cleanWikiName = MarkupParser.cleanLink(wikiName).toLowerCase() + filename;
+ final String oldStyleName = MarkupParser.wikifyLink(wikiName).toLowerCase() + filename;
+ final Set< String > allPages = m_engine.getReferenceManager().findCreated();
int counter = 0;
- for( Iterator< String > i = allPages.iterator(); i.hasNext() && counter < maxLength; )
- {
- String p = i.next();
- String pp = p.toLowerCase();
- if( pp.startsWith( cleanWikiName) || pp.startsWith( oldStyleName ) )
- {
+ for( Iterator< String > i = allPages.iterator(); i.hasNext() && counter < maxLength; ) {
+ final String p = i.next();
+ final String pp = p.toLowerCase();
+ if( pp.startsWith( cleanWikiName) || pp.startsWith( oldStyleName ) ) {
list.add( p );
counter++;
}
@@ -194,7 +186,9 @@ public class SearchManager extends BasicPageFilter implements InternalModule, Wi
}
sw.stop();
- if( log.isDebugEnabled() ) log.debug("Suggestion request for "+wikiName+" done in "+sw);
+ if( log.isDebugEnabled() ) {
+ log.debug( "Suggestion request for " + wikiName + " done in " + sw );
+ }
return list;
}
@@ -252,23 +246,13 @@ public class SearchManager extends BasicPageFilter implements InternalModule, Wi
* @throws FilterException if the search provider failed to initialize
*/
@Override
- public void initialize(WikiEngine engine, Properties properties)
- throws FilterException
- {
+ public void initialize( final WikiEngine engine, final Properties properties ) throws FilterException {
m_engine = engine;
-
loadSearchProvider(properties);
- try
- {
- m_searchProvider.initialize(engine, properties);
- }
- catch (NoRequiredPropertyException e)
- {
- log.error( e.getMessage(), e );
- }
- catch (IOException e)
- {
+ try {
+ m_searchProvider.initialize( engine, properties );
+ } catch( final NoRequiredPropertyException | IOException e ) {
log.error( e.getMessage(), e );
}
}
@@ -280,14 +264,13 @@ public class SearchManager extends BasicPageFilter implements InternalModule, Wi
final String providerClassName = properties.getProperty( PROP_SEARCHPROVIDER, DEFAULT_SEARCHPROVIDER );
try {
- Class<?> providerClass = ClassUtil.findClass( "org.apache.wiki.search", providerClassName );
+ final Class<?> providerClass = ClassUtil.findClass( "org.apache.wiki.search", providerClassName );
m_searchProvider = (SearchProvider)providerClass.newInstance();
- } catch( ClassNotFoundException | InstantiationException | IllegalAccessException e ) {
+ } catch( final ClassNotFoundException | InstantiationException | IllegalAccessException e ) {
log.warn("Failed loading SearchProvider, will use BasicSearchProvider.", e);
}
- if( null == m_searchProvider )
- {
+ if( null == m_searchProvider ) {
// FIXME: Make a static with the default search provider
m_searchProvider = new BasicSearchProvider();
}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/xmlrpc/RPCServlet.java b/jspwiki-main/src/main/java/org/apache/wiki/xmlrpc/RPCServlet.java
index ef23d4c..29ec933 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/xmlrpc/RPCServlet.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/xmlrpc/RPCServlet.java
@@ -18,18 +18,6 @@
*/
package org.apache.wiki.xmlrpc;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.util.Vector;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
import org.apache.log4j.Logger;
import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiEngine;
@@ -39,6 +27,17 @@ import org.apache.xmlrpc.XmlRpcContext;
import org.apache.xmlrpc.XmlRpcHandlerMapping;
import org.apache.xmlrpc.XmlRpcServer;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.Vector;
+
/**
* Handles all incoming servlet requests for XML-RPC calls.
* <P>
@@ -62,149 +61,120 @@ public class RPCServlet extends HttpServlet
private WikiEngine m_engine;
private XmlRpcServer m_xmlrpcServer = new XmlRpcServer();
- static Logger log = Logger.getLogger( RPCServlet.class );
+ private static final Logger log = Logger.getLogger( RPCServlet.class );
- public void initHandler( String prefix, String handlerName )
- throws ClassNotFoundException,
- InstantiationException,
- IllegalAccessException
- {
+ public void initHandler( final String prefix, final String handlerName ) throws ClassNotFoundException {
/*
Class handlerClass = Class.forName( handlerName );
WikiRPCHandler rpchandler = (WikiRPCHandler) handlerClass.newInstance();
rpchandler.initialize( m_engine );
m_xmlrpcServer.addHandler( prefix, rpchandler );
*/
- Class< ? > handlerClass = Class.forName( handlerName );
+ final Class< ? > handlerClass = Class.forName( handlerName );
m_xmlrpcServer.addHandler( prefix, new LocalHandler(handlerClass) );
}
/**
* Initializes the servlet.
*/
- public void init( ServletConfig config )
- throws ServletException
- {
+ public void init( final ServletConfig config ) throws ServletException {
m_engine = WikiEngine.getInstance( config );
String handlerName = config.getInitParameter( "handler" );
String prefix = config.getInitParameter( "prefix" );
- if( handlerName == null ) handlerName = "org.apache.wiki.xmlrpc.RPCHandler";
- if( prefix == null ) prefix = XMLRPC_PREFIX;
+ if( handlerName == null ) {
+ handlerName = "org.apache.wiki.xmlrpc.RPCHandler";
+ }
+ if( prefix == null ) {
+ prefix = XMLRPC_PREFIX;
+ }
- try
- {
+ try {
initHandler( prefix, handlerName );
//
// FIXME: The metaweblog API should be possible to turn off.
//
- initHandler( "metaWeblog",
- "org.apache.wiki.xmlrpc.MetaWeblogHandler" );
- }
- catch( Exception e )
- {
+ initHandler( "metaWeblog", "org.apache.wiki.xmlrpc.MetaWeblogHandler" );
+ } catch( final Exception e ) {
log.fatal("Unable to start RPC interface: ", e);
throw new ServletException( "No RPC interface", e );
}
}
/**
- * Handle HTTP POST. This is an XML-RPC call, and we'll just forward
- * the query to an XmlRpcServer.
+ * Handle HTTP POST. This is an XML-RPC call, and we'll just forward the query to an XmlRpcServer.
*/
- public void doPost( HttpServletRequest request, HttpServletResponse response )
- throws ServletException
- {
+ public void doPost( final HttpServletRequest request, final HttpServletResponse response ) throws ServletException {
log.debug("Received POST to RPCServlet");
- try
- {
- WikiContext ctx = m_engine.createContext( request, WikiContext.NONE );
-
- XmlRpcContext xmlrpcContext = new WikiXmlRpcContext( m_xmlrpcServer.getHandlerMapping(),
- ctx );
-
- byte[] result = m_xmlrpcServer.execute( request.getInputStream(), xmlrpcContext );
+ try {
+ final WikiContext ctx = new WikiContext( m_engine, request, WikiContext.NONE );
+ final XmlRpcContext xmlrpcContext = new WikiXmlRpcContext( m_xmlrpcServer.getHandlerMapping(), ctx );
+ final byte[] result = m_xmlrpcServer.execute( request.getInputStream(), xmlrpcContext );
//
- // I think it's safe to write the output as UTF-8:
- // The XML-RPC standard never creates other than USASCII
- // (which is UTF-8 compatible), and our special UTF-8
- // hack just creates UTF-8. So in all cases our butt
+ // I think it's safe to write the output as UTF-8: The XML-RPC standard never creates other than USASCII
+ // (which is UTF-8 compatible), and our special UTF-8 hack just creates UTF-8. So in all cases our butt
// should be covered.
//
response.setContentType( "text/xml; charset=utf-8" );
response.setContentLength( result.length );
- OutputStream out = response.getOutputStream();
+ final OutputStream out = response.getOutputStream();
out.write( result );
out.flush();
// log.debug("Result = "+new String(result) );
- }
- catch( IOException e )
- {
+ } catch( final IOException e ) {
throw new ServletException("Failed to build RPC result", e);
}
}
/**
- * Handles HTTP GET. However, we do not respond to GET requests,
- * other than to show an explanatory text.
+ * Handles HTTP GET. However, we do not respond to GET requests, other than to show an explanatory text.
*/
- public void doGet( HttpServletRequest request, HttpServletResponse response )
- throws ServletException
- {
+ public void doGet( final HttpServletRequest request, final HttpServletResponse response ) throws ServletException {
log.debug("Received HTTP GET to RPCServlet");
- try
- {
- String msg = "We do not support HTTP GET here. Sorry.";
+ try {
+ final String msg = "We do not support HTTP GET here. Sorry.";
response.setContentType( "text/plain" );
response.setContentLength( msg.length() );
- PrintWriter writer = new PrintWriter( new OutputStreamWriter( response.getOutputStream() ) );
+ final PrintWriter writer = new PrintWriter( new OutputStreamWriter( response.getOutputStream() ) );
writer.println( msg );
writer.flush();
- }
- catch( IOException e )
- {
+ } catch( final IOException e ) {
throw new ServletException("Failed to build RPC result", e);
}
}
- private static class LocalHandler
- implements ContextXmlRpcHandler
- {
+ private static class LocalHandler implements ContextXmlRpcHandler {
private Class< ? > m_clazz;
- public LocalHandler( Class< ? > clazz )
+ public LocalHandler( final Class< ? > clazz )
{
m_clazz = clazz;
}
- public Object execute(String method, Vector params, XmlRpcContext context) throws Exception
- {
- WikiRPCHandler rpchandler = (WikiRPCHandler) m_clazz.newInstance();
+ public Object execute( final String method, final Vector params, final XmlRpcContext context ) throws Exception {
+ final WikiRPCHandler rpchandler = (WikiRPCHandler) m_clazz.newInstance();
rpchandler.initialize( ((WikiXmlRpcContext)context).getWikiContext() );
- Invoker invoker = new Invoker( rpchandler );
-
+ final Invoker invoker = new Invoker( rpchandler );
return invoker.execute( method, params );
}
}
- private static class WikiXmlRpcContext
- implements XmlRpcContext
- {
+ private static class WikiXmlRpcContext implements XmlRpcContext {
+
private XmlRpcHandlerMapping m_mapping;
private WikiContext m_context;
- public WikiXmlRpcContext( XmlRpcHandlerMapping map, WikiContext ctx )
- {
+ public WikiXmlRpcContext( final XmlRpcHandlerMapping map, final WikiContext ctx ) {
m_mapping = map;
m_context = ctx;
}
@@ -214,14 +184,12 @@ public class RPCServlet extends HttpServlet
return m_mapping;
}
- public String getPassword()
- {
+ public String getPassword() {
// TODO Auto-generated method stub
return null;
}
- public String getUserName()
- {
+ public String getUserName() {
// TODO Auto-generated method stub
return null;
}
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/search/SearchManagerTest.java b/jspwiki-main/src/test/java/org/apache/wiki/search/SearchManagerTest.java
index 9944ed4..ecc3b2a 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/search/SearchManagerTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/search/SearchManagerTest.java
@@ -78,7 +78,7 @@ public class SearchManagerTest {
Callable< Boolean > findsResultsFor( final Collection< SearchResult > res, final String text ) {
return () -> {
final MockHttpServletRequest request = m_engine.newHttpRequest();
- final WikiContext ctx = m_engine.createContext( request, WikiContext.EDIT );
+ final WikiContext ctx = new WikiContext( m_engine, request, WikiContext.EDIT );
final Collection< SearchResult > search = m_mgr.findPages( text, ctx );
if( search != null && search.size() > 0 ) {
// debugSearchResults( search );
@@ -121,7 +121,7 @@ public class SearchManagerTest {
final String txt = "It was the dawn of the third age of mankind, ten years after the Earth-Minbari War.";
final MockHttpServletRequest request = m_engine.newHttpRequest();
request.getParameterMap().put( "page", new String[]{ "TestPage" } );
- final WikiContext ctx = m_engine.createContext( request, WikiContext.EDIT );
+ final WikiContext ctx = new WikiContext( m_engine, request, WikiContext.EDIT );
m_engine.getPageManager().saveText( ctx, txt );
m_engine.getPageManager().saveText( ctx, "The Babylon Project was a dream given form. Its goal: to prevent another war by creating a place where humans and aliens could work out their differences peacefully." );
@@ -143,7 +143,7 @@ public class SearchManagerTest {
final String txt = "It was the dawn of the third age of mankind, ten years after the Earth-Minbari War.";
final MockHttpServletRequest request = m_engine.newHttpRequest();
request.getParameterMap().put( "page", new String[]{ "TestPage" } );
- final WikiContext ctx = m_engine.createContext( request, WikiContext.EDIT );
+ final WikiContext ctx = new WikiContext( m_engine, request, WikiContext.EDIT );
m_engine.getPageManager().saveText( ctx, txt );
Collection< SearchResult > res = new ArrayList<>();