[struts] 01/01: WW-5080 Defines a new result type plain to use directly with Java code

2020-06-28 Thread lukaszlenart
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-5080-plain-result
in repository https://gitbox.apache.org/repos/asf/struts.git

commit bd9455d224bf02205c14fbafc85d868e3f2f053b
Author: Lukasz Lenart 
AuthorDate: Mon Jun 29 08:16:48 2020 +0200

WW-5080 Defines a new result type plain to use directly with Java code
---
 .../org/apache/struts2/result/PlainResult.java |  71 ++
 .../apache/struts2/result/plain/BodyWriter.java|  41 
 .../struts2/result/plain/DateHttpHeader.java   |  38 
 .../apache/struts2/result/plain/HttpCookies.java   |  39 
 .../apache/struts2/result/plain/HttpHeader.java|  27 ++
 .../apache/struts2/result/plain/HttpHeaders.java   |  58 
 .../apache/struts2/result/plain/IntHttpHeader.java |  39 
 .../struts2/result/plain/ResponseBuilder.java  |  89 +
 .../struts2/result/plain/StringHttpHeader.java |  39 
 .../org/apache/struts2/result/PlainResultTest.java | 105 +
 10 files changed, 546 insertions(+)

diff --git a/core/src/main/java/org/apache/struts2/result/PlainResult.java 
b/core/src/main/java/org/apache/struts2/result/PlainResult.java
new file mode 100644
index 000..e5a8c41
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/result/PlainResult.java
@@ -0,0 +1,71 @@
+/*
+ * 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.result;
+
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.Result;
+import org.apache.struts2.StrutsException;
+import org.apache.struts2.result.plain.BodyWriter;
+import org.apache.struts2.result.plain.HttpCookies;
+import org.apache.struts2.result.plain.HttpHeader;
+import org.apache.struts2.result.plain.HttpHeaders;
+import org.apache.struts2.result.plain.ResponseBuilder;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+
+public abstract class PlainResult implements Result {
+
+@Override
+public void execute(ActionInvocation invocation) throws Exception {
+BodyWriter body = new BodyWriter();
+HttpHeaders headers = new HttpHeaders();
+HttpCookies cookies = new HttpCookies();
+
+ResponseBuilder builder = new ResponseBuilder(body, headers, cookies);
+write(builder);
+
+HttpServletResponse response = 
invocation.getInvocationContext().getServletResponse();
+
+if (response.isCommitted()) {
+throw new StrutsException("Http response already committed, cannot 
modify it!");
+}
+
+for (HttpHeader header : headers.getStringHeaders()) {
+response.addHeader(header.getName(), header.getValue());
+}
+for (HttpHeader header : headers.getDateHeaders()) {
+response.addDateHeader(header.getName(), header.getValue());
+}
+for (HttpHeader header : headers.getIntHeaders()) {
+response.addIntHeader(header.getName(), header.getValue());
+}
+
+for (Cookie cookie : cookies.getCookies()) {
+response.addCookie(cookie);
+}
+
+response.getWriter().write(body.getBody());
+response.flushBuffer();
+}
+
+protected abstract void write(ResponseBuilder response);
+
+}
+
diff --git a/core/src/main/java/org/apache/struts2/result/plain/BodyWriter.java 
b/core/src/main/java/org/apache/struts2/result/plain/BodyWriter.java
new file mode 100644
index 000..ec58c35
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/result/plain/BodyWriter.java
@@ -0,0 +1,41 @@
+/*
+ * 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 L

[struts] branch WW-5080-plain-result created (now bd9455d)

2020-06-28 Thread lukaszlenart
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a change to branch WW-5080-plain-result
in repository https://gitbox.apache.org/repos/asf/struts.git.


  at bd9455d  WW-5080 Defines a new result type plain to use directly with 
Java code

This branch includes the following new commits:

 new bd9455d  WW-5080 Defines a new result type plain to use directly with 
Java code

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




[struts] 01/01: WW-5080 Defines a new result type plain to use directly with Java code

2020-06-28 Thread lukaszlenart
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-5080-plain-result
in repository https://gitbox.apache.org/repos/asf/struts.git

commit ac0641234d3a18313bac6e160adc44c6d8c9c487
Author: Lukasz Lenart 
AuthorDate: Mon Jun 29 08:16:48 2020 +0200

WW-5080 Defines a new result type plain to use directly with Java code
---
 .../org/apache/struts2/result/PlainResult.java |  64 
 .../apache/struts2/result/plain/BodyWriter.java|  41 
 .../struts2/result/plain/DateHttpHeader.java   |  38 +++
 .../apache/struts2/result/plain/HttpCookies.java   |  39 
 .../apache/struts2/result/plain/HttpHeader.java|  27 +
 .../apache/struts2/result/plain/HttpHeaders.java   |  58 +++
 .../apache/struts2/result/plain/IntHttpHeader.java |  39 
 .../struts2/result/plain/ResponseBuilder.java  | 111 +
 .../struts2/result/plain/StringHttpHeader.java |  39 
 .../org/apache/struts2/result/PlainResultTest.java | 105 +++
 10 files changed, 561 insertions(+)

diff --git a/core/src/main/java/org/apache/struts2/result/PlainResult.java 
b/core/src/main/java/org/apache/struts2/result/PlainResult.java
new file mode 100644
index 000..99e978a
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/result/PlainResult.java
@@ -0,0 +1,64 @@
+/*
+ * 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.result;
+
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.Result;
+import org.apache.struts2.StrutsException;
+import org.apache.struts2.result.plain.HttpHeader;
+import org.apache.struts2.result.plain.ResponseBuilder;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+
+public abstract class PlainResult implements Result {
+
+@Override
+public void execute(ActionInvocation invocation) throws Exception {
+ResponseBuilder builder = new ResponseBuilder();
+write(builder);
+
+HttpServletResponse response = 
invocation.getInvocationContext().getServletResponse();
+
+if (response.isCommitted()) {
+throw new StrutsException("Http response already committed, cannot 
modify it!");
+}
+
+for (HttpHeader header : builder.getStringHeaders()) {
+response.addHeader(header.getName(), header.getValue());
+}
+for (HttpHeader header : builder.getDateHeaders()) {
+response.addDateHeader(header.getName(), header.getValue());
+}
+for (HttpHeader header : builder.getIntHeaders()) {
+response.addIntHeader(header.getName(), header.getValue());
+}
+
+for (Cookie cookie : builder.getCookies()) {
+response.addCookie(cookie);
+}
+
+response.getWriter().write(builder.getBody());
+response.flushBuffer();
+}
+
+protected abstract void write(ResponseBuilder response);
+
+}
+
diff --git a/core/src/main/java/org/apache/struts2/result/plain/BodyWriter.java 
b/core/src/main/java/org/apache/struts2/result/plain/BodyWriter.java
new file mode 100644
index 000..ff22769
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/result/plain/BodyWriter.java
@@ -0,0 +1,41 @@
+/*
+ * 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.result.plain;
+
+import java.io.StringWriter;
+
+class BodyWri

[struts] branch WW-5080-plain-result updated (bd9455d -> ac06412)

2020-06-28 Thread lukaszlenart
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a change to branch WW-5080-plain-result
in repository https://gitbox.apache.org/repos/asf/struts.git.


 discard bd9455d  WW-5080 Defines a new result type plain to use directly with 
Java code
 new ac06412  WW-5080 Defines a new result type plain to use directly with 
Java code

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (bd9455d)
\
 N -- N -- N   refs/heads/WW-5080-plain-result (ac06412)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/struts2/result/PlainResult.java | 19 +-
 .../apache/struts2/result/plain/BodyWriter.java|  2 +-
 .../apache/struts2/result/plain/HttpCookies.java   |  2 +-
 .../apache/struts2/result/plain/HttpHeaders.java   |  2 +-
 .../struts2/result/plain/ResponseBuilder.java  | 30 +++---
 5 files changed, 35 insertions(+), 20 deletions(-)



[struts] 01/01: WW-5080 Defines a new result type plain to use directly with Java code

2020-06-28 Thread lukaszlenart
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-5080-plain-result
in repository https://gitbox.apache.org/repos/asf/struts.git

commit f15d85b496d7723cd8dfbe984ea48ad1363806e9
Author: Lukasz Lenart 
AuthorDate: Mon Jun 29 08:16:48 2020 +0200

WW-5080 Defines a new result type plain to use directly with Java code
---
 .../org/apache/struts2/result/PlainResult.java |  64 +++
 .../apache/struts2/result/plain/BodyWriter.java|  41 +++
 .../struts2/result/plain/DateHttpHeader.java   |  38 +++
 .../apache/struts2/result/plain/HttpCookies.java   |  39 +++
 .../apache/struts2/result/plain/HttpHeader.java|  27 +
 .../apache/struts2/result/plain/HttpHeaders.java   |  58 ++
 .../apache/struts2/result/plain/IntHttpHeader.java |  39 +++
 .../struts2/result/plain/ResponseBuilder.java  | 111 +++
 .../struts2/result/plain/StringHttpHeader.java |  39 +++
 .../org/apache/struts2/result/PlainResultTest.java | 123 +
 10 files changed, 579 insertions(+)

diff --git a/core/src/main/java/org/apache/struts2/result/PlainResult.java 
b/core/src/main/java/org/apache/struts2/result/PlainResult.java
new file mode 100644
index 000..99e978a
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/result/PlainResult.java
@@ -0,0 +1,64 @@
+/*
+ * 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.result;
+
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.Result;
+import org.apache.struts2.StrutsException;
+import org.apache.struts2.result.plain.HttpHeader;
+import org.apache.struts2.result.plain.ResponseBuilder;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+
+public abstract class PlainResult implements Result {
+
+@Override
+public void execute(ActionInvocation invocation) throws Exception {
+ResponseBuilder builder = new ResponseBuilder();
+write(builder);
+
+HttpServletResponse response = 
invocation.getInvocationContext().getServletResponse();
+
+if (response.isCommitted()) {
+throw new StrutsException("Http response already committed, cannot 
modify it!");
+}
+
+for (HttpHeader header : builder.getStringHeaders()) {
+response.addHeader(header.getName(), header.getValue());
+}
+for (HttpHeader header : builder.getDateHeaders()) {
+response.addDateHeader(header.getName(), header.getValue());
+}
+for (HttpHeader header : builder.getIntHeaders()) {
+response.addIntHeader(header.getName(), header.getValue());
+}
+
+for (Cookie cookie : builder.getCookies()) {
+response.addCookie(cookie);
+}
+
+response.getWriter().write(builder.getBody());
+response.flushBuffer();
+}
+
+protected abstract void write(ResponseBuilder response);
+
+}
+
diff --git a/core/src/main/java/org/apache/struts2/result/plain/BodyWriter.java 
b/core/src/main/java/org/apache/struts2/result/plain/BodyWriter.java
new file mode 100644
index 000..ff22769
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/result/plain/BodyWriter.java
@@ -0,0 +1,41 @@
+/*
+ * 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.result.plain;
+
+import java.io.StringWriter;
+
+class BodyWriter {

[struts] branch WW-5080-plain-result updated (ac06412 -> f15d85b)

2020-06-28 Thread lukaszlenart
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a change to branch WW-5080-plain-result
in repository https://gitbox.apache.org/repos/asf/struts.git.


 discard ac06412  WW-5080 Defines a new result type plain to use directly with 
Java code
 new f15d85b  WW-5080 Defines a new result type plain to use directly with 
Java code

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (ac06412)
\
 N -- N -- N   refs/heads/WW-5080-plain-result (f15d85b)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/struts2/result/PlainResultTest.java | 18 ++
 1 file changed, 18 insertions(+)