Skip to content

Commit 9557aed

Browse files
committed
Moved from RestExpress/examples
1 parent 34262ca commit 9557aed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2578
-12
lines changed

.gitignore

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
*.class
2-
3-
# Mobile Tools for Java (J2ME)
4-
.mtj.tmp/
5-
6-
# Package Files #
7-
*.jar
8-
*.war
9-
*.ear
10-
11-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12-
hs_err_pid*
1+
.project
2+
.classpath
3+
target/
4+
.settings/
5+
*.iml

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
RestExpress Examples
2+
====================
3+
4+
A few examples to illustrate how RestExpress works.
5+
6+
* echo - An echo service with no database back-end.
7+
* blogging - A blogging service with a MongoDB back-end.
8+
* benchmark - ?

benchmark/README

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
This kickstart project illustrates how to create a simple RestExpress project. Complete with Ant
2+
build, it contains a skeleton main() class, RestServer, and an empty, but functional service.
3+
4+
Alternatively, there is a kickstart zip file generated in the release process. Simply:
5+
6+
1) Unzip the file.
7+
2) Run ant to build it.
8+
3) 'ant run' to run it.
9+
10+
Then:
11+
12+
1) Change the Routes.java file to match your URL requirements using the using the RouteBuilder DSL.
13+
2) Implement the functionality for those URLs in a service class, much like KickstartService.java
14+
does.
15+
3) Impress your superiors with the speed at which you've completed your tasks.

benchmark/pom.xml

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<name>RestExpress-Benchmark-Example</name>
6+
<!--
7+
To run the project: mvn clean package exec:java
8+
To create a project deployable assembly:
9+
mvn clean package
10+
mvn assembly:single
11+
-->
12+
<description>A RestExpress Benchmark Server</description>
13+
<url>https://github.com/RestExpress/RestExpress-Examples</url>
14+
<groupId>org.restexpress.examples</groupId>
15+
<artifactId>restexpress-benchmark-example</artifactId>
16+
<version>0.1-SNAPSHOT</version>
17+
<packaging>jar</packaging>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>com.strategicgains</groupId>
22+
<artifactId>RestExpress</artifactId>
23+
<version>0.10.4</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.slf4j</groupId>
27+
<artifactId>slf4j-jcl</artifactId>
28+
<version>1.7.5</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>junit</groupId>
32+
<artifactId>junit</artifactId>
33+
<version>4.11</version>
34+
<type>jar</type>
35+
<scope>test</scope>
36+
<optional>true</optional>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.apache.httpcomponents</groupId>
40+
<artifactId>httpclient</artifactId>
41+
<version>4.2.5</version>
42+
<type>jar</type>
43+
<scope>test</scope>
44+
</dependency>
45+
</dependencies>
46+
47+
<build>
48+
<defaultGoal>package</defaultGoal>
49+
50+
<plugins>
51+
<plugin>
52+
<groupId>org.apache.maven.plugins</groupId>
53+
<artifactId>maven-compiler-plugin</artifactId>
54+
<version>3.0</version>
55+
<configuration>
56+
<source>1.7</source>
57+
<target>1.7</target>
58+
<encoding>UTF-8</encoding>
59+
</configuration>
60+
</plugin>
61+
<plugin>
62+
<groupId>org.codehaus.mojo</groupId>
63+
<artifactId>exec-maven-plugin</artifactId>
64+
<version>1.2.1</version>
65+
<configuration>
66+
<mainClass>org.restexpress.scaffold.minimal.Main</mainClass>
67+
</configuration>
68+
</plugin>
69+
<plugin>
70+
<groupId>org.apache.maven.plugins</groupId>
71+
<artifactId>maven-jar-plugin</artifactId>
72+
<version>2.4</version>
73+
<configuration>
74+
<archive>
75+
<addMavenDescriptor>false</addMavenDescriptor>
76+
<manifest>
77+
<addClasspath>true</addClasspath>
78+
<classpathPrefix>./lib/</classpathPrefix>
79+
<mainClass>org.restexpress.scaffold.minimal.Main</mainClass>
80+
</manifest>
81+
</archive>
82+
</configuration>
83+
</plugin>
84+
<plugin>
85+
<groupId>org.apache.maven.plugins</groupId>
86+
<artifactId>maven-assembly-plugin</artifactId>
87+
<version>2.4</version>
88+
<configuration>
89+
<descriptors>
90+
<descriptor>zip-with-dependencies.xml</descriptor>
91+
</descriptors>
92+
</configuration>
93+
</plugin>
94+
</plugins>
95+
</build>
96+
97+
<reporting>
98+
<plugins>
99+
<plugin>
100+
<groupId>org.codehaus.mojo</groupId>
101+
<artifactId>versions-maven-plugin</artifactId>
102+
<version>2.0</version>
103+
</plugin>
104+
</plugins>
105+
</reporting>
106+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.benchmark;
2+
3+
import org.jboss.netty.handler.codec.http.HttpMethod;
4+
5+
import com.strategicgains.restexpress.Request;
6+
import com.strategicgains.restexpress.Response;
7+
import com.strategicgains.restexpress.RestExpress;
8+
9+
public class Main
10+
{
11+
public static void main(String[] args)
12+
{
13+
RestExpress server = new RestExpress()
14+
.setName("Echo");
15+
16+
server.uri("/echo", new Object()
17+
{
18+
public String read(Request req, Response res)
19+
{
20+
String value = req.getRawHeader("echo");
21+
res.setContentType("text/xml");
22+
23+
if (value == null)
24+
{
25+
return "<http_test><error>no value specified</error></http_test>";
26+
}
27+
else
28+
{
29+
return String.format("<http_test><value>%s</value></http_test>", value);
30+
}
31+
}
32+
})
33+
.method(HttpMethod.GET)
34+
.noSerialization();
35+
36+
server.bind(8000);
37+
server.awaitShutdown();
38+
}}

