本文整理匯總了Java中org.apache.http.impl.nio.DefaultNHttpServerConnection類的典型用法代碼示例。如果您正苦於以下問題:Java DefaultNHttpServerConnection類的具體用法?Java DefaultNHttpServerConnection怎麽用?Java DefaultNHttpServerConnection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DefaultNHttpServerConnection類屬於org.apache.http.impl.nio包,在下文中一共展示了DefaultNHttpServerConnection類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: start
import org.apache.http.impl.nio.DefaultNHttpServerConnection; //導入依賴的package包/類
public void start() throws Exception {
// Create HTTP protocol basic processing chain
HttpProcessor httpProcessor = HttpProcessorBuilder.create()
.add(new ResponseDate()).add(new ResponseContent())
.add(new ResponseConnControl()).build();
// Create server
HttpAsyncService protocolHandler = new HttpAsyncService(httpProcessor,
uriMapper);
NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory = new DefaultNHttpServerConnectionFactory();
IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(
protocolHandler, connFactory);
IOReactorConfig config = IOReactorConfig.custom()
.setIoThreadCount(threads).setSoReuseAddress(true).build();
ListeningIOReactor ioReactor = new DefaultListeningIOReactor(config);
// Start server
ioReactor.listen(new InetSocketAddress(port));
ioReactor.execute(ioEventDispatch);
}
示例2: OppoMessenger
import org.apache.http.impl.nio.DefaultNHttpServerConnection; //導入依賴的package包/類
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED")
public OppoMessenger(final String remoteHost, final int remotePort, final int localPort,
final HttpClientService httpClient)
throws IOException {
this.httpClient = httpClient;
// Set up the server
final HttpProcessor processor = HttpProcessorBuilder.create()
.add(new ResponseContent())
.add(new ResponseContentEncoding())
.add(new ResponseConnControl())
.build();
final HttpAsyncService service = new HttpAsyncService(processor, mapper);
final NHttpConnectionFactory<DefaultNHttpServerConnection> connectionFactory = new DefaultNHttpServerConnectionFactory(ConnectionConfig.DEFAULT);
final IOEventDispatch dispatch = new DefaultHttpServerIODispatch(service, connectionFactory);
server = new DefaultListeningIOReactor(IOReactorConfig.DEFAULT);
server.listen(new InetSocketAddress(localPort));
new Thread(new Runnable() {
@Override public void run() {
try {
server.execute(dispatch);
} catch (final IOException e) {
logger().level(Error).message("HTTP server failed").error(e).log();
}
}
}, "Oppo HTTP server");
// Set up the client
deviceUrlBase = "http://" + remoteHost + ':' + remotePort + '/';
}