本文整理汇总了Java中org.vertx.java.core.http.HttpClientResponse类的典型用法代码示例。如果您正苦于以下问题:Java HttpClientResponse类的具体用法?Java HttpClientResponse怎么用?Java HttpClientResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpClientResponse类属于org.vertx.java.core.http包,在下文中一共展示了HttpClientResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.vertx.java.core.http.HttpClientResponse; //导入依赖的package包/类
public static void main(String[] args) {
// Configure the client.
String adCode3rd = "/?advideo/3.0/78.109/5798044/0//cc=2;vidAS=pre_roll;vidRT=VAST;vidRTV=2.0.1";
HttpClient httpClient = VertxFactory.newVertx().createHttpClient();
httpClient.setHost("adserver.adtech.de");
httpClient.get(adCode3rd, new Handler<HttpClientResponse>() {
@Override
public void handle(HttpClientResponse httpClientResponse) {
httpClientResponse.bodyHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer buffer) {
System.out.println("Response (" + buffer.length() + "): ");
System.out.println(buffer.getString(0, buffer.length()));
}
});
}
});
Utils.sleep(10000);
}
示例2: handle
import org.vertx.java.core.http.HttpClientResponse; //导入依赖的package包/类
@Override
public void handle(HttpClientResponse clientResponse) {
delegate.handle(clientResponse);
MultiMap headers = clientResponse.headers();
for (String headerName : rewriteHeaders) {
List<String> headerValues = headers.getAll(headerName);
int size = headerValues.size();
if (size > 0) {
List<String> newHeaders = new ArrayList<String>(size);
for (String headerValue : headerValues) {
String newValue = headerValue;
if (headerValue != null && headerValue.length() > 0) {
newValue = proxyMappingDetails.rewriteBackendUrl(headerValue);
}
}
LOG.info("Rewriting header " + headerName + " from: " + headerValues + " to: " + newHeaders);
headers.set(headerName, newHeaders);
}
}
}
示例3: doQuery
import org.vertx.java.core.http.HttpClientResponse; //导入依赖的package包/类
private void doQuery(
final String query,
final String token,
final Handler<HttpClientResponse> handler) {
try {
IConnection<HttpClient> connection = connections().next();
UbidotsQuery queryHandler = new UbidotsQuery(
connection,
query,
token,
handler);
connection.doRequest(queryHandler);
} catch (ConnectionException e) {
logger().error("Failed to query ubidots service", e);
}
}
示例4: handleFailure
import org.vertx.java.core.http.HttpClientResponse; //导入依赖的package包/类
private void handleFailure(
final HttpConnection connection,
final HttpClientResponse response,
final Handler<Boolean> handler) {
if (response.statusCode() < HTTP_SUCCESS_CODE
|| response.statusCode() >= HTTP_REDIRECTION_CODE) {
connection.disconnect();
if (handler != null) {
handler.handle(FALSE);
}
m_logger.error("Ignoring host: {}",
connection.getAddress(),
new IllegalStateException("Connection failure: "
+ response.statusCode()
+ "/"
+ response.statusMessage()));
}
}
示例5: refreshToken
import org.vertx.java.core.http.HttpClientResponse; //导入依赖的package包/类
public void refreshToken(final Handler<Boolean> handler){
HttpClientRequest req = cursusClient.post(wsEndpoint.getPath() + "/AuthentificationImpl.svc/json/AuthentificationExtranet", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse response) {
if(response.statusCode() >= 300){
handler.handle(false);
log.error(response.statusMessage());
return;
}
response.bodyHandler(new Handler<Buffer>() {
public void handle(Buffer body) {
log.info("[Cursus][refreshToken] Token refreshed.");
JsonObject authData = new JsonObject(body.toString());
authData.putNumber("tokenInit", new Date().getTime());
cursusMap.put("auth", authData.encode());
handler.handle(true);
}
});
}
});
req.putHeader(HttpHeaders.ACCEPT, "application/json; charset=UTF-8")
.putHeader(HttpHeaders.CONTENT_TYPE, "application/json");
req.end(authConf.encode());
}
示例6: parseData
import org.vertx.java.core.http.HttpClientResponse; //导入依赖的package包/类
private void parseData(HttpClientResponse response, final Handler<JsonObject> handler) {
if (response.statusCode() == 200) {
final Buffer buff = new Buffer();
response.dataHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer event) {
buff.appendBuffer(event);
}
});
response.endHandler(new Handler<Void>() {
@Override
public void handle(Void end) {
handleResponse(buff.toString(), handler);
}
});
} else {
handler.handle(new JsonObject().putString("status", "error").putString("message", response.statusMessage()));
}
}
示例7: processMessage
import org.vertx.java.core.http.HttpClientResponse; //导入依赖的package包/类
private void processMessage(final HttpServerRequest request, SoapHelper.SoapDescriptor messageDescriptor){
String xml = "";
try {
xml = SoapHelper.createSoapMessage(messageDescriptor);
} catch (SOAPException | IOException e) {
log.error("["+MaxicoursController.class.getSimpleName()+"]("+messageDescriptor.getBodyTagName()+") Error while building the soap request.");
renderError(request);
return;
}
HttpClientRequest req = soapClient.post(soapEndpoint.getPath(), new Handler<HttpClientResponse>() {
public void handle(final HttpClientResponse response) {
response.bodyHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer body) {
request.response().end(body);
}
});
}
});
req
.putHeader("SOAPAction", messageDescriptor.getBodyTag())
.putHeader(HttpHeaders.CONTENT_TYPE, "text/xml;charset=UTF-8");
req.end(xml);
}
示例8: getSimpleConnection
import org.vertx.java.core.http.HttpClientResponse; //导入依赖的package包/类
@Test
@Ignore
public void getSimpleConnection() throws InterruptedException, IOException {
CountDownLatch latch = new CountDownLatch(1);
CountDownLatch latch2 = new CountDownLatch(1);
HttpClient client = getClient();
HttpClientRequest request = client.get("/employee", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(body->System.out.println("Got a response: " +body.toString()));
latch.countDown();
}
});
request.end();
latch.await();
}
示例9: testSimpleRESTGETWithParameterPath
import org.vertx.java.core.http.HttpClientResponse; //导入依赖的package包/类
@Test
public void testSimpleRESTGETWithParameterPath() throws InterruptedException, MalformedURLException {
connectMain(1);
CountDownLatch latch = new CountDownLatch(1);
HttpClientRequest request = getClient().get("/service-REST-GET/testEmployeeFour/123/employee/andy", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(body -> {System.out.println("Got a response: " + body.toString());
Assert.assertEquals(body.toString(), "123:andy");});
latch.countDown();
}
});
request.end();
latch.await();
}
示例10: testSimpleRESTGETWithParameterPath2
import org.vertx.java.core.http.HttpClientResponse; //导入依赖的package包/类
@Test
public void testSimpleRESTGETWithParameterPath2() throws InterruptedException, MalformedURLException {
connectMain(1);
CountDownLatch latch = new CountDownLatch(1);
HttpClientRequest request = getClient().get("/service-REST-GET/testEmployeeThree/456/andy", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(body -> {System.out.println("Got a response: " + body.toString());
Assert.assertEquals(body.toString(), "456:andy");});
latch.countDown();
}
});
request.end();
latch.await();
}
示例11: testSimpleRESTGETWithParameterPathError
import org.vertx.java.core.http.HttpClientResponse; //导入依赖的package包/类
@Test
public void testSimpleRESTGETWithParameterPathError() throws InterruptedException, MalformedURLException {
connectMain(1);
CountDownLatch latch = new CountDownLatch(1);
HttpClientRequest request = getClient().get("/service-REST-GET/testEmployeeFour/123/andy", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(body -> {System.out.println("Got a response: " + body.toString());
Assert.assertEquals(body.toString(), "no route found");});
latch.countDown();
}
});
request.end();
latch.await();
}
示例12: testSimpleRESTGETWithQueryParameter
import org.vertx.java.core.http.HttpClientResponse; //导入依赖的package包/类
@Test
public void testSimpleRESTGETWithQueryParameter() throws InterruptedException, MalformedURLException {
connectMain(1);
CountDownLatch latch = new CountDownLatch(1);
HttpClientRequest request = getClient().get("/service-REST-GET/testEmployeeOne?name=789&lastname=andy", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(body -> {System.out.println("Got a response: " + body.toString());
Assert.assertEquals(body.toString(), "789:andy");});
latch.countDown();
}
});
request.end();
latch.await();
}
示例13: testSimpleRESTGETWithQueryParameterAndReturnValue
import org.vertx.java.core.http.HttpClientResponse; //导入依赖的package包/类
@Test
public void testSimpleRESTGETWithQueryParameterAndReturnValue() throws InterruptedException, MalformedURLException {
connectMain(1);
CountDownLatch latch = new CountDownLatch(1);
HttpClientRequest request = getClient().get("/service-REST-GET/testEmployeeTwo?id=123", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(body -> {System.out.println("Got a response123: " + body.toString());
Assert.assertEquals(body.toString(), "{\n" +
" \"id\" : \"123\"\n" +
"}");});
latch.countDown();
}
});
request.end();
latch.await();
}
示例14: testSimpleRESTGETWithQueryParameterAndObjectReturnValue
import org.vertx.java.core.http.HttpClientResponse; //导入依赖的package包/类
@Test
public void testSimpleRESTGETWithQueryParameterAndObjectReturnValue() throws InterruptedException, MalformedURLException {
connectMain(1);
CountDownLatch latch = new CountDownLatch(1);
HttpClientRequest request = getClient().get("/service-REST-GET/testEmployeeFive?id=123", new Handler<HttpClientResponse>() {
public void handle(HttpClientResponse resp) {
resp.bodyHandler(body -> {System.out.println("Got a response123: " + body.toString());
Assert.assertEquals(body.toString(), "{\"employeeId\":\"fg\",\"jobDescription\":\"dfg\",\"jobType\":\"dfg\",\"firstName\":\"fdg\",\"lastName\":\"dfg\"}");});
latch.countDown();
}
});
request.end();
latch.await();
}
示例15: handle
import org.vertx.java.core.http.HttpClientResponse; //导入依赖的package包/类
@Override
public void handle(final HttpClientResponse response) {
final int statusCode = response.statusCode();
logger.trace("[RESPONSE-" + getId() + "] statuscode: " + statusCode + ", time: " + timeFormatter.format(new Date()));
response.bodyHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer body) {
// The entire response body has been received
JsonObject restResponse = new JsonObject();
responseData.append(body);
logger.trace("> response: (" + getId() + ")" + responseData);
if (responseData != null && responseData.length() > 0) {
if (responseData.toString().startsWith("[")) restResponse = new JsonArray(responseData.toString()).get(0);
else restResponse = new JsonObject(responseData.toString());
}
// send response
if (statusCode >= 200 && statusCode < 300) sendResponse(true, statusCode, restResponse);
else sendResponse(false, statusCode, restResponse);
logger.trace("[RESPONSE-" + getId() + "] body parsed" + ", time: " + timeFormatter.format(new Date()));
}
});
}