本文整理匯總了Java中org.springframework.http.client.ClientHttpRequestExecution類的典型用法代碼示例。如果您正苦於以下問題:Java ClientHttpRequestExecution類的具體用法?Java ClientHttpRequestExecution怎麽用?Java ClientHttpRequestExecution使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ClientHttpRequestExecution類屬於org.springframework.http.client包,在下文中一共展示了ClientHttpRequestExecution類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: intercept
import org.springframework.http.client.ClientHttpRequestExecution; //導入依賴的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: interceptNeverRetry
import org.springframework.http.client.ClientHttpRequestExecution; //導入依賴的package包/類
@Test
public void interceptNeverRetry() throws Throwable {
HttpRequest request = mock(HttpRequest.class);
when(request.getURI()).thenReturn(new URI("http://foo"));
ClientHttpResponse clientHttpResponse = new MockClientHttpResponse(new byte[]{}, HttpStatus.OK);
LoadBalancedRetryPolicyFactory lbRetryPolicyFactory = mock(LoadBalancedRetryPolicyFactory.class);
when(lbRetryPolicyFactory.create(eq("foo"), any(ServiceInstanceChooser.class))).thenReturn(null);
ServiceInstance serviceInstance = mock(ServiceInstance.class);
when(client.choose(eq("foo"))).thenReturn(serviceInstance);
when(client.execute(eq("foo"), eq(serviceInstance), any(LoadBalancerRequest.class))).thenReturn(clientHttpResponse);
when(this.lbRequestFactory.createRequest(any(), any(), any())).thenReturn(mock(LoadBalancerRequest.class));
lbProperties.setEnabled(true);
RetryLoadBalancerInterceptor interceptor = new RetryLoadBalancerInterceptor(client, lbProperties, lbRetryPolicyFactory,
lbRequestFactory, backOffPolicyFactory, retryListenerFactory);
byte[] body = new byte[]{};
ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);
interceptor.intercept(request, body, execution);
verify(lbRequestFactory).createRequest(request, body, execution);
}
示例3: run
import org.springframework.http.client.ClientHttpRequestExecution; //導入依賴的package包/類
@Override
public void run() {
MockClientHttpRequest request = new MockClientHttpRequest();
MockClientHttpResponse response = new MockClientHttpResponse(new byte[0], HttpStatus.OK);
ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);
response.getHeaders().add("X-RateLimit-Remaining", "50");
response.getHeaders().add("X-RateLimit-Reset", String.valueOf((System.currentTimeMillis() / 1000) + 1));
try {
when(execution.execute(request, new byte[0])).thenReturn(response);
this.interceptor.intercept(request, new byte[0], execution);
} catch (IOException e) {
} finally {
this.latch.countDown();
}
}
開發者ID:pivotalsoftware,項目名稱:github-cla-integration,代碼行數:19,代碼來源:RateLimitingClientHttpRequestInterceptorTest.java
示例4: intercept
import org.springframework.http.client.ClientHttpRequestExecution; //導入依賴的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: setApiKey
import org.springframework.http.client.ClientHttpRequestExecution; //導入依賴的package包/類
/**
* Sets the api key.
*
* @throws JsonParseException the json parse exception
* @throws JsonMappingException the json mapping exception
* @throws IOException Signals that an I/O exception has occurred.
*/
private void setApiKey() throws JsonParseException, JsonMappingException, IOException{
ArrayList<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
interceptors.add((HttpRequest request, byte[] body, ClientHttpRequestExecution execution) -> {
if(body.length > 0) {
body = addTokenInObject(body, new JsonNodeFormatter());
}else{
try {
request = addTokenInURI(request);
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
return execution.execute(request, body);
});
this.restTemplate.setInterceptors(interceptors);
}
示例6: init
import org.springframework.http.client.ClientHttpRequestExecution; //導入依賴的package包/類
/**
* Init
*/
@PostConstruct
protected void init() {
restTemplateForAuthenticationFlow = new CookieStoreRestTemplate();
cookieStore = restTemplateForAuthenticationFlow.getCookieStore();
logger.debug("Inject cookie store used in the rest template for authentication flow into the authRestTemplate so that they will match");
authRestTemplate.restTemplate.setCookieStoreAndUpdateRequestFactory(cookieStore);
List<ClientHttpRequestInterceptor> interceptors = Collections
.<ClientHttpRequestInterceptor>singletonList(new ClientHttpRequestInterceptor() {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
if (latestCsrfToken != null) {
// At the beginning of auth flow, there's no token yet
injectCsrfTokenIntoHeader(request, latestCsrfToken);
}
return execution.execute(request, body);
}
});
restTemplateForAuthenticationFlow.setRequestFactory(new InterceptingClientHttpRequestFactory(restTemplateForAuthenticationFlow.getRequestFactory(), interceptors));
}
示例7: intercept
import org.springframework.http.client.ClientHttpRequestExecution; //導入依賴的package包/類
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException {
HttpHeaders headers = request.getHeaders();
String hybrisRequestId = headers.getFirst(YaasAwareTrait.Headers.REQUEST_ID);
LOGGER.debug(CHECKING_IF_IS_PRESENT, YaasAwareTrait.Headers.REQUEST_ID, hybrisRequestId);
if (StringUtils.isEmpty(hybrisRequestId)) {
headers.set(YaasAwareTrait.Headers.REQUEST_ID, StringUtils.EMPTY);
LOGGER.debug(ADDING_UPDATING_WITH, YaasAwareTrait.Headers.REQUEST_ID, StringUtils.EMPTY);
}
String hybrisHop = headers.getFirst(YaasAwareTrait.Headers.HOP);
LOGGER.debug(CHECKING_IF_IS_PRESENT, YaasAwareTrait.Headers.HOP, hybrisHop);
String newHybrisHop = "0";
if (NumberUtils.isDigits(hybrisHop)) {
int hop = NumberUtils.toInt(hybrisHop);
hop++;
newHybrisHop = Integer.toString(hop);
}
headers.set(YaasAwareTrait.Headers.HOP, newHybrisHop);
LOGGER.debug(ADDING_UPDATING_WITH, YaasAwareTrait.Headers.HOP, newHybrisHop);
return clientHttpRequestExecution.execute(request, body);
}
示例8: intercept
import org.springframework.http.client.ClientHttpRequestExecution; //導入依賴的package包/類
@Override
public ClientHttpResponse intercept(
HttpRequest request, byte[] body, ClientHttpRequestExecution execution
) throws IOException {
Tracer tracer = Tracer.getInstance();
Span spanAroundCall = null;
try {
if (surroundCallsWithSubspan) {
// Will start a new trace if necessary, or a subspan if a trace is already in progress.
spanAroundCall = tracer.startSpanInCurrentContext(getSubspanSpanName(request), SpanPurpose.CLIENT);
}
HttpRequest wrapperRequest = new HttpRequestWrapperWithModifiableHeaders(request);
propagateTracingHeaders(wrapperRequest, tracer.getCurrentSpan());
return execution.execute(wrapperRequest, body);
}
finally {
if (spanAroundCall != null) {
// Span.close() contains the logic we want - if the spanAroundCall was an overall span (new trace)
// then tracer.completeRequestSpan() will be called, otherwise it's a subspan and
// tracer.completeSubSpan() will be called.
spanAroundCall.close();
}
}
}
示例9: intercept
import org.springframework.http.client.ClientHttpRequestExecution; //導入依賴的package包/類
@Override
public ClientHttpResponse intercept(final HttpRequest request, final byte[] body,
final ClientHttpRequestExecution execution) throws IOException {
final HttpHeaders headers = request.getHeaders();
ClientHttpResponse execute = execution.execute(request, body);
if (execute.getStatusCode() == HttpStatus.UNAUTHORIZED) {
List<String> list = execute.getHeaders().get("Www-Authenticate");
if (!CollectionUtils.isEmpty(list)) {
String tokenString = list.get(0);
RegistryAuthAdapter.AuthContext ctx = new RegistryAuthAdapter.AuthContext(headers,
HttpHeaders.readOnlyHttpHeaders(headers),
tokenString);
adapter.handle(ctx);
return execution.execute(request, body);
}
}
return execute;
}
示例10: interceptSetsContentTypeAndAcceptHeaders
import org.springframework.http.client.ClientHttpRequestExecution; //導入依賴的package包/類
@Test
public void interceptSetsContentTypeAndAcceptHeaders() throws IOException {
HttpRequest request = mock(HttpRequest.class);
when(request.getHeaders()).thenReturn(new HttpHeaders());
ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);
interceptor.intercept(request, new byte[] {1}, execution);
ArgumentCaptor<HttpRequest> finalRequest = ArgumentCaptor.forClass(HttpRequest.class);
verify(execution).execute(finalRequest.capture(), aryEq(new byte[] {1}));
HttpHeaders finalHeaders = finalRequest.getValue().getHeaders();
assertThat(finalHeaders.getAccept(), contains(MediaType.valueOf("application/hal+json")));
assertThat(finalHeaders.getContentType(), is(MediaType.valueOf("application/hal+json")));
}
示例11: intercept
import org.springframework.http.client.ClientHttpRequestExecution; //導入依賴的package包/類
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
throws IOException {
if (LOG.isTraceEnabled()) {
LOG.trace(request.getMethod().name() + " " + request.getURI() + " : "
+ new String(body, "UTF-8"));
}
ClientHttpResponse response = execution.execute(request, body);
if (LOG.isTraceEnabled()) {
LOG.trace("response " + response.getStatusCode().value() + " : "
+ IOUtils.toString(response.getBody()));
}
return response;
}
示例12: intercept
import org.springframework.http.client.ClientHttpRequestExecution; //導入依賴的package包/類
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException
{
long startTime = System.currentTimeMillis();
ClientHttpResponse response = execution.execute(request, body);
long endTime = System.currentTimeMillis();
if(useDebug)
{
LOG.debug("Request for {} took {} ms", request.getURI().toString(), endTime - startTime);
}
else
{
LOG.info("Request for {} took {} ms", request.getURI().toString(), endTime - startTime);
}
return response;
}
示例13: intercept
import org.springframework.http.client.ClientHttpRequestExecution; //導入依賴的package包/類
@Override
public ClientHttpResponse intercept(final HttpRequest request, final byte[] body,
final ClientHttpRequestExecution execution) throws IOException {
final HttpHeaders requestHeaders = request.getHeaders();
for (final Entry<String, String> entry : headers.entrySet()) {
requestHeaders.add(entry.getKey(), entry.getValue());
}
return execution.execute(request, body);
}
示例14: intercept
import org.springframework.http.client.ClientHttpRequestExecution; //導入依賴的package包/類
@Override
public ClientHttpResponse intercept(final HttpRequest request, final byte[] body,
final ClientHttpRequestExecution execution) throws IOException {
final RequestArguments arguments = toArguments(request, body);
final RequestExecution requestExecution = () -> {
final CompletableFuture<ClientHttpResponse> future = new CompletableFuture<>();
try {
future.complete(execution.execute(request, body));
} catch (final Exception e) {
future.completeExceptionally(e);
}
return future;
};
// since there is no routing to be done, we just call the plugin twice in succession
final RequestExecution before = plugin.interceptBeforeRouting(arguments, requestExecution);
final RequestExecution after = plugin.interceptAfterRouting(arguments, before);
return Completion.join(after.execute());
}
示例15: intercept
import org.springframework.http.client.ClientHttpRequestExecution; //導入依賴的package包/類
/**
* This isn't needed now - but was needed when trying to figure out why term extractor wasn't
* returning data.
*/
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
throws IOException {
// HttpHeaders headers = request.getHeaders();
// headers.add("Accept",
// "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
/*
* headers.add("X-User-Agent",
* "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 Query String Parametersview sourceview URL encoded"
* );
* headers.add("Accept-Encoding", "gzip, deflate, sdch");
* headers.add("Accept-Language", "en-US,en;q=0.8");
* headers.add("Cache-Control", "max-age=0");
* headers.add("Connection", "keep-alive");
* headers.add("Cookie",
* "CTK=19asr9k230nph1f0; RF=\"TFTzyBUJoNr4wP5QpciSOn6ifEMTEVq4ARC0hGY5P-gkhvCY-D1UltWIqfxDhxhHqiN1UggLuPE=\"; IRF=\"1qRi-3v0F_uf-yOkOwHemehIPriDHeZ-AD_rnIAayJ8=\"; CSRF=RCTCj8Abxq9j3u0bL2cYybndr26rFwzL; LC=\"co=FR&hl=fr_FR\"; SHOE=\"uQsQNsQkFYUJ008ISZ8DRWVFtv6W_JMN4mdL-LLfXiJuOW0VoJAjjiVpkv4kQoV23Sg-_-1ytM1OqAz8ROZROJDcOAoDohJHdMU_EBqxbwMOyVIOjrryq7DH189GzMI=\"; PUB=1; BIGipServerjob_iad=!YlkJJm1KgDuhYWHnj+SL47ecq6aoxVInDdjtEnHOjpnVpzOxZBWTrFttjRp0eryuGzkmkx1TYdWHS2k=; INDEED_CSRF_TOKEN=ClPCTHOQ2zlw3egLg2bQl8WakmtEeWpf; _mkto_trk=id:699-SXJ-715&token:_mch-indeed.com-1420554563497-42566; TS01c598d3=0160a2beff09f16a3c10d0f0f0a6a553318c160463ca6c315ab349cad0aefb8dfaa95db17be5052c844f60ecad51ec7c72d952d440688e76cfdabdb3074ee99a7773918ac93d8b06d43de5f602f27582982fb39fbe34263631f197d1f19e0fb70752db8b562fd68ecd5716b3e3d26da06ac246cd6f060c5f347cb466bd53402f81a2506ff7ee638943466c4de4e47bb62d5ee23bd42ae6ba9a59c0ca38e446b40736cbc688; DCT=4; JSESSIONID=97208F039EED60B31A14EF12640B8D84.jasxB_iad-job18; TS016080f8=0160a2beff8af91efc651c51dff589379d71c19e188469c827f0265638b0194c2885f98c9fe455fc17b6ea59258cb631c44485df3e271eae4c2090e2cedce12f163b39094c07e6f01fc7144638866b7333691120a4c4648f7b3b8f00c08419b665958f61ce"
* );
* headers.add("DNT", "1");
* headers.add("Host", "api.indeed.com");
*/
return execution.execute(request, body);
}