本文整理汇总了Java中org.springframework.web.client.RequestCallback类的典型用法代码示例。如果您正苦于以下问题:Java RequestCallback类的具体用法?Java RequestCallback怎么用?Java RequestCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequestCallback类属于org.springframework.web.client包,在下文中一共展示了RequestCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loginAndSaveJsessionIdCookie
import org.springframework.web.client.RequestCallback; //导入依赖的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.RequestCallback; //导入依赖的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: doExecute
import org.springframework.web.client.RequestCallback; //导入依赖的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);
}
示例4: testGetForJsonCWithConcreteItemType
import org.springframework.web.client.RequestCallback; //导入依赖的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));
}
示例5: testNormal
import org.springframework.web.client.RequestCallback; //导入依赖的package包/类
@Test
public void testNormal(@Mocked RequestCallback callback) throws IOException {
CseClientHttpRequest request = new CseClientHttpRequest();
CseRequestCallback cb = new CseRequestCallback(null, callback);
cb.doWithRequest(request);
Assert.assertEquals(null, request.getContext());
}
示例6: testCseEntity
import org.springframework.web.client.RequestCallback; //导入依赖的package包/类
@Test
public void testCseEntity(@Injectable CseHttpEntity<?> entity,
@Mocked RequestCallback callback) throws IOException {
CseClientHttpRequest request = new CseClientHttpRequest();
entity.addContext("c1", "c2");
CseRequestCallback cb = new CseRequestCallback(entity, callback);
cb.doWithRequest(request);
Assert.assertEquals(entity.getContext(), request.getContext());
}
示例7: doExecute
import org.springframework.web.client.RequestCallback; //导入依赖的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);
}
示例8: getForObjectPrivate
import org.springframework.web.client.RequestCallback; //导入依赖的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;
}
示例9: doExecute
import org.springframework.web.client.RequestCallback; //导入依赖的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);
}
}
示例10: execute
import org.springframework.web.client.RequestCallback; //导入依赖的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;
}
示例11: exchange
import org.springframework.web.client.RequestCallback; //导入依赖的package包/类
private ResponseEntity<T> exchange(RequestEntity<?> requestEntity) {
Type type = this.responseType;
if (type instanceof TypeVariable || type instanceof WildcardType) {
type = Object.class;
}
RequestCallback requestCallback = rest.httpEntityCallback((Object) requestEntity,
type);
ResponseExtractor<ResponseEntity<T>> responseExtractor = rest
.responseEntityExtractor(type);
return rest.execute(requestEntity.getUrl(), requestEntity.getMethod(),
requestCallback, responseExtractor);
}
示例12: execute
import org.springframework.web.client.RequestCallback; //导入依赖的package包/类
@Override
public <T> T execute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Map<String, ?> urlVariables) throws RestClientException {
LOG.trace("Injecting execute(String, HttpMethod, RequestCallback, ResponseExtractor, Map) method. Applying retry template.");
final long start = System.currentTimeMillis();
T t = retryTemplate.execute(retryContext -> super.execute(url, method, requestCallback, responseExtractor, urlVariables));
LOG.info("[API]:" + url + " took\t" + (System.currentTimeMillis() - start) + "ms");
return t;
}
示例13: doExecute
import org.springframework.web.client.RequestCallback; //导入依赖的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 (Exception e) {
log.error("Exception occurred while sending the message to uri [" + url +"]. Exception [" + e.getCause() + "]");
throw new AssertionError(e);
}
}
示例14: readStream
import org.springframework.web.client.RequestCallback; //导入依赖的package包/类
private void readStream(RestTemplate restTemplate) {
restTemplate.execute(buildUri(), HttpMethod.GET, new RequestCallback() {
@Override
public void doWithRequest(ClientHttpRequest request) throws IOException {
}
},
new ResponseExtractor<String>() {
@Override
public String extractData(ClientHttpResponse response) throws IOException {
InputStream inputStream = response.getBody();
LineNumberReader reader = null;
try {
reader = new LineNumberReader(new InputStreamReader(inputStream));
resetBackOffs();
while (running.get()) {
String line = reader.readLine();
if (!StringUtils.hasText(line)) {
break;
}
doSendLine(line);
}
}
finally {
if (reader != null) {
reader.close();
}
}
return null;
}
}
);
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:36,代码来源:AbstractTwitterInboundChannelAdapter.java
示例15: twitterTemplate
import org.springframework.web.client.RequestCallback; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Bean
public TwitterTemplate twitterTemplate() {
TwitterTemplate mockTemplate = mock(TwitterTemplate.class);
RestTemplate restTemplate = mock(RestTemplate.class);
final ClientHttpResponse response = mock(ClientHttpResponse.class);
ByteArrayInputStream bais = new ByteArrayInputStream("foo".getBytes());
try {
when(response.getBody()).thenReturn(bais);
}
catch (IOException e) {
}
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
uri().set(invocation.getArgumentAt(0, URI.class));
ResponseExtractor<?> extractor = invocation.getArgumentAt(3, ResponseExtractor.class);
extractor.extractData(response);
return null;
}
}).when(restTemplate).execute(any(URI.class), any(HttpMethod.class), any(RequestCallback.class),
any(ResponseExtractor.class));
when(mockTemplate.getRestTemplate()).thenReturn(restTemplate);
return mockTemplate;
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:28,代码来源:TwitterSourceIntegrationTests.java