本文整理匯總了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);
}
}