use of org.apache.hc.core5.http.io.SocketConfig in project JAuswertung by dennisfabri.
the class HttpServerPlugin method startUp.
boolean startUp() {
try {
state = true;
final SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(15, TimeUnit.SECONDS).setTcpNoDelay(true).build();
httpServer = ServerBootstrap.bootstrap().setListenerPort(port).setSocketConfig(socketConfig).setExceptionListener(new ExceptionListener() {
@Override
public void onError(final Exception ex) {
ex.printStackTrace();
}
@Override
public void onError(final HttpConnection conn, final Exception ex) {
if (ex instanceof SocketTimeoutException) {
System.err.println("Connection timed out");
} else if (ex instanceof ConnectionClosedException) {
System.err.println(ex.getMessage());
} else {
ex.printStackTrace();
}
}
}).register("*", new DPRequestHandler(getDataProvider())).create();
httpServer.start();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
httpServer.close(CloseMode.GRACEFUL);
}
});
httpServer.start();
httpOptions.setEnabled(false);
filter.setEnabled(source.getExportMode() == ExportMode.Filtered);
return true;
} catch (Exception e) {
e.printStackTrace();
DialogUtils.wichtigeMeldung(null, I18n.get("HttpServerNotStartet"));
shutDown();
httpServer = null;
state = false;
httpOptions.setEnabled(true);
filter.setEnabled(false);
return false;
}
}
use of org.apache.hc.core5.http.io.SocketConfig in project sonarlint-language-server by SonarSource.
the class SecurityHotspotsHandlerServer method initialize.
public void initialize(String ideName, String clientVersion, @Nullable String workspaceName) {
final var socketConfig = SocketConfig.custom().setSoTimeout(15, TimeUnit.SECONDS).setTcpNoDelay(true).build();
port = INVALID_PORT;
var triedPort = STARTING_PORT;
HttpServer startedServer = null;
while (port < 0 && triedPort <= ENDING_PORT) {
try {
startedServer = ServerBootstrap.bootstrap().setLocalAddress(InetAddress.getLoopbackAddress()).setListenerPort(triedPort).setSocketConfig(socketConfig).addFilterFirst("CORS", new CorsFilter()).register("/sonarlint/api/status", new StatusRequestHandler(ideName, clientVersion, workspaceName)).register("/sonarlint/api/hotspots/show", new ShowHotspotRequestHandler(output, bindingManager, client, telemetry)).create();
startedServer.start();
port = triedPort;
} catch (Exception t) {
output.debug("Error while starting port: " + t.getMessage());
triedPort++;
}
}
if (port > 0) {
output.info("Started security hotspot handler on port " + port);
server = startedServer;
} else {
output.error("Unable to start security hotspot handler");
server = null;
}
}
use of org.apache.hc.core5.http.io.SocketConfig in project eomcs-java by eomcs.
the class Exam0110 method main.
public static void main(final String[] args) throws Exception {
final SocketConfig socketConfig = //
SocketConfig.custom().setSoTimeout(15, //
TimeUnit.SECONDS).setTcpNoDelay(//
true).build();
final HttpServer server = //
ServerBootstrap.bootstrap().setListenerPort(// 웹서버 포트 번호 설정
9999).setSocketConfig(// 기본 소켓 동작 설정
socketConfig).setSslContext(// SSL 설정
null).setExceptionListener(// 예외 처리자 설정
new MyExceptionListener()).register("*", // 요청 처리자 설정
new HttpFileHandler()).create();
// 웹서버를 시작시킨다.
server.start();
// 웹서버를 종료시키는 스레드를 등록한다.
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
server.close(CloseMode.GRACEFUL);
}
});
System.out.println("서버 시작(9999)!");
server.awaitTermination(TimeValue.MAX_VALUE);
}
use of org.apache.hc.core5.http.io.SocketConfig in project eomcs-java by eomcs.
the class Exam0210 method main.
public static void main(final String[] args) throws Exception {
final SocketConfig socketConfig = //
SocketConfig.custom().setSoTimeout(15, //
TimeUnit.SECONDS).setTcpNoDelay(//
true).build();
final HttpServer server = //
ServerBootstrap.bootstrap().setListenerPort(// 웹서버 포트 번호 설정
9999).setSocketConfig(// 기본 소켓 동작 설정
socketConfig).setSslContext(// SSL 설정
null).setExceptionListener(// 예외 처리자 설정
new MyExceptionListener()).register("*", // 요청 처리자 설정
new MyRequestHandler()).create();
// 웹서버를 시작시킨다.
server.start();
// 웹서버를 종료시키는 스레드를 등록한다.
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
server.close(CloseMode.GRACEFUL);
}
});
System.out.println("서버 시작(9999)!");
server.awaitTermination(TimeValue.MAX_VALUE);
}
use of org.apache.hc.core5.http.io.SocketConfig in project httpcomponents-core by apache.
the class ClassicFileServerExample method main.
public static void main(final String[] args) throws Exception {
if (args.length < 1) {
System.err.println("Please specify document root directory");
System.exit(1);
}
// Document root directory
final String docRoot = args[0];
int port = 8080;
if (args.length >= 2) {
port = Integer.parseInt(args[1]);
}
SSLContext sslContext = null;
if (port == 8443) {
// Initialize SSL context
final URL url = ClassicFileServerExample.class.getResource("/my.keystore");
if (url == null) {
System.out.println("Keystore not found");
System.exit(1);
}
sslContext = SSLContexts.custom().loadKeyMaterial(url, "secret".toCharArray(), "secret".toCharArray()).build();
}
final SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(15, TimeUnit.SECONDS).setTcpNoDelay(true).build();
final HttpServer server = ServerBootstrap.bootstrap().setListenerPort(port).setSocketConfig(socketConfig).setSslContext(sslContext).setExceptionListener(new ExceptionListener() {
@Override
public void onError(final Exception ex) {
ex.printStackTrace();
}
@Override
public void onError(final HttpConnection conn, final Exception ex) {
if (ex instanceof SocketTimeoutException) {
System.err.println("Connection timed out");
} else if (ex instanceof ConnectionClosedException) {
System.err.println(ex.getMessage());
} else {
ex.printStackTrace();
}
}
}).register("*", new HttpFileHandler(docRoot)).create();
server.start();
Runtime.getRuntime().addShutdownHook(new Thread(() -> server.close(CloseMode.GRACEFUL)));
System.out.println("Listening on port " + port);
server.awaitTermination(TimeValue.MAX_VALUE);
}
Aggregations