本文整理汇总了Java中com.ning.http.client.AsyncHttpClient.close方法的典型用法代码示例。如果您正苦于以下问题:Java AsyncHttpClient.close方法的具体用法?Java AsyncHttpClient.close怎么用?Java AsyncHttpClient.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ning.http.client.AsyncHttpClient
的用法示例。
在下文中一共展示了AsyncHttpClient.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import com.ning.http.client.AsyncHttpClient; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
AsyncHttpClient client = new AsyncHttpClient();
try {
Future<Response> f = client.preparePost(webServer.getCallHttpUrl()).addParameter("param1", "value1").execute();
Response response = f.get();
} finally {
client.close();
}
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
String destinationId = webServer.getHostAndPort();
String httpUrl = webServer.getCallHttpUrl();
verifier.verifyTrace(event("ASYNC_HTTP_CLIENT", AsyncHttpClient.class.getMethod("executeRequest", Request.class, AsyncHandler.class), null, null, destinationId,
annotation("http.url", httpUrl)));
verifier.verifyTraceCount(0);
}
示例2: shouldGetBadRequest
import com.ning.http.client.AsyncHttpClient; //导入方法依赖的package包/类
@Test
public void shouldGetBadRequest() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final AsyncHttpClient c = new AsyncHttpClient();
template.sendBody(RouteManager.SEDA_INPUT,jsonDiff);
latch.await(2,TimeUnit.SECONDS);
//get a sessionid
Response r1 = c.prepareGet("http://localhost:"+restPort+SIGNALK_AUTH+"/demo/pass").execute().get();
//latch2.await(3, TimeUnit.SECONDS);
assertEquals(200, r1.getStatusCode());
Response reponse = c.prepareGet("http://localhost:"+restPort+SIGNALK_API+"/vessels/*/navigation").setCookies(r1.getCookies()).execute().get();
//latch.await(3, TimeUnit.SECONDS);
logger.debug(reponse.getResponseBody());
assertEquals(400, reponse.getStatusCode());
assertEquals("Bad Request" , reponse.getResponseBody());
c.close();
}
示例3: shouldGetEmptyResponse
import com.ning.http.client.AsyncHttpClient; //导入方法依赖的package包/类
@Test
public void shouldGetEmptyResponse() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final AsyncHttpClient c = new AsyncHttpClient();
template.sendBody(RouteManager.SEDA_INPUT,jsonDiff);
latch.await(2,TimeUnit.SECONDS);
//get a sessionid
Response r1 = c.prepareGet("http://localhost:"+restPort+SIGNALK_AUTH+"/demo/pass").execute().get();
//latch2.await(3, TimeUnit.SECONDS);
assertEquals(200, r1.getStatusCode());
Response reponse = c.prepareGet("http://localhost:"+restPort+SIGNALK_API+"/vessels/self/navigation/nothing").setCookies(r1.getCookies()).execute().get();
//latch.await(3, TimeUnit.SECONDS);
logger.debug(reponse.getResponseBody());
assertEquals(200, reponse.getStatusCode());
assertEquals("{}" , reponse.getResponseBody());
c.close();
}
示例4: shutdown
import com.ning.http.client.AsyncHttpClient; //导入方法依赖的package包/类
/**
* Shutdown each AHC client in the map.
*/
public void shutdown() {
for (Entry<HttpClientType, AsyncHttpClient> entry : map.entrySet()) {
AsyncHttpClient client = entry.getValue();
if (client != null)
client.close();
}
}
示例5: shouldGetWsUrl
import com.ning.http.client.AsyncHttpClient; //导入方法依赖的package包/类
@Test
public void shouldGetWsUrl() throws Exception {
final AsyncHttpClient c = new AsyncHttpClient();
//get a sessionid
Response r1 = c.prepareGet("http://localhost:"+restPort+SIGNALK_AUTH+"/demo/pass").execute().get();
assertEquals(200, r1.getStatusCode());
Response r2 = c.prepareGet("http://localhost:"+restPort+SIGNALK_DISCOVERY).setCookies(r1.getCookies()).execute().get();
Json json = Json.read(r2.getResponseBody());
assertEquals("ws://localhost:"+wsPort+SIGNALK_WS, json.at("endpoints").at("v1").at(websocketUrl).asString());
c.close();
}
示例6: doTest
import com.ning.http.client.AsyncHttpClient; //导入方法依赖的package包/类
@Override
protected void doTest(int port) throws Exception {
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
int statusCode = asyncHttpClient
.prepareGet("http://localhost:" + port + contextPath + "/first-include")
.execute().get().getStatusCode();
asyncHttpClient.close();
if (statusCode != 200) {
throw new IllegalStateException("Unexpected status code: " + statusCode);
}
}
示例7: shouldGetListResponse
import com.ning.http.client.AsyncHttpClient; //导入方法依赖的package包/类
@Test
public void shouldGetListResponse() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final AsyncHttpClient c = new AsyncHttpClient();
template.sendBody(RouteManager.SEDA_INPUT,jsonDiff);
latch.await(2,TimeUnit.SECONDS);
//get a sessionid
Response r1 = c.prepareGet("http://localhost:"+restPort+SIGNALK_AUTH+"/demo/pass").execute().get();
//latch2.await(3, TimeUnit.SECONDS);
assertEquals(200, r1.getStatusCode());
Response reponse = c.prepareGet("http://localhost:"+restPort+SIGNALK_API+"/list/vessels/"+SignalKConstants.self+"/*").setCookies(r1.getCookies()).execute().get();
//latch.await(3, TimeUnit.SECONDS);
logger.debug(reponse.getResponseBody());
assertEquals(200, reponse.getStatusCode());
Json resp = Json.read(reponse.getResponseBody());
Json list = resp.at(SignalKConstants.PATHLIST);
assertTrue(list.isArray());
assertTrue(list.asJsonList().get(0).asString().startsWith("vessels."+SignalKConstants.self));
reponse = c.prepareGet("http://localhost:"+restPort+SIGNALK_API+"/list/vessels/*/navigation/*").setCookies(r1.getCookies()).execute().get();
//latch.await(3, TimeUnit.SECONDS);
logger.debug(reponse.getResponseBody());
assertEquals(200, reponse.getStatusCode());
//{\"updates\":[{\"values\":[{\"value\":3.0176,\"path\":\"navigation.courseOverGroundTrue\"}],\"source\":{\"timestamp\":\"2014-08-15T16:00:00.081Z\",\"source\":\"/dev/actisense-N2K-115-128267\"}}],\"context\":\"vessels.self\"}
resp = Json.read(reponse.getResponseBody());
list = resp.at(SignalKConstants.PATHLIST);
assertTrue(list.isArray());
assertTrue(list.asJsonList().get(0).asString().startsWith("vessels.*.navigation"));
c.close();
}
示例8: run
import com.ning.http.client.AsyncHttpClient; //导入方法依赖的package包/类
@Override
public void run() {
AsyncHttpClient httpClient = createHttpClient();
try {
replayLog(httpClient);
} catch (Exception e) {
LOG.error(String.format("log replayer failed: %s", e.getMessage()), e);
} finally {
httpClient.close();
}
}
示例9: run
import com.ning.http.client.AsyncHttpClient; //导入方法依赖的package包/类
@Override
public void run() {
AsyncHttpClient httpClient = createHttpClient();
try {
applyBurst(httpClient, this.requestRate, this.duration.orElse(Integer.MAX_VALUE));
} catch (Exception e) {
LOG.error(String.format("log replayer failed: %s", e.getMessage()), e);
} finally {
httpClient.close();
}
}
示例10: doTest
import com.ning.http.client.AsyncHttpClient; //导入方法依赖的package包/类
@Override
protected void doTest(int port) throws Exception {
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
int statusCode = asyncHttpClient.prepareGet("http://localhost:" + port + "/hello.xhtml")
.execute().get().getStatusCode();
asyncHttpClient.close();
if (statusCode != 200) {
throw new IllegalStateException("Unexpected status code: " + statusCode);
}
}
示例11: doTest
import com.ning.http.client.AsyncHttpClient; //导入方法依赖的package包/类
@Override
protected void doTest(int port) throws Exception {
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
int statusCode =
asyncHttpClient.prepareGet("http://localhost:" + port + contextPath + "/async3")
.execute().get().getStatusCode();
asyncHttpClient.close();
if (statusCode != 200) {
throw new IllegalStateException("Unexpected status code: " + statusCode);
}
}
示例12: transactionMarker
import com.ning.http.client.AsyncHttpClient; //导入方法依赖的package包/类
@Override
public void transactionMarker() throws Exception {
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
int statusCode =
asyncHttpClient.prepareGet("http://localhost:" + getPort() + "/hello1/")
.execute().get().getStatusCode();
asyncHttpClient.close();
if (statusCode != 200) {
throw new IllegalStateException("Unexpected status code: " + statusCode);
}
}
示例13: doTest
import com.ning.http.client.AsyncHttpClient; //导入方法依赖的package包/类
@Override
protected void doTest(int port) throws Exception {
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
int statusCode =
asyncHttpClient.prepareGet("http://localhost:" + port + "/hello/abc/xyz")
.execute().get().getStatusCode();
asyncHttpClient.close();
if (statusCode != 200) {
throw new IllegalStateException("Unexpected status code: " + statusCode);
}
}
示例14: executeApp
import com.ning.http.client.AsyncHttpClient; //导入方法依赖的package包/类
@Override
public void executeApp() throws Exception {
int port = getAvailablePort();
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir("target/tomcat");
tomcat.setPort(port);
Context context =
tomcat.addContext("", new File("src/test/resources").getAbsolutePath());
WebappLoader webappLoader = new WebappLoader(RenderJspInTomcat.class.getClassLoader());
context.setLoader(webappLoader);
Tomcat.addServlet(context, "hello", new ForwardingServlet());
context.addServletMapping("/hello", "hello");
Tomcat.addServlet(context, "jsp", new JspServlet());
context.addServletMapping("*.jsp", "jsp");
tomcat.start();
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
int statusCode = asyncHttpClient.prepareGet("http://localhost:" + port + "/hello")
.execute().get().getStatusCode();
asyncHttpClient.close();
if (statusCode != 200) {
throw new IllegalStateException("Unexpected status code: " + statusCode);
}
tomcat.stop();
tomcat.destroy();
}
示例15: doTest
import com.ning.http.client.AsyncHttpClient; //导入方法依赖的package包/类
@Override
protected void doTest(int port) throws Exception {
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
int statusCode = asyncHttpClient.prepareGet("http://localhost:" + port + "/hello/5")
.execute().get().getStatusCode();
asyncHttpClient.close();
if (statusCode != 200) {
throw new IllegalStateException("Unexpected status code: " + statusCode);
}
}