當前位置: 首頁>>代碼示例>>Java>>正文


Java ResponseExtractor.extractData方法代碼示例

本文整理匯總了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;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:11,代碼來源:RestTemplateXhrTransportTests.java

示例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);
	}
}
 
開發者ID:wayshall,項目名稱:onetwo,代碼行數:14,代碼來源:ExtRestTemplate.java

示例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;
}
 
開發者ID:SAP,項目名稱:cf-java-client-sap,代碼行數:48,代碼來源:LoggingRestTemplate.java

示例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);
}
 
開發者ID:zalando,項目名稱:riptide,代碼行數:5,代碼來源:MessageWorker.java

示例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());
	}
}
 
開發者ID:bestarandyan,項目名稱:ShoppingMall,代碼行數:64,代碼來源:CustomRestTemplate.java


注:本文中的org.springframework.web.client.ResponseExtractor.extractData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。