benchmark/zip-with-dependencies.xml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<assembly
2+
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
5+
<id>zip-with-dependencies</id>
6+
<formats>
7+
<format>zip</format>
8+
</formats>
9+
<fileSets>
10+
<fileSet>
11+
<directory>${project.basedir}</directory>
12+
<outputDirectory>/</outputDirectory>
13+
<includes>
14+
<include>README*</include>
15+
<include>LICENSE*</include>
16+
<include>NOTICE*</include>
17+
<include>config/**/*</include>
18+
</includes>
19+
</fileSet>
20+
<fileSet>
21+
<directory>${project.build.directory}</directory>
22+
<outputDirectory>/</outputDirectory>
23+
<includes>
24+
<include>*.jar</include>
25+
</includes>
26+
</fileSet>
27+
</fileSets>
28+
<dependencySets>
29+
<dependencySet>
30+
<outputDirectory>lib</outputDirectory>
31+
<useProjectArtifact>false</useProjectArtifact>
32+
</dependencySet>
33+
</dependencySets>
34+
</assembly>

blogging/README

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
====================================================================================================
2+
BLOGGING EXAMPLE APPLICATION
3+
----------------------------------------------------------------------------------------------------
4+
This application supports the concept of a blog, blog entry, and blog entry comment, in hierarchical
5+
fashion. Which is roughly the concepts that a blogging system like WordPress supports. One could
6+
use these RESTful services to create a blogging system.
7+
8+
This is a fully functional RestExpress application that utilizes the sub-projects, Syntaxe and
9+
RepoExpress for domain validation and object persistence, respectively. It also utilizes the
10+
MongoDB ObjectId as the ID for the persisted objects, which illustrates how to install your own
11+
object ID converters for persistence and XML and JSON marshaling.
12+
13+
Additionally, the project illustrates how to map exceptions that are non-runtime exceptions
14+
(checked exceptions) into ServiceExceptions that RestExpress knows how to translate into an HTTP
15+
response.
16+
17+
To run it, install and start MongoDB, then type 'mvn clean package exec:java'.
18+
19+
The URL '/console/routes' will show you the routes available in the application
20+
(e.g. curl -i localhost:8081/console/routes.xml). Or simply look in the Routes.java file.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Default is 8081
2+
#port = 3339
3+
4+
thread.pool.size = 100
5+
6+
# The default service response format (default is JSON)
7+
#default.Format = json
8+
9+
# A comma-delimited string of MongoDB server hosts
10+
mongodb.bootstraps = localhost:27017
11+
mongodb.database = pts_2012_blogging
12+
mongodb.connectionsPerHost = 100
13+
#mongodb.user =
14+
#mongodb.password =
15+
16+
# The base URL, used as a prefix for links returned in data.
17+
# default is http://localhost:<port>
18+
#base.url = http://localhost:8081

