本文整理汇总了Java中io.vertx.core.http.HttpClientResponse.getHeader方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientResponse.getHeader方法的具体用法?Java HttpClientResponse.getHeader怎么用?Java HttpClientResponse.getHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.http.HttpClientResponse
的用法示例。
在下文中一共展示了HttpClientResponse.getHeader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSetCseContext
import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
@Test
public void testSetCseContext() {
boolean status = false;
try {
Invocation invocation = mock(Invocation.class);
HttpClientResponse httpResponse = mock(HttpClientResponse.class);
OperationMeta operationMeta = mock(OperationMeta.class);
RestOperationMeta swaggerRestOperation = mock(RestOperationMeta.class);
HttpClientRequest request = mock(HttpClientRequest.class);
Endpoint endpoint = mock(Endpoint.class);
when(invocation.getOperationMeta()).thenReturn(operationMeta);
URLPathBuilder urlPathBuilder = mock(URLPathBuilder.class);
when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
when(invocation.getEndpoint()).thenReturn(endpoint);
String contentType = httpResponse.getHeader("Content-Type");
ProduceProcessor produceProcessor = mock(ProduceProcessor.class);
when(swaggerRestOperation.findProduceProcessor(contentType)).thenReturn(produceProcessor);
this.setCseContext(invocation, request);
} catch (Exception ex) {
status = true;
}
Assert.assertFalse(status);
}
示例2: testHandleResponse
import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
@Test
public void testHandleResponse() {
boolean status = false;
try {
Invocation invocation = mock(Invocation.class);
AsyncResponse asyncResp = mock(AsyncResponse.class);
HttpClientResponse httpResponse = mock(HttpClientResponse.class);
OperationMeta operationMeta = mock(OperationMeta.class);
RestOperationMeta swaggerRestOperation = mock(RestOperationMeta.class);
Endpoint endpoint = mock(Endpoint.class);
when(invocation.getOperationMeta()).thenReturn(operationMeta);
URLPathBuilder urlPathBuilder = mock(URLPathBuilder.class);
when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
when(invocation.getEndpoint()).thenReturn(endpoint);
String contentType = httpResponse.getHeader("Content-Type");
ProduceProcessor produceProcessor = mock(ProduceProcessor.class);
when(swaggerRestOperation.findProduceProcessor(contentType)).thenReturn(produceProcessor);
this.handleResponse(invocation, httpResponse, asyncResp);
} catch (Exception ex) {
status = true;
}
Assert.assertFalse(status);
}
示例3: handleSuccess
import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
@Override
public void handleSuccess(HttpClientResponse rh) {
WebRootResponse response = new WebRootResponse();
NodeDownloadResponse downloadResponse = new NodeDownloadResponse();
String contentType = rh.getHeader(MeshHeaders.WEBROOT_RESPONSE_TYPE);
if (contentType == null) {
future.fail("The {" + MeshHeaders.WEBROOT_RESPONSE_TYPE + "} header was not set correctly.");
return;
}
if (contentType.startsWith("node")) {
// Delegate the response to the json handler
ModelResponseHandler<NodeResponse> handler = new ModelResponseHandler<>(NodeResponse.class, getMethod(), contentType);
handler.handle(rh);
handler.getFuture().setHandler(rh2 -> {
if (rh2.failed()) {
future.fail(rh2.cause());
} else {
response.setNodeResponse(rh2.result());
future.complete(response);
}
});
} else {
downloadResponse.setContentType(contentType);
String disposition = rh.getHeader("content-disposition");
String filename = disposition.substring(disposition.indexOf("=") + 1);
downloadResponse.setFilename(filename);
rh.bodyHandler(buffer -> {
downloadResponse.setBuffer(buffer);
response.setDownloadResponse(downloadResponse);
future.complete(response);
});
}
}
示例4: handleSuccess
import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
/**
* Handle the mesh response. This method will deserialise the JSON response.
*/
public void handleSuccess(HttpClientResponse response) {
String contentType = response.getHeader("Content-Type");
//FIXME TODO in theory it would also be possible that a customer uploads JSON into mesh. In those cases we would also need to return it directly (without parsing)
if (contentType == null && response.statusCode() == NO_CONTENT.code()) {
if (log.isDebugEnabled()) {
log.debug("Got {" + NO_CONTENT.code() + "} response.");
}
future.complete();
} else if (contentType != null && contentType.startsWith(HttpConstants.APPLICATION_JSON)) {
response.bodyHandler(bh -> {
String json = bh.toString();
if (log.isDebugEnabled()) {
log.debug(json);
}
try {
T restObj = JsonUtil.readValue(json, classOfT);
future.complete(restObj);
} catch (Exception e) {
log.error("Failed to deserialize json to class {" + classOfT + "}", e);
future.fail(e);
}
});
} else {
//TODO move regular string success handler into dedicated interface
if (classOfT.isAssignableFrom(String.class)) {
response.bodyHandler(buffer -> {
future.complete((T) buffer.toString());
});
} else {
response.bodyHandler(buffer -> {
future.fail(new RuntimeException("Request can't be handled by this handler since the content type was {" + contentType + "}"));
});
}
}
}
示例5: handleSuccess
import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
@Override
public void handleSuccess(HttpClientResponse rh) {
NodeDownloadResponse response = new NodeDownloadResponse();
String contentType = rh.getHeader(HttpHeaders.CONTENT_TYPE.toString());
response.setContentType(contentType);
String disposition = rh.getHeader("content-disposition");
String filename = disposition.substring(disposition.indexOf("=") + 1);
response.setFilename(filename);
rh.bodyHandler(buffer -> {
response.setBuffer(buffer);
future.complete(response);
});
}
示例6: handleSuccess
import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
default void handleSuccess(HttpClientResponse response) {
String contentType = response.getHeader("Content-Type");
// FIXME TODO in theory it would also be possible that a customer uploads JSON into mesh. In those cases we would also need to return it directly
// (without parsing)
if (contentType == null && response.statusCode() == NO_CONTENT.code()) {
if (log.isDebugEnabled()) {
log.debug("Got {" + NO_CONTENT.code() + "} response.");
}
getFuture().complete();
} else if (contentType.startsWith(HttpConstants.APPLICATION_JSON)) {
response.bodyHandler(bh -> {
String json = bh.toString();
if (log.isDebugEnabled()) {
log.debug(json);
}
try {
getFuture().setBodyJson(json);
getFuture().complete(new JsonObject(json));
} catch (Exception e) {
log.error("Failed to deserialize json", e);
getFuture().fail(e);
}
});
} else {
response.bodyHandler(buffer -> {
getFuture().fail(new RuntimeException("Request can't be handled by this handler since the content type was {" + contentType + "}"));
});
}
}
示例7: processRedirection
import io.vertx.core.http.HttpClientResponse; //导入方法依赖的package包/类
private void processRedirection(HttpClientResponse resp, String url) {
status = ProcessStatus.REDIRECT;
String followUrl = resp.getHeader("Location");
if (followUrl == null || followUrl.isEmpty() || followUrl.equals(url)) {
logger.error("Failed to download {}, because redirection to invalid url", url);
} else {
this.url = followUrl;
process(followUrl);
}
}