incubator-ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1190396 - in /incubator/ace/trunk: ./ ace-http-redirector/ ace-http-redirector/src/ ace-http-redirector/src/main/ ace-http-redirector/src/main/java/ ace-http-redirector/src/main/java/org/ ace-http-redirector/src/main/java/org/apache/ ace-h...
Date Fri, 28 Oct 2011 15:22:16 GMT
Author: marrs
Date: Fri Oct 28 15:22:15 2011
New Revision: 1190396

URL: http://svn.apache.org/viewvc?rev=1190396&view=rev
Log:
ACE-49 added a new bundle that allows you to configure redirects

Added:
    incubator/ace/trunk/ace-http-redirector/
    incubator/ace/trunk/ace-http-redirector/pom.xml
    incubator/ace/trunk/ace-http-redirector/src/
    incubator/ace/trunk/ace-http-redirector/src/main/
    incubator/ace/trunk/ace-http-redirector/src/main/java/
    incubator/ace/trunk/ace-http-redirector/src/main/java/org/
    incubator/ace/trunk/ace-http-redirector/src/main/java/org/apache/
    incubator/ace/trunk/ace-http-redirector/src/main/java/org/apache/ace/
    incubator/ace/trunk/ace-http-redirector/src/main/java/org/apache/ace/http/
    incubator/ace/trunk/ace-http-redirector/src/main/java/org/apache/ace/http/redirector/
    incubator/ace/trunk/ace-http-redirector/src/main/java/org/apache/ace/http/redirector/Activator.java
    incubator/ace/trunk/ace-http-redirector/src/main/java/org/apache/ace/http/redirector/RedirectServlet.java
    incubator/ace/trunk/ace-target-devserver/src/main/resources/conf/org.apache.ace.http.redirector.factory/
    incubator/ace/trunk/ace-target-devserver/src/main/resources/conf/org.apache.ace.http.redirector.factory/root-to-ace.cfg
Modified:
    incubator/ace/trunk/ace-target-devserver/pom.xml
    incubator/ace/trunk/pom.xml
    incubator/ace/trunk/pom/pom.xml

Added: incubator/ace/trunk/ace-http-redirector/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-http-redirector/pom.xml?rev=1190396&view=auto
==============================================================================
--- incubator/ace/trunk/ace-http-redirector/pom.xml (added)
+++ incubator/ace/trunk/ace-http-redirector/pom.xml Fri Oct 28 15:22:15 2011
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <!--
+
+        Licensed to the Apache Software Foundation (ASF) under one or more
+        contributor license agreements.  See the NOTICE file distributed with
+        this work for additional information regarding copyright ownership.
+        The ASF licenses this file to You under the Apache License, Version 2.0
+        (the "License"); you may not use this file except in compliance with
+        the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.ace</groupId>
+        <artifactId>ace-pom</artifactId>
+        <version>0.8.1-incubator-SNAPSHOT</version>
+        <relativePath>../pom/pom.xml</relativePath>
+    </parent>
+
+    <version>0.8.1-incubator-SNAPSHOT</version>
+    <artifactId>org.apache.ace.http.redirector</artifactId>
+    <packaging>bundle</packaging>
+
+    <name>Apache ACE :: Http Redirector</name>
+    <description>Redirects HTTP requests from one (local) URL to another. Multiple
redirects can be configured via a managed service factory.</description>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/incubator/ace/trunk/ace-http-redirector</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/ace/trunk/ace-http-redirector</developerConnection>
+        <url>http://svn.apache.org/repos/asf/incubator/ace/trunk/ace-http-redirector</url>
+    </scm>
+
+    <properties>
+        <export.package>
+        </export.package>
+        <private.package>
+            org.apache.ace.http.redirector
+        </private.package>
+        <import.package>
+            *
+        </import.package>
+        <bundle.activator>
+            org.apache.ace.http.redirector.Activator
+        </bundle.activator>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.dependencymanager</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>org.apache.ace.httplistener</artifactId>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file