blogging/pom.xml

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<name>RestExpress-Blogging-Example</name>
6+
<!--
7+
To run the project: mvn clean package exec:java
8+
* mongod must be running.
9+
10+
To create a project deployable assembly (zip file):
11+
mvn clean package
12+
mvn assembly:single
13+
14+
To run the deployable assembly:
15+
unzip <zip file made in above step>
16+
cd <newly unzipped director>
17+
java -jar <jar file name>
18+
19+
To run the project via Maven:
20+
mvn clean package exec:java
21+
-->
22+
<description>A Basic, MongoDB-backed Blogging Service Suite</description>
23+
<url>https://github.com/RestExpress/RestExpress</url>
24+
<groupId>com.strategicgains.example</groupId>
25+
<artifactId>restexpress-blogging-example</artifactId>
26+
<version>0.1-SNAPSHOT</version>
27+
<packaging>jar</packaging>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>com.strategicgains</groupId>
32+
<artifactId>RestExpress</artifactId>
33+
<version>0.9.0-SNAPSHOT</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>com.strategicgains</groupId>
37+
<artifactId>HyperExpress</artifactId>
38+
<version>1.0.1</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>com.strategicgains</groupId>
42+
<artifactId>PluginExpress</artifactId>
43+
<version>0.1.1</version>
44+
</dependency>
45+
<dependency>
46+
<groupId>com.strategicgains</groupId>
47+
<artifactId>Syntaxe</artifactId>
48+
<version>0.4.4</version>
49+
</dependency>
50+
<dependency>
51+
<groupId>com.strategicgains.repoexpress</groupId>
52+
<artifactId>repoexpress-mongodb</artifactId>
53+
<version>0.3.1</version>
54+
</dependency>
55+
<dependency>
56+
<groupId>com.strategicgains.domain-eventing</groupId>
57+
<artifactId>domain-eventing-core</artifactId>
58+
<version>0.4.1</version>
59+
</dependency>
60+
<dependency>
61+
<groupId>junit</groupId>
62+
<artifactId>junit</artifactId>
63+
<version>4.8.2</version>
64+
<type>jar</type>
65+
<scope>test</scope>
66+
<optional>true</optional>
67+
</dependency>
68+
</dependencies>
69+
70+
<build>
71+
<defaultGoal>compile</defaultGoal>
72+
<sourceDirectory>src/java</sourceDirectory>
73+
<testSourceDirectory>test/java</testSourceDirectory>
74+
75+
<plugins>
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-compiler-plugin</artifactId>
79+
<version>3.0</version>
80+
<configuration>
81+
<source>1.6</source>
82+
<target>1.6</target>
83+
<encoding>UTF-8</encoding>
84+
</configuration>
85+
</plugin>
86+
<plugin>
87+
<groupId>org.codehaus.mojo</groupId>
88+
<artifactId>exec-maven-plugin</artifactId>
89+
<version>1.2.1</version>
90+
<configuration>
91+
<mainClass>com.kickstart.Main</mainClass>
92+
</configuration>
93+
</plugin>
94+
<plugin>
95+
<groupId>org.apache.maven.plugins</groupId>
96+
<artifactId>maven-jar-plugin</artifactId>
97+
<version>2.4</version>
98+
<configuration>
99+
<archive>
100+
<addMavenDescriptor>false</addMavenDescriptor>
101+
<manifest>
102+
<addClasspath>true</addClasspath>
103+
<classpathPrefix>./lib/</classpathPrefix>
104+
<mainClass>com.kickstart.Main</mainClass>
105+
</manifest>
106+
</archive>
107+
</configuration>
108+
</plugin>
109+
<plugin>
110+
<groupId>org.apache.maven.plugins</groupId>
111+
<artifactId>maven-assembly-plugin</artifactId>
112+
<version>2.4</version>
113+
<configuration>
114+
<descriptors>
115+
<descriptor>zip-with-dependencies.xml</descriptor>
116+
</descriptors>
117+
</configuration>
118+
</plugin>
119+
</plugins>
120+
</build>
121+
</project>

0 commit comments

Comments
 (0)