|
@ -11,14 +11,15 @@ import com.amazonaws.services.s3.AmazonS3ClientBuilder; |
|
|
public class TCPTimeCounterRESTService { |
|
|
public class TCPTimeCounterRESTService { |
|
|
static final String webContextPath = "/counter"; |
|
|
static final String webContextPath = "/counter"; |
|
|
static final String bucketName = "vertsys-counter"; |
|
|
static final String bucketName = "vertsys-counter"; |
|
|
|
|
|
|
|
|
|
|
|
static final String dnsNameELB = "VertSys-ELB1-b88aad9416b2929b.elb.eu-central-1.amazonaws.com"; |
|
|
|
|
|
|
|
|
private Long getCounter() { |
|
|
private Long getCounter() { |
|
|
// Verbindung zu S3 |
|
|
// Verbindung zu S3 |
|
|
AmazonS3 s3Client = AmazonS3ClientBuilder.defaultClient(); |
|
|
AmazonS3 s3Client = AmazonS3ClientBuilder.defaultClient(); |
|
|
String region = s3Client.getRegionName(); |
|
|
String region = s3Client.getRegionName(); |
|
|
return new Long(s3Client.getObjectAsString(bucketName, region)); |
|
|
return new Long(s3Client.getObjectAsString(bucketName, region)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean setCounter(Long counter) { |
|
|
private boolean setCounter(Long counter) { |
|
|
// Verbindung zu S3 |
|
|
// Verbindung zu S3 |
|
|
AmazonS3 s3Client = AmazonS3ClientBuilder.defaultClient(); |
|
|
AmazonS3 s3Client = AmazonS3ClientBuilder.defaultClient(); |
|
@ -36,7 +37,10 @@ public class TCPTimeCounterRESTService { |
|
|
@GET |
|
|
@GET |
|
|
@Produces(MediaType.TEXT_HTML) |
|
|
@Produces(MediaType.TEXT_HTML) |
|
|
public String getCounterHtml() { |
|
|
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>"; |
|
|
|
|
|
|
|
|
return "<html><head><title>TCPTimeCounter REST Service</title>" + |
|
|
|
|
|
"<meta http-equiv=\"refresh\" content=\"5\"/></head><body>" + |
|
|
|
|
|
"<h2>Verteilte Systeme HS Fulda - TCPTimeCounter REST Service</h2>"+ |
|
|
|
|
|
"<p><b>HTML-Output:</b> " + getCounter() + "</p></body></html>"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@GET |
|
|
@GET |
|
@ -50,7 +54,7 @@ public class TCPTimeCounterRESTService { |
|
|
@Produces(MediaType.TEXT_PLAIN) |
|
|
@Produces(MediaType.TEXT_PLAIN) |
|
|
public String incrCounterPlain(@FormParam("input") String input) { |
|
|
public String incrCounterPlain(@FormParam("input") String input) { |
|
|
Long currentCounterValue = getCounter(); |
|
|
Long currentCounterValue = getCounter(); |
|
|
currentCounterValue = currentCounterValue + (new Long(input)).longValue(); |
|
|
|
|
|
|
|
|
currentCounterValue = currentCounterValue + (new Long(input)).longValue(); |
|
|
setCounter(currentCounterValue); |
|
|
setCounter(currentCounterValue); |
|
|
return "Plain-Text: TCPTimeCounter counter increased by " + input + " to " + currentCounterValue; |
|
|
return "Plain-Text: TCPTimeCounter counter increased by " + input + " to " + currentCounterValue; |
|
|
} |
|
|
} |
|
@ -60,9 +64,14 @@ public class TCPTimeCounterRESTService { |
|
|
@Produces(MediaType.TEXT_HTML) |
|
|
@Produces(MediaType.TEXT_HTML) |
|
|
public String incrCounterHtml(@FormParam("input") String input) { |
|
|
public String incrCounterHtml(@FormParam("input") String input) { |
|
|
Long currentCounterValue = getCounter(); |
|
|
Long currentCounterValue = getCounter(); |
|
|
currentCounterValue = currentCounterValue + (new Long(input)).longValue(); |
|
|
|
|
|
|
|
|
currentCounterValue = currentCounterValue + (new Long(input)).longValue(); |
|
|
setCounter(currentCounterValue); |
|
|
setCounter(currentCounterValue); |
|
|
return "<html><title>TCPTimeCounter counter increased by " + input + " to " + currentCounterValue + "</h2></body></html>"; |
|
|
|
|
|
|
|
|
return "<html><head><title>TCPTimeCounter REST Service</title></head></body>" + |
|
|
|
|
|
"<h2>Verteilte Systeme HS Fulda - TCPTimeCounter REST Service</h2>" + |
|
|
|
|
|
"<p><b>HTML-Output:</b> counter increased by " + |
|
|
|
|
|
input + " to " + currentCounterValue + "</p>" + |
|
|
|
|
|
"<form method=POST action=\"http://" + dnsNameELB + ":36042/counter\">" + |
|
|
|
|
|
"<input name=\"input\" value=\"\"></form></body></html>"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@POST |
|
|
@POST |
|
@ -72,7 +81,8 @@ public class TCPTimeCounterRESTService { |
|
|
Long currentCounterValue = getCounter(); |
|
|
Long currentCounterValue = getCounter(); |
|
|
currentCounterValue = currentCounterValue + (new Long(input)).longValue(); |
|
|
currentCounterValue = currentCounterValue + (new Long(input)).longValue(); |
|
|
setCounter(currentCounterValue); |
|
|
setCounter(currentCounterValue); |
|
|
return "{\n \"type\": \"JSON\",\n \"output\": \"Plain-Text: TCPTimeCounter counter increased by " + input + " to " + currentCounterValue + "\"\n}"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return "{\n \"type\": \"JSON\",\n \"output\": \"Plain-Text: TCPTimeCounter counter increased by " + input |
|
|
|
|
|
+ " to " + currentCounterValue + "\"\n}"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |