Skip to content

Commit 27e9052

Browse files
committed
Added Warehouse JSON Example, Improved Documentation
1 parent d2c9362 commit 27e9052

27 files changed

Lines changed: 945 additions & 24 deletions

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ hs_err_pid*
167167
/jsonRPC/calculator/client/tmp/
168168
/jsonRPC/calculator/client/bin/
169169
/jsonRPC/calculator/client/.classpath
170+
### warehouse server example
171+
/jsonRPC/warehouse/server/target/
172+
/jsonRPC/warehouse/server/temp/
173+
/jsonRPC/warehouse/server/tmp/
174+
/jsonRPC/warehouse/server/bin/
175+
/jsonRPC/warehouse/server/.classpath
176+
### warehouse client example
177+
/jsonRPC/warehouse/client/target/
178+
/jsonRPC/warehouse/client/temp/
179+
/jsonRPC/warehouse/client/tmp/
180+
/jsonRPC/warehouse/client/bin/
181+
/jsonRPC/warehouse/client/.classpath
170182

171183

172184
## MPI

jsonRPC/README.md

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ We introduce a new [data type](http://github.com/thomasWeise/distributedComputin
2020

2121
You need to compile (via [Maven](http://maven.apache.org/)) and deploy to a [servlet container](https://en.wikipedia.org/wiki/Web_container).
2222

23-
### 1.5. (Complex Number) Calculator Web Service Client
23+
### 1.2. (Complex Number) Calculator Web Service Client
2424

2525
The example client of the calculator JSON RPC introduced above creates two complex numbers `3+11i` and `5+7i`, multiplies then with each other, and prints the result. The multiplication is, of course, done by the web service. This example is very similar to the Complex Number Calculator [Web Service](http://github.com/thomasWeise/distributedComputingExamples/tree/master/webServices/) example client.
2626

@@ -30,6 +30,29 @@ The compiled jar archive is a stand-alone executable which you can run via `java
3030
1. [`CalculatorInterface.java`](http://github.com/thomasWeise/distributedComputingExamples/tree/master/jsonRPC/examples/calculator/client/src/main/java/calculator/CalculatorInterface.java)
3131
1. [`TestClient.java`](http://github.com/thomasWeise/distributedComputingExamples/tree/master/jsonRPC/examples/calculator/client/src/main/java/calculator/TestClient.java)
3232

33+
34+
### 1.3. Warehouse JSON RPC Service
35+
36+
The warehouse RPC service example shows how we can construct a stand-alone JSON RPC service managing the number of certain stocks in a warehouse. It basically maintains a [`HashMap`](http://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html) storing the number of available items of a given type. This example is very similar to the Warehouse [Web Service](http://github.com/thomasWeise/distributedComputingExamples/tree/master/webServices/) example server.
37+
38+
The RPC server offers a method for getting the number of items of a given type and one method for changing it. The [Warehouse class](http://github.com/thomasWeise/distributedComputingExamples/tree/master/jsonRPC/examples/warehouse/server/src/main/java/warehouseServer/Warehouse.java) implementing [service interface](http://github.com/thomasWeise/distributedComputingExamples/tree/master/jsonRPC/examples/warehouse/server/src/main/java/warehouseServer/WarehouseInterface.java) itself is a plain Java object without any annotation or fancy stuff.
39+
40+
1. [`WarehouseInterface.java`](http://github.com/thomasWeise/distributedComputingExamples/tree/master/webServices/examples/jsonRPC/server/src/main/java/warehouseServer/WarehouseInterface.java)
41+
1. [`Warehouse.java`](http://github.com/thomasWeise/distributedComputingExamples/tree/master/webServices/examples/jsonRPC/server/src/main/java/warehouseServer/Warehouse.java)
42+
1. [`WarehouseServlet.java`](http://github.com/thomasWeise/distributedComputingExamples/tree/master/webServices/examples/jsonRPC/server/src/main/java/warehouseServer/WarehouseServlet.java)
43+
1. [`Main.java`](http://github.com/thomasWeise/distributedComputingExamples/tree/master/webServices/examples/jsonRPC/server/src/main/java/warehouseServer/Main.java)
44+
1. [`web.xml`](http://github.com/thomasWeise/distributedComputingExamples/tree/master/webServices/examples/jsonRPC/server/src/main/resources/webapp/WEB-INF/web.xml)
45+
46+
You need to compile this example with [Maven](http://maven.apache.org/)) to build a stand-alone `jar` archive. This archive does not need to be deployed anywhere, since it already contains the (Jetty) servlet container. You will obtain the fat `jar` file `warehouseJSONServer-full.jar` which you can run as `java -jar warehouseJSONServer-full.jar` from the command line.
47+
48+
### 1.4. Warehouse JSON RPC Client
49+
50+
The example client of the warehouse JSON RPC service introduced above: It checks the warehouse for the number of "cars" and "cats", changes these numbers, and checks back the results. The client is compiled into a fat jar named `warehouseJSONClient-full.jar` containing all the required libraries. You can directly execute it via `java -jar warehouseJSONClient-full.jar` from the command line.
51+
52+
1. [`WarehouseInterface.java`](http://github.com/thomasWeise/distributedComputingExamples/tree/master/jsonRPC/examples/warehouse/client/src/main/java/warehouseClient/WarehouseInterface.java)
53+
2. [`WarehouseTest.java`](http://github.com/thomasWeise/distributedComputingExamples/tree/master/jsonRPC/examples/warehouse/client/src/main/java/warehouseClient/WarehouseTest.java)
54+
55+
3356
## 2. Building and Deployment
3457

3558
### 2.1. Import Project into Eclipse
@@ -73,12 +96,38 @@ Now you can build the deployable server projects, i.e., generate a [`war`](https
7396
15. After building the `war` archive, you can now deploy it.
7497

7598

76-
##### 2.2.2. Building a Client (for using a JSON RPC Service) in Eclipse
99+
##### 2.2.2. Building a Stand-Alone Server
100+
101+
The stand-alone server projects, such as the Warehouse Server, are built into a single `jar` archive containing not just the servlet but also the servlet container. These archives do not need to be deployed and can directly be executed from the command line using `java -jar ...`. If you want to, e.g., build the `warehouse/server` example, you would take the following steps:
102+
103+
1. Make sure that you can see the `package view` on the left-hand side of the Eclipse window.
104+
2. Right-click on the project (`warehouseJSONServer`) in the `package view`.
105+
3. In the opening pop-up menu, choose `Run As`.
106+
4. In the opening sub-menu choose `Run Configurations...`.
107+
5. In the opening window, choose `Maven Build`
108+
6. In the new window `Run Configurations` / `Create, manage, and run configurations`, choose `Maven Build` in the small white pane on the left side.
109+
7. Click `New launch configuration` (the first symbol from the left on top of the small white pane).
110+
8. Write a useful name for this configuration in the `Name` field. You can use this configuration again later.
111+
9. In the tab `Main` enter the `Base directory` of the project, this is the folder called `jsonRPC/warehouse/server` containing the Eclipse/Maven project.
112+
10. Under `Goals`, enter `clean compile package`. This will build a `jar` archive.
113+
11. Click `Apply`
114+
12. Click `Run`
115+
13. The build will start, you will see its status output in the console window.
116+
14. The folder `target` will contain the files `warehouseJSONServer.jar` and `warehouseJSONServer-full.jar` after the build. The first one requires several libraries in the classpath, the latter one is stand-alone, the one we are after.
117+
118+
If you are in the `target` folder with your command line/terminal, you can now run the client which uses the web service by doing
119+
120+
java -jar warehouseJSONServer-full.jar
121+
122+
This will start up the servlet containing and the RPC servlet as well.
123+
124+
125+
##### 2.2.3. Building a Client (for using a JSON RPC Service) in Eclipse
77126

78127
Now you can build the client projects, i.e., generate the normal [`jar`](https://en.wikipedia.org/wiki/JAR_%28file_format%29) which you can directly execute via `java -jar ...`. If you want to, e.g., build the `calculator/client` example, you would take the following steps:
79128

80129
1. Make sure that you can see the `package view` on the left-hand side of the Eclipse window.
81-
2. Right-click on the project (`calculatorRPCClient`) in the `package view`.
130+
2. Right-click on the project (`calculatorJSONClient`) in the `package view`.
82131
3. In the opening pop-up menu, choose `Run As`.
83132
4. In the opening sub-menu choose `Run Configurations...`.
84133
5. In the opening window, choose `Maven Build`

jsonRPC/calculator/client/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
<project.build.sourceEncoding>${encoding}</project.build.sourceEncoding>
3737
<project.reporting.outputEncoding>${encoding}</project.reporting.outputEncoding>
3838
<jdk.version>1.7</jdk.version>
39-
<axis2.version>1.6.3</axis2.version>
4039
<project.mainClass>calculatorClient.TestClient</project.mainClass>
4140
</properties>
4241

jsonRPC/calculator/server/pom.xml

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>thomasWeise</groupId>
66
<artifactId>calculatorJSONServer</artifactId>
77
<version>0.8.0</version>
8-
<packaging>war</packaging>
8+
<packaging>war</packaging>
99
<name>Calculator Server</name>
1010
<description>The server part of the calculator JSON RPC example.</description>
1111

@@ -36,7 +36,6 @@
3636
<project.build.sourceEncoding>${encoding}</project.build.sourceEncoding>
3737
<project.reporting.outputEncoding>${encoding}</project.reporting.outputEncoding>
3838
<jdk.version>1.7</jdk.version>
39-
<axis2.version>1.6.4</axis2.version>
4039
</properties>
4140

4241
<licenses>
@@ -76,11 +75,12 @@
7675
<groupId>javax.portlet</groupId>
7776
<artifactId>portlet-api</artifactId>
7877
<version>2.0</version>
79-
</dependency> <dependency>
80-
<groupId>com.fasterxml.jackson.core</groupId>
81-
<artifactId>jackson-databind</artifactId>
82-
<version>2.7.2</version>
83-
</dependency>
78+
</dependency>
79+
<dependency>
80+
<groupId>com.fasterxml.jackson.core</groupId>
81+
<artifactId>jackson-databind</artifactId>
82+
<version>2.7.2</version>
83+
</dependency>
8484
</dependencies>
8585

8686
<build>
@@ -100,13 +100,6 @@
100100
</configuration>
101101
</plugin>
102102

103-
<plugin>
104-
<groupId>org.apache.axis2</groupId>
105-
<artifactId>axis2-aar-maven-plugin</artifactId>
106-
<version>${axis2.version}</version>
107-
<extensions>true</extensions>
108-
</plugin>
109-
110103
</plugins>
111104
</build>
112105

jsonRPC/calculator/server/src/main/java/calculator/CalculatorServlet.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
public class CalculatorServlet extends HttpServlet {
1414

15-
private Calculator userService;
15+
private Calculator service;
1616
private JsonRpcServer jsonRpcServer;
1717

1818
@Override
@@ -29,8 +29,8 @@ protected void doGet(final HttpServletRequest req,
2929

3030
@Override
3131
public void init(final ServletConfig config) {
32-
this.userService = new Calculator();
32+
this.service = new Calculator();
3333
this.jsonRpcServer = new JsonRpcServer(new ObjectMapper(),
34-
this.userService, CalculatorInterface.class);
34+
this.service, CalculatorInterface.class);
3535
}
3636
}

jsonRPC/make_linux.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ echo "We now build all the JSON RPC examples."
1212
cd "$currentDir/calculator"
1313
"$currentDir/calculator/make_linux.sh"
1414

15+
cd "$currentDir/warehouse"
16+
"$currentDir/warehouse/make_linux.sh"
17+
1518
echo "Successfully finished building all the JSON RPC examples."
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Java
2+
*.class
3+
4+
# Mobile Tools for Java (J2ME)
5+
.mtj.tmp/
6+
7+
# Package Files #
8+
*.jar
9+
*.war
10+
*.ear
11+
12+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
13+
hs_err_pid*
14+
/target/
15+
16+
# other files, potentially created by build tools
17+
/.classpath
18+
/bin
19+
/classes
20+
/build
21+
/temp
22+
/tmp
23+
/out
24+
/.gradle
25+
/dependency-reduced-pom.xml

jsonRPC/warehouse/client/.project

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>warehouseJSONClient</name>
4+
<comment>The client side of the Warehouse JSON RPC example.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
</projectDescription>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
eclipse.preferences.version=1
2+
encoding//src/main/java=UTF-8
3+
encoding//src/main/resources=UTF-8
4+
encoding//src/test/java=UTF-8
5+
encoding//src/test/resources=UTF-8
6+
encoding/<project>=UTF-8
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
3+
org.eclipse.jdt.core.compiler.compliance=1.7
4+
org.eclipse.jdt.core.compiler.doc.comment.support=disabled
5+
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=ignore
6+
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
7+
org.eclipse.jdt.core.compiler.problem.comparingIdentical=ignore
8+
org.eclipse.jdt.core.compiler.problem.deadCode=ignore
9+
org.eclipse.jdt.core.compiler.problem.deprecation=ignore
10+
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=enabled
11+
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
12+
org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore
13+
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
14+
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
15+
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
16+
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
17+
org.eclipse.jdt.core.compiler.problem.finalParameterBound=ignore
18+
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=ignore
19+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=ignore
20+
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=ignore
21+
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled
22+
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=ignore
23+
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
24+
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
25+
org.eclipse.jdt.core.compiler.problem.invalidJavadoc=error
26+
org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
27+
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
28+
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
29+
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private
30+
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
31+
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=ignore
32+
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
33+
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
34+
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=error
35+
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
36+
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=private
37+
org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=all_standard_tags
38+
org.eclipse.jdt.core.compiler.problem.missingJavadocTags=error
39+
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
40+
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
41+
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=private
42+
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
43+
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
44+
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore
45+
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
46+
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=ignore
47+
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=ignore
48+
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
49+
org.eclipse.jdt.core.compiler.problem.nullReference=ignore
50+
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=ignore
51+
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
52+
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
53+
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
54+
org.eclipse.jdt.core.compiler.problem.rawTypeReference=ignore
55+
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
56+
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
57+
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
58+
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
59+
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
60+
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=enabled
61+
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=ignore
62+
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
63+
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
64+
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
65+
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=ignore
66+
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled
67+
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=ignore
68+
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
69+
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=ignore
70+
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
71+
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
72+
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
73+
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
74+
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
75+
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
76+
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
77+
org.eclipse.jdt.core.compiler.problem.unusedImport=ignore
78+
org.eclipse.jdt.core.compiler.problem.unusedLabel=ignore
79+
org.eclipse.jdt.core.compiler.problem.unusedLocal=ignore
80+
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
81+
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
82+
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
83+
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
84+
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
85+
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=ignore
86+
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=ignore
87+
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=ignore
88+
org.eclipse.jdt.core.compiler.source=1.7

0 commit comments

Comments
 (0)