Added: incubator/ace/trunk/ace-http-redirector/src/main/java/org/apache/ace/http/redirector/Activator.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-http-redirector/src/main/java/org/apache/ace/http/redirector/Activator.java?rev=1190396&view=auto
==============================================================================
--- incubator/ace/trunk/ace-http-redirector/src/main/java/org/apache/ace/http/redirector/Activator.java
(added)
+++ incubator/ace/trunk/ace-http-redirector/src/main/java/org/apache/ace/http/redirector/Activator.java
Fri Oct 28 15:22:15 2011
@@ -0,0 +1,62 @@
+package org.apache.ace.http.redirector;
+
+import java.util.Dictionary;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.servlet.Servlet;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+import org.osgi.service.log.LogService;
+
+public class Activator extends DependencyActivatorBase implements ManagedServiceFactory {
+    private static final String PID = "org.apache.ace.http.redirector.factory";
+    private final ConcurrentHashMap<String, Component> m_servlets = new ConcurrentHashMap<String,
Component>();
+    
+    @Override
+    public void init(BundleContext context, DependencyManager manager) throws Exception {
+        manager.add(createComponent()
+            .setInterface(ManagedServiceFactory.class.getName(), new Properties() {{ put(Constants.SERVICE_PID,
PID); }})
+            .setImplementation(this)
+        );
+    }
+
+    @Override
+    public void destroy(BundleContext context, DependencyManager manager) throws Exception
{
+    }
+    
+    public String getName() {
+        return "Http Redirector";
+    }
+
+    public void updated(String pid, Dictionary properties) throws ConfigurationException
{
+        Component component = m_servlets.get(pid);
+        if (component == null) {
+            component = getDependencyManager().createComponent()
+                .setInterface(Servlet.class.getName(), properties)
+                .setImplementation(new RedirectServlet(properties))
+                ;
+            m_servlets.put(pid, component);
+            getDependencyManager().add(component);
+        }
+        else {
+            RedirectServlet servlet = (RedirectServlet) component.getService();
+            if (servlet != null) {
+                servlet.update(properties);
+            }
+        }
+    }
+
+    public void deleted(String pid) {
+        Component component = m_servlets.remove(pid);
+        if (component != null) {
+            getDependencyManager().remove(component);
+        }
+    }
+}

Added: incubator/ace/trunk/ace-http-redirector/src/main/java/org/apache/ace/http/redirector/RedirectServlet.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-http-redirector/src/main/java/org/apache/ace/http/redirector/RedirectServlet.java?rev=1190396&view=auto
==============================================================================
--- incubator/ace/trunk/ace-http-redirector/src/main/java/org/apache/ace/http/redirector/RedirectServlet.java
(added)
+++ incubator/ace/trunk/ace-http-redirector/src/main/java/org/apache/ace/http/redirector/RedirectServlet.java
Fri Oct 28 15:22:15 2011
@@ -0,0 +1,64 @@
+package org.apache.ace.http.redirector;
+
+import java.io.IOException;
+import java.util.Dictionary;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.ace.http.listener.constants.HttpConstants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationException;
+
+/**
+ * Servlet that will redirect from a source URL to a target URL. If you append ?show to the
source URL,
+ * it will instead show you the redirect (and you can still click on the target URL).
+ */
+public class RedirectServlet extends HttpServlet {
+    public static final String REDIRECT_URL_KEY = "org.apache.ace.webui.vaadin.redirect";
+    private final Object LOCK = new Object();
+    private volatile ServiceRegistration m_registration;
+    private String m_redirectURL;
+    private String m_sourceURL;
+    
+    public RedirectServlet(Dictionary properties) throws ConfigurationException {
+        setup(properties);
+    }
+
+    @Override
+    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException {
+        String src;
+        String url;
+        synchronized (LOCK) {
+            src = m_sourceURL;
+            url = m_redirectURL;
+        }
+        if (req.getParameter("show") != null) {
+            resp.setContentType("text/html");
+            resp.getWriter().println("<h1>Http Redirector</h1><p>Redirect
configured from " + src + " to <a href=\"" + url + "\">" + url + "</a></p>");
+        }
+        else {
+            resp.sendRedirect(url);
+        }
+    }
+    
+    public void update(Dictionary properties) throws ConfigurationException {
+        setup(properties);
+        m_registration.setProperties(properties);
+    }
+
+    private void setup(Dictionary properties) throws ConfigurationException {
+        synchronized (LOCK) {
+            m_redirectURL = (String) properties.get(REDIRECT_URL_KEY);
+            m_sourceURL = (String) properties.get(HttpConstants.ENDPOINT);
+            if (m_sourceURL == null) {
+                throw new ConfigurationException(HttpConstants.ENDPOINT, "needs to be specified");
+            }
+            if (m_redirectURL == null) {
+                throw new ConfigurationException(REDIRECT_URL_KEY, "needs to be specified");
+            }
+        }
+    }
+}

