Sebastian Sdorra avatar Sebastian Sdorra committed 6ea72cd

improve url mapping

Comments (0)

Files changed (7)

scm-plugin-backend/src/main/java/sonia/scm/plugin/RedirectFilter.java

+/**
+ * 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);
+    }
+
+  }
+}

scm-plugin-backend/src/main/java/sonia/scm/plugin/ScmBackendModule.java

 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;
 
 import java.util.Map;
 
 import javax.xml.bind.JAXB;
-import sonia.scm.web.proxy.ProxyConfigurationProvider;
-import sonia.scm.web.proxy.ProxyServlet;
 
 /**
  *
   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 --------------------------------------------------------------
 
     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);
 
     // 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);
   }
 
   /**

scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/DetailResource.java

  * @author Sebastian Sdorra
  */
 @Singleton
-@Path("/detail/{groupId}/{artifactId}.html")
+@Path("/page/detail/{groupId}/{artifactId}.html")
 public class DetailResource extends CachedViewableResource
 {
 

scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/OverviewResource.java

 
 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 ------------------------------------------------------------
  *
  * @author Sebastian Sdorra
  */
-@Path("/index.html")
+@Path("/page/index.html")
 public class OverviewResource extends ViewableResource
 {
 
    */
   @Inject
   public OverviewResource(ServletContext context, PluginBackend backend,
-                          BackendConfiguration configuration)
+    BackendConfiguration configuration)
   {
     super(context, configuration);
     this.backend = backend;
    * @param plugin
    */
   private void append(Map<String, Category> categories,
-                      PluginInformation plugin)
+    PluginInformation plugin)
   {
     String name = plugin.getCategory();
 

scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/PluginResource.java

  * @author Sebastian Sdorra
  */
 @Singleton
-@Path("{version}/plugins")
+@Path("/api/{version}/plugins")
 public class PluginResource implements PluginBackendListener
 {
 

scm-plugin-backend/src/main/java/sonia/scm/plugin/rest/ScreenshotResource.java

  *
  * @author Sebastian Sdorra
  */
-@Path("/screenshot/{groupId}/{artifactId}/{number}/{size}.jpg")
+@Path("/page/screenshot/{groupId}/{artifactId}/{number}/{size}.jpg")
 public class ScreenshotResource
 {
 

scm-plugin-backend/src/main/webapp/redirect.html

-<!--
-
-    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>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.