struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r1397705 - in /struts/struts2/trunk: core/src/main/java/org/apache/struts2/dispatcher/ plugins/rest/src/main/java/org/apache/struts2/rest/ plugins/rest/src/test/java/org/apache/struts2/rest/ xwork-core/src/main/java/com/opensymphony/xwork2/
Date Fri, 12 Oct 2012 19:56:31 GMT
Author: lukaszlenart
Date: Fri Oct 12 19:56:30 2012
New Revision: 1397705

URL: http://svn.apache.org/viewvc?rev=1397705&view=rev
Log:
WW-2537 adds usage of generics and some minor code improvements

Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/HttpHeaderResult.java
    struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionInvocation.java
    struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionProxyFactory.java
    struts/struts2/trunk/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/HttpHeaderResult.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/HttpHeaderResult.java?rev=1397705&r1=1397704&r2=1397705&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/HttpHeaderResult.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/HttpHeaderResult.java
Fri Oct 12 19:56:30 2012
@@ -21,19 +21,16 @@
 
 package org.apache.struts2.dispatcher;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.struts2.ServletActionContext;
-
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.Result;
 import com.opensymphony.xwork2.util.TextParseUtil;
 import com.opensymphony.xwork2.util.ValueStack;
+import org.apache.struts2.ServletActionContext;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
+import java.util.Map;
 
 
 /**
@@ -130,7 +127,7 @@ public class HttpHeaderResult implements
      *
      * @return a Map of all HTTP headers.
      */
-    public Map getHeaders() {
+    public Map<String, String> getHeaders() {
         return headers;
     }
 
@@ -154,10 +151,14 @@ public class HttpHeaderResult implements
         this.status = status;
     }
 
