Browse Source

initial version of REST web server for TCPTimeCounter

master
Sebastian Rieger 7 years ago
parent
commit
4d8a7cdb5a
  1. BIN
      VerteilteSysteme-Examples/build/RMIEchoServer.jar
  2. BIN
      VerteilteSysteme-Examples/build/RMIMandelbrotCalculationsServer.jar
  3. BIN
      VerteilteSysteme-Examples/build/TCPPerfServer.jar
  4. BIN
      VerteilteSysteme-Examples/build/TCPServer.jar
  5. BIN
      VerteilteSysteme-Examples/build/TCPServerMulti.jar
  6. BIN
      VerteilteSysteme-Examples/build/TCPTimeCounterRESTServer.jar
  7. BIN
      VerteilteSysteme-Examples/build/TCPTimeCounterServer.jar
  8. BIN
      VerteilteSysteme-Examples/build/UDPServer.jar
  9. BIN
      VerteilteSysteme-Examples/build/UDPServerMulti.jar
  10. BIN
      VerteilteSysteme-Examples/build/UDPTimeCounterServer.jar
  11. 34
      VerteilteSysteme-Examples/build/build-server-jars.xml
  12. 32
      VerteilteSysteme-Examples/src/verteiltesysteme/aws/TCPTimeCounterRESTServer.java
  13. 78
      VerteilteSysteme-Examples/src/verteiltesysteme/aws/TCPTimeCounterRESTService.java
  14. 2
      VerteilteSysteme-Examples/src/verteiltesysteme/aws/user-data.txt

BIN
VerteilteSysteme-Examples/build/RMIEchoServer.jar

BIN
VerteilteSysteme-Examples/build/RMIMandelbrotCalculationsServer.jar

BIN
VerteilteSysteme-Examples/build/TCPPerfServer.jar

BIN
VerteilteSysteme-Examples/build/TCPServer.jar

BIN
VerteilteSysteme-Examples/build/TCPServerMulti.jar

BIN
VerteilteSysteme-Examples/build/TCPTimeCounterRESTServer.jar

BIN
VerteilteSysteme-Examples/build/TCPTimeCounterServer.jar

BIN
VerteilteSysteme-Examples/build/UDPServer.jar

BIN
VerteilteSysteme-Examples/build/UDPServerMulti.jar

BIN
VerteilteSysteme-Examples/build/UDPTimeCounterServer.jar

34
VerteilteSysteme-Examples/build/build-server-jars.xml

@ -7,7 +7,7 @@
<property name="dir.workspace" value=".." />
<property name="dir.jarfile" value="." />
<target name="all" depends="create_run_jar_tcpserver, create_run_jar_udpserver, create_run_jar_tcpservermulti, create_run_jar_udpservermulti, create_run_jar_udptimecounterserver, create_run_jar_tcpperfserver, create_run_jar_rmiechoserver, create_run_jar_rmimandelbrotcalculationsserver, create_run_jar_tcptimecounterserver">
<target name="all" depends="create_run_jar_tcpserver, create_run_jar_udpserver, create_run_jar_tcpservermulti, create_run_jar_udpservermulti, create_run_jar_udptimecounterserver, create_run_jar_tcpperfserver, create_run_jar_rmiechoserver, create_run_jar_rmimandelbrotcalculationsserver, create_run_jar_tcptimecounterserver, create_run_jar_tcptimecounterrestserver">
</target>
<target name="create_run_jar_tcpserver">
@ -91,33 +91,25 @@
</target>
<target name="create_run_jar_tcptimecounterserver">
<!--
<path id="build.classpath">
<fileset dir="${dir.buildfile}/lib-aws">
<include name="*.jar" />
</fileset>
</path>
<pathconvert property="mf.classpath" pathsep=" ">
<path refid="build.classpath" />
<flattenmapper />
</pathconvert>
-->
<jar destfile="${dir.jarfile}/TCPTimeCounterServer.jar" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="verteiltesysteme.aws.TCPTimeCounterServer" />
<!--
<attribute name="Class-Path" value="${mf.classpath}" />
-->
</manifest>
<fileset dir="${dir.buildfile}/bin" />
<!--
<fileset dir="${dir.buildfile}/lib-aws">
<include name="*.jar" />
</fileset>
-->
<zipgroupfileset dir="${dir.buildfile}/lib-aws" includes="*.jar" />
</jar>
</target>
<target name="create_run_jar_tcptimecounterrestserver">
<jar destfile="${dir.jarfile}/TCPTimeCounterRESTServer.jar" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="verteiltesysteme.aws.TCPTimeCounterRESTServer" />
</manifest>
<fileset dir="${dir.buildfile}/bin" />
<zipgroupfileset dir="${dir.buildfile}/lib-aws" includes="*.jar" />
<zipgroupfileset dir="${dir.buildfile}/lib" includes="*.jar" />
</jar>
</target>
</project>

