/* 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"; static final String bucketRegion = "eu-central-1"; private Long getCounter() { // Verbindung zu S3 AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(bucketRegion).build(); return new Long(s3Client.getObjectAsString(bucketName, bucketRegion)); } private boolean setCounter(Long counter) { // Verbindung zu S3 AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(bucketRegion).build(); s3Client.putObject(bucketName, bucketRegion, 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-Output: " + getCounter() + "
"+ "