本文整理汇总了Java中org.apache.http.impl.bootstrap.ServerBootstrap类的典型用法代码示例。如果您正苦于以下问题:Java ServerBootstrap类的具体用法?Java ServerBootstrap怎么用?Java ServerBootstrap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServerBootstrap类属于org.apache.http.impl.bootstrap包,在下文中一共展示了ServerBootstrap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: start
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
/**
* Starts the HTTP server.
*
* @return the listening port.
*/
static int start () throws IOException
{
server = ServerBootstrap.bootstrap ().registerHandler ("*",
new HttpRequestHandler ()
{
@Override
public void handle (HttpRequest request, HttpResponse response,
HttpContext context)
throws HttpException, IOException
{
response.setStatusCode (HttpStatus.SC_OK);
response.setEntity (new StringEntity ("0123456789"));
}
})
.create ();
server.start ();
return server.getLocalPort ();
}
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:28,代码来源:TestInterruptibleHttpClient.java
示例2: setUp
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("/content", new HttpRequestHandler() {
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
String contentType = request.getFirstHeader(Exchange.CONTENT_TYPE).getValue();
assertEquals(CONTENT_TYPE, contentType);
response.setEntity(new StringEntity(contentType, "ASCII"));
response.setStatusCode(HttpStatus.SC_OK);
}
}).create();
localServer.start();
super.setUp();
}
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:HttpProducerContentTypeTest.java
示例3: setUp
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
Map<String, String> expectedHeaders = new HashMap<String, String>();
expectedHeaders.put("Content-Type", "text/plain");
expectedHeaders.put("Content-Encoding", "gzip");
localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("/", new HeaderValidationHandler("POST", null, getBody(), getExpectedContent(), expectedHeaders)).create();
localServer.start();
super.setUp();
}
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:HttpCompressionTest.java
示例4: setUp
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("/search", new BasicValidationHandler("GET", null, null, getExpectedContent())).
registerHandler("/test%20/path", new BasicValidationHandler("GET", null, null, getExpectedContent())).
registerHandler("/testWithQueryParams", new BasicValidationHandler("GET", "abc=123", null, getExpectedContent())).
create();
localServer.start();
super.setUp();
}
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:HttpPathTest.java
示例5: setUp
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("/test", new RedirectHandler(HttpStatus.SC_MOVED_PERMANENTLY)).
registerHandler("/someplaceelse", new BasicValidationHandler("GET", null, null, "Bye World")).
registerHandler("/test", new RedirectHandler(HttpStatus.SC_MOVED_PERMANENTLY)).
create();
localServer.start();
super.setUp();
}
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:HttpRedirectTest.java
示例6: setUp
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
Map<String, String> expectedHeaders = new HashMap<>();
expectedHeaders.put("Proxy-Connection", "Keep-Alive");
proxy = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("*", new HeaderValidationHandler("GET", null, null, getExpectedContent(), expectedHeaders)).create();
proxy.start();
super.setUp();
}
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:HttpProxyServerTest.java
示例7: setUp
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("/", new HttpRequestHandler() {
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
response.setStatusCode(HttpStatus.SC_OK);
response.setEntity(new StringEntity("" + counter.incrementAndGet()));
}
}).create();
localServer.start();
super.setUp();
}
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:HttpConcurrentTest.java
示例8: setUp
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("/", new BasicValidationHandler("GET", "hl=en&q=camel", null, getExpectedContent())).
registerHandler("/test/", new BasicValidationHandler("GET", "[email protected]+camel", null, getExpectedContent())).
registerHandler("/user/pass", new BasicValidationHandler("GET", "password=baa&username=foo", null, getExpectedContent())).
create();
localServer.start();
super.setUp();
}
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:HttpQueryTest.java
示例9: setUp
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("/myapp", new HttpRequestHandler() {
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
String uri = request.getRequestLine().getUri();
assertEquals("/myapp?from=me&to=foo&to=bar", uri);
response.setHeader("bar", "yes");
response.addHeader("foo", "123");
response.addHeader("foo", "456");
response.setEntity(new StringEntity("OK", "ASCII"));
response.setStatusCode(HttpStatus.SC_OK);
}
}).create();
localServer.start();
super.setUp();
}
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:HttpProducerTwoParametersWithSameKeyTest.java
示例10: setUp
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("/myget", new BasicValidationHandler("GET", null, null, getExpectedContent())).
registerHandler("/mypost", new BasicValidationHandler("POST", null, null, getExpectedContent())).
registerHandler("/myget2", new BasicValidationHandler("GET", "q=Camel", null, getExpectedContent())).
create();
localServer.start();
super.setUp();
}
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:HttpProducerSelectMethodTest.java
示例11: setUp
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
Map<String, String> expectedHeaders = new HashMap<String, String>();
expectedHeaders.put("TestHeader", "test");
expectedHeaders.put("Accept-Language", "pl");
localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("/", new MyHeaderValidationHandler("GET", "HTTP/1.0", getExpectedContent(), expectedHeaders)).create();
localServer.start();
super.setUp();
}
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:HttpCamelHeadersTest.java
示例12: setUp
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("/get", new BasicValidationHandler("GET", null, null, getExpectedContent())).
registerHandler("/patch", new BasicValidationHandler("PATCH", null, null, getExpectedContent())).
registerHandler("/patch1", new BasicValidationHandler("PATCH", null, "rocks camel?", getExpectedContent())).
registerHandler("/post", new BasicValidationHandler("POST", null, null, getExpectedContent())).
registerHandler("/post1", new BasicValidationHandler("POST", null, null, getExpectedContent())).
registerHandler("/put", new BasicValidationHandler("PUT", null, null, getExpectedContent())).
registerHandler("/trace", new BasicValidationHandler("TRACE", null, null, getExpectedContent())).
registerHandler("/options", new BasicValidationHandler("OPTIONS", null, null, getExpectedContent())).
registerHandler("/delete", new BasicValidationHandler("DELETE", null, null, getExpectedContent())).
registerHandler("/head", new BasicValidationHandler("HEAD", null, null, getExpectedContent())).create();
localServer.start();
super.setUp();
}
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:HttpMethodsTest.java
示例13: setUp
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
Map<String, String> expectedHeaders = new HashMap<>();
expectedHeaders.put("User-Agent", "myCoolCamelCaseAgent");
localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("*", new HeaderValidationHandler("GET", null, null, getExpectedContent(), expectedHeaders)).create();
localServer.start();
super.setUp();
}
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:HttpProducerWithSystemPropertiesTest.java
示例14: setUp
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
Map<String, String> expectedHeaders = new HashMap<String, String>();
expectedHeaders.put("Content-Type", "image/jpeg");
localServer = ServerBootstrap.bootstrap().
setHttpProcessor(getBasicHttpProcessor()).
setConnectionReuseStrategy(getConnectionReuseStrategy()).
setResponseFactory(getHttpResponseFactory()).
setExpectationVerifier(getHttpExpectationVerifier()).
setSslContext(getSSLContext()).
registerHandler("/post", new BasicValidationHandler("POST", null, getBody(), getExpectedContent())).
registerHandler("/post1", new HeaderValidationHandler("POST", null, null, getExpectedContent(), expectedHeaders)).
create();
localServer.start();
super.setUp();
}
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:HttpBodyTest.java
示例15: setUp
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
final SocketConfig socketConfig = SocketConfig.custom()
.setSoTimeout(15000)
.build();
this.serverBootstrap = ServerBootstrap.bootstrap()
.setSocketConfig(socketConfig)
.setServerInfo(ORIGIN)
.registerHandler("/echo/*", new EchoHandler())
.registerHandler("/random/*", new RandomHandler());
if (this.scheme.equals(ProtocolScheme.https)) {
this.serverBootstrap.setSslContext(SSLTestContexts.createServerSSLContext());
}
this.connManager = new PoolingHttpClientConnectionManager();
this.clientBuilder = HttpClientBuilder.create()
.setDefaultSocketConfig(socketConfig)
.setConnectionManager(this.connManager);
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:20,代码来源:LocalServerTestBase.java
示例16: testBasicSSL
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Test
public void testBasicSSL() throws Exception {
this.server = ServerBootstrap.bootstrap()
.setServerInfo(LocalServerTestBase.ORIGIN)
.setSslContext(SSLTestContexts.createServerSSLContext())
.create();
this.server.start();
final HttpContext context = new BasicHttpContext();
final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
SSLTestContexts.createClientSSLContext(), hostVerifier);
final Socket socket = socketFactory.createSocket(context);
final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
try {
final SSLSession sslsession = sslSocket.getSession();
Assert.assertNotNull(sslsession);
Assert.assertTrue(hostVerifier.isFired());
} finally {
sslSocket.close();
}
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestSSLSocketFactory.java
示例17: testBasicDefaultHostnameVerifier
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Test
public void testBasicDefaultHostnameVerifier() throws Exception {
this.server = ServerBootstrap.bootstrap()
.setServerInfo(LocalServerTestBase.ORIGIN)
.setSslContext(SSLTestContexts.createServerSSLContext())
.create();
this.server.start();
final HttpContext context = new BasicHttpContext();
final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
SSLTestContexts.createClientSSLContext(), SSLConnectionSocketFactory.getDefaultHostnameVerifier());
final Socket socket = socketFactory.createSocket(context);
final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
try {
final SSLSession sslsession = sslSocket.getSession();
Assert.assertNotNull(sslsession);
} finally {
sslSocket.close();
}
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:24,代码来源:TestSSLSocketFactory.java
示例18: testClientAuthSSL
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Test
public void testClientAuthSSL() throws Exception {
this.server = ServerBootstrap.bootstrap()
.setServerInfo(LocalServerTestBase.ORIGIN)
.setSslContext(SSLTestContexts.createServerSSLContext())
.create();
this.server.start();
final HttpContext context = new BasicHttpContext();
final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
SSLTestContexts.createClientSSLContext(), hostVerifier);
final Socket socket = socketFactory.createSocket(context);
final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
try {
final SSLSession sslsession = sslSocket.getSession();
Assert.assertNotNull(sslsession);
Assert.assertTrue(hostVerifier.isFired());
} finally {
sslSocket.close();
}
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestSSLSocketFactory.java
示例19: testSSLTrustVerification
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Test(expected=SSLException.class)
public void testSSLTrustVerification() throws Exception {
this.server = ServerBootstrap.bootstrap()
.setServerInfo(LocalServerTestBase.ORIGIN)
.setSslContext(SSLTestContexts.createServerSSLContext())
.create();
this.server.start();
final HttpContext context = new BasicHttpContext();
// Use default SSL context
final SSLContext defaultsslcontext = SSLContexts.createDefault();
final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(defaultsslcontext,
NoopHostnameVerifier.INSTANCE);
final Socket socket = socketFactory.createSocket(context);
final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
sslSocket.close();
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:22,代码来源:TestSSLSocketFactory.java
示例20: getDefaultServer
import org.apache.http.impl.bootstrap.ServerBootstrap; //导入依赖的package包/类
private static HttpServer getDefaultServer(Path folderRoot) {
return ServerBootstrap.bootstrap()
.setListenerPort(PhotatoConfig.serverPort)
.setServerInfo(serverName)
.setSocketConfig(getSocketConfig())
.setExceptionLogger(new StdErrorExceptionLogger())
.registerHandler("*", new LoadingHandler(folderRoot))
.create();
}
开发者ID:trebonius0,项目名称:Photato,代码行数:10,代码来源:Photato.java
注:本文中的org.apache.http.impl.bootstrap.ServerBootstrap类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论