diff flys-client/src/main/java/de/intevation/flys/client/server/LoginServlet.java @ 3851:a4c9296f6efa

Use the Context PATH servlet variable when using URLs in the GGInAFilter flys-client/trunk@5591 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Mon, 24 Sep 2012 13:04:53 +0000
parents 2e12518ff5b4
children 17fe00c09b7c
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/LoginServlet.java	Mon Sep 24 11:53:29 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/LoginServlet.java	Mon Sep 24 13:04:53 2012 +0000
@@ -22,20 +22,25 @@
 
     private static Logger logger = Logger.getLogger(LoginServlet.class);
 
-    private void redirectFailure(HttpServletResponse resp) throws IOException {
-        resp.sendRedirect("/login.jsp");
+    private void redirectFailure(HttpServletResponse resp, String path)
+        throws IOException {
+        resp.sendRedirect(path + "/login.jsp");
     }
 
-    private void redirectFailure(HttpServletResponse resp, Exception e) throws IOException {
-        this.redirectFailure(resp, e.getMessage());
+    private void redirectFailure(HttpServletResponse resp, String path,
+            Exception e) throws IOException {
+        this.redirectFailure(resp, path, e.getMessage());
     }
 
-    private void redirectFailure(HttpServletResponse resp, String message) throws IOException {
-        resp.sendRedirect("/login.jsp?error=" + message);
+    private void redirectFailure(HttpServletResponse resp, String path,
+            String message) throws IOException {
+        resp.sendRedirect(path + "/login.jsp?error=" + message);
     }
-    private void redirectSuccess(HttpServletResponse resp, String uri) throws IOException {
+
+    private void redirectSuccess(HttpServletResponse resp, String path,
+            String uri) throws IOException {
         if (uri == null) {
-            uri = "/FLYS.html";
+            uri = path + "/FLYS.html";
         }
         resp.sendRedirect(uri);
     }
@@ -44,7 +49,7 @@
     protected void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
         logger.debug("Processing get request");
-        this.redirectFailure(resp);
+        this.redirectFailure(resp, req.getContextPath());
     }
 
     @Override
@@ -59,7 +64,7 @@
 
         if (username == null || password == null) {
             logger.debug("No username or password provided");
-            this.redirectFailure(resp);
+            this.redirectFailure(resp, req.getContextPath());
             return;
         }
 
@@ -67,7 +72,7 @@
             Authentication aresp = this.auth(username, password, encoding);
             if (aresp == null || !aresp.isSuccess()) {
                 logger.debug("Authentication not successful");
-                this.redirectFailure(resp);
+                this.redirectFailure(resp, req.getContextPath());
             }
             User user = aresp.getUser();
 
@@ -76,7 +81,8 @@
             if (!client.userExists(user)) {
                 logger.debug("Creating db user");
                 if (!client.createUser(user)) {
-                    this.redirectFailure(resp, "Could not create new user");
+                    this.redirectFailure(resp, req.getContextPath(),
+                            "Could not create new user");
                 }
             }
 
@@ -85,11 +91,11 @@
 
             String uri = (String)session.getAttribute("requesturi");
 
-            this.redirectSuccess(resp, uri);
+            this.redirectSuccess(resp, req.getContextPath(), uri);
         }
         catch(AuthenticationException e) {
             logger.error(e);
-            this.redirectFailure(resp, e);
+            this.redirectFailure(resp, req.getContextPath(), e);
         }
     }
 

http://dive4elements.wald.intevation.org