32
VerteilteSysteme-Examples/src/verteiltesysteme/aws/TCPTimeCounterRESTServer.java

@ -0,0 +1,32 @@
/* Beispiel angelehnt an http://www.torsten-horn.de/techdocs/jee-rest.htm */
package verteiltesysteme.aws;
import java.io.IOException;
import java.net.URI;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;
public class TCPTimeCounterRESTServer
{
public static void main( String[] args ) throws IOException, InterruptedException
{
String baseUrl = ( args.length > 0 ) ? args[0] : "http://localhost:36042";
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(
URI.create( baseUrl ), new ResourceConfig( TCPTimeCounterRESTService.class ), false );
Runtime.getRuntime().addShutdownHook( new Thread( new Runnable() {
@Override
public void run() {
server.shutdownNow();
}
} ) );
server.start();
System.out.println("Grizzly-HTTP-Server gestartet");
System.out.println("Stoppen des Grizzly-HTTP-Servers mit: Strg+C\n");
System.out.println("RESTful Web Service URL: " + baseUrl + TCPTimeCounterRESTService.webContextPath);
Thread.currentThread().join();
}
}

78
VerteilteSysteme-Examples/src/verteiltesysteme/aws/TCPTimeCounterRESTService.java

@ -0,0 +1,78 @@
/* Beispiel angelehnt an http://www.torsten-horn.de/techdocs/jee-rest.htm */
package verteiltesysteme.aws;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
@Path(TCPTimeCounterRESTService.webContextPath)
public class TCPTimeCounterRESTService {
static final String webContextPath = "/counter";
static final String bucketName = "vertsys-counter";
private Long getCounter() {
// Verbindung zu S3
AmazonS3 s3Client = AmazonS3ClientBuilder.defaultClient();
String region = s3Client.getRegionName();
return new Long(s3Client.getObjectAsString(bucketName, region));
}
private boolean setCounter(Long counter) {
// Verbindung zu S3
AmazonS3 s3Client = AmazonS3ClientBuilder.defaultClient();
String region = s3Client.getRegionName();
s3Client.putObject(bucketName, region, new Long(counter).toString());
return true;
}
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getCounterPlain() {
return "Plain-Text: " + getCounter();
}
@GET
@Produces(MediaType.TEXT_HTML)
public String getCounterHtml() {
return "<html><head><title>TCPTimeCounter REST Service</title><meta http-equiv=\"refresh\" content=\"5\"/></head><body><h2>HTML: " + getCounter() + "</h2></body></html>";
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getCounterJson() {
return "{\n \"type\": \"JSON\",\n \"output\": \"" + getCounter() + "\"\n}";
}
@POST
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public String incrCounterPlain(@FormParam("input") String input) {
Long currentCounterValue = getCounter();
currentCounterValue = currentCounterValue + (new Long(input)).longValue();
setCounter(currentCounterValue);
return "Plain-Text: TCPTimeCounter counter increased by " + input + " to " + currentCounterValue;
}
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)
public String incrCounterHtml(@FormParam("input") String input) {
Long currentCounterValue = getCounter();
currentCounterValue = currentCounterValue + (new Long(input)).longValue();
setCounter(currentCounterValue);
return "<html><title>TCPTimeCounter counter increased by " + input + " to " + currentCounterValue + "</h2></body></html>";
}
@POST
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON)
public String incrCounterJson(@QueryParam("input") String input) {
Long currentCounterValue = getCounter();
currentCounterValue = currentCounterValue + (new Long(input)).longValue();
setCounter(currentCounterValue);
return "{\n \"type\": \"JSON\",\n \"output\": \"Plain-Text: TCPTimeCounter counter increased by " + input + " to " + currentCounterValue + "\"\n}";
}
}

2
VerteilteSysteme-Examples/src/verteiltesysteme/aws/user-data.txt

@ -11,7 +11,7 @@
SCRIPT_ROOT_PATH="/tmp/init-script"
VERTSYS_PATH="$SCRIPT_ROOT_PATH/verteilte-systeme-bsc-ai-examples/VerteilteSysteme-Examples/build/"
#JARS = "TCPServer.jar TCPServerMulti.jar UDPServer.jar UDPServerMulti.jar UDPTimeCounterServer.jar TCPTimeCounterServer.jar TCPPerfServer.jar"
JARS="TCPServer.jar TCPPerfServer.jar UDPServer.jar UDPTimeCounterServer.jar TCPTimeCounterServer.jar"
JARS="TCPServer.jar TCPPerfServer.jar UDPServer.jar UDPTimeCounterServer.jar TCPTimeCounterServer.jar TCPTimeCounterRESTServer.jar"
REPO="https://gogs.informatik.hs-fulda.de/srieger/verteilte-systeme-bsc-ai-examples.git"
# Create path to run the script

Loading…
Cancel
Save