Improved short url hook.
This commit is contained in:
parent
d33924e876
commit
9b9721f275
2 changed files with 75 additions and 3 deletions
|
@ -121,6 +121,73 @@ public class KissDispatcherFactory
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is available class.
|
||||
*
|
||||
* @param className
|
||||
* the class name
|
||||
* @return true, if is available class
|
||||
*/
|
||||
private boolean isAvailableClass(final String className)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
try
|
||||
{
|
||||
Class<HttpServlet> servletClass = (Class<HttpServlet>) Class.forName(className);
|
||||
result = true;
|
||||
}
|
||||
catch (java.lang.ClassNotFoundException exception)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is availableget path.
|
||||
*
|
||||
* @param servletConfig
|
||||
* the servlet config
|
||||
* @param request
|
||||
* the request
|
||||
* @param response
|
||||
* the response
|
||||
* @param urlPath
|
||||
* the url path
|
||||
* @return true, if is availableget path
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
* @throws ServletException
|
||||
* the servlet exception
|
||||
*/
|
||||
public boolean isAvailablePath(final String urlPath)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
if (this.cache.containsKey(urlPath))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
String className = "website." + translateToClassName(urlPath);
|
||||
if (isAvailableClass(className) || isAvailableClass(className.replaceAll("Xhtml$", "Page")))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instance.
|
||||
*
|
||||
|
|
|
@ -56,7 +56,14 @@ public class ShortURLHook extends HookCore
|
|||
|
||||
String urlPath = request.getPathInfo();
|
||||
|
||||
result = ShortURLRewriter.matches(urlPath);
|
||||
if ((ShortURLRewriter.matches(urlPath)) && (!KissDispatcherFactory.instance().isAvailablePath(urlPath)))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
|
@ -77,7 +84,5 @@ public class ShortURLHook extends HookCore
|
|||
logger.info("rewritedURLPath={}", rewritedURLPath);
|
||||
|
||||
KissDispatcherFactory.instance().dispatchPathToServlet(servletConfig, request, response, rewritedURLPath);
|
||||
// KissDispatcherFactory.instance().dispatchPathToServlet(servletConfig,
|
||||
// request, response, urlPath, rewritedURLPath);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue