use of org.eclipse.jetty.server.NetworkConnector in project spring-boot by spring-projects.
the class JettyWebServer method start.
@Override
public void start() throws WebServerException {
synchronized (this.monitor) {
if (this.started) {
return;
}
this.server.setConnectors(this.connectors);
if (!this.autoStart) {
return;
}
try {
this.server.start();
for (Handler handler : this.server.getHandlers()) {
handleDeferredInitialize(handler);
}
Connector[] connectors = this.server.getConnectors();
for (Connector connector : connectors) {
try {
connector.start();
} catch (IOException ex) {
if (connector instanceof NetworkConnector) {
PortInUseException.throwIfPortBindingException(ex, () -> ((NetworkConnector) connector).getPort());
}
throw ex;
}
}
this.started = true;
logger.info("Jetty started on port(s) " + getActualPortsDescription() + " with context path '" + getContextPath() + "'");
} catch (WebServerException ex) {
stopSilently();
throw ex;
} catch (Exception ex) {
stopSilently();
throw new WebServerException("Unable to start embedded Jetty server", ex);
}
}
}
use of org.eclipse.jetty.server.NetworkConnector in project cxf by apache.
the class CodeGenBugTest method testHelloWorldExternalBindingFile.
@Test
public void testHelloWorldExternalBindingFile() throws Exception {
Server server = new Server(0);
try {
ResourceHandler reshandler = new ResourceHandler();
reshandler.setResourceBase(getLocation("/wsdl2java_wsdl/"));
// this is the only handler we're supposed to need, so we don't need to
// 'add' it.
server.setHandler(reshandler);
server.start();
// give network connector a little time to spin up
Thread.sleep(250);
int port = ((NetworkConnector) server.getConnectors()[0]).getLocalPort();
env.put(ToolConstants.CFG_WSDLURL, "http://localhost:" + port + "/hello_world.wsdl");
env.put(ToolConstants.CFG_BINDING, "http://localhost:" + port + "/remote-hello_world_binding.xsd");
processor.setContext(env);
processor.execute();
reshandler.stop();
} finally {
server.stop();
server.destroy();
}
}
use of org.eclipse.jetty.server.NetworkConnector in project qpid-broker-j by apache.
the class HttpManagement method logOperationalListenMessages.
private void logOperationalListenMessages() {
for (Map.Entry<HttpPort<?>, ServerConnector> portConnector : _portConnectorMap.entrySet()) {
HttpPort<?> port = portConnector.getKey();
NetworkConnector connector = portConnector.getValue();
logOperationalListenMessages(port, connector.getLocalPort());
}
}
use of org.eclipse.jetty.server.NetworkConnector in project dropwizard by dropwizard.
the class DefaultServerFactoryTest method testGracefulShutdown.
@Test
void testGracefulShutdown() throws Exception {
CountDownLatch requestReceived = new CountDownLatch(1);
CountDownLatch shutdownInvoked = new CountDownLatch(1);
environment.jersey().register(new TestResource(requestReceived, shutdownInvoked));
final ScheduledExecutorService executor = Executors.newScheduledThreadPool(3);
http.configure(environment);
final Server server = http.build(environment);
((AbstractNetworkConnector) server.getConnectors()[0]).setPort(0);
((AbstractNetworkConnector) server.getConnectors()[1]).setPort(0);
ScheduledFuture<Void> cleanup = executor.schedule(() -> {
if (!server.isStopped()) {
server.stop();
}
executor.shutdownNow();
return null;
}, 5, TimeUnit.SECONDS);
server.start();
final int port = ((AbstractNetworkConnector) server.getConnectors()[0]).getLocalPort();
Future<String> futureResult = executor.submit(() -> {
URL url = new URL("http://localhost:" + port + "/app/test");
URLConnection connection = url.openConnection();
connection.connect();
try (InputStream in = connection.getInputStream()) {
return new String(ByteStreams.toByteArray(in), StandardCharsets.UTF_8);
}
});
requestReceived.await(10, TimeUnit.SECONDS);
Future<Void> serverStopped = executor.submit(() -> {
server.stop();
return null;
});
Connector[] connectors = server.getConnectors();
assertThat(connectors).isNotEmpty();
assertThat(connectors[0]).isInstanceOf(NetworkConnector.class);
NetworkConnector connector = (NetworkConnector) connectors[0];
// wait for server to close the connectors
while (true) {
if (!connector.isOpen()) {
shutdownInvoked.countDown();
break;
}
Thread.sleep(5);
}
String result = futureResult.get();
assertThat(result).isEqualTo("test");
serverStopped.get();
// cancel the cleanup future since everything succeeded
cleanup.cancel(false);
executor.shutdownNow();
}
use of org.eclipse.jetty.server.NetworkConnector in project spring-framework by spring-projects.
the class WebRequestDataBinderIntegrationTests method startJettyServer.
@BeforeAll
void startJettyServer() throws Exception {
// Let server pick its own random, available port.
jettyServer = new Server(0);
ServletContextHandler handler = new ServletContextHandler();
MultipartConfigElement multipartConfig = new MultipartConfigElement("");
ServletHolder holder = new ServletHolder(partsServlet);
holder.getRegistration().setMultipartConfig(multipartConfig);
handler.addServlet(holder, "/parts");
holder = new ServletHolder(partListServlet);
holder.getRegistration().setMultipartConfig(multipartConfig);
handler.addServlet(holder, "/partlist");
jettyServer.setHandler(handler);
jettyServer.start();
Connector[] connectors = jettyServer.getConnectors();
NetworkConnector connector = (NetworkConnector) connectors[0];
baseUrl = "http://localhost:" + connector.getLocalPort();
}
Aggregations