Commentaries - explanations to the source text of the program, located directly inside the commented code.
public static void main(String[] args) throws IOException {
// "ua.in.link.rest.server" - name of package with classes for Jersey server
ResourceConfig rc = new PackagesResourceConfig("ua.in.link.rest.server");
// creating httpServer for url "http://localhost:8080"
HttpServer httpServer = GrizzlyServerFactory.createHttpServer("http://localhost:8080", rc);
InetSocketAddress socketAddres = httpServer.getAddress();
doSomethisWithSocket(socketAddres); // waiting for Enter before stoping the server
System.in.read();
httpServer.stop();
}
// "ua.in.link.rest.server" - name of package with classes for Jersey server
ResourceConfig rc = new PackagesResourceConfig("ua.in.link.rest.server");
private static final String JERSEY_CLASSES_PACKAGE_NAME = "ua.in.link.rest.server";
public static void main(String[] args) throws IOException {
ResourceConfig rc = new PackagesResourceConfig(JERSEY_CLASSES_PACKAGE_NAME);
// creating httpServer for url "http://localhost:8080"
HttpServer httpServer = GrizzlyServerFactory.createHttpServer("http://localhost:8080", rc);
InetSocketAddress socketAddres = httpServer.getAddress();
doSomethisWithSocket(socketAddres);
// waiting for Enter before stoping the server
System.in.read();
httpServer.stop();
}
// creating httpServer for url "http://localhost:8080"
HttpServer httpServer = GrizzlyServerFactory.createHttpServer("http://localhost:8080", rc);
InetSocketAddress socketAddres = httpServer.getAddress();
doSomethisWithSocket(socketAddres);
HttpServer httpServer = GrizzlyServerFactory.createHttpServer("http://localhost:8080", rc);
HttpServer httpServer = GrizzlyServerFactory.createHttpServer("http://localhost:8080", rc);
InetSocketAddress socketAddres = httpServer.getAddress();
doSomethisWithSocket(socketAddres);
ResourceConfig rc = new PackagesResourceConfig(JERSEY_CLASSES_PACKAGE_NAME);
private static final String JERSEY_CLASSES_PACKAGE_NAME = "ua.in.link.rest.server";
private static final String SERVER_URL = "http://localhost:8080";
public static void main(String[] args) throws IOException {
HttpServer httpServer = startServer();
InetSocketAddress socketAddres = httpServer.getAddress();
prepareSocket(socketAddres);
// waiting for Enter before stoping the server
System.in.read();
httpServer.stop();
}
private static HttpServer startServer() {
ResourceConfig rc = new PackagesResourceConfig(JERSEY_CLASSES_PACKAGE_NAME);
return GrizzlyServerFactory.createHttpServer(SERVER_URL, rc);
}
private static void prepareSocket(InetSocketAddress socketAddres){
doSomethisWithSocket(socketAddres);
}
private static HttpServer startServer() {
ResourceConfig rc = new PackagesResourceConfig(JERSEY_CLASSES_PACKAGE_NAME);
HttpServer httpServer = GrizzlyServerFactory.createHttpServer(SERVER_URL, rc);
InetSocketAddress socketAddres = httpServer.getAddress();
prepareSocket(socketAddres);
return httpServer;
}
private static final String JERSEY_CLASSES_PACKAGE_NAME = "ua.in.link.rest.server";
private static final String SERVER_URL = "http://localhost:8080";
private static final String PRESS_ENTER__TO_STOP_STRING = "Press Enter to stop server";
public static void main(String[] args) throws IOException {
HttpServer httpServer = startServer();
InetSocketAddress socketAddres = httpServer.getAddress();
prepareSocket(socketAddres);
userStopsServer(httpServer);
}
private static HttpServer startServer() {
ResourceConfig rc = new PackagesResourceConfig(JERSEY_CLASSES_PACKAGE_NAME);
return GrizzlyServerFactory.createHttpServer(SERVER_URL, rc);
}
private static void prepareSocket(InetSocketAddress socketAddres){
doSomethisWithSocket(socketAddres);
}
private static void userStopsServer(HttpServer httpServer){
System.out.println(PRESS_ENTER__TO_STOP_STRING + httpServer.toString());
System.in.read();
httpServer.stop();
}
, , ; , , — , , , , ., , , . . ( ), — , .
/**
*
*
*
*
* @_
* @return _
*/
Source: https://habr.com/ru/post/178653/
All Articles