本文整理匯總了Java中org.springframework.web.client.ResponseExtractor.extractData方法的典型用法代碼示例。如果您正苦於以下問題:Java ResponseExtractor.extractData方法的具體用法?Java ResponseExtractor.extractData怎麽用?Java ResponseExtractor.extractData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.web.client.ResponseExtractor
的用法示例。
在下文中一共展示了ResponseExtractor.extractData方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: retrieveToken
import org.springframework.web.client.ResponseExtractor; //導入方法依賴的package包/類
protected OAuth2AccessToken retrieveToken(final AccessTokenRequest request,
OAuth2ProtectedResourceDetails resource,
MultiValueMap<String, String> form,
HttpHeaders headers) throws OAuth2AccessDeniedException {
try {
this.authenticationHandler.authenticateTokenRequest(resource, form, headers);
this.tokenRequestEnhancer.enhance(request, resource, form, headers);
final ResponseExtractor<OAuth2AccessToken> delegate = this.getResponseExtractor();
ResponseExtractor<OAuth2AccessToken> extractor = new ResponseExtractor<OAuth2AccessToken>() {
public OAuth2AccessToken extractData(ClientHttpResponse response) throws IOException {
if(response.getHeaders().containsKey("Set-Cookie")) {
request.setCookie(response.getHeaders().getFirst("Set-Cookie"));
}
return (OAuth2AccessToken)delegate.extractData(response);
}
};
System.out.println("URI == " + this.getAccessTokenUri(resource, form));
return (OAuth2AccessToken)this.getRestTemplate().execute(this.getAccessTokenUri(resource, form),
this.getHttpMethod(),
this.getRequestCallback(resource, form, headers),
extractor,
form.toSingleValueMap());
} catch (OAuth2Exception var8) {
System.out.println(var8.toString());
throw new OAuth2AccessDeniedException("Access token denied.", resource, var8);
} catch (RestClientException var9) {
System.out.println(var9.toString());
throw new OAuth2AccessDeniedException("Error requesting access token.", resource, var9);
}
}
開發者ID:luotuo,項目名稱:springboot-security-wechat,代碼行數:33,代碼來源:MyAuthorizationCodeAccessTokenProvider.java
示例2: execute
import org.springframework.web.client.ResponseExtractor; //導入方法依賴的package包/類
@Override
public <T> T execute(URI url, HttpMethod method, RequestCallback callback, ResponseExtractor<T> extractor) throws RestClientException {
try {
extractor.extractData(this.responses.remove());
}
catch (Throwable t) {
throw new RestClientException("Failed to invoke extractor", t);
}
return null;
}
示例3: handleError
import org.springframework.web.client.ResponseExtractor; //導入方法依賴的package包/類
@Override
public void handleError(ClientHttpResponse response) throws IOException {
ResponseExtractor<ResponseEntity<Object>> responseExtractor = null;
if(extErrorResultType!=null){
responseExtractor = responseEntityExtractor(extErrorResultType);
}
if (responseExtractor != null) {
ResponseEntity<?> errorData = responseExtractor.extractData(response);
extErrorHandler.onError(errorData.getBody());
}else{
super.handleError(response);
}
}
示例4: doExecute
import org.springframework.web.client.ResponseExtractor; //導入方法依賴的package包/類
@Override
protected <T> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback, final ResponseExtractor<T>
responseExtractor) throws RestClientException {
final String[] status = new String[1];
final HttpStatus[] httpStatus = new HttpStatus[1];
final Object[] headers = new Object[1];
final String[] message = new String[1];
T results = null;
RestClientException exception = null;
try {
results = super.doExecute(url, method, requestCallback,
new ResponseExtractor<T>() {
@SuppressWarnings("rawtypes")
public T extractData(ClientHttpResponse response) throws IOException {
httpStatus[0] = response.getStatusCode();
headers[0] = response.getHeaders();
T data = null;
if (responseExtractor != null && (data = responseExtractor.extractData(response)) != null) {
if (data instanceof String) {
message[0] = ((String) data).length() + " bytes";
} else if (data instanceof Map) {
message[0] = ((Map) data).keySet().toString();
} else {
message[0] = data.getClass().getName();
}
return data;
} else {
message[0] = "<no data>";
return null;
}
}
});
status[0] = "OK";
} catch (RestClientException e) {
status[0] = "ERROR";
message[0] = e.getMessage();
exception = e;
if (e instanceof HttpStatusCodeException) {
httpStatus[0] = ((HttpStatusCodeException) e).getStatusCode();
}
}
addLogMessage(method, url, status[0], httpStatus[0], message[0]);
if (exception != null) {
throw exception;
}
return results;
}
示例5: readBody
import org.springframework.web.client.ResponseExtractor; //導入方法依賴的package包/類
private <I> I readBody(final Type type, final ClientHttpResponse response) throws IOException {
final ResponseExtractor<I> extractor = new HttpMessageConverterExtractor<>(type, converters);
return extractor.extractData(response);
}
示例6: doExecute
import org.springframework.web.client.ResponseExtractor; //導入方法依賴的package包/類
/**
* Execute the given method on the provided URI. The {@link 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</code>)
* @param responseExtractor
* object that extracts the return value from the response (can be <code>null</code>)
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
*/
protected <T> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor) {
Assert.notNull(url, "'url' must not be null");
Assert.notNull(method, "'method' must not be null");
ClientHttpResponse response = null;
ClientHttpRequest request = null;
try {
// add by leo
if (containsRequest(url.toString()))
abortRequest(url.toString());
request = createRequest(url, method);
if (requestCallback != null) {
requestCallback.doWithRequest(request);
}
response = request.execute();
if (!getErrorHandler().hasError(response)) {
logResponseStatus(method, url, response);
} else {
handleResponseError(method, url, response);
}
if (responseExtractor != null) {
return responseExtractor.extractData(response);
} else {
return null;
}
} catch (ConnectTimeoutException e) {
throw new ClientException("請求超時,請稍後重試!", ClientException.REQUEST_NETWORK, e);
} catch (Exception ex) {
if (ex.getMessage() != null) {
String str = ex.getMessage().toLowerCase(Locale.getDefault());
if (str.contains("shutdown") || str.contains("request already aborted") || str.contains("socket closed"))
throw new ClientException("request already aborted", ClientException.REQUEST_ABORTED);
}
throw new ServerException("請求異常,請稍後再試!", ex);
} finally {
if (response != null) {
response.close();
}
removeRequest(url.toString());
}
}