cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1521065 - in /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs: ext/MessageContextImpl.java provider/FormEncodingProvider.java utils/FormUtils.java
Date Mon, 09 Sep 2013 12:10:39 GMT
Author: sergeyb
Date: Mon Sep  9 12:10:39 2013
New Revision: 1521065

URL: http://svn.apache.org/r1521065
Log:
Minimiaing a need to use servlet api on the client side when reading form response

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java?rev=1521065&r1=1521064&r2=1521065&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
Mon Sep  9 12:10:39 2013
@@ -152,7 +152,11 @@ public class MessageContextImpl implemen
     }
     
     public HttpServletRequest getHttpServletRequest() {
-        return getContext(HttpServletRequest.class);
+        try {
+            return getContext(HttpServletRequest.class);
+        } catch (Throwable t) {
+            return null;
+        }
     }
 
     public HttpServletResponse getHttpServletResponse() {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java?rev=1521065&r1=1521064&r2=1521065&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
Mon Sep  9 12:10:39 2013
@@ -169,12 +169,22 @@ public class FormEncodingProvider<T> imp
                                                decode);
         } else {
             String enc = HttpUtils.getEncoding(mt, "UTF-8");
-            FormUtils.populateMapFromString(params,
-                                            PhaseInterceptorChain.getCurrentMessage(),
-                                            FormUtils.readBody(is, enc),
-                                            enc,
-                                            decode,
-                                            mc != null ? mc.getHttpServletRequest() : null);
+            
+            Object servletRequest = mc != null ? mc.getHttpServletRequest() : null;
+            if (servletRequest == null) {
+                FormUtils.populateMapFromString(params,
+                                                PhaseInterceptorChain.getCurrentMessage(),
+                                                FormUtils.readBody(is, enc),
+                                                enc,
+                                                decode);
+            } else {
+                FormUtils.populateMapFromString(params,
+                                                PhaseInterceptorChain.getCurrentMessage(),
+                                                FormUtils.readBody(is, enc),
+                                                enc,
+                                                decode,
+                                                (javax.servlet.http.HttpServletRequest)servletRequest);
+            }
         }
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java?rev=1521065&r1=1521064&r2=1521065&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java Mon
Sep  9 12:10:39 2013
@@ -31,7 +31,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.logging.Logger;
 
-import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.BadRequestException;
 import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.WebApplicationException;
@@ -126,28 +125,37 @@ public final class FormUtils {
                                              Message m,
                                              String postBody, 
                                              String enc,
+                                             boolean decode) {
+        List<String> parts = Arrays.asList(StringUtils.split(postBody, "&"));
+        checkNumberOfParts(m, parts.size());
+        for (String part : parts) {
+            String[] keyValue = new String[2];
+            int index = part.indexOf("=");
+            if (index != -1) {
+                keyValue[0] = part.substring(0, index);
+                keyValue[1] = index + 1 < part.length() ? part.substring(index + 1) :
"";
+            } else {
+                keyValue[0] = part;
+                keyValue[1] = "";
+            }
+            String name = HttpUtils.urlDecode(keyValue[0], enc);
+            if (decode) {
+                params.add(name, HttpUtils.urlDecode(keyValue[1], enc));
+            } else {
+                params.add(name, keyValue[1]);
+            }
+        }
+        
+    }
+    
+    public static void populateMapFromString(MultivaluedMap<String, String> params,
+                                             Message m,
+                                             String postBody, 
+                                             String enc,
                                              boolean decode,
-                                             HttpServletRequest request) {
+                                             javax.servlet.http.HttpServletRequest request)
{
         if (!StringUtils.isEmpty(postBody)) {
-            List<String> parts = Arrays.asList(StringUtils.split(postBody, "&"));
-            checkNumberOfParts(m, parts.size());
-            for (String part : parts) {
-                String[] keyValue = new String[2];
-                int index = part.indexOf("=");
-                if (index != -1) {
-                    keyValue[0] = part.substring(0, index);
-                    keyValue[1] = index + 1 < part.length() ? part.substring(index + 1)
: "";
-                } else {
-                    keyValue[0] = part;
-                    keyValue[1] = "";
-                }
-                String name = HttpUtils.urlDecode(keyValue[0], enc);
-                if (decode) {
-                    params.add(name, HttpUtils.urlDecode(keyValue[1], enc));
-                } else {
-                    params.add(name, keyValue[1]);
-                }
-            }
+            populateMapFromString(params, m, postBody, enc, decode);
         } else if (request != null) {
             for (Enumeration<String> en = request.getParameterNames(); en.hasMoreElements();)
{
                 String paramName = en.nextElement();



Mime
View raw message