cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1198587 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/
Date Sun, 06 Nov 2011 23:07:55 GMT
Author: sergeyb
Date: Sun Nov  6 23:07:55 2011
New Revision: 1198587

URL: http://svn.apache.org/viewvc?rev=1198587&view=rev
Log:
Merged revisions 1198584 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1198584 | sergeyb | 2011-11-06 23:03:00 +0000 (Sun, 06 Nov 2011) | 1 line
  
  [CXF-3894] RequestDispatcherProvider and FormUtils logging improvements
........

Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Nov  6 23:07:55 2011
@@ -1 +1 @@
-/cxf/trunk:1197048
+/cxf/trunk:1197048,1198584

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java?rev=1198587&r1=1198586&r2=1198587&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
Sun Nov  6 23:07:55 2011
@@ -24,9 +24,6 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.Encoded;
@@ -192,22 +189,9 @@ public class FormEncodingProvider implem
             (MultivaluedMap<String, String>)(obj instanceof Form ? ((Form)obj).getData()
: obj);
         boolean encoded = AnnotationUtils.getAnnotation(anns, Encoded.class) != null;
         
-        String encoding = HttpUtils.getSetEncoding(mt, headers, "UTF-8");
+        String enc = HttpUtils.getSetEncoding(mt, headers, "UTF-8");
         
-        for (Iterator<Map.Entry<String, List<String>>> it = map.entrySet().iterator();
it.hasNext();) {
-            Map.Entry<String, List<String>> entry = it.next();
-            for (Iterator<String> entryIterator = entry.getValue().iterator(); entryIterator.hasNext();)
{
-                String value = entryIterator.next();
-                os.write(entry.getKey().getBytes(encoding));
-                os.write('=');
-                String data = encoded ? value : HttpUtils.urlEncode(value);
-                os.write(data.getBytes(encoding));
-                if (entryIterator.hasNext() || it.hasNext()) {
-                    os.write('&');
-                }
-            }
-
-        }
+        FormUtils.writeMapToOutputStream(map, os, enc, encoded);
         
     }
 

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties?rev=1198587&r1=1198586&r2=1198587&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties
Sun Nov  6 23:07:55 2011
@@ -21,5 +21,6 @@
 JAXB_EXCEPTION=JAXBException occurred : {0}
 NO_COLLECTION_ROOT=No collection name is provided
 NO_MSG_WRITER =.No message body writer found for class : {0}.
+RESPONSE_REDIRECTED_TO=Setting an instance of \"{0}\" as HttpServletRequest attribute \"{1}\"
and redirecting the response to \"{2}\".
 EMPTY_BODY=Message body is empty
 

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java?rev=1198587&r1=1198586&r2=1198587&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
Sun Nov  6 23:07:55 2011
@@ -27,6 +27,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.servlet.RequestDispatcher;
@@ -76,6 +77,7 @@ public class RequestDispatcherProvider e
     private String dispatcherName;
     private String servletPath;
     private boolean saveParametersAsAttributes;
+    private boolean logRedirects;
     
     @Context
     private MessageContext mc; 
@@ -114,12 +116,14 @@ public class RequestDispatcherProvider e
             HttpServletRequestFilter servletRequest = 
                 new HttpServletRequestFilter(mc.getHttpServletRequest(), path, 
                                              theServletPath, saveParametersAsAttributes);
+            String attributeName = getBeanName(o);
             if (REQUEST_SCOPE.equals(scope)) {
-                servletRequest.setAttribute(getBeanName(o), o);
+                servletRequest.setAttribute(attributeName, o);
             } else if (SESSION_SCOPE.equals(scope)) {
-                servletRequest.getSession(true).setAttribute(getBeanName(o), o);
+                servletRequest.getSession(true).setAttribute(attributeName, o);
             } 
             setRequestParameters(servletRequest);
+            logRedirection(path, attributeName, o);
             rd.forward(servletRequest, mc.getHttpServletResponse());
         } catch (Throwable ex) {
             mc.put(AbstractHTTPDestination.REQUEST_REDIRECTED, Boolean.FALSE);
@@ -128,6 +132,16 @@ public class RequestDispatcherProvider e
         }
     }
 
+    private void logRedirection(String path, String attributeName, Object o) {
+        Level level = logRedirects ? Level.INFO : Level.FINE;  
+        if (LOG.isLoggable(level)) {
+            String message = 
+                new org.apache.cxf.common.i18n.Message("RESPONSE_REDIRECTED_TO", 
+                    BUNDLE, o.getClass().getName(), attributeName, path).toString();
+            LOG.log(level, message);
+        }
+    }
+    
     private String getResourcePath(String clsName) {
         String clsResourcePath = classResources.get(clsName);
         if (clsResourcePath != null) {
@@ -199,6 +213,10 @@ public class RequestDispatcherProvider e
     public void setBeanName(String beanName) {
         this.beanName = beanName;
     }
+    
+    public void setLogRedirects(String value) {
+        this.logRedirects = Boolean.valueOf(value);
+    }
 
     protected String getBeanName(Object bean) {
         if (beanName != null) {

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java?rev=1198587&r1=1198586&r2=1198587&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java
Sun Nov  6 23:07:55 2011
@@ -22,24 +22,31 @@ package org.apache.cxf.jaxrs.utils;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.Arrays;
 import java.util.Enumeration;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.logging.Logger;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MultivaluedMap;
 
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
 import org.apache.cxf.jaxrs.ext.multipart.Attachment;
 import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
+import org.apache.cxf.phase.PhaseInterceptorChain;
 
 public final class FormUtils {
-
     public static final String FORM_PARAM_MAP = "org.apache.cxf.form_data";
+    
+    private static final Logger LOG = LogUtils.getL7dLogger(FormUtils.class);
     private static final String MULTIPART_FORM_DATA_TYPE = "form-data";  
         
     private FormUtils() {
@@ -97,6 +104,36 @@ public final class FormUtils {
                 String[] values = request.getParameterValues(paramName);
                 params.put(HttpUtils.urlDecode(paramName), Arrays.asList(values));
             }
+            String chain = PhaseInterceptorChain.getCurrentMessage().getInterceptorChain().toString();
+            if (chain.contains(LoggingInInterceptor.class.getSimpleName())) {
+                ByteArrayOutputStream bos = new ByteArrayOutputStream();
+                try {
+                    writeMapToOutputStream(params, bos, enc, false);
+                    LOG.info(bos.toString(enc));
+                } catch (IOException ex) {
+                    // ignore
+                }
+            }
+        }
+    }
+    
+    public static void writeMapToOutputStream(MultivaluedMap<String, String> map, 
+                                              OutputStream os,
+                                              String enc,
+                                              boolean encoded) throws IOException {
+        for (Iterator<Map.Entry<String, List<String>>> it = map.entrySet().iterator();
it.hasNext();) {
+            Map.Entry<String, List<String>> entry = it.next();
+            for (Iterator<String> entryIterator = entry.getValue().iterator(); entryIterator.hasNext();)
{
+                String value = entryIterator.next();
+                os.write(entry.getKey().getBytes(enc));
+                os.write('=');
+                String data = encoded ? value : HttpUtils.urlEncode(value);
+                os.write(data.getBytes(enc));
+                if (entryIterator.hasNext() || it.hasNext()) {
+                    os.write('&');
+                }
+            }
+
         }
     }
     



Mime
View raw message