struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [2/5] struts git commit: Adds an abstract layer to allow easily handle API change
Date Thu, 03 Aug 2017 14:05:01 GMT
Adds an abstract layer to allow easily handle API change


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

Branch: refs/heads/master
Commit: 3bd072ca053aed787f3a16865266d8832fcd18b0
Parents: 2f690cf
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Wed Aug 2 14:58:15 2017 +0200
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Wed Aug 2 14:58:15 2017 +0200

----------------------------------------------------------------------
 .../handler/AbstractContentTypeHandler.java     | 44 ++++++++++++++++++++
 .../rest/handler/FormUrlEncodedHandler.java     |  8 ++--
 .../struts2/rest/handler/HtmlHandler.java       |  8 ++--
 .../struts2/rest/handler/JacksonLibHandler.java |  7 ++--
 .../struts2/rest/handler/JsonLibHandler.java    |  7 ++--
 .../rest/handler/MultipartFormDataHandler.java  |  8 ++--
 .../struts2/rest/handler/XStreamHandler.java    |  7 ++--
 7 files changed, 71 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/3bd072ca/plugins/rest/src/main/java/org/apache/struts2/rest/handler/AbstractContentTypeHandler.java
----------------------------------------------------------------------
diff --git a/plugins/rest/src/main/java/org/apache/struts2/rest/handler/AbstractContentTypeHandler.java
b/plugins/rest/src/main/java/org/apache/struts2/rest/handler/AbstractContentTypeHandler.java
new file mode 100644
index 0000000..ae9b3b8
--- /dev/null
+++ b/plugins/rest/src/main/java/org/apache/struts2/rest/handler/AbstractContentTypeHandler.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.struts2.rest.handler;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+
+abstract public class AbstractContentTypeHandler implements ContentTypeHandler {
+
+    private static final Logger LOG = LogManager.getLogger(AbstractContentTypeHandler.class);
+
+    @Override
+    public void toObject(Reader in, Object target) throws IOException {
+        LOG.warn("This method is deprecated!");
+    }
+
+    @Override
+    public String fromObject(Object obj, String resultCode, Writer stream) throws IOException
{
+        LOG.warn("This method is deprecated!");
+        return null;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/struts/blob/3bd072ca/plugins/rest/src/main/java/org/apache/struts2/rest/handler/FormUrlEncodedHandler.java
----------------------------------------------------------------------
diff --git a/plugins/rest/src/main/java/org/apache/struts2/rest/handler/FormUrlEncodedHandler.java
b/plugins/rest/src/main/java/org/apache/struts2/rest/handler/FormUrlEncodedHandler.java
index 90a08b8..835fb89 100644
--- a/plugins/rest/src/main/java/org/apache/struts2/rest/handler/FormUrlEncodedHandler.java
+++ b/plugins/rest/src/main/java/org/apache/struts2/rest/handler/FormUrlEncodedHandler.java
@@ -20,6 +20,8 @@
  */
 package org.apache.struts2.rest.handler;
 
+import com.opensymphony.xwork2.ActionInvocation;
+
 import java.io.Writer;
 import java.io.IOException;
 import java.io.Reader;
@@ -34,11 +36,11 @@ import java.io.Reader;
  * @see <a href="http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4">http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4</a>
  *
  */
-public class FormUrlEncodedHandler implements ContentTypeHandler {
+public class FormUrlEncodedHandler extends  AbstractContentTypeHandler {
 
     public static final String CONTENT_TYPE = "application/x-www-form-urlencoded";
 
-    public String fromObject(Object obj, String resultCode, Writer out) throws IOException
{
+    public String fromObject(ActionInvocation invocation, Object obj, String resultCode,
Writer out) throws IOException {
         throw new IOException("Conversion from Object to '"+getContentType()+"' is not supported");
     }
 
@@ -48,7 +50,7 @@ public class FormUrlEncodedHandler implements ContentTypeHandler {
      * @param in The input stream, usually the body of the request
      * @param target The target, usually the action class
      */
-    public void toObject(Reader in, Object target) {
+    public void toObject(ActionInvocation invocation, Reader in, Object target) {
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/struts/blob/3bd072ca/plugins/rest/src/main/java/org/apache/struts2/rest/handler/HtmlHandler.java
----------------------------------------------------------------------
diff --git a/plugins/rest/src/main/java/org/apache/struts2/rest/handler/HtmlHandler.java b/plugins/rest/src/main/java/org/apache/struts2/rest/handler/HtmlHandler.java
index 32161fc..94709e1 100644
--- a/plugins/rest/src/main/java/org/apache/struts2/rest/handler/HtmlHandler.java
+++ b/plugins/rest/src/main/java/org/apache/struts2/rest/handler/HtmlHandler.java
@@ -21,6 +21,8 @@
 
 package org.apache.struts2.rest.handler;
 
+import com.opensymphony.xwork2.ActionInvocation;
+
 import java.io.IOException;
 import java.io.Reader;
 import java.io.Writer;
@@ -28,13 +30,13 @@ import java.io.Writer;
 /**
  * Handles HTML content, usually just a simple passthrough to the framework
  */
-public class HtmlHandler implements ContentTypeHandler {
+public class HtmlHandler extends AbstractContentTypeHandler {
 
-    public String fromObject(Object obj, String resultCode, Writer out) throws IOException
{
+    public String fromObject(ActionInvocation invocation, Object obj, String resultCode,
Writer out) throws IOException {
         return resultCode;
     }
 
-    public void toObject(Reader in, Object target) {
+    public void toObject(ActionInvocation invocation, Reader in, Object target) {
     }
 
     public String getExtension() {

http://git-wip-us.apache.org/repos/asf/struts/blob/3bd072ca/plugins/rest/src/main/java/org/apache/struts2/rest/handler/JacksonLibHandler.java
----------------------------------------------------------------------
diff --git a/plugins/rest/src/main/java/org/apache/struts2/rest/handler/JacksonLibHandler.java
b/plugins/rest/src/main/java/org/apache/struts2/rest/handler/JacksonLibHandler.java
index 0621cd7..dd9dee3 100644
--- a/plugins/rest/src/main/java/org/apache/struts2/rest/handler/JacksonLibHandler.java
+++ b/plugins/rest/src/main/java/org/apache/struts2/rest/handler/JacksonLibHandler.java
@@ -24,6 +24,7 @@ package org.apache.struts2.rest.handler;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.ObjectReader;
 import com.fasterxml.jackson.databind.SerializationFeature;
+import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.inject.Inject;
 import org.apache.struts2.StrutsConstants;
 
@@ -34,19 +35,19 @@ import java.io.Writer;
 /**
  * Handles JSON content using jackson-lib
  */
-public class JacksonLibHandler implements ContentTypeHandler {
+public class JacksonLibHandler extends AbstractContentTypeHandler {
 
     private static final String DEFAULT_CONTENT_TYPE = "application/json";
     private String defaultEncoding = "ISO-8859-1";
     private ObjectMapper mapper = new ObjectMapper();
 
-    public void toObject(Reader in, Object target) throws IOException {
+    public void toObject(ActionInvocation invocation, Reader in, Object target) throws IOException
{
         mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
         ObjectReader or = mapper.readerForUpdating(target);
         or.readValue(in);
     }
 
-    public String fromObject(Object obj, String resultCode, Writer stream) throws IOException
{
+    public String fromObject(ActionInvocation invocation, Object obj, String resultCode,
Writer stream) throws IOException {
         mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
         mapper.writeValue(stream, obj);
         return null;

http://git-wip-us.apache.org/repos/asf/struts/blob/3bd072ca/plugins/rest/src/main/java/org/apache/struts2/rest/handler/JsonLibHandler.java
----------------------------------------------------------------------
diff --git a/plugins/rest/src/main/java/org/apache/struts2/rest/handler/JsonLibHandler.java
b/plugins/rest/src/main/java/org/apache/struts2/rest/handler/JsonLibHandler.java
index 5bc0749..4bd96c7 100644
--- a/plugins/rest/src/main/java/org/apache/struts2/rest/handler/JsonLibHandler.java
+++ b/plugins/rest/src/main/java/org/apache/struts2/rest/handler/JsonLibHandler.java
@@ -26,6 +26,7 @@ import java.io.Reader;
 import java.io.Writer;
 import java.util.Collection;
 
+import com.opensymphony.xwork2.ActionInvocation;
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
 import net.sf.json.JsonConfig;
@@ -37,12 +38,12 @@ import com.opensymphony.xwork2.inject.Inject;
 /**
  * Handles JSON content using json-lib
  */
-public class JsonLibHandler implements ContentTypeHandler {
+public class JsonLibHandler extends AbstractContentTypeHandler {
 
     private static final String DEFAULT_CONTENT_TYPE = "application/json";
     private String defaultEncoding = "ISO-8859-1";
 
-    public void toObject(Reader in, Object target) throws IOException {
+    public void toObject(ActionInvocation invocation, Reader in, Object target) throws IOException
{
         StringBuilder sb = new StringBuilder();
         char[] buffer = new char[1024];
         int len = 0;
@@ -63,7 +64,7 @@ public class JsonLibHandler implements ContentTypeHandler {
         }
     }
 
-    public String fromObject(Object obj, String resultCode, Writer stream) throws IOException
{
+    public String fromObject(ActionInvocation invocation, Object obj, String resultCode,
Writer stream) throws IOException {
         if (obj != null) {
             if (isArray(obj)) {
                 JSONArray jsonArray = JSONArray.fromObject(obj);

http://git-wip-us.apache.org/repos/asf/struts/blob/3bd072ca/plugins/rest/src/main/java/org/apache/struts2/rest/handler/MultipartFormDataHandler.java
----------------------------------------------------------------------
diff --git a/plugins/rest/src/main/java/org/apache/struts2/rest/handler/MultipartFormDataHandler.java
b/plugins/rest/src/main/java/org/apache/struts2/rest/handler/MultipartFormDataHandler.java
index affef17..cceaedd 100644
--- a/plugins/rest/src/main/java/org/apache/struts2/rest/handler/MultipartFormDataHandler.java
+++ b/plugins/rest/src/main/java/org/apache/struts2/rest/handler/MultipartFormDataHandler.java
@@ -20,6 +20,8 @@
  */
 package org.apache.struts2.rest.handler;
 
+import com.opensymphony.xwork2.ActionInvocation;
+
 import java.io.Writer;
 import java.io.IOException;
 import java.io.Reader;
@@ -34,11 +36,11 @@ import java.io.Reader;
  *
  * @see <a href="http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4">http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4</a>
  */
-public class MultipartFormDataHandler implements ContentTypeHandler {
+public class MultipartFormDataHandler extends AbstractContentTypeHandler {
 
     public static final String CONTENT_TYPE = "multipart/form-data";
 
-    public String fromObject(Object obj, String resultCode, Writer out) throws IOException
{
+    public String fromObject(ActionInvocation invocation, Object obj, String resultCode,
Writer out) throws IOException {
         throw new IOException("Conversion from Object to '"+getContentType()+"' is not supported");
     }
 
@@ -48,7 +50,7 @@ public class MultipartFormDataHandler implements ContentTypeHandler {
      * @param in The input stream, usually the body of the request
      * @param target The target, usually the action class
      */
-    public void toObject(Reader in, Object target) {
+    public void toObject(ActionInvocation invocation, Reader in, Object target) {
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/struts/blob/3bd072ca/plugins/rest/src/main/java/org/apache/struts2/rest/handler/XStreamHandler.java
----------------------------------------------------------------------
diff --git a/plugins/rest/src/main/java/org/apache/struts2/rest/handler/XStreamHandler.java
b/plugins/rest/src/main/java/org/apache/struts2/rest/handler/XStreamHandler.java
index 94be7af..5650702 100644
--- a/plugins/rest/src/main/java/org/apache/struts2/rest/handler/XStreamHandler.java
+++ b/plugins/rest/src/main/java/org/apache/struts2/rest/handler/XStreamHandler.java
@@ -21,6 +21,7 @@
 
 package org.apache.struts2.rest.handler;
 
+import com.opensymphony.xwork2.ActionInvocation;
 import com.thoughtworks.xstream.XStream;
 
 import java.io.IOException;
@@ -30,9 +31,9 @@ import java.io.Writer;
 /**
  * Handles XML content
  */
-public class XStreamHandler implements ContentTypeHandler {
+public class XStreamHandler extends AbstractContentTypeHandler {
 
-    public String fromObject(Object obj, String resultCode, Writer out) throws IOException
{
+    public String fromObject(ActionInvocation invocation, Object obj, String resultCode,
Writer out) throws IOException {
         if (obj != null) {
             XStream xstream = createXStream();
             xstream.toXML(obj, out);
@@ -40,7 +41,7 @@ public class XStreamHandler implements ContentTypeHandler {
         return null;
     }
 
-    public void toObject(Reader in, Object target) {
+    public void toObject(ActionInvocation invocation, Reader in, Object target) {
         XStream xstream = createXStream();
         xstream.fromXML(in, target);
     }


Mime
View raw message