forked from srieger/verteilte-systeme-bsc-ai-examples
Sebastian Rieger
7 years ago
2 changed files with 95 additions and 95 deletions
-
126VerteilteSysteme-Examples/src/verteiltesysteme/rest/RESTClient.java
-
64VerteilteSysteme-Examples/src/verteiltesysteme/rest/RESTServer.java
@ -1,64 +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)); |
|||
|
|||
} |
|||
/* 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:36040"; |
|||
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)); |
|||
|
|||
} |
|||
} |
@ -1,33 +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(); |
|||
} |
|||
/* 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:36040"; |
|||
|
|||
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(); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue