tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject [2/2] tomee git commit: removing some jsf hacks + basic impl of redirect in openejb-http (very basic and not complete))
Date Fri, 02 Jan 2015 12:54:23 GMT
removing some jsf hacks + basic impl of redirect in openejb-http (very basic and not complete))


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/a4fd7074
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/a4fd7074
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/a4fd7074

Branch: refs/heads/develop
Commit: a4fd70746e3d9540ff75ed748318d263feb6a424
Parents: 530fe3c
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Fri Jan 2 13:54:03 2015 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Fri Jan 2 13:54:03 2015 +0100

----------------------------------------------------------------------
 .../openejb/server/httpd/HttpRequestImpl.java   |  5 +--
 .../openejb/server/httpd/HttpResponseImpl.java  | 35 ++++++++++++++------
 .../server/httpd/OpenEJBHttpRegistry.java       | 12 -------
 3 files changed, 25 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/a4fd7074/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
----------------------------------------------------------------------
diff --git a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
index 8fa7ceb..e30e40b 100644
--- a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
+++ b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpRequestImpl.java
@@ -264,7 +264,7 @@ public class HttpRequestImpl implements HttpRequest {
     public String getPathInfo() {
         // hack for jsf, would need to rething all our getpathInfo() to get rid of it
         // Note: if you tackle it ensure to not break CXF integrations
-        if (path != null && path.endsWith(".jsf") || servletPath != null &&
servletPath.endsWith(".jsf")) {
+        if (path != null && path.contains(".jsf") || servletPath != null &&
servletPath.endsWith(".jsf")) {
             return null;
         }
         if (servletPath != null) {
@@ -322,9 +322,6 @@ public class HttpRequestImpl implements HttpRequest {
             return servletPath;
         }
         if (path != null && path.endsWith(".jsf")) { // see getPathInfo()
-            if (contextPath != null && path.startsWith('/' + contextPath)) { // weird
case with encoded url in forms, still this missing router surely
-                return path.substring(contextPath.length() + 1);
-            }
             return path;
         }
         if ("/".equals(path) && uri != null) { // not initialized, contextpath =
"" so let use it for our router (HttpListenerRegistry)

http://git-wip-us.apache.org/repos/asf/tomee/blob/a4fd7074/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpResponseImpl.java
----------------------------------------------------------------------
diff --git a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpResponseImpl.java
b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpResponseImpl.java
index a30f020..8e46b5f 100644
--- a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpResponseImpl.java
+++ b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpResponseImpl.java
@@ -31,9 +31,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
 import java.net.URLConnection;
-import java.net.URLEncoder;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
@@ -157,21 +155,17 @@ public class HttpResponseImpl implements HttpResponse {
 
     @Override
     public String encodeURL(String s) {
-        try {
-            return URLEncoder.encode(s, "UTF-8");
-        } catch (UnsupportedEncodingException e) {
-            return s;
-        }
+        return toEncoded(s);
     }
 
     @Override
     public String encodeRedirectURL(String s) {
-        return encodeURL(s);
+        return toEncoded(s);
     }
 
     @Override
     public String encodeUrl(String s) {
-        return encodeURL(s);
+        return toEncoded(s);
     }
 
     @Override
@@ -216,8 +210,19 @@ public class HttpResponseImpl implements HttpResponse {
     }
 
     @Override
-    public void sendRedirect(String s) throws IOException {
-        // no-op
+    public void sendRedirect(final String path) throws IOException {
+        if (commited) {
+            throw new IllegalStateException("response already committed");
+        }
+        resetBuffer();
+
+        try {
+            setStatus(SC_FOUND);
+
+            setHeader("Location", base() + toEncoded(path));
+        } catch (final IllegalArgumentException e) {
+            setStatus(SC_NOT_FOUND);
+        }
     }
 
     @Override
@@ -716,4 +721,12 @@ public class HttpResponseImpl implements HttpResponse {
     public void setStatusMessage(String responseString) {
         this.setResponseString(responseString);
     }
+
+    private String base() {
+        return request == null ? "" : request.getURI().getScheme() + "://" + request.getURI().getAuthority();
+    }
+
+    private String toEncoded(final String url) {
+        return url; // should add ;JSESSIONID=xxx but breaks other things and here we don't
need it that much
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tomee/blob/a4fd7074/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpRegistry.java
----------------------------------------------------------------------
diff --git a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpRegistry.java
b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpRegistry.java
index 140be2e..8030f02 100644
--- a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpRegistry.java
+++ b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpRegistry.java
@@ -26,11 +26,9 @@ import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.webbeans.config.WebBeansContext;
 
-import java.io.OutputStream;
 import java.net.InetAddress;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -122,16 +120,6 @@ public class OpenEJBHttpRegistry {
 
                         final String ctx = (web.getContextRoot().startsWith("/") ? "" : "/")
+ web.getContextRoot();
                         httpRequest.initPathFromContext(ctx);
-                        if (httpRequest.getServletPath().startsWith('/' + ctx)) { // yes
double /, there is an encoding issue with JSF forms with our embedded mode
-                            final String servlet = URLDecoder.decode(httpRequest.getServletPath().substring(ctx.length()
+ 1), "UTF-8");
-                            final int query = servlet.indexOf('?');
-                            if (query > 0) {
-                                httpRequest.initServletPath(servlet.substring(0, query));
-                                httpRequest.addQueryParams(servlet.substring(query + 1));
-                            } else {
-                                httpRequest.initServletPath(servlet);
-                            }
-                        }
                         wbc = web.getWebbeansContext() != null ? web.getWebbeansContext()
: web.getAppContext().getWebBeansContext();
                     } else {
                         thread.setContextClassLoader(classLoader);


Mime
View raw message