本文整理汇总了Java中org.springframework.http.client.ClientHttpResponse类的典型用法代码示例。如果您正苦于以下问题:Java ClientHttpResponse类的具体用法?Java ClientHttpResponse怎么用?Java ClientHttpResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClientHttpResponse类属于org.springframework.http.client包,在下文中一共展示了ClientHttpResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: intercept
import org.springframework.http.client.ClientHttpResponse; //导入依赖的package包/类
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
ClientHttpRequestExecution execution) throws IOException {
if (omegaContext.globalTxId() != null) {
request.getHeaders().add(GLOBAL_TX_ID_KEY, omegaContext.globalTxId());
request.getHeaders().add(LOCAL_TX_ID_KEY, omegaContext.localTxId());
LOG.debug("Added {} {} and {} {} to request header",
GLOBAL_TX_ID_KEY,
omegaContext.globalTxId(),
LOCAL_TX_ID_KEY,
omegaContext.localTxId());
}
return execution.execute(request, body);
}
开发者ID:apache,项目名称:incubator-servicecomb-saga,代码行数:17,代码来源:TransactionClientHttpRequestInterceptor.java
示例2: getTags
import org.springframework.http.client.ClientHttpResponse; //导入依赖的package包/类
@Override
public Iterable<Tag> getTags(String urlTemplate, HttpRequest request, ClientHttpResponse response)
{
Tag uriTag = StringUtils.hasText(urlTemplate)? RestTemplateExchangeTags.uri(urlTemplate): RestTemplateExchangeTags.uri(request);
return Arrays.asList(RestTemplateExchangeTags.method(request), uriTag,
RestTemplateExchangeTags.status(response),
RestTemplateExchangeTags.clientName(request),
modelName(request),
modelImage(request),
modelVersion(request),
projectName(),
deploymentName(),
deploymentVersion(),
predictorName(),
predictorVersion());
}
示例3: handleError
import org.springframework.http.client.ClientHttpResponse; //导入依赖的package包/类
@Override
public void handleError(ClientHttpResponse response) throws IOException {
String seyrenResponseBody;
LOGGER.debug("Response : {} {}", response.getStatusCode(), response.getStatusText());
if (response.getBody() != null) {
seyrenResponseBody = CharStreams.toString(new InputStreamReader(response.getBody(), "UTF-8"));
} else {
seyrenResponseBody = "Response whithout body";
}
CerebroException exception = new CerebroException(ErrorCode.SEYREN_ERROR, seyrenResponseBody);
throw exception;
}
示例4: intercept
import org.springframework.http.client.ClientHttpResponse; //导入依赖的package包/类
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
throws IOException
{
if (log.isDebugEnabled())
{
log.debug(String.format("Request: %s %s %s", request.getMethod(), request.getURI(),
new String(body, getCharset(request))));
}
ClientHttpResponse response = execution.execute(request, body);
if (log.isDebugEnabled())
{
log.debug(String.format("Response: %s %s", response.getStatusCode().value(),
copyToString(response.getBody(), getCharset(response))));
}
return response;
}
示例5: doExecute
import org.springframework.http.client.ClientHttpResponse; //导入依赖的package包/类
/**
* Execute the given method on the provided URI. The
* {@link org.springframework.http.client.ClientHttpRequest}
* is processed using the {@link RequestCallback}; the response with
* the {@link ResponseExtractor}.
* @param url the fully-expanded URL to connect to
* @param method the HTTP method to execute (GET, POST, etc.)
* @param requestCallback object that prepares the request (can be {@code null})
* @param responseExtractor object that extracts the return value from the response (can
* be {@code null})
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
*/
protected <T> ListenableFuture<T> doExecute(URI url, HttpMethod method, AsyncRequestCallback requestCallback,
ResponseExtractor<T> responseExtractor) throws RestClientException {
Assert.notNull(url, "'url' must not be null");
Assert.notNull(method, "'method' must not be null");
try {
AsyncClientHttpRequest request = createAsyncRequest(url, method);
if (requestCallback != null) {
requestCallback.doWithRequest(request);
}
ListenableFuture<ClientHttpResponse> responseFuture = request.executeAsync();
return new ResponseExtractorFuture<T>(method, url, responseFuture,
responseExtractor);
}
catch (IOException ex) {
throw new ResourceAccessException("I/O error on " + method.name() +
" request for \"" + url + "\":" + ex.getMessage(), ex);
}
}
示例6: adapt
import org.springframework.http.client.ClientHttpResponse; //导入依赖的package包/类
@Override
protected final T adapt(ClientHttpResponse response) throws ExecutionException {
try {
if (!getErrorHandler().hasError(response)) {
logResponseStatus(this.method, this.url, response);
}
else {
handleResponseError(this.method, this.url, response);
}
return convertResponse(response);
}
catch (IOException ex) {
throw new ExecutionException(ex);
}
finally {
if (response != null) {
response.close();
}
}
}
示例7: traceResponse
import org.springframework.http.client.ClientHttpResponse; //导入依赖的package包/类
private void traceResponse(ClientHttpResponse response) throws IOException {
StringBuilder inputStringBuilder = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getBody(), "UTF-8"));
String line = bufferedReader.readLine();
while (line != null) {
inputStringBuilder.append(line);
inputStringBuilder.append('\n');
line = bufferedReader.readLine();
}
log.debug("============================response begin==========================================");
log.debug("Status code : {}", response.getStatusCode());
log.debug("Status text : {}", response.getStatusText());
log.debug("Headers : {}", response.getHeaders());
log.debug("Response body: {}", inputStringBuilder.toString());
log.debug("=======================response end=================================================");
}
示例8: testPerformDiagnosis
import org.springframework.http.client.ClientHttpResponse; //导入依赖的package包/类
@Test
public void testPerformDiagnosis() throws IOException, URISyntaxException {
Identifier<Jvm> aJvmId = new Identifier<>(11L);
Jvm jvm = mock(Jvm.class);
when(jvm.getId()).thenReturn(aJvmId);
final URI uri = new URI("http://test.com");
when(jvm.getStatusUri()).thenReturn(new URI("http://test.com"));
when(Config.mockJvmPersistenceService.getJvm(aJvmId)).thenReturn(jvm);
ClientHttpResponse mockResponse = mock(ClientHttpResponse.class);
when(mockResponse.getStatusCode()).thenReturn(HttpStatus.OK);
when(Config.mockClientFactoryHelper.requestGet(any(URI.class))).thenReturn(mockResponse);
jvmService.performDiagnosis(aJvmId, new User("user"));
verify(Config.mockClientFactoryHelper).requestGet(eq(uri));
reset(Config.mockClientFactoryHelper);
when(mockResponse.getStatusCode()).thenReturn(HttpStatus.REQUEST_TIMEOUT);
when(Config.mockClientFactoryHelper.requestGet(any(URI.class))).thenReturn(mockResponse);
jvmService.performDiagnosis(aJvmId, new User("user"));
verify(Config.mockClientFactoryHelper).requestGet(eq(uri));
}
示例9: handleClientErrors
import org.springframework.http.client.ClientHttpResponse; //导入依赖的package包/类
private static void handleClientErrors(ClientHttpResponse response) throws IOException {
HttpStatus statusCode = response.getStatusCode();
Map<String, Object> errorMap = extractErrorDetailsFromResponse(response);
String errorText = "";
if (errorMap.containsKey("error")) {
errorText = (String) errorMap.get("error");
} else if (errorMap.containsKey("errors")) {
Object errors = errorMap.get("errors");
if (errors instanceof List) {
@SuppressWarnings("unchecked")
List<Map<String, String>> errorsList = (List<Map<String, String>>) errors;
errorText = errorsList.get(0).get("message");
} else if (errors instanceof String) {
errorText = (String) errors;
}
}
if (statusCode == HttpStatus.BAD_REQUEST) {
if (errorText.contains("Rate limit exceeded.")) {
throw new RateLimitExceededException(TWITTER);
}
} else if (statusCode == HttpStatus.UNAUTHORIZED) {
if (errorText == null) {
throw new NotAuthorizedException(TWITTER, response.getStatusText());
} else if ("Could not authenticate you.".equals(errorText)) {
throw new MissingAuthorizationException(TWITTER);
} else if ("Could not authenticate with OAuth.".equals(errorText)) { // revoked token
throw new RevokedAuthorizationException(TWITTER);
} else if ("Invalid / expired Token".equals(errorText)) {
// Note that Twitter doesn't actually expire tokens
throw new InvalidAuthorizationException(TWITTER, errorText);
} else {
throw new NotAuthorizedException(TWITTER, errorText);
}
} else if (statusCode == HttpStatus.FORBIDDEN) {
if (errorText.equals(DUPLICATE_STATUS_TEXT) || errorText.contains("You already said that")) {
throw new DuplicateStatusException(TWITTER, errorText);
} else if (errorText.equals(STATUS_TOO_LONG_TEXT) || errorText.contains(MESSAGE_TOO_LONG_TEXT)) {
throw new MessageTooLongException(errorText);
} else if (errorText.equals(INVALID_MESSAGE_RECIPIENT_TEXT)) {
throw new InvalidMessageRecipientException(errorText);
} else if (errorText.equals(DAILY_RATE_LIMIT_TEXT)) {
throw new RateLimitExceededException(TWITTER);
} else {
throw new OperationNotPermittedException(TWITTER, errorText);
}
} else if (statusCode == HttpStatus.NOT_FOUND) {
throw new ResourceNotFoundException(TWITTER, errorText);
} else if (statusCode == HttpStatus.valueOf(ENHANCE_YOUR_CALM) || statusCode == HttpStatus
.valueOf(TOO_MANY_REQUESTS)) {
throw new RateLimitExceededException(TWITTER);
}
}
示例10: extractErrorDetailsFromResponse
import org.springframework.http.client.ClientHttpResponse; //导入依赖的package包/类
private static Map<String, Object> extractErrorDetailsFromResponse(ClientHttpResponse response) throws IOException {
ObjectMapper mapper = new ObjectMapper(new JsonFactory());
try {
return mapper.readValue(response.getBody(), new TypeReference<Map<String, Object>>() {
});
} catch (JsonParseException e) {
log.error("Can not parse error details from response", e);
return Collections.emptyMap();
}
}
示例11: execute
import org.springframework.http.client.ClientHttpResponse; //导入依赖的package包/类
@Override
public ClientHttpResponse execute() throws IOException {
path = findUriPath(uri);
requestMeta = createRequestMeta(method.name(), uri);
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri.getRawSchemeSpecificPart());
queryParams = queryStringDecoder.parameters();
Object[] args = this.collectArguments();
// 异常流程,直接抛异常出去
return this.invoke(args);
}
示例12: intercept
import org.springframework.http.client.ClientHttpResponse; //导入依赖的package包/类
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
logRequest(request, body);
ClientHttpResponse response = execution.execute(request, body);
logResponse(response);
return response;
}
示例13: intercept
import org.springframework.http.client.ClientHttpResponse; //导入依赖的package包/类
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
traceRequest(request, body);
ClientHttpResponse response = execution.execute(request, body);
traceResponse(response);
return response;
}
示例14: intercept
import org.springframework.http.client.ClientHttpResponse; //导入依赖的package包/类
@Override
public ClientHttpResponse intercept(final HttpRequest request, final byte[] body,
final ClientHttpRequestExecution execution) throws IOException {
HttpHeaders headers = request.getHeaders();
headers.add("X-Auth-Token", tokenManager.getTokenHolder().getScopedToken(projectId));
if (LOG.isInfoEnabled()) {
LOG.info("X-Auth-Token: " + tokenManager.getTokenHolder().getScopedToken(projectId));
}
return execution.execute(request, body);
}
示例15: assertNetworkCallFails
import org.springframework.http.client.ClientHttpResponse; //导入依赖的package包/类
private void assertNetworkCallFails(RestTemplate restTemplate, ClientHttpRequestFactory requestFactory) {
restTemplate.setRequestFactory(requestFactory);
try {
HttpStatus status = restTemplate.execute(CCNG_API_URL + "/info", HttpMethod.GET, null, new ResponseExtractor<HttpStatus>() {
public HttpStatus extractData(ClientHttpResponse response) throws IOException {
return response.getStatusCode();
}
});
Assert.fail("Expected byteman rules to detect direct socket connections, status is:" + status);
} catch (Exception e) {
// good, byteman rejected it as expected
// e.printStackTrace();
}
assertEquals("Not expecting Jetty to receive requests since we asked direct connections", 0, nbInJvmProxyRcvReqs.get());
}