org.springframework.http.RequestEntity

Here are the examples of the java api org.springframework.http.RequestEntity taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

301 Examples 7

19 View Source File : SampleTomcatDeployApplicationIT.java
License : Apache License 2.0
Project Creator : yuanmabiji

private void replacedertThatPathProducesExpectedResponse(String path, MediaType accept, MediaType contentType) {
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(URI.create("http://localhost:" + this.port + path)).accept(accept).build();
    ResponseEnreplacedy<String> response = this.rest.exchange(request, String.clreplaced);
    replacedertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
    replacedertThat(contentType.isCompatibleWith(response.getHeaders().getContentType())).as("%s is compatible with %s", contentType, response.getHeaders().getContentType()).isTrue();
}

19 View Source File : SampleWebJspApplicationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void customErrorPage() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    RequestEnreplacedy<Void> request = new RequestEnreplacedy<>(headers, HttpMethod.GET, URI.create("/foo"));
    ResponseEnreplacedy<String> enreplacedy = this.restTemplate.exchange(request, String.clreplaced);
    replacedertThat(enreplacedy.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
    replacedertThat(enreplacedy.getBody()).contains("Something went wrong: 500 Internal Server Error");
}

19 View Source File : SampleSessionApplicationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

private ResponseEnreplacedy<String> nextRequest(RestTemplate restTemplate, URI uri, String cookie) {
    HttpHeaders headers = new HttpHeaders();
    headers.set("Cookie", cookie);
    RequestEnreplacedy<Object> request = new RequestEnreplacedy<>(headers, HttpMethod.GET, uri);
    return restTemplate.exchange(request, String.clreplaced);
}

19 View Source File : SampleSessionApplicationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

private ResponseEnreplacedy<String> firstRequest(RestTemplate restTemplate, URI uri) {
    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization", "Basic " + Base64.getEncoder().encodeToString("user:preplacedword".getBytes()));
    RequestEnreplacedy<Object> request = new RequestEnreplacedy<>(headers, HttpMethod.GET, uri);
    return restTemplate.exchange(request, String.clreplaced);
}

19 View Source File : CorsSampleActuatorApplicationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void preflightRequestWhenCorsConfigInvalidShouldReturnForbidden() throws Exception {
    RequestEnreplacedy<?> enreplacedy = RequestEnreplacedy.options(new URI("/actuator/env")).header("Origin", "http://localhost:9095").header("Access-Control-Request-Method", "GET").build();
    ResponseEnreplacedy<byte[]> exchange = this.testRestTemplate.exchange(enreplacedy, byte[].clreplaced);
    replacedertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
}

19 View Source File : CorsSampleActuatorApplicationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void preflightRequestToEndpointShouldReturnOk() throws Exception {
    RequestEnreplacedy<?> healthRequest = RequestEnreplacedy.options(new URI("/actuator/env")).header("Origin", "http://localhost:8080").header("Access-Control-Request-Method", "GET").build();
    ResponseEnreplacedy<?> exchange = this.testRestTemplate.exchange(healthRequest, Map.clreplaced);
    replacedertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.OK);
}

19 View Source File : BasicErrorControllerIntegrationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
@SuppressWarnings("rawtypes")
public void testRequestBodyValidationForMachineClient() {
    load("--server.error.include-exception=true");
    RequestEnreplacedy request = RequestEnreplacedy.post(URI.create(createUrl("/bodyValidation"))).accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).body("{}");
    ResponseEnreplacedy<Map> enreplacedy = new TestRestTemplate().exchange(request, Map.clreplaced);
    String resp = enreplacedy.getBody().toString();
    replacedertThat(resp).contains("Error count: 1");
    replacedertThat(resp).contains("errors=[{");
    replacedertThat(resp).contains("codes=[");
    replacedertThat(resp).contains(MethodArgumentNotValidException.clreplaced.getName());
}

19 View Source File : BasicErrorControllerIntegrationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
@SuppressWarnings("rawtypes")
public void testNoExceptionByDefaultForMachineClient() {
    load();
    RequestEnreplacedy request = RequestEnreplacedy.get(URI.create(createUrl("/bind"))).accept(MediaType.APPLICATION_JSON).build();
    ResponseEnreplacedy<Map> enreplacedy = new TestRestTemplate().exchange(request, Map.clreplaced);
    String resp = enreplacedy.getBody().toString();
    replacedertThat(resp).doesNotContain("org.springframework.validation.BindException");
}

19 View Source File : BasicErrorControllerIntegrationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void testConventionTemplateMapping() {
    load();
    RequestEnreplacedy<?> request = RequestEnreplacedy.get(URI.create(createUrl("/noStorage"))).accept(MediaType.TEXT_HTML).build();
    ResponseEnreplacedy<String> enreplacedy = new TestRestTemplate().exchange(request, String.clreplaced);
    String resp = enreplacedy.getBody();
    replacedertThat(resp).contains("We are out of storage");
}

19 View Source File : BasicErrorControllerIntegrationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
@SuppressWarnings("rawtypes")
public void testBindingExceptionForMachineClient() {
    load("--server.error.include-exception=true");
    RequestEnreplacedy request = RequestEnreplacedy.get(URI.create(createUrl("/bind"))).accept(MediaType.APPLICATION_JSON).build();
    ResponseEnreplacedy<Map> enreplacedy = new TestRestTemplate().exchange(request, Map.clreplaced);
    String resp = enreplacedy.getBody().toString();
    replacedertThat(resp).contains("Error count: 1");
    replacedertThat(resp).contains("errors=[{");
    replacedertThat(resp).contains("codes=[");
    replacedertThat(resp).contains("org.springframework.validation.BindException");
}

19 View Source File : CloudFoundrySecurityService.java
License : Apache License 2.0
Project Creator : yuanmabiji

/**
 * Return the access level that should be granted to the given token.
 * @param token the token
 * @param applicationId the cloud foundry application ID
 * @return the access level that should be granted
 * @throws CloudFoundryAuthorizationException if the token is not authorized
 */
public AccessLevel getAccessLevel(String token, String applicationId) throws CloudFoundryAuthorizationException {
    try {
        URI uri = getPermissionsUri(applicationId);
        RequestEnreplacedy<?> request = RequestEnreplacedy.get(uri).header("Authorization", "bearer " + token).build();
        Map<?, ?> body = this.restTemplate.exchange(request, Map.clreplaced).getBody();
        if (Boolean.TRUE.equals(body.get("read_sensitive_data"))) {
            return AccessLevel.FULL;
        }
        return AccessLevel.RESTRICTED;
    } catch (HttpClientErrorException ex) {
        if (ex.getStatusCode().equals(HttpStatus.FORBIDDEN)) {
            throw new CloudFoundryAuthorizationException(Reason.ACCESS_DENIED, "Access denied");
        }
        throw new CloudFoundryAuthorizationException(Reason.INVALID_TOKEN, "Invalid token", ex);
    } catch (HttpServerErrorException ex) {
        throw new CloudFoundryAuthorizationException(Reason.SERVICE_UNAVAILABLE, "Cloud controller not reachable");
    }
}

19 View Source File : ApplicationTests.java
License : MIT License
Project Creator : yidao620c

@Test
public void testRestTemplate() {
    LoginParam param = new LoginParam();
    param.setUsername("admin");
    param.setPreplacedword("12345678");
    String loginUrl = String.format("http://localhost:%d/login", port);
    BaseResponse r = restTemplate.postForObject(loginUrl, param, BaseResponse.clreplaced);
    replacedertThat(r.isSuccess(), is(true));
    String token = (String) r.getData();
    UnbindParam unbindParam = new UnbindParam();
    unbindParam.setImei("imei");
    unbindParam.setLocation("location");
    // 设置HTTP Header信息
    String unbindUrl = String.format("http://localhost:%d/unbind", port);
    URI uri;
    try {
        uri = new URI(unbindUrl);
    } catch (URISyntaxException e) {
        logger.error("URI构建失败", e);
        throw new RuntimeException("URI构建失败");
    }
    RequestEnreplacedy<UnbindParam> requestEnreplacedy = RequestEnreplacedy.post(uri).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).header("Authorization", token).body(unbindParam);
    ResponseEnreplacedy<BaseResponse> responseEnreplacedy = restTemplate.exchange(requestEnreplacedy, BaseResponse.clreplaced);
    BaseResponse r2 = responseEnreplacedy.getBody();
    replacedertThat(r2.isSuccess(), is(true));
    replacedertThat(r2.getData(), is("unbind"));
}

19 View Source File : SimpleUrlHandlerMappingIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void testHandlerNotFound() throws Exception {
    URI url = new URI("http://localhost:" + this.port + "/oops");
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(url).build();
    try {
        new RestTemplate().exchange(request, byte[].clreplaced);
    } catch (HttpClientErrorException ex) {
        replacedertEquals(HttpStatus.NOT_FOUND, ex.getStatusCode());
    }
}

19 View Source File : SimpleUrlHandlerMappingIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void testRequestToHeaderSettingHandler() throws Exception {
    URI url = new URI("http://localhost:" + this.port + "/header");
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(url).build();
    ResponseEnreplacedy<byte[]> response = new RestTemplate().exchange(request, byte[].clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
    replacedertEquals("bar", response.getHeaders().getFirst("foo"));
}

19 View Source File : SimpleUrlHandlerMappingIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void testRequestToBarHandler() throws Exception {
    URI url = new URI("http://localhost:" + this.port + "/bar");
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(url).build();
    ResponseEnreplacedy<byte[]> response = new RestTemplate().exchange(request, byte[].clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
    replacedertArrayEquals("bar".getBytes("UTF-8"), response.getBody());
}

19 View Source File : SimpleUrlHandlerMappingIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void testRequestToFooHandler() throws Exception {
    URI url = new URI("http://localhost:" + this.port + "/foo");
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(url).build();
    ResponseEnreplacedy<byte[]> response = new RestTemplate().exchange(request, byte[].clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
    replacedertArrayEquals("foo".getBytes("UTF-8"), response.getBody());
}

19 View Source File : RequestMappingViewResolutionIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

// SPR-15291
@Test
public void redirect() throws Exception {
    SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory() {

        @Override
        protected void prepareConnection(HttpURLConnection conn, String method) throws IOException {
            super.prepareConnection(conn, method);
            conn.setInstanceFollowRedirects(false);
        }
    };
    URI uri = new URI("http://localhost:" + this.port + "/redirect");
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(uri).accept(MediaType.ALL).build();
    ResponseEnreplacedy<Void> response = new RestTemplate(factory).exchange(request, Void.clreplaced);
    replacedertEquals(HttpStatus.SEE_OTHER, response.getStatusCode());
    replacedertEquals("/", response.getHeaders().getLocation().toString());
}

19 View Source File : RequestMappingViewResolutionIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void etagCheckWithNotModifiedResponse() throws Exception {
    URI uri = new URI("http://localhost:" + this.port + "/html");
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(uri).ifNoneMatch("\"deadb33f8badf00d\"").build();
    ResponseEnreplacedy<String> response = getRestTemplate().exchange(request, String.clreplaced);
    replacedertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
    replacedertNull(response.getBody());
}

19 View Source File : RequestMappingIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void forwardedHeaders() {
    // One integration test to verify triggering of Forwarded header support.
    // More fine-grained tests in ForwardedHeaderTransformerTests.
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(URI.create("http://localhost:" + this.port + "/uri")).header("Forwarded", "host=84.198.58.199;proto=https").build();
    ResponseEnreplacedy<String> enreplacedy = getRestTemplate().exchange(request, String.clreplaced);
    replacedertEquals("https://84.198.58.199/uri", enreplacedy.getBody());
}

19 View Source File : PublisherHandlerFunctionIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void postMono() {
    URI uri = URI.create("http://localhost:" + port + "/mono");
    Person person = new Person("Jack");
    RequestEnreplacedy<Person> requestEnreplacedy = RequestEnreplacedy.post(uri).body(person);
    ResponseEnreplacedy<Person> result = restTemplate.exchange(requestEnreplacedy, Person.clreplaced);
    replacedertEquals(HttpStatus.OK, result.getStatusCode());
    replacedertEquals("Jack", result.getBody().getName());
}

19 View Source File : WebSessionIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void changeSessionId() throws Exception {
    // First request: no session yet, new session created
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(createUri()).build();
    ResponseEnreplacedy<Void> response = this.restTemplate.exchange(request, Void.clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
    String oldId = extractSessionId(response.getHeaders());
    replacedertNotNull(oldId);
    replacedertEquals(1, this.handler.getSessionRequestCount());
    // Second request: session id changes
    URI uri = new URI("http://localhost:" + this.port + "/?changeId");
    request = RequestEnreplacedy.get(uri).header("Cookie", "SESSION=" + oldId).build();
    response = this.restTemplate.exchange(request, Void.clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
    String newId = extractSessionId(response.getHeaders());
    replacedertNotNull("Expected new session id", newId);
    replacedertNotEquals(oldId, newId);
    replacedertEquals(2, this.handler.getSessionRequestCount());
}

19 View Source File : WebSessionIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void invalidate() throws Exception {
    // First request: no session yet, new session created
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(createUri()).build();
    ResponseEnreplacedy<Void> response = this.restTemplate.exchange(request, Void.clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
    String id = extractSessionId(response.getHeaders());
    replacedertNotNull(id);
    // Second request: invalidates session
    URI uri = new URI("http://localhost:" + this.port + "/?invalidate");
    request = RequestEnreplacedy.get(uri).header("Cookie", "SESSION=" + id).build();
    response = this.restTemplate.exchange(request, Void.clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
    String value = response.getHeaders().getFirst("Set-Cookie");
    replacedertNotNull(value);
    replacedertTrue("Actual value: " + value, value.contains("Max-Age=0"));
}

19 View Source File : WebSessionIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void expiredSessionEnds() throws Exception {
    // First request: no session yet, new session created
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(createUri()).build();
    ResponseEnreplacedy<Void> response = this.restTemplate.exchange(request, Void.clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
    String id = extractSessionId(response.getHeaders());
    replacedertNotNull(id);
    // Now fast-forward by 31 minutes
    InMemoryWebSessionStore store = (InMemoryWebSessionStore) this.sessionManager.getSessionStore();
    store.setClock(Clock.offset(store.getClock(), Duration.ofMinutes(31)));
    // Second request: session expires
    URI uri = new URI("http://localhost:" + this.port + "/?expire");
    request = RequestEnreplacedy.get(uri).header("Cookie", "SESSION=" + id).build();
    response = this.restTemplate.exchange(request, Void.clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
    String value = response.getHeaders().getFirst("Set-Cookie");
    replacedertNotNull(value);
    replacedertTrue("Actual value: " + value, value.contains("Max-Age=0"));
}

19 View Source File : WebSessionIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void expiredSessionIsRecreated() throws Exception {
    // First request: no session yet, new session created
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(createUri()).build();
    ResponseEnreplacedy<Void> response = this.restTemplate.exchange(request, Void.clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
    String id = extractSessionId(response.getHeaders());
    replacedertNotNull(id);
    replacedertEquals(1, this.handler.getSessionRequestCount());
    // Second request: same session
    request = RequestEnreplacedy.get(createUri()).header("Cookie", "SESSION=" + id).build();
    response = this.restTemplate.exchange(request, Void.clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
    replacedertNull(response.getHeaders().get("Set-Cookie"));
    replacedertEquals(2, this.handler.getSessionRequestCount());
    // Now fast-forward by 31 minutes
    InMemoryWebSessionStore store = (InMemoryWebSessionStore) this.sessionManager.getSessionStore();
    WebSession session = store.retrieveSession(id).block();
    replacedertNotNull(session);
    store.setClock(Clock.offset(store.getClock(), Duration.ofMinutes(31)));
    // Third request: expired session, new session created
    request = RequestEnreplacedy.get(createUri()).header("Cookie", "SESSION=" + id).build();
    response = this.restTemplate.exchange(request, Void.clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
    id = extractSessionId(response.getHeaders());
    replacedertNotNull("Expected new session id", id);
    replacedertEquals(1, this.handler.getSessionRequestCount());
}

19 View Source File : WebSessionIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void createSession() throws Exception {
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(createUri()).build();
    ResponseEnreplacedy<Void> response = this.restTemplate.exchange(request, Void.clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
    String id = extractSessionId(response.getHeaders());
    replacedertNotNull(id);
    replacedertEquals(1, this.handler.getSessionRequestCount());
    request = RequestEnreplacedy.get(createUri()).header("Cookie", "SESSION=" + id).build();
    response = this.restTemplate.exchange(request, Void.clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
    replacedertNull(response.getHeaders().get("Set-Cookie"));
    replacedertEquals(2, this.handler.getSessionRequestCount());
}

19 View Source File : ZeroCopyIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void zeroCopy() throws Exception {
    // Zero-copy only does not support servlet
    replacedumeTrue(server instanceof ReactorHttpServer || server instanceof UndertowHttpServer);
    URI url = new URI("http://localhost:" + port);
    RequestEnreplacedy<?> request = RequestEnreplacedy.get(url).build();
    ResponseEnreplacedy<byte[]> response = new RestTemplate().exchange(request, byte[].clreplaced);
    Resource logo = new ClreplacedPathResource("spring.png", ZeroCopyIntegrationTests.clreplaced);
    replacedertTrue(response.hasBody());
    replacedertEquals(logo.contentLength(), response.getHeaders().getContentLength());
    replacedertEquals(logo.contentLength(), response.getBody().length);
    replacedertEquals(MediaType.IMAGE_PNG, response.getHeaders().getContentType());
}

19 View Source File : WriteOnlyHandlerIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void writeOnly() throws Exception {
    RestTemplate restTemplate = new RestTemplate();
    this.body = randomBytes();
    RequestEnreplacedy<byte[]> request = RequestEnreplacedy.post(new URI("http://localhost:" + port)).body("".getBytes(StandardCharsets.UTF_8));
    ResponseEnreplacedy<byte[]> response = restTemplate.exchange(request, byte[].clreplaced);
    replacedertArrayEquals(body, response.getBody());
}

19 View Source File : ServerHttpsRequestIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void checkUri() throws Exception {
    URI url = new URI("https://localhost:" + port + "/foo?param=bar");
    RequestEnreplacedy<Void> request = RequestEnreplacedy.post(url).build();
    ResponseEnreplacedy<Void> response = this.restTemplate.exchange(request, Void.clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
}

19 View Source File : ServerHttpRequestIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void checkUri() throws Exception {
    URI url = new URI("http://localhost:" + port + "/foo?param=bar");
    RequestEnreplacedy<Void> request = RequestEnreplacedy.post(url).build();
    ResponseEnreplacedy<Void> response = new RestTemplate().exchange(request, Void.clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
}

19 View Source File : RandomHandlerIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void random() throws Throwable {
    // TODO: fix Reactor support
    RestTemplate restTemplate = new RestTemplate();
    byte[] body = randomBytes();
    RequestEnreplacedy<byte[]> request = RequestEnreplacedy.post(new URI("http://localhost:" + port)).body(body);
    ResponseEnreplacedy<byte[]> response = restTemplate.exchange(request, byte[].clreplaced);
    replacedertNotNull(response.getBody());
    replacedertEquals(RESPONSE_SIZE, response.getHeaders().getContentLength());
    replacedertEquals(RESPONSE_SIZE, response.getBody().length);
}

19 View Source File : MultipartIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void getFormParts() throws Exception {
    RestTemplate restTemplate = new RestTemplate();
    RequestEnreplacedy<MultiValueMap<String, Object>> request = RequestEnreplacedy.post(new URI("http://localhost:" + port + "/form-parts")).contentType(MediaType.MULTIPART_FORM_DATA).body(generateBody());
    ResponseEnreplacedy<Void> response = restTemplate.exchange(request, Void.clreplaced);
    replacedertEquals(HttpStatus.OK, response.getStatusCode());
}

19 View Source File : EchoHandlerIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void echo() throws Exception {
    RestTemplate restTemplate = new RestTemplate();
    byte[] body = randomBytes();
    RequestEnreplacedy<byte[]> request = RequestEnreplacedy.post(new URI("http://localhost:" + port)).body(body);
    ResponseEnreplacedy<byte[]> response = restTemplate.exchange(request, byte[].clreplaced);
    replacedertArrayEquals(body, response.getBody());
}

19 View Source File : TccCoordinatorClient.java
License : Apache License 2.0
Project Creator : SpringCloud

public ResponseEnreplacedy<String> confirm(Transaction transaction) {
    RequestEnreplacedy<Transaction> requestEnreplacedy = RequestEnreplacedy.put(URI.create(tccCoordinatorUrl + "/confirm")).contentType(APPLICATION_TCC_JSON).body(transaction);
    return restTemplate.exchange(requestEnreplacedy, String.clreplaced);
}

19 View Source File : TccCoordinatorClient.java
License : Apache License 2.0
Project Creator : SpringCloud

public ResponseEnreplacedy<String> cancel(Transaction transaction) {
    RequestEnreplacedy<Transaction> requestEnreplacedy = RequestEnreplacedy.put(URI.create(tccCoordinatorUrl + "/cancel")).contentType(APPLICATION_TCC_JSON).body(transaction);
    return restTemplate.exchange(requestEnreplacedy, String.clreplaced);
}

19 View Source File : RequestForwarder.java
License : MIT License
Project Creator : spring2go

public ResponseEnreplacedy<byte[]> forwardHttpRequest(RequestData data, String traceId, MappingProperties mapping) {
    ForwardDestination destination = resolveForwardDestination(data.getUri(), mapping);
    prepareForwardedRequestHeaders(data, destination);
    traceInterceptor.onForwardStart(traceId, destination.getMappingName(), data.getMethod(), data.getHost(), destination.getUri().toString(), data.getBody(), data.getHeaders());
    RequestEnreplacedy<byte[]> request = new RequestEnreplacedy<>(data.getBody(), data.getHeaders(), data.getMethod(), destination.getUri());
    ResponseData response = sendRequest(traceId, request, mapping, destination.getMappingMetricsName(), data);
    log.debug(String.format("Forwarded: %s %s %s -> %s %d", data.getMethod(), data.getHost(), data.getUri(), destination.getUri(), response.getStatus().value()));
    traceInterceptor.onForwardComplete(traceId, response.getStatus(), response.getBody(), response.getHeaders());
    postForwardResponseInterceptor.intercept(response, mapping);
    prepareForwardedResponseHeaders(response);
    return status(response.getStatus()).headers(response.getHeaders()).body(response.getBody());
}

19 View Source File : MainPage.java
License : MIT License
Project Creator : spring2go

private void tryToGetUserInfo(ModelAndView mv, String token) {
    RestTemplate restTemplate = new RestTemplate();
    MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    headers.add("Authorization", "Bearer " + token);
    String endpoint = "http://localhost:8080/api/userinfo";
    try {
        RequestEnreplacedy<Object> request = new RequestEnreplacedy<>(headers, HttpMethod.GET, URI.create(endpoint));
        ResponseEnreplacedy<UserInfo> userInfo = restTemplate.exchange(request, UserInfo.clreplaced);
        if (userInfo.getStatusCode().is2xxSuccessful()) {
            mv.addObject("userInfo", userInfo.getBody());
        } else {
            throw new RuntimeException("it was not possible to retrieve user profile");
        }
    } catch (HttpClientErrorException e) {
        throw new RuntimeException("it was not possible to retrieve user profile");
    }
}

19 View Source File : AuthorizationCodeTokenService.java
License : MIT License
Project Creator : spring2go

public OAuth2Token getToken(String authorizationCode) {
    RestTemplate rest = new RestTemplate();
    String authBase64 = configuration.encodeCredentials("clientapp", "112233");
    RequestEnreplacedy<MultiValueMap<String, String>> requestEnreplacedy = new RequestEnreplacedy<>(configuration.getBody(authorizationCode), configuration.getHeader(authBase64), HttpMethod.POST, URI.create("http://localhost:8080/oauth/token"));
    ResponseEnreplacedy<OAuth2Token> responseEnreplacedy = rest.exchange(requestEnreplacedy, OAuth2Token.clreplaced);
    if (responseEnreplacedy.getStatusCode().is2xxSuccessful()) {
        return responseEnreplacedy.getBody();
    }
    throw new RuntimeException("error trying to retrieve access token");
}

@Test
public void setAndGetSessionAttributeIsCorrect() {
    RestTemplate restTemplate = new RestTemplate();
    ResponseEnreplacedy<String> response = restTemplate.getForEnreplacedy(url.concat("/setter?name=MyKey&value=TEST"), String.clreplaced);
    replacedertThat(response.getBody()).isEqualTo("SUCCESS");
    // System.err.printf("HTTP RESPONSE HEADERS [%s]%n", response.getHeaders());
    String httpHeaderWithSessionId = StringUtils.collectionToCommaDelimitedString(response.getHeaders().get(HTTP_HEADER_AUTHENTICATION_INFO));
    replacedertThat(httpHeaderWithSessionId).contains(sessionId.get());
    replacedertThat(this.sessionsRegion.keySetOnServer()).containsExactlyInAnyOrder(sessionId.get());
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(URI.create(url.concat("/getter?name=MyKey"))).header(HTTP_HEADER_AUTHENTICATION_INFO, httpHeaderWithSessionId).build();
    response = restTemplate.exchange(request, String.clreplaced);
    replacedertThat(response.getBody()).isEqualTo("TEST");
}

@Test
public void setAndGetSessionAttributeIsCorrect() {
    RestTemplate restTemplate = new RestTemplate();
    ResponseEnreplacedy<String> response = restTemplate.getForEnreplacedy(url.concat("/setter?name=MyKey&value=TEST"), String.clreplaced);
    replacedertThat(response.getBody()).isEqualTo("SUCCESS");
    // System.err.printf("HTTP RESPONSE HEADERS [%s]%n", response.getHeaders());
    String httpHeaderWithSessionId = StringUtils.collectionToCommaDelimitedString(response.getHeaders().get(HTTP_HEADER_AUTHENTICATION_INFO));
    replacedertThat(httpHeaderWithSessionId).contains(sessionId.get());
    replacedertThat(this.sessionsRegion.keySet()).containsExactlyInAnyOrder(sessionId.get());
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(URI.create(url.concat("/getter?name=MyKey"))).header(HTTP_HEADER_AUTHENTICATION_INFO, httpHeaderWithSessionId).build();
    response = restTemplate.exchange(request, String.clreplaced);
    replacedertThat(response.getBody()).isEqualTo("TEST");
}

19 View Source File : StartApplicationIntegrationTests.java
License : Apache License 2.0
Project Creator : spring-io

@Test
void metadataCanBeSerialized() throws URISyntaxException, IOException {
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(new URI("/")).accept(MediaType.parseMediaType("application/vnd.initializr.v2.1+json")).build();
    ResponseEnreplacedy<String> response = this.restTemplate.exchange(request, String.clreplaced);
    replacedertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
    new ObjectMapper().readTree(response.getBody());
}

19 View Source File : StartApplicationIntegrationTests.java
License : Apache License 2.0
Project Creator : spring-io

@Test
void configurationCanBeSerialized() throws URISyntaxException {
    RequestEnreplacedy<Void> request = RequestEnreplacedy.get(new URI("/metadata/config")).accept(MediaType.APPLICATION_JSON).build();
    ResponseEnreplacedy<String> response = this.restTemplate.exchange(request, String.clreplaced);
    replacedertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
    InitializrMetadata actual = InitializrMetadataBuilder.create().withInitializrMetadata(new ByteArrayResource(response.getBody().getBytes())).build();
    replacedertThat(actual).isNotNull();
    InitializrMetadata expected = this.metadataProvider.get();
    replacedertThat(actual.getDependencies().getAll().size()).isEqualTo(expected.getDependencies().getAll().size());
    replacedertThat(actual.getConfiguration().getEnv().getBoms().size()).isEqualTo(expected.getConfiguration().getEnv().getBoms().size());
}

19 View Source File : HttpArtifactoryRepository.java
License : Apache License 2.0
Project Creator : spring-io

private void deployUsingChecksum(DeployableArtifact artifact) throws IOException {
    RequestEnreplacedy<Void> request = deployRequest(artifact).header("X-Checksum-Deploy", "true").build();
    this.restTemplate.exchange(request, Void.clreplaced);
}

19 View Source File : HttpArtifactoryBuildRuns.java
License : Apache License 2.0
Project Creator : spring-io

@Override
public List<DeployedArtifact> getDeployedArtifacts(String buildNumber) {
    replacedert.notNull(buildNumber, "Build number must not be null");
    URI uri = UriComponentsBuilder.fromUriString(this.uri).path("/api/search/aql").buildAndExpand(NO_VARIABLES).encode().toUri();
    RequestEnreplacedy<String> request = RequestEnreplacedy.post(uri).contentType(MediaType.TEXT_PLAIN).body(buildFetchQuery(this.buildName, buildNumber));
    return this.restTemplate.exchange(request, DeployedArtifactQueryResponse.clreplaced).getBody().getResults();
}

19 View Source File : HttpArtifactoryBuildRuns.java
License : Apache License 2.0
Project Creator : spring-io

private void add(BuildInfo buildInfo) {
    URI uri = UriComponentsBuilder.fromUriString(this.uri).path("api/build").buildAndExpand(NO_VARIABLES).encode().toUri();
    RequestEnreplacedy<BuildInfo> request = RequestEnreplacedy.put(uri).contentType(MediaType.APPLICATION_JSON).body(buildInfo);
    ResponseEnreplacedy<Void> exchange = this.restTemplate.exchange(request, Void.clreplaced);
    exchange.getBody();
}

19 View Source File : RestTemplateSaganClient.java
License : Apache License 2.0
Project Creator : spring-cloud

@Override
public Project updateRelease(String projectName, List<ReleaseUpdate> releaseUpdates) {
    RequestEnreplacedy<List<ReleaseUpdate>> request = RequestEnreplacedy.put(URI.create(this.baseUrl + "/project_metadata/" + projectName + "/releases")).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE).body(releaseUpdates);
    ResponseEnreplacedy<Project> enreplacedy = this.restTemplate.exchange(request, Project.clreplaced);
    Project project = enreplacedy.getBody();
    log.info("Response from Sagan\n\n[{}] \n with body [{}]", enreplacedy, project);
    return project;
}

19 View Source File : RestTemplateSaganClient.java
License : Apache License 2.0
Project Creator : spring-cloud

@Override
public Project patchProject(Project project) {
    RequestEnreplacedy<Project> request = RequestEnreplacedy.patch(URI.create(this.baseUrl + "/project_metadata/" + project.id)).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE).body(project);
    ResponseEnreplacedy<Project> enreplacedy = this.restTemplate.exchange(request, Project.clreplaced);
    Project updatedProject = enreplacedy.getBody();
    log.info("Response from Sagan\n\n[{}] \n with body [{}]", enreplacedy, updatedProject);
    return updatedProject;
}

19 View Source File : ProxyExchange.java
License : Apache License 2.0
Project Creator : spring-cloud

public Mono<ResponseEnreplacedy<T>> head() {
    RequestEnreplacedy<?> requestEnreplacedy = headers((BodyBuilder) RequestEnreplacedy.head(uri)).build();
    return exchange(requestEnreplacedy);
}

19 View Source File : ProxyExchange.java
License : Apache License 2.0
Project Creator : spring-cloud

public Mono<ResponseEnreplacedy<T>> delete() {
    RequestEnreplacedy<Void> requestEnreplacedy = headers((BodyBuilder) RequestEnreplacedy.delete(uri)).build();
    return exchange(requestEnreplacedy);
}

19 View Source File : ProxyExchange.java
License : Apache License 2.0
Project Creator : spring-cloud

public Mono<ResponseEnreplacedy<T>> get() {
    RequestEnreplacedy<?> requestEnreplacedy = headers((BodyBuilder) RequestEnreplacedy.get(uri)).build();
    return exchange(requestEnreplacedy);
}

19 View Source File : ProxyExchange.java
License : Apache License 2.0
Project Creator : spring-cloud

public Mono<ResponseEnreplacedy<T>> options() {
    RequestEnreplacedy<?> requestEnreplacedy = headers((BodyBuilder) RequestEnreplacedy.options(uri)).build();
    return exchange(requestEnreplacedy);
}

See More Examples