improve url mapping

This commit is contained in:
Sebastian Sdorra
2013-01-05 11:11:49 +01:00
parent 79b76c2c0c
commit 5ec0cc1833
7 changed files with 117 additions and 59 deletions

View File

@@ -0,0 +1,87 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.plugin;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Singleton;
import sonia.scm.web.filter.HttpFilter;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Sebastian Sdorra
*/
@Singleton
public class RedirectFilter extends HttpFilter
{
private static final String STARTPAGE = "/page/index.html";
/**
* Method description
*
*
* @param request
* @param response
* @param chain
*
* @throws IOException
* @throws ServletException
*/
@Override
protected void doFilter(HttpServletRequest request,
HttpServletResponse response, FilterChain chain)
throws IOException, ServletException
{
String url =
request.getRequestURI().substring(request.getContextPath().length());
if (url.equals("") || url.equals("/"))
{
response.sendRedirect(request.getContextPath() + STARTPAGE);
}
else
{
chain.doFilter(request, response);
}
}
}

View File

@@ -52,11 +52,14 @@ import sonia.scm.plugin.scanner.PluginScannerFactory;
import sonia.scm.plugin.scanner.PluginScannerScheduler;
import sonia.scm.plugin.scanner.TimerPluginScannerScheduler;
import sonia.scm.util.Util;
import sonia.scm.web.proxy.ProxyConfigurationProvider;
import sonia.scm.web.proxy.ProxyServlet;
//~--- JDK imports ------------------------------------------------------------
import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
import com.sun.jersey.spi.container.servlet.ServletContainer;
import java.io.File;
@@ -64,8 +67,6 @@ import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.JAXB;
import sonia.scm.web.proxy.ProxyConfigurationProvider;
import sonia.scm.web.proxy.ProxyServlet;
/**
*
@@ -90,10 +91,17 @@ public class ScmBackendModule extends ServletModule
public static final String FILE_CONFIG = "config.xml";
/** Field description */
public static final String PATTERN_API = "/api/*";
public static final String PACKAGE = "sonia.scm.plugin.rest";
/** Field description */
public static final String PATTERN_PAGE = "/page/*";
public static final String PATTERN_NEWS = "/news*";
/** Field description */
public static final String PATTERN_REST_API = "/*";
/** Field description */
public static final String PATTERN_REST_EXCLUDE =
"/(template/|news).*";
//~--- methods --------------------------------------------------------------
@@ -116,15 +124,14 @@ public class ScmBackendModule extends ServletModule
if (!configurationFile.exists())
{
throw new ConfigurationException(
"could not find configuration at ".concat(
configurationFile.getPath()));
"could not find configuration at ".concat(configurationFile.getPath()));
}
BackendConfiguration configuration = JAXB.unmarshal(configurationFile,
BackendConfiguration.class);
bind(File.class).annotatedWith(Names.named(DIRECTORY_PROPERTY)).toInstance(
baseDirectory);
baseDirectory);
bind(BackendConfiguration.class).toInstance(configuration);
bind(PluginBackend.class).to(DefaultPluginBackend.class);
bind(PluginScannerFactory.class).to(DefaultPluginScannerFactory.class);
@@ -148,13 +155,18 @@ public class ScmBackendModule extends ServletModule
// news proxy
bind(ProxyConfigurationProvider.class).to(NewsProxyURLProvider.class);
serve("/news*").with(ProxyServlet.class);
serve(PATTERN_NEWS).with(ProxyServlet.class);
// redirect for start page
filter(PATTERN_REST_API).through(RedirectFilter.class);
// rest
Map<String, String> params = new HashMap<String, String>();
params.put(PackagesResourceConfig.PROPERTY_PACKAGES,
"sonia.scm.plugin.rest");
serve(PATTERN_API, PATTERN_PAGE).with(GuiceContainer.class, params);
params.put(PackagesResourceConfig.PROPERTY_PACKAGES, PACKAGE);
params.put(ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX,
PATTERN_REST_EXCLUDE);
filter(PATTERN_REST_API).through(GuiceContainer.class, params);
}
/**

View File

@@ -77,7 +77,7 @@ import javax.ws.rs.core.Response.Status;
* @author Sebastian Sdorra
*/
@Singleton
@Path("/detail/{groupId}/{artifactId}.html")
@Path("/page/detail/{groupId}/{artifactId}.html")
public class DetailResource extends CachedViewableResource
{

View File

@@ -37,13 +37,12 @@ package sonia.scm.plugin.rest;
import com.google.inject.Inject;
import sonia.scm.plugin.*;
import sonia.scm.plugin.BackendConfiguration;
import sonia.scm.plugin.Category;
import sonia.scm.plugin.CategoryNameComaparator;
import sonia.scm.plugin.PluginBackend;
import sonia.scm.plugin.PluginInformation;
import sonia.scm.util.LinkTextParser;
import sonia.scm.plugin.PluginUtil;
import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
@@ -65,7 +64,7 @@ import javax.ws.rs.Path;
*
* @author Sebastian Sdorra
*/
@Path("/index.html")
@Path("/page/index.html")
public class OverviewResource extends ViewableResource
{
@@ -85,7 +84,7 @@ public class OverviewResource extends ViewableResource
*/
@Inject
public OverviewResource(ServletContext context, PluginBackend backend,
BackendConfiguration configuration)
BackendConfiguration configuration)
{
super(context, configuration);
this.backend = backend;
@@ -118,7 +117,7 @@ public class OverviewResource extends ViewableResource
* @param plugin
*/
private void append(Map<String, Category> categories,
PluginInformation plugin)
PluginInformation plugin)
{
String name = plugin.getCategory();

View File

@@ -74,7 +74,7 @@ import javax.ws.rs.core.Response;
* @author Sebastian Sdorra
*/
@Singleton
@Path("{version}/plugins")
@Path("/api/{version}/plugins")
public class PluginResource implements PluginBackendListener
{

View File

@@ -71,7 +71,7 @@ import javax.ws.rs.core.Response.Status;
*
* @author Sebastian Sdorra
*/
@Path("/screenshot/{groupId}/{artifactId}/{number}/{size}.jpg")
@Path("/page/screenshot/{groupId}/{artifactId}/{number}/{size}.jpg")
public class ScreenshotResource
{

View File

@@ -1,40 +0,0 @@
<!--
Copyright (c) 2010, Sebastian Sdorra
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of SCM-Manager; nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
http://bitbucket.org/sdorra/scm-manager
-->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="0;url=page/index.html">
</head>
<body></body>
</html>