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


Java ResponseExtractor類代碼示例

本文整理匯總了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;
          }
         });
}
 
開發者ID:Appverse,項目名稱:appverse-server,代碼行數:26,代碼來源:IntegrationWebsocketTest.java

示例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);
  }
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:27,代碼來源:TestRestTemplateWrapper.java

示例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();
}
 
開發者ID:holon-platform,項目名稱:holon-core,代碼行數:20,代碼來源:SpringResponseEntity.java

示例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);
}
 
開發者ID:Clcanny,項目名稱:MicroServiceDemo,代碼行數:24,代碼來源:RestTemplate.java

示例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());
            }
        });
    });
}
 
開發者ID:davidehringer,項目名稱:bosh-java-client,代碼行數:17,代碼來源:SpringJobs.java

示例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));
}
 
開發者ID:KRMAssociatesInc,項目名稱:eHMP,代碼行數:17,代碼來源:JdsTemplateTests.java

示例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;
        }
    };
}
 
開發者ID:openmhealth,項目名稱:shimmer,代碼行數:27,代碼來源:IHealthShim.java

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

示例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);
}
 
開發者ID:ugouku,項目名稱:shoucang,代碼行數:12,代碼來源:BasicAuthRestTemplate.java

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

示例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;
}
 
開發者ID:zg2pro,項目名稱:spring-rest-basis,代碼行數:14,代碼來源:AbstractZg2proRestTemplate.java

示例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);
    }
}
 
開發者ID:mkopylec,項目名稱:errorest-spring-boot-starter,代碼行數:9,代碼來源:ErrorestTemplate.java

示例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;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:11,代碼來源:RestTemplateXhrTransportTests.java


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