Browse Source

Merge branch 'master' of ssh://git@gogs.informatik.hs-fulda.de/srieger/verteilte-systeme-bsc-ai-examples.git

master
Sebastian Rieger 6 years ago
parent
commit
db894dffeb
  1. 14
      VerteilteSysteme-Examples/.classpath
  2. BIN
      VerteilteSysteme-Examples/lib/grizzly-http-all-2.4.2.jar
  3. BIN
      VerteilteSysteme-Examples/lib/hk2-api-2.5.0-b42.jar
  4. BIN
      VerteilteSysteme-Examples/lib/hk2-locator-2.5.0-b42.jar
  5. BIN
      VerteilteSysteme-Examples/lib/hk2-utils-2.5.0-b42.jar
  6. BIN
      VerteilteSysteme-Examples/lib/javax.annotation-api-1.2.jar
  7. BIN
      VerteilteSysteme-Examples/lib/javax.inject-2.5.0-b42.jar
  8. BIN
      VerteilteSysteme-Examples/lib/javax.json.bind-api-1.0.jar
  9. BIN
      VerteilteSysteme-Examples/lib/javax.ws.rs-api-2.1.jar
  10. BIN
      VerteilteSysteme-Examples/lib/jersey-client.jar
  11. BIN
      VerteilteSysteme-Examples/lib/jersey-common.jar
  12. BIN
      VerteilteSysteme-Examples/lib/jersey-container-grizzly2-http-2.26.jar
  13. BIN
      VerteilteSysteme-Examples/lib/jersey-hk2.jar
  14. BIN
      VerteilteSysteme-Examples/lib/jersey-server.jar
  15. BIN
      VerteilteSysteme-Examples/lib/validation-api-1.1.0.Final.jar
  16. 64
      VerteilteSysteme-Examples/src/verteiltesysteme/rest/RESTClient.java
  17. 33
      VerteilteSysteme-Examples/src/verteiltesysteme/rest/RESTServer.java
  18. 30
      VerteilteSysteme-Examples/src/verteiltesysteme/rest/RESTToLowerCaseService.java
  19. 30
      VerteilteSysteme-Examples/src/verteiltesysteme/rest/RESTToUpperCaseService.java

14
VerteilteSysteme-Examples/.classpath

@ -2,5 +2,19 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/grizzly-http-all-2.4.2.jar"/>
<classpathentry kind="lib" path="lib/hk2-api-2.5.0-b42.jar"/>
<classpathentry kind="lib" path="lib/hk2-locator-2.5.0-b42.jar"/>
<classpathentry kind="lib" path="lib/hk2-utils-2.5.0-b42.jar"/>
<classpathentry kind="lib" path="lib/javax.annotation-api-1.2.jar"/>
<classpathentry kind="lib" path="lib/javax.inject-2.5.0-b42.jar"/>
<classpathentry kind="lib" path="lib/javax.json.bind-api-1.0.jar"/>
<classpathentry kind="lib" path="lib/javax.ws.rs-api-2.1.jar"/>
<classpathentry kind="lib" path="lib/jersey-client.jar"/>
<classpathentry kind="lib" path="lib/jersey-common.jar"/>
<classpathentry kind="lib" path="lib/jersey-container-grizzly2-http-2.26.jar"/>
<classpathentry kind="lib" path="lib/jersey-hk2.jar"/>
<classpathentry kind="lib" path="lib/jersey-server.jar"/>
<classpathentry kind="lib" path="lib/validation-api-1.1.0.Final.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

BIN
VerteilteSysteme-Examples/lib/grizzly-http-all-2.4.2.jar

BIN
VerteilteSysteme-Examples/lib/hk2-api-2.5.0-b42.jar

BIN
VerteilteSysteme-Examples/lib/hk2-locator-2.5.0-b42.jar

BIN
VerteilteSysteme-Examples/lib/hk2-utils-2.5.0-b42.jar

BIN
VerteilteSysteme-Examples/lib/javax.annotation-api-1.2.jar

BIN
VerteilteSysteme-Examples/lib/javax.inject-2.5.0-b42.jar

BIN
VerteilteSysteme-Examples/lib/javax.json.bind-api-1.0.jar

BIN
VerteilteSysteme-Examples/lib/javax.ws.rs-api-2.1.jar

BIN
VerteilteSysteme-Examples/lib/jersey-client.jar

BIN
VerteilteSysteme-Examples/lib/jersey-common.jar

BIN
VerteilteSysteme-Examples/lib/jersey-container-grizzly2-http-2.26.jar

BIN
VerteilteSysteme-Examples/lib/jersey-hk2.jar

BIN
VerteilteSysteme-Examples/lib/jersey-server.jar

BIN
VerteilteSysteme-Examples/lib/validation-api-1.1.0.Final.jar

64
VerteilteSysteme-Examples/src/verteiltesysteme/rest/RESTClient.java