Modified: incubator/ace/trunk/ace-target-devserver/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-target-devserver/pom.xml?rev=1190396&r1=1190395&r2=1190396&view=diff
==============================================================================
--- incubator/ace/trunk/ace-target-devserver/pom.xml (original)
+++ incubator/ace/trunk/ace-target-devserver/pom.xml Fri Oct 28 15:22:15 2011
@@ -274,6 +274,11 @@
         </dependency>
         <dependency>
             <groupId>org.apache.ace</groupId>
+            <artifactId>org.apache.ace.http.redirector</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
             <artifactId>org.apache.ace.obr.metadata</artifactId>
             <scope>runtime</scope>
         </dependency>

Added: incubator/ace/trunk/ace-target-devserver/src/main/resources/conf/org.apache.ace.http.redirector.factory/root-to-ace.cfg
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-target-devserver/src/main/resources/conf/org.apache.ace.http.redirector.factory/root-to-ace.cfg?rev=1190396&view=auto
==============================================================================
--- incubator/ace/trunk/ace-target-devserver/src/main/resources/conf/org.apache.ace.http.redirector.factory/root-to-ace.cfg
(added)
+++ incubator/ace/trunk/ace-target-devserver/src/main/resources/conf/org.apache.ace.http.redirector.factory/root-to-ace.cfg
Fri Oct 28 15:22:15 2011
@@ -0,0 +1,2 @@
+org.apache.ace.server.servlet.endpoint=/
+org.apache.ace.webui.vaadin.redirect=/ace/

Modified: incubator/ace/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/pom.xml?rev=1190396&r1=1190395&r2=1190396&view=diff
==============================================================================
--- incubator/ace/trunk/pom.xml (original)
+++ incubator/ace/trunk/pom.xml Fri Oct 28 15:22:15 2011
@@ -80,6 +80,7 @@
         <module>ace-deployment-verifier</module>
         <module>ace-deployment-verifier-ui</module>
         <module>ace-httplistener</module>
+        <module>ace-http-redirector</module>
 
         <module>ace-server-log-store</module>
         <module>ace-server-log-ui</module>
@@ -205,6 +206,7 @@
                 <module>ace-discovery-api</module>
                 <module>ace-discovery-property</module>
                 <module>ace-httplistener</module>
+                <module>ace-http-redirector</module>
                 <module>ace-obr-metadata</module>
                 <module>ace-obr-storage</module>
                 <module>ace-obr-servlet</module>

Modified: incubator/ace/trunk/pom/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/pom/pom.xml?rev=1190396&r1=1190395&r2=1190396&view=diff
==============================================================================
--- incubator/ace/trunk/pom/pom.xml (original)
+++ incubator/ace/trunk/pom/pom.xml Fri Oct 28 15:22:15 2011
@@ -470,6 +470,11 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.ace</groupId>
+                <artifactId>org.apache.ace.http.redirector</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.ace</groupId>
                 <artifactId>org.apache.ace.identification.api</artifactId>
                 <version>${project.version}</version>
             </dependency>



Mime
View raw message