use of org.simpleframework.transport.connect.Connection in project gradle by gradle.
the class SimpleHttpFileServerFactory method start.
public HttpFileServer start(File contentRoot, int port) {
Container container = new SimpleFileServerContainer(new FileContext(contentRoot));
try {
final Server server = new ContainerServer(container);
Connection connection = new SocketConnection(server);
InetSocketAddress address = new InetSocketAddress(port);
InetSocketAddress usedAddress = (InetSocketAddress) connection.connect(address);
return new SimpleHttpFileServer(contentRoot, usedAddress.getPort(), new Stoppable() {
public void stop() {
try {
server.stop();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
});
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.simpleframework.transport.connect.Connection in project jersey by jersey.
the class SimpleContainerFactory method _create.
private static SimpleServer _create(final URI address, final SSLContext context, final SimpleContainer container, final UnsafeValue<SocketProcessor, IOException> serverProvider) throws ProcessingException {
if (address == null) {
throw new IllegalArgumentException(LocalizationMessages.URI_CANNOT_BE_NULL());
}
final String scheme = address.getScheme();
int defaultPort = org.glassfish.jersey.server.spi.Container.DEFAULT_HTTP_PORT;
if (context == null) {
if (!scheme.equalsIgnoreCase("http")) {
throw new IllegalArgumentException(LocalizationMessages.WRONG_SCHEME_WHEN_USING_HTTP());
}
} else {
if (!scheme.equalsIgnoreCase("https")) {
throw new IllegalArgumentException(LocalizationMessages.WRONG_SCHEME_WHEN_USING_HTTPS());
}
defaultPort = org.glassfish.jersey.server.spi.Container.DEFAULT_HTTPS_PORT;
}
int port = address.getPort();
if (port == -1) {
port = defaultPort;
}
final InetSocketAddress listen = new InetSocketAddress(port);
final Connection connection;
try {
final SimpleTraceAnalyzer analyzer = new SimpleTraceAnalyzer();
final SocketProcessor server = serverProvider.get();
connection = new SocketConnection(server, analyzer);
final SocketAddress socketAddr = connection.connect(listen, context);
container.onServerStart();
return new SimpleServer() {
@Override
public void close() throws IOException {
container.onServerStop();
analyzer.stop();
connection.close();
}
@Override
public int getPort() {
return ((InetSocketAddress) socketAddr).getPort();
}
@Override
public boolean isDebug() {
return analyzer.isActive();
}
@Override
public void setDebug(boolean enable) {
if (enable) {
analyzer.start();
} else {
analyzer.stop();
}
}
};
} catch (final IOException ex) {
throw new ProcessingException(LocalizationMessages.ERROR_WHEN_CREATING_SERVER(), ex);
}
}
Aggregations