From fec7a22c44c62fb1dffff2f490f64ed6ff20d28c Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 13 Sep 2011 16:41:54 +0200 Subject: [PATCH] added proxy servlet for news fetching --- scm-plugin-backend/pom.xml | 6 ++ .../scm/plugin/BackendConfiguration.java | 28 +++++++ .../scm/plugin/NewsProxyURLProvider.java | 83 +++++++++++++++++++ .../sonia/scm/plugin/ScmBackendModule.java | 6 ++ 4 files changed, 123 insertions(+) create mode 100644 scm-plugin-backend/src/main/java/sonia/scm/plugin/NewsProxyURLProvider.java diff --git a/scm-plugin-backend/pom.xml b/scm-plugin-backend/pom.xml index 9881793eec..b469916271 100644 --- a/scm-plugin-backend/pom.xml +++ b/scm-plugin-backend/pom.xml @@ -57,6 +57,12 @@ 0.9.29 + + rome + rome + 1.0 + + net.sf.ehcache ehcache-core diff --git a/scm-plugin-backend/src/main/java/sonia/scm/plugin/BackendConfiguration.java b/scm-plugin-backend/src/main/java/sonia/scm/plugin/BackendConfiguration.java index 54e8c5f05b..75b04c60d8 100644 --- a/scm-plugin-backend/src/main/java/sonia/scm/plugin/BackendConfiguration.java +++ b/scm-plugin-backend/src/main/java/sonia/scm/plugin/BackendConfiguration.java @@ -41,6 +41,8 @@ import sonia.scm.xml.XmlIntervalAdapter; import java.io.File; +import java.net.URL; + import java.util.Set; import javax.xml.bind.annotation.XmlAccessType; @@ -81,6 +83,17 @@ public class BackendConfiguration return excludes; } + /** + * Method description + * + * + * @return + */ + public URL getNewsUrl() + { + return newsUrl; + } + /** * Method description * @@ -149,6 +162,17 @@ public class BackendConfiguration this.multithreaded = multithreaded; } + /** + * Method description + * + * + * @param newsUrl + */ + public void setNewsUrl(URL newsUrl) + { + this.newsUrl = newsUrl; + } + /** * Method description * @@ -186,6 +210,10 @@ public class BackendConfiguration /** Field description */ private boolean multithreaded = true; + /** Field description */ + @XmlElement(name= "news-url") + private URL newsUrl; + /** Field description */ @XmlElement(name = "repository") @XmlElementWrapper(name = "repositories") diff --git a/scm-plugin-backend/src/main/java/sonia/scm/plugin/NewsProxyURLProvider.java b/scm-plugin-backend/src/main/java/sonia/scm/plugin/NewsProxyURLProvider.java new file mode 100644 index 0000000000..f83e64dac7 --- /dev/null +++ b/scm-plugin-backend/src/main/java/sonia/scm/plugin/NewsProxyURLProvider.java @@ -0,0 +1,83 @@ +/** + * 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.Inject; + +import sonia.scm.web.proxy.ProxyURLProvider; + +//~--- JDK imports ------------------------------------------------------------ + +import java.net.URL; + +/** + * + * @author Sebastian Sdorra + */ +public class NewsProxyURLProvider implements ProxyURLProvider +{ + + /** + * Constructs ... + * + * + * @param configuration + */ + @Inject + public NewsProxyURLProvider(BackendConfiguration configuration) + { + this.configuration = configuration; + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + @Override + public URL getProxyURL() + { + return configuration.getNewsUrl(); + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + private BackendConfiguration configuration; +} diff --git a/scm-plugin-backend/src/main/java/sonia/scm/plugin/ScmBackendModule.java b/scm-plugin-backend/src/main/java/sonia/scm/plugin/ScmBackendModule.java index 4a7a60f273..9a0ab9250e 100644 --- a/scm-plugin-backend/src/main/java/sonia/scm/plugin/ScmBackendModule.java +++ b/scm-plugin-backend/src/main/java/sonia/scm/plugin/ScmBackendModule.java @@ -44,6 +44,8 @@ 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.ProxyServet; +import sonia.scm.web.proxy.ProxyURLProvider; //~--- JDK imports ------------------------------------------------------------ @@ -117,6 +119,10 @@ public class ScmBackendModule extends ServletModule bind(PluginScannerFactory.class).to(DefaultPluginScannerFactory.class); bind(PluginScannerScheduler.class).to(TimerPluginScannerScheduler.class); + // news proxy + bind(ProxyURLProvider.class).to(NewsProxyURLProvider.class); + serve("/news*").with(ProxyServet.class); + Map params = new HashMap(); params.put(PackagesResourceConfig.PROPERTY_PACKAGES,