struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [6/6] struts-examples git commit: Adds simple JSON example
Date Thu, 14 Jul 2016 09:50:02 GMT
Adds simple JSON example


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

Branch: refs/heads/master
Commit: 62a6110bfd78a135d56c53bf1261d68cc3d8f646
Parents: 1dfc0aa
Author: Lukasz Lenart <lukasz.lenart@gmail.com>
Authored: Thu Jul 14 11:49:45 2016 +0200
Committer: Lukasz Lenart <lukasz.lenart@gmail.com>
Committed: Thu Jul 14 11:49:45 2016 +0200

----------------------------------------------------------------------
 json/pom.xml                                   | 108 ++++++++++++++++++++
 json/src/main/java/org/demo/ConsumeAction.java |  38 +++++++
 json/src/main/java/org/demo/MyBean.java        |  36 +++++++
 json/src/main/java/org/demo/ProduceAction.java |  43 ++++++++
 json/src/main/resources/log4j2.xml             |  16 +++
 json/src/main/resources/struts.xml             |  31 ++++++
 json/src/main/webapp/WEB-INF/result.jsp        |  21 ++++
 json/src/main/webapp/WEB-INF/web.xml           |  23 +++++
 json/src/main/webapp/index.html                |  10 ++
 9 files changed, 326 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts-examples/blob/62a6110b/json/pom.xml
----------------------------------------------------------------------
diff --git a/json/pom.xml b/json/pom.xml
new file mode 100644
index 0000000..fc758c7
--- /dev/null
+++ b/json/pom.xml
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <artifactId>struts-examples</artifactId>
+    <groupId>org.apache.struts</groupId>
+    <version>1.0.0</version>
+  </parent>
+
+  <groupId>org.demo</groupId>
+  <artifactId>json</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>war</packaging>
+  <name>json</name>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+
+    <dependency>
+      <groupId>org.apache.struts</groupId>
+      <artifactId>struts2-core</artifactId>
+      <version>${struts2.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.struts</groupId>
+      <artifactId>struts2-config-browser-plugin</artifactId>
+      <version>${struts2.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.struts</groupId>
+      <artifactId>struts2-json-plugin</artifactId>
+      <version>${struts2.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-api</artifactId>
+      <version>${log4j2.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-core</artifactId>
+      <version>${log4j2.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.5</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>javax.servlet-api</artifactId>
+      <version>3.1.0</version>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>jsp-api</artifactId>
+      <version>2.0</version>
+      <scope>provided</scope>
+    </dependency>
+
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.3</version>
+        <configuration>
+          <encoding>UTF-8</encoding>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.mortbay.jetty</groupId>
+        <artifactId>jetty-maven-plugin</artifactId>
+        <version>8.1.16.v20140903</version>
+        <configuration>
+          <stopKey>CTRL+C</stopKey>
+          <stopPort>8999</stopPort>
+          <systemProperties>
+            <systemProperty>
+              <name>xwork.loggerFactory</name>
+              <value>com.opensymphony.xwork2.util.logging.log4j2.Log4j2LoggerFactory</value>
+            </systemProperty>
+          </systemProperties>
+          <scanIntervalSeconds>10</scanIntervalSeconds>
+          <webAppSourceDirectory>${basedir}/src/main/webapp/</webAppSourceDirectory>
+          <webAppConfig>
+            <descriptor>${basedir}/src/main/webapp/WEB-INF/web.xml</descriptor>
+          </webAppConfig>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/62a6110b/json/src/main/java/org/demo/ConsumeAction.java
----------------------------------------------------------------------
diff --git a/json/src/main/java/org/demo/ConsumeAction.java b/json/src/main/java/org/demo/ConsumeAction.java
new file mode 100644
index 0000000..c142581
--- /dev/null
+++ b/json/src/main/java/org/demo/ConsumeAction.java
@@ -0,0 +1,38 @@
+/*
+ * $Id$
+ *
+ * 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.demo;
+
+import com.opensymphony.xwork2.ActionSupport;
+
+public class ConsumeAction extends ActionSupport {
+
+    private MyBean bean = new MyBean();
+
+    public String execute() throws Exception {
+        return SUCCESS;
+    }
+
+    public MyBean getBean() {
+        return bean;
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/62a6110b/json/src/main/java/org/demo/MyBean.java
----------------------------------------------------------------------
diff --git a/json/src/main/java/org/demo/MyBean.java b/json/src/main/java/org/demo/MyBean.java
new file mode 100644
index 0000000..17deffb
--- /dev/null
+++ b/json/src/main/java/org/demo/MyBean.java
@@ -0,0 +1,36 @@
+package org.demo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class MyBean {
+
+    private int counter;
+    private List<String> names;
+
+    public MyBean() {
+        counter = 0;
+        names = new ArrayList<String>();
+    }
+
+    public MyBean(int counter, List<String> names) {
+        this.counter = counter;
+        this.names = names;
+    }
+
+    public int getCounter() {
+        return counter;
+    }
+
+    public List<String> getNames() {
+        return names;
+    }
+
+    public void setCounter(int counter) {
+        this.counter = counter;
+    }
+
+    public void setNames(List<String> names) {
+        this.names = names;
+    }
+}

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/62a6110b/json/src/main/java/org/demo/ProduceAction.java
----------------------------------------------------------------------
diff --git a/json/src/main/java/org/demo/ProduceAction.java b/json/src/main/java/org/demo/ProduceAction.java
new file mode 100644
index 0000000..35c674b
--- /dev/null
+++ b/json/src/main/java/org/demo/ProduceAction.java
@@ -0,0 +1,43 @@
+/*
+ * $Id$
+ *
+ * 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.demo;
+
+import com.opensymphony.xwork2.ActionSupport;
+
+import java.util.Arrays;
+
+/**
+ * <code>Set welcome message.</code>
+ */
+public class ProduceAction extends ActionSupport {
+
+    private MyBean bean;
+
+    public String execute() throws Exception {
+        bean = new MyBean(2, Arrays.asList("Lukas", "Antonio"));
+        return SUCCESS;
+    }
+
+    public MyBean getBean() {
+        return bean;
+    }
+}

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/62a6110b/json/src/main/resources/log4j2.xml
----------------------------------------------------------------------
diff --git a/json/src/main/resources/log4j2.xml b/json/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..e3c583b
--- /dev/null
+++ b/json/src/main/resources/log4j2.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration>
+    <Appenders>
+        <Console name="STDOUT" target="SYSTEM_OUT">
+            <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
+        </Console>
+    </Appenders>
+    <Loggers>
+        <Logger name="com.opensymphony.xwork2" level="info"/>
+        <Logger name="org.apache.struts2" level="info"/>
+        <Logger name="org.demo" level="debug"/>
+        <Root level="warn">
+            <AppenderRef ref="STDOUT"/>
+        </Root>
+    </Loggers>
+</Configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/62a6110b/json/src/main/resources/struts.xml
----------------------------------------------------------------------
diff --git a/json/src/main/resources/struts.xml b/json/src/main/resources/struts.xml
new file mode 100644
index 0000000..b82521b
--- /dev/null
+++ b/json/src/main/resources/struts.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE struts PUBLIC
+    "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
+    "http://struts.apache.org/dtds/struts-2.5.dtd">
+<struts>
+  <constant name="struts.enable.DynamicMethodInvocation" value="false"/>
+  <constant name="struts.devMode" value="true"/>
+
+  <package name="default" namespace="/" extends="json-default">
+
+    <default-action-ref name="produce"/>
+
+    <action name="produce" class="org.demo.ProduceAction">
+      <result type="json">
+        <param name="root">bean</param>
+      </result>
+    </action>
+
+    <action name="consume" class="org.demo.ConsumeAction">
+      <interceptor-ref name="basicStack"/>
+      <interceptor-ref name="json">
+        <param name="root">bean</param>
+        <param name="accept">application/json</param>
+      </interceptor-ref>
+      <result>WEB-INF/result.jsp</result>
+    </action>
+
+  </package>
+
+  <!-- Add addition packages and configuration here. -->
+</struts>

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/62a6110b/json/src/main/webapp/WEB-INF/result.jsp
----------------------------------------------------------------------
diff --git a/json/src/main/webapp/WEB-INF/result.jsp b/json/src/main/webapp/WEB-INF/result.jsp
new file mode 100644
index 0000000..de96c61
--- /dev/null
+++ b/json/src/main/webapp/WEB-INF/result.jsp
@@ -0,0 +1,21 @@
+<%@ page contentType="text/html; charset=UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<html>
+<head>
+  <title>JSON Result</title>
+</head>
+
+<body>
+<ul>
+  <li>
+    counter: <s:property value="bean.counter"/>
+  </li>
+  <s:iterator value="bean.names" var="name" status="idx">
+  <li>
+    name<s:property value="#idx"/>: <s:property value="#name"/>
+  </li>
+  </s:iterator>
+</ul>
+
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/62a6110b/json/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/json/src/main/webapp/WEB-INF/web.xml b/json/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..8858656
--- /dev/null
+++ b/json/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app id="struts_blank" version="2.4"
+         xmlns="http://java.sun.com/xml/ns/j2ee" 
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+  <display-name>Struts Blank</display-name>
+
+  <filter>
+    <filter-name>struts2</filter-name>
+    <filter-class>
+      org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
+    </filter-class>
+  </filter>
+
+  <filter-mapping>
+    <filter-name>struts2</filter-name>
+    <url-pattern>/*</url-pattern>
+  </filter-mapping>
+
+  <welcome-file-list>
+    <welcome-file>index.html</welcome-file>
+  </welcome-file-list>
+</web-app>

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/62a6110b/json/src/main/webapp/index.html
----------------------------------------------------------------------
diff --git a/json/src/main/webapp/index.html b/json/src/main/webapp/index.html
new file mode 100644
index 0000000..dc2bbd0
--- /dev/null
+++ b/json/src/main/webapp/index.html
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+<head>
+    <META HTTP-EQUIV="Refresh" CONTENT="0;URL=example/HelloWorld.action">
+</head>
+
+<body>
+<p>Loading ...</p>
+</body>
+</html>


Mime
View raw message