@ -0,0 +1,64 @@
/* Beispiel angelehnt an http://www.torsten-horn.de/techdocs/jee-rest.htm */
package verteiltesysteme.rest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.ws.rs.client.*;
import javax.ws.rs.core.MediaType;
public class RESTClient {
public static void main(String[] args) {
String baseUrl = (args.length > 1) ? args[1] : "http://localhost:4434";
String webContextPathUpper = "/touppercase";
String webContextPathLower = "/tolowercase";
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
String input = null;
try {
System.out.println("Bitte geben Sie eine Zeichenkette ein: ");
input = inFromUser.readLine();
} catch (IOException e) {
e.printStackTrace();
}
// Nutzung des RESTful Web Service für toUpperCase()
System.out.println("****************************");
System.out.println("* toUpperCase *");
System.out.println("****************************");
System.out.println("\nAngefragte URL: " + baseUrl + webContextPathUpper + "?input=" + input);
Client c = ClientBuilder.newClient();
WebTarget target = c.target(baseUrl);
System.out.println("\nTextausgabe:");
System.out.println(
target.path(webContextPathUpper).queryParam("input", input).request(MediaType.TEXT_PLAIN).get(String.class));
System.out.println("\nJSON-Ausgabe:");
System.out.println(target.path(webContextPathUpper).queryParam("input", input).request(MediaType.APPLICATION_JSON)
.get(String.class));
System.out.println("\nHTML-Ausgabe:");
System.out.println(
target.path(webContextPathUpper).queryParam("input", input).request(MediaType.TEXT_HTML).get(String.class));
// Nutzung des RESTful Web Service für toLowerCase()
System.out.println("\n****************************");
System.out.println("* toLowerCase *");
System.out.println("****************************");
System.out.println("\nAngefragte URL: " + baseUrl + webContextPathLower + "?input=" + input);
System.out.println("\nTextausgabe:");
System.out.println(
target.path(webContextPathLower).queryParam("input", input).request(MediaType.TEXT_PLAIN).get(String.class));
System.out.println("\nJSON-Ausgabe:");
System.out.println(target.path(webContextPathLower).queryParam("input", input).request(MediaType.APPLICATION_JSON)
.get(String.class));
System.out.println("\nHTML-Ausgabe:");
System.out.println(
target.path(webContextPathLower).queryParam("input", input).request(MediaType.TEXT_HTML).get(String.class));
}
}

33
VerteilteSysteme-Examples/src/verteiltesysteme/rest/RESTServer.java

@ -0,0 +1,33 @@
/* Beispiel angelehnt an http://www.torsten-horn.de/techdocs/jee-rest.htm */
package verteiltesysteme.rest;
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 RESTServer
{
public static void main( String[] args ) throws IOException, InterruptedException
{
String baseUrl = ( args.length > 0 ) ? args[0] : "http://localhost:4434";
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(
URI.create( baseUrl ), new ResourceConfig( RESTToUpperCaseService.class, RESTToLowerCaseService.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 + RESTToUpperCaseService.webContextPath);
System.out.println("RESTful Web Service URL: " + baseUrl + RESTToLowerCaseService.webContextPath);
Thread.currentThread().join();
}
}

30
VerteilteSysteme-Examples/src/verteiltesysteme/rest/RESTToLowerCaseService.java

@ -0,0 +1,30 @@
/* Beispiel angelehnt an http://www.torsten-horn.de/techdocs/jee-rest.htm */
package verteiltesysteme.rest;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@Path( RESTToLowerCaseService.webContextPath )
public class RESTToLowerCaseService
{
static final String webContextPath = "/touppercase";
@GET @Produces( MediaType.TEXT_PLAIN )
public String toUpperCasePlain( @QueryParam("input") String input )
{
return "Plain-Text: " + input.toUpperCase();
}
@GET @Produces( MediaType.TEXT_HTML )
public String toUpperCaseHtml( @QueryParam("input") String input )
{
return "<html><title>RESTService</title><body><h2>HTML: " + input.toUpperCase() + "</h2></body></html>";
}
@GET @Produces( MediaType.APPLICATION_JSON )
public String toUpperCaseJson( @QueryParam("input") String input )
{
return "{\n \"type\": \"JSON\",\n \"output\": \"" + input.toUpperCase() + "\"\n}";
}
}

30
VerteilteSysteme-Examples/src/verteiltesysteme/rest/RESTToUpperCaseService.java

@ -0,0 +1,30 @@
/* Beispiel angelehnt an http://www.torsten-horn.de/techdocs/jee-rest.htm */
package verteiltesysteme.rest;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@Path( RESTToUpperCaseService.webContextPath )
public class RESTToUpperCaseService
{
static final String webContextPath = "/tolowercase";
@GET @Produces( MediaType.TEXT_PLAIN )
public String toLowerCasePlain( @QueryParam("input") String input )
{
return "Plain-Text: " + input.toLowerCase();
}
@GET @Produces( MediaType.TEXT_HTML )
public String toLowerCaseHtml( @QueryParam("input") String input )
{
return "<html><title>RESTService</title><body><h2>HTML: " + input.toLowerCase() + "</h2></body></html>";
}
@GET @Produces( MediaType.APPLICATION_JSON )
public String toLowerCaseJson( @QueryParam("input") String input )
{
return "{\n \"type\": \"JSON\",\n \"output\": \"" + input.toLowerCase() + "\"\n}";
}
}
Loading…
Cancel
Save