You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
2.1 KiB

  1. /* Beispiel angelehnt an http://www.torsten-horn.de/techdocs/jee-rest.htm */
  2. package verteiltesysteme.rest;
  3. import java.io.IOException;
  4. import java.net.URI;
  5. import org.glassfish.grizzly.http.server.HttpServer;
  6. import org.glassfish.grizzly.ssl.SSLContextConfigurator;
  7. import org.glassfish.grizzly.ssl.SSLEngineConfigurator;
  8. import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
  9. import org.glassfish.jersey.server.ResourceConfig;
  10. public class RESTSSLServer
  11. {
  12. private static final String KEYSTORE_SERVER_FILE = "./build/keystore_server";
  13. private static final String KEYSTORE_SERVER_PWD = "notsecure";
  14. public static void main( String[] args ) throws IOException, InterruptedException
  15. {
  16. String baseUrl = ( args.length > 0 ) ? args[0] : "http://localhost:36040";
  17. // Grizzly ssl configuration
  18. SSLContextConfigurator sslContext = new SSLContextConfigurator();
  19. // set up security context
  20. sslContext.setKeyStoreFile(KEYSTORE_SERVER_FILE); // contains server keypair
  21. sslContext.setKeyStorePass(KEYSTORE_SERVER_PWD);
  22. // keytool -genkey -keystore ./keystore_server -alias serverKey -dname "CN=localhost, OU=VertSys, O=HS-Fulda, L=Fulda, ST=Hessen, C=DE"
  23. final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(
  24. URI.create( baseUrl ), new ResourceConfig( RESTToUpperCaseService.class, RESTToLowerCaseService.class ), true, new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false) );
  25. Runtime.getRuntime().addShutdownHook( new Thread( new Runnable() {
  26. @Override
  27. public void run() {
  28. server.shutdownNow();
  29. }
  30. } ) );
  31. server.start();
  32. System.out.println("Grizzly-HTTP-Server gestartet");
  33. System.out.println("Stoppen des Grizzly-HTTP-Servers mit: Strg+C\n");
  34. System.out.println("RESTful Web Service URL: " + baseUrl + RESTToUpperCaseService.webContextPath);
  35. System.out.println("RESTful Web Service URL: " + baseUrl + RESTToLowerCaseService.webContextPath);
  36. Thread.currentThread().join();
  37. }
  38. }