Skip to content

Commit

Permalink
Finish Struts2 example
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Mershon committed Aug 5, 2014
1 parent eeefd23 commit aadd134
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 0 deletions.
Empty file removed struts2/.git-keep
Empty file.
6 changes: 6 additions & 0 deletions struts2/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# copied sources from the core
src/main/webapp/index.html
src/main/webapp/css
src/main/webapp/js

target
12 changes: 12 additions & 0 deletions struts2/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Requirements
--
* maven

Getting Started
--
`cp ../../html5/index.html src/main/webapp/`
`cp -r ../../html5/css src/main/webapp/`
`cp -r ../../html5/js src/main/webapp/`
`mvn -Djetty.port=9000 jetty:run`


114 changes: 114 additions & 0 deletions struts2/example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?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>
<groupId>example</groupId>
<artifactId>json-parsing</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>json-parsing</name>

<properties>
<struts2.version>2.3.16.3</struts2.version>
<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-junit-plugin</artifactId>
<version>${struts2.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.7.v20120910</version>
<configuration>
<stopKey>CTRL+C</stopKey>
<stopPort>8999</stopPort>
<systemProperties>
<systemProperty>
<name>log4j.configuration</name>
<value>file:${basedir}/src/main/resources/log4j.properties</value>
</systemProperty>
<systemProperty>
<name>slf4j</name>
<value>false</value>
</systemProperty>
</systemProperties>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webAppSourceDirectory>${basedir}/src/main/webapp/</webAppSourceDirectory>
<webAppConfig>
<contextPath>/</contextPath>
<descriptor>${basedir}/src/main/webapp/WEB-INF/web.xml</descriptor>
</webAppConfig>
</configuration>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
60 changes: 60 additions & 0 deletions struts2/example/src/main/java/example/SendAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package example;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionSupport;

import com.google.gson.Gson;

public class SendAction extends ActionSupport {
private String subject;
private String body;
private String receivers;

public String send() {
Gson converter = new Gson();
List<Map> receiversList =
converter.fromJson(this.receivers, List.class);

System.out.println("\nTo: ");
for (Map recv : receiversList) {
if ("to".equals(recv.get("type"))) {
System.out.println(recv.get("address"));
}
}
System.out.println("\nCC: ");
for (Map recv : receiversList) {
if ("cc".equals(recv.get("type"))) {
System.out.println(recv.get("address"));
}
}
System.out.println("\nSubject: " + subject);
System.out.println("\nBody: " + body);

return SUCCESS;
}

public String getSubject() {
return this.subject;
}
public void setSubject(String subject) {
this.subject = subject;
}

public String getBody() {
return this.body;
}
public void setBody(String body) {
this.body = body;
}

public String getReceivers() {
return this.receivers;
}
public void setReceivers(String receivers) {
this.receivers = receivers;
}

}
29 changes: 29 additions & 0 deletions struts2/example/src/main/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Log4J Settings for log4j 1.2.x (via jakarta-commons-logging)
#
# The five logging levels used by Log are (in order):
#
# 1. DEBUG (the least serious)
# 2. INFO
# 3. WARN
# 4. ERROR
# 5. FATAL (the most serious)


# Set root logger level to WARN and append to stdout
log4j.rootLogger=WARN, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%d %5p (%c:%L) - %m%n

# Print only messages of level ERROR or above in the package noModule.
log4j.logger.noModule=ERROR

# OpenSymphony Stuff
log4j.logger.com.opensymphony=INFO

# Struts2 Stuff
log4j.logger.org.apache.struts2=INFO
25 changes: 25 additions & 0 deletions struts2/example/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<constant name="struts.devMode" value="true"/>
<constant name="struts.action.excludePattern" value="index.html,/js/.*?,/css/.*?"></constant>

<package name="default" namespace="/" extends="struts-default">

<default-action-ref name="index"/>

<action name="index">
<result name="success">index.html</result>
</action>

<action name="send" class="example.SendAction" method="send">
<result name="success" type="plainText">ok.jsp</result>
</action>

</package>

<!-- Add addition packages and configuration here. -->
</struts>
23 changes: 23 additions & 0 deletions struts2/example/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -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>JSON Parsing Example</display-name>

<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.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>
1 change: 1 addition & 0 deletions struts2/example/src/main/webapp/ok.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ok

0 comments on commit aadd134

Please sign in to comment.