[wsas-java-dev] svn commit r65 - in wsas/java/trunk/modules: core/src/org/wso2/wsas/transport/jetty servlet-edition/conf servlet-edition/src/org/wso2/wsas

svn at wso2.com svn at wso2.com
Fri Dec 1 06:38:39 PST 2006


Author: saminda
Date: Fri Dec  1 06:38:37 2006
New Revision: 65

Added:
   wsas/java/trunk/modules/servlet-edition/src/org/wso2/wsas/RequestRedirectionFilter.java
Modified:
   wsas/java/trunk/modules/core/src/org/wso2/wsas/transport/jetty/ManagementConsoleRequestHandler.java
   wsas/java/trunk/modules/servlet-edition/conf/web.xml
   wsas/java/trunk/modules/servlet-edition/src/org/wso2/wsas/MainServlet.java
Log:
1. Giving the correct host address to the user 


Modified: wsas/java/trunk/modules/core/src/org/wso2/wsas/transport/jetty/ManagementConsoleRequestHandler.java
==============================================================================
--- wsas/java/trunk/modules/core/src/org/wso2/wsas/transport/jetty/ManagementConsoleRequestHandler.java	(original)
+++ wsas/java/trunk/modules/core/src/org/wso2/wsas/transport/jetty/ManagementConsoleRequestHandler.java	Fri Dec  1 06:38:37 2006
@@ -35,7 +35,6 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.Map;
-import java.net.SocketException;
 
 /**
  * 

Modified: wsas/java/trunk/modules/servlet-edition/conf/web.xml
==============================================================================
--- wsas/java/trunk/modules/servlet-edition/conf/web.xml	(original)
+++ wsas/java/trunk/modules/servlet-edition/conf/web.xml	Fri Dec  1 06:38:37 2006
@@ -21,11 +21,18 @@
 <web-app>
     <display-name>WSO2 WSAS</display-name>
     <filter>
+        <filter-name>RequestFilter</filter-name>
+        <filter-class>org.wso2.wsas.RequestRedirectionFilter</filter-class>
+    </filter>
+    <filter>
         <filter-name>AdminFilter</filter-name>
         <filter-class>org.wso2.adminui.AdminUIServletFilter</filter-class>
-
     </filter>
     <filter-mapping>
+        <filter-name>RequestFilter</filter-name>
+        <url-pattern>/*</url-pattern>
+    </filter-mapping>
+    <filter-mapping>
         <filter-name>AdminFilter</filter-name>
         <url-pattern>/*</url-pattern>
     </filter-mapping>

Modified: wsas/java/trunk/modules/servlet-edition/src/org/wso2/wsas/MainServlet.java
==============================================================================
--- wsas/java/trunk/modules/servlet-edition/src/org/wso2/wsas/MainServlet.java	(original)
+++ wsas/java/trunk/modules/servlet-edition/src/org/wso2/wsas/MainServlet.java	Fri Dec  1 06:38:37 2006
@@ -194,6 +194,10 @@
                     init((Map) serverManager.configContext.
                             getProperty(ServerConstants.GENERATED_PAGES),
                          serverConfig.getFirstProperty("AdminWeb.ContextPath"));
+            // set redirection
+            ((RequestRedirectionFilter) servletContext
+                    .getAttribute(RequestRedirectionFilter.class.getName()))
+                    .init(serverConfig.getFirstProperty("AdminWeb.ContextPath"));
 
             log.info("Using Repository " + serverManager.axis2RepoLocation);
             log.info("");
@@ -257,6 +261,12 @@
                                     getProperty(ServerConstants.GENERATED_PAGES),
                                  ServerConfiguration.getInstance().
                                          getFirstProperty("AdminWeb.ContextPath"));
+                } else if (attrib instanceof RequestRedirectionFilter) {
+                    ((RequestRedirectionFilter) servletContext
+                            .getAttribute(RequestRedirectionFilter.class.getName()))
+                            .init(ServerConfiguration.getInstance().getFirstProperty(
+                                    "AdminWeb.ContextPath"));
+
                 }
             }
         } catch (ServletException e) {

Added: wsas/java/trunk/modules/servlet-edition/src/org/wso2/wsas/RequestRedirectionFilter.java
==============================================================================
--- (empty file)
+++ wsas/java/trunk/modules/servlet-edition/src/org/wso2/wsas/RequestRedirectionFilter.java	Fri Dec  1 06:38:37 2006
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+package org.wso2.wsas;
+
+import org.wso2.wsf.common.util.NetworkUtils;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+/*
+ * 
+ */
+
+public class RequestRedirectionFilter implements Filter {
+
+    private FilterConfig filterConfig;
+    private String contextRoot;
+
+    /**
+     * This init method will be invoked at MainServlet. This will be called at the startup time as
+     * well as when the system is re-starting.
+     *
+     * @param filterConfig
+     * @throws ServletException
+     */
+    public void init(FilterConfig filterConfig) throws ServletException {
+        this.filterConfig = filterConfig;
+        filterConfig.getServletContext().setAttribute(this.getClass().getName(), this);
+    }
+
+    public void init(String contextRoot) throws ServletException {
+        this.contextRoot = contextRoot;
+        init(filterConfig);
+    }
+
+    public void doFilter(ServletRequest request, ServletResponse response,
+                         FilterChain filterChain) throws IOException, ServletException {
+        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
+        HttpServletResponse httpServletResponse = (HttpServletResponse)response;
+        if (httpServletRequest.getRequestURL().toString()
+                .indexOf(NetworkUtils.getLocalHostname()) == -1) {
+            httpServletResponse.sendRedirect("https://" +
+                                  NetworkUtils.getLocalHostname() + ":" + ServerManager.httpsPort +
+                                  (contextRoot.equals("/") ? contextRoot : contextRoot + "/")); // set the redirection
+        } else {
+            filterChain.doFilter(request,response);
+        }
+
+    }
+
+    public void destroy() {
+        // TODO
+    }
+}




More information about the Wsas-java-dev mailing list