本文整理匯總了Java中org.springframework.web.client.ResponseExtractor類的典型用法代碼示例。如果您正苦於以下問題:Java ResponseExtractor類的具體用法?Java ResponseExtractor怎麽用?Java ResponseExtractor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ResponseExtractor類屬於org.springframework.web.client包,在下文中一共展示了ResponseExtractor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loginAndSaveJsessionIdCookie
import org.springframework.web.client.ResponseExtractor; //導入依賴的package包/類
private static void loginAndSaveJsessionIdCookie(final String user, final String password,
final HttpHeaders headersToUpdate) {
String url = "http://localhost:" + port + "/";
new RestTemplate().execute(url, HttpMethod.POST,
new RequestCallback() {
@Override
public void doWithRequest(ClientHttpRequest request) throws IOException {
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add("username", user);
map.add("password", password);
new FormHttpMessageConverter().write(map, MediaType.APPLICATION_FORM_URLENCODED, request);
}
},
new ResponseExtractor<Object>() {
@Override
public Object extractData(ClientHttpResponse response) throws IOException {
headersToUpdate.add("Cookie", response.getHeaders().getFirst("Set-Cookie"));
return null;
}
});
}
示例2: executeWithUnderlyingRestTemplate
import org.springframework.web.client.ResponseExtractor; //導入依賴的package包/類
@Test
public void executeWithUnderlyingRestTemplate() {
RequestCallback requestCallback = clientHttpRequest -> {
};
ResponseExtractor<ResponseEntity<String>> responseExtractor = clientHttpResponse -> responseEntity;
ResponseEntity<String> actual;
for (HttpMethod method : httpMethods) {
when(underlying.execute(url, method, requestCallback, responseExtractor, param1, param2))
.thenReturn(responseEntity);
actual = wrapper.execute(url, method, requestCallback, responseExtractor, param1, param2);
assertThat(actual, is(responseEntity));
verify(underlying).execute(url, method, requestCallback, responseExtractor, param1, param2);
when(underlying.execute(url, method, requestCallback, responseExtractor, paramsMap)).thenReturn(responseEntity);
actual = wrapper.execute(url, method, requestCallback, responseExtractor, paramsMap);
assertThat(actual, is(responseEntity));
verify(underlying).execute(url, method, requestCallback, responseExtractor, paramsMap);
when(underlying.execute(uri, method, requestCallback, responseExtractor)).thenReturn(responseEntity);
actual = wrapper.execute(uri, method, requestCallback, responseExtractor);
assertThat(actual, is(responseEntity));
verify(underlying).execute(uri, method, requestCallback, responseExtractor);
}
}
示例3: readResponse
import org.springframework.web.client.ResponseExtractor; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private <E> Optional<E> readResponse(ResponseType<E> type) {
final Type responseType = type.getType();
try {
// check InputStream
if (InputStream.class == responseType) {
return (Optional<E>) Optional.ofNullable(response.getBody().getInputStream());
}
if (Void.class != responseType) {
ResponseExtractor<E> extractor = new HttpMessageConverterExtractor<>(responseType,
getMessageConverters());
return Optional.ofNullable(extractor.extractData(httpResponse));
}
} catch (Exception e) {
throw new HttpEntityProcessingException("Failed to read HTTP entity as [" + type + "]", e);
}
return Optional.empty();
}
示例4: doExecute
import org.springframework.web.client.ResponseExtractor; //導入依賴的package包/類
@Override
@Nullable
protected <T> T doExecute(URI url, @Nullable HttpMethod method, @Nullable RequestCallback requestCallback,
@Nullable ResponseExtractor<T> responseExtractor) throws RestClientException {
String from = name;
String to = url.
toString().
replace("http://", "").
replace("http:// www.", "").
replace("www.", "").
replace("/", "%20").
toLowerCase();
System.out.println(from);
System.out.println(to);
try {
restTemplate.postForObject("http://trace-callback-service/" + from + "/" + to, null, Object.class);
} catch (Exception exception) {
}
return super.doExecute(url, method, requestCallback, responseExtractor);
}
示例5: getGzip
import org.springframework.web.client.ResponseExtractor; //導入依賴的package包/類
private final Observable<File> getGzip(Consumer<UriComponentsBuilder> builderCallback) {
// For responses that have a Content-Type of application/x-gzip, we need to
// decompress them. The RestTemplate and HttpClient don't handle this for
// us
return createObservable(() -> {
UriComponentsBuilder builder = UriComponentsBuilder.fromUri(this.root);
builderCallback.accept(builder);
URI uri = builder.build().toUri();
return this.restOperations.execute(uri, HttpMethod.GET, null, new ResponseExtractor<File>() {
@Override
public File extractData(ClientHttpResponse response) throws IOException {
return decompress(response.getBody());
}
});
});
}
示例6: testGetForJsonCWithConcreteItemType
import org.springframework.web.client.ResponseExtractor; //導入依賴的package包/類
@Test
public void testGetForJsonCWithConcreteItemType() throws Exception {
JsonNode mockResponse = new ObjectMapper().readTree("{\"apiVersion\":\"2.3\",\"data\":{\"items\":[{\"bar\":\"fred\",\"baz\":true},{\"bar\":\"wilma\",\"baz\":false}]}}");
when(mockRestTemplate.execute(eq(URI.create(JDS_URL + "/vpr/34/find/foo")), eq(HttpMethod.GET), any(RequestCallback.class), any(ResponseExtractor.class))).thenReturn(mockResponse);
JsonCCollection<Foo> r = t.getForJsonC(Foo.class, "/vpr/34/find/foo");
assertThat(r.apiVersion, is("2.3"));
assertThat(r.getItems().size(), equalTo(2));
assertThat(r.getItems().get(0).getBar(), is("fred"));
assertThat(r.getItems().get(0).isBaz(), is(true));
assertThat(r.getItems().get(1).getBar(), is("wilma"));
assertThat(r.getItems().get(1).isBaz(), is(false));
verify(mockRestTemplate).execute(eq(URI.create(JDS_URL + "/vpr/34/find/foo")), eq(HttpMethod.GET), any(RequestCallback.class), any(ResponseExtractor.class));
}
示例7: getResponseExtractor
import org.springframework.web.client.ResponseExtractor; //導入依賴的package包/類
@Override
protected ResponseExtractor<OAuth2AccessToken> getResponseExtractor() {
return new ResponseExtractor<OAuth2AccessToken>() {
@Override
public OAuth2AccessToken extractData(ClientHttpResponse response) throws IOException {
JsonNode node = new ObjectMapper().readTree(response.getBody());
String token = Preconditions
.checkNotNull(node.path("AccessToken").textValue(), "Missing access token: %s", node);
String refreshToken = Preconditions
.checkNotNull(node.path("RefreshToken").textValue(), "Missing refresh token: %s" + node);
String userId =
Preconditions.checkNotNull(node.path("UserID").textValue(), "Missing UserID: %s", node);
long expiresIn = node.path("Expires").longValue() * 1000;
Preconditions.checkArgument(expiresIn > 0, "Missing Expires: %s", node);
DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken(token);
accessToken.setExpiration(new Date(System.currentTimeMillis() + expiresIn));
accessToken.setRefreshToken(new DefaultOAuth2RefreshToken(refreshToken));
accessToken.setAdditionalInformation(ImmutableMap.<String, Object>of("UserID", userId));
return accessToken;
}
};
}
示例8: assertNetworkCallFails
import org.springframework.web.client.ResponseExtractor; //導入依賴的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());
}
示例9: getAuthorizationResponseExtractor
import org.springframework.web.client.ResponseExtractor; //導入依賴的package包/類
protected ResponseExtractor<ResponseEntity<Void>> getAuthorizationResponseExtractor() {
return new ResponseExtractor<ResponseEntity<Void>>() {
public ResponseEntity<Void> extractData(ClientHttpResponse response) throws IOException {
return new ResponseEntity(response.getHeaders(), response.getStatusCode());
}
};
}
開發者ID:luotuo,項目名稱:springboot-security-wechat,代碼行數:8,代碼來源:MyAuthorizationCodeAccessTokenProvider.java
示例10: 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
示例11: doExecute
import org.springframework.web.client.ResponseExtractor; //導入依賴的package包/類
@Override
protected <T> T doExecute(URI url, HttpMethod method,
RequestCallback requestCallback,
ResponseExtractor<T> responseExtractor) throws RestClientException {
RequestCallbackDecorator requestCallbackDecorator = new RequestCallbackDecorator(
requestCallback);
return super.doExecute(url, method, requestCallbackDecorator,
responseExtractor);
}
示例12: download
import org.springframework.web.client.ResponseExtractor; //導入依賴的package包/類
@Override
public void download(String path, File destination) {
Assert.hasLength(path, "Path must not be empty");
URI uri = UriComponentsBuilder.fromUriString(this.uri).path(this.repositoryName)
.path("/" + path).buildAndExpand(NO_VARIABLES).encode().toUri();
ResponseExtractor<Void> responseExtractor = (response) -> {
Path fullPath = destination.toPath().resolve(path);
Files.createDirectories(fullPath.getParent());
Files.copy(response.getBody(), fullPath);
return null;
};
this.restTemplate.execute(uri, HttpMethod.GET, null, responseExtractor);
}
示例13: getForObjectPrivate
import org.springframework.web.client.ResponseExtractor; //導入依賴的package包/類
private Path getForObjectPrivate(String serviceUrl, String tmpFilePath) {
final Map singleValueMap = getFilesStreamingOperationsHttpHeaders().toSingleValueMap();
final Path temp = Paths.get(tmpFilePath);
RequestCallback requestCallback = (ClientHttpRequest request) -> {
request.getHeaders().setAll(singleValueMap);
};
ResponseExtractor<Void> responseExtractor = (ClientHttpResponse response) -> {
Files.copy(response.getBody(), temp, StandardCopyOption.REPLACE_EXISTING);
return null;
};
this.execute(serviceUrl, HttpMethod.GET, requestCallback, responseExtractor);
return temp;
}
示例14: doExecute
import org.springframework.web.client.ResponseExtractor; //導入依賴的package包/類
@Override
protected <T> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor) throws RestClientException {
try {
return super.doExecute(url, method, requestCallback, responseExtractor);
} catch (HttpStatusCodeException ex) {
throw createExternalHttpRequestException(method, url, ex);
}
}
示例15: 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;
}