use of org.simpleframework.transport.SocketProcessor 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