+    public int getStatus() {
+        return status;
+    }
+
     /**
      * Adds an HTTP header to the response
-     * @param name
-     * @param value
+     * @param name header name
+     * @param value header value
      */
     public void addHeader(String name, String value) {
         headers.put(name, value);
@@ -186,9 +187,8 @@ public class HttpHeaderResult implements
         }
 
         if (headers != null) {
-            for (Iterator iterator = headers.entrySet().iterator();
-                 iterator.hasNext();) {
-                Map.Entry entry = (Map.Entry) iterator.next();
+            for (Map.Entry<String, String> stringStringEntry : headers.entrySet())
{
+                Map.Entry entry = (Map.Entry) stringStringEntry;
                 String value = (String) entry.getValue();
                 String finalValue = parse ? TextParseUtil.translateVariables(value, stack)
: value;
                 response.addHeader((String) entry.getKey(), finalValue);

Modified: struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionInvocation.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionInvocation.java?rev=1397705&r1=1397704&r2=1397705&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionInvocation.java
(original)
+++ struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionInvocation.java
Fri Oct 12 19:56:30 2012
@@ -41,7 +41,6 @@ import org.apache.struts2.rest.handler.H
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.lang.reflect.Field;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -67,13 +66,13 @@ public class RestActionInvocation extend
     protected boolean isFirstInterceptor = true;
     protected boolean hasErrors;
 
-    protected RestActionInvocation(Map extraContext, boolean pushAction) {
+    protected RestActionInvocation(final Map<String, Object> extraContext, boolean
pushAction) {
         super(extraContext, pushAction);
     }
 
     @Inject("struts.rest.logger")
     public void setLogger(String value) {
-        logger = new Boolean(value);
+        logger = Boolean.valueOf(value);
     }
 
     @Inject("struts.rest.defaultErrorResultName")
@@ -99,7 +98,7 @@ public class RestActionInvocation extend
 
     /**
      * Save the result to be used later.
-     * @param actionConfig
+     * @param actionConfig current ActionConfig
      * @param methodResult the result of the action.
      * @return the result code to process.
      *
@@ -250,26 +249,13 @@ public class RestActionInvocation extend
     }
 
     /**
-     * Get the status code from HttpHeaderResult
-     * and it is saved in the HttpHeaders object.
-     * @throws Exception
+     * Get the status code from HttpHeaderResult and it is saved in the HttpHeaders object.
      */
-    private void updateStatusFromResult() {
-
-        if (this.result instanceof HttpHeaderResult) {
-            try {
-                Field field = result.getClass().getDeclaredField("status");
-                if (field != null) {
-                    field.setAccessible(true);
-                    int status = (Integer)field.get(result);
-                    if (status != -1) {
-                        this.httpHeaders.setStatus(status);
-                    }
-                }
-            } catch (Exception e) {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug(e.getMessage(), e);
-                }
+    protected void updateStatusFromResult() {
+        if (result instanceof HttpHeaderResult) {
+            int status = ((HttpHeaderResult) result).getStatus();
+            if (status != -1) {
+                httpHeaders.setStatus(status);
             }
         }
     }
@@ -284,7 +270,7 @@ public class RestActionInvocation extend
     private void findResult() throws Exception {
 
         boolean isHttpHeaderResult = false;
-        if (result != null && this.result instanceof HttpHeaderResult) {
+        if (result != null && result instanceof HttpHeaderResult) {
             result = null;
             isHttpHeaderResult = true;
         }
@@ -297,15 +283,14 @@ public class RestActionInvocation extend
                     invocationContext, proxy.getActionName(), proxy.getConfig(), resultCode);
         }
 
-        if (this.result == null && this.hasErrors && defaultErrorResultName
!= null) {
+        if (result == null && hasErrors && defaultErrorResultName != null)
{
 
             // Get default error result
-            ResultConfig resultConfig = this.proxy.getConfig().getResults()
-                .get(defaultErrorResultName);
+            ResultConfig resultConfig = this.proxy.getConfig().getResults().get(defaultErrorResultName);
             if (resultConfig != null) {
                 this.result = objectFactory.buildResult(resultConfig, invocationContext.getContextMap());
                 if (LOG.isDebugEnabled()) {
-                LOG.debug("Found default error result.");
+                    LOG.debug("Found default error result.");
                 }
             }
         }
@@ -397,9 +382,7 @@ public class RestActionInvocation extend
              message += "] took " + total + " ms (execution: " + executionTime
                 + " ms, result: " + processResult + " ms)";
 
-             if (LOG.isInfoEnabled()) {
              LOG.info(message);
-             }
          }
     }
 

Modified: struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionProxyFactory.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionProxyFactory.java?rev=1397705&r1=1397704&r2=1397705&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionProxyFactory.java
(original)
+++ struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionProxyFactory.java
Fri Oct 12 19:56:30 2012
@@ -44,7 +44,9 @@ public class RestActionProxyFactory exte
     }
 
     @Override
-    public ActionProxy createActionProxy(String namespace, String actionName, String methodName,
Map extraContext, boolean executeResult, boolean cleanupContext) {
+    public ActionProxy createActionProxy(String namespace, String actionName, String methodName,
Map<String, Object> extraContext,
+                                         boolean executeResult, boolean cleanupContext)
+    {
         if (this.namespace == null || namespace.startsWith(this.namespace)) {
             ActionInvocation inv = new RestActionInvocation(extraContext, true);
             container.inject(inv);

Modified: struts/struts2/trunk/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java?rev=1397705&r1=1397704&r2=1397705&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java
(original)
+++ struts/struts2/trunk/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java
Fri Oct 12 19:56:30 2012
@@ -93,7 +93,7 @@ public class RestActionInvocationTest ex
 		String actionMessage = "Error!";
 		RestActionSupport action = (RestActionSupport)restActionInvocation.getAction();
 		action.addActionError(actionMessage);
-		Map errors = new HashMap();
+		Map<String, Object> errors = new HashMap<String, Object>();
 		List<String> list = new ArrayList<String>();
 		list.add(actionMessage);
     	errors.put("actionErrors", list);
@@ -236,7 +236,7 @@ public class RestActionInvocationTest ex
 
     class RestActionInvocationTester extends RestActionInvocation {
     	RestActionInvocationTester() {
-            super(new HashMap<String,String>(), true);
+            super(new HashMap<String, Object>(), true);
             List<InterceptorMapping> interceptorMappings = new ArrayList<InterceptorMapping>();
             MockInterceptor mockInterceptor = new MockInterceptor();
             mockInterceptor.setFoo("interceptor");

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java?rev=1397705&r1=1397704&r2=1397705&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
Fri Oct 12 19:56:30 2012
@@ -15,7 +15,6 @@
  */
 package com.opensymphony.xwork2;
 
-import com.opensymphony.xwork2.config.Configuration;
 import com.opensymphony.xwork2.config.ConfigurationException;
 import com.opensymphony.xwork2.config.entities.ActionConfig;
 import com.opensymphony.xwork2.config.entities.InterceptorMapping;
@@ -75,7 +74,6 @@ public class DefaultActionInvocation imp
     protected ActionEventListener actionEventListener;
     protected ValueStackFactory valueStackFactory;
     protected Container container;
-    private Configuration configuration;
     protected UnknownHandlerManager unknownHandlerManager;
 
     public DefaultActionInvocation(final Map<String, Object> extraContext, final boolean
pushAction) {
@@ -94,11 +92,6 @@ public class DefaultActionInvocation imp
     }
 
     @Inject
-    public void setConfiguration(Configuration configuration) {
-        this.configuration = configuration;
-    }
-
-    @Inject
     public void setObjectFactory(ObjectFactory fac) {
         this.objectFactory = fac;
     }
@@ -182,7 +175,7 @@ public class DefaultActionInvocation imp
      * Result is executed. The ActionInvocation implementation must guarantee that listeners
will be called in the order
      * in which they are registered. Listener registration and execution does not need to
be thread-safe.
      *
-     * @param listener
+     * @param listener to register
      */
     public void addPreResultListener(PreResultListener listener) {
         if (preResultListeners == null) {
@@ -242,7 +235,7 @@ public class DefaultActionInvocation imp
             }
 
             if (interceptors.hasNext()) {
-                final InterceptorMapping interceptor = (InterceptorMapping) interceptors.next();
+                final InterceptorMapping interceptor = interceptors.next();
                 String interceptorMsg = "interceptor: " + interceptor.getName();
                 UtilTimerStack.push(interceptorMsg);
                 try {
@@ -303,7 +296,7 @@ public class DefaultActionInvocation imp
         } catch (IllegalAccessException e) {
             throw new XWorkException("Illegal access to constructor, is it public?", e, proxy.getConfig());
         } catch (Exception e) {
-            String gripe = "";
+            String gripe;
 
             if (proxy == null) {
                 gripe = "Whoa!  No ActionProxy instance found in current ActionInvocation.
 This is bad ... very bad";
@@ -478,7 +471,7 @@ public class DefaultActionInvocation imp
 
     /**
      * Save the result to be used later.
-     * @param actionConfig
+     * @param actionConfig current ActionConfig
      * @param methodResult the result of the action.
      * @return the result code to process.
      */



Mime
View raw message