Java Code Examples for org.springframework.http.RequestEntity#getBody()

The following examples show how to use org.springframework.http.RequestEntity#getBody() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyExchange.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
private Mono<ResponseEntity<T>> exchange(RequestEntity<?> requestEntity) {
	Type type = this.responseType;
	RequestBodySpec builder = rest.method(requestEntity.getMethod())
			.uri(requestEntity.getUrl())
			.headers(headers -> addHeaders(headers, requestEntity.getHeaders()));
	Mono<ClientResponse> result;
	if (requestEntity.getBody() instanceof Publisher) {
		@SuppressWarnings("unchecked")
		Publisher<Object> publisher = (Publisher<Object>) requestEntity.getBody();
		result = builder.body(publisher, Object.class).exchange();
	}
	else if (requestEntity.getBody() != null) {
		result = builder.body(BodyInserters.fromValue(requestEntity.getBody()))
				.exchange();
	}
	else {
		if (hasBody) {
			result = builder
					.headers(headers -> addHeaders(headers,
							exchange.getRequest().getHeaders()))
					.body(exchange.getRequest().getBody(), DataBuffer.class)
					.exchange();
		}
		else {
			result = builder.headers(headers -> addHeaders(headers,
					exchange.getRequest().getHeaders())).exchange();
		}
	}
	return result.flatMap(
			response -> response.toEntity(ParameterizedTypeReference.forType(type)));
}
 
Example 2
Source File: CustomRequestEntityConverter.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public RequestEntity<?> convert(OAuth2AuthorizationCodeGrantRequest req) {
    RequestEntity<?> entity = defaultConverter.convert(req);
    MultiValueMap<String, String> params = (MultiValueMap<String,String>) entity.getBody();
    params.add("test2", "extra2");
    System.out.println(params.entrySet());
    return new RequestEntity<>(params, entity.getHeaders(), entity.getMethod(), entity.getUrl());
}
 
Example 3
Source File: InterceptEverythingAndLogController.java    From pcf-crash-course-with-spring-boot with MIT License 4 votes vote down vote up
@RequestMapping()
public ResponseEntity<byte[]> logRequestAndExecute(RequestEntity<byte[]> incomingRequest) {

	LOGGER.info("Intercepted Request: {}", incomingRequest);
	
	HttpHeaders headers = new HttpHeaders();
	
	headers.putAll(incomingRequest.getHeaders());

	URI uri = headers.remove(X_CF_FORWARDED_URL_HEADER).stream().findFirst().map(URI::create)
			.orElseThrow(() -> new RuntimeException("Header is missing " + X_CF_FORWARDED_URL_HEADER));

	RequestEntity<byte[]> outgoingRequest = new RequestEntity<>(incomingRequest.getBody(), headers, incomingRequest.getMethod(), uri);

	// Execute the request specified in the given RequestEntity and 
	// return the response as ResponseEntity.
	ResponseEntity<byte[]> response = restOperations.exchange(outgoingRequest, byte[].class);
	
	LOGGER.info("Sent Response: {}", response);
	
	return response;
}
 
Example 4
Source File: MainControllerStatsIntegrationTests.java    From initializr with Apache License 2.0 4 votes vote down vote up
@PostMapping("/elastic/test/my-entity")
public void handleProjectRequestDocument(RequestEntity<String> input) {
	String authorization = input.getHeaders().getFirst(HttpHeaders.AUTHORIZATION);
	Content content = new Content(authorization, input.getBody());
	this.stats.add(content);
}