use of org.springframework.core.ParameterizedTypeReference in project tutorials by eugenp.
the class StoreApi method deleteOrder.
/**
* Delete purchase order by ID
* For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors
* <p><b>400</b> - Invalid ID supplied
* <p><b>404</b> - Order not found
* @param orderId ID of the order that needs to be deleted
* @throws RestClientException if an error occurs while attempting to invoke the API
*/
public void deleteOrder(Long orderId) throws RestClientException {
Object postBody = null;
// verify the required parameter 'orderId' is set
if (orderId == null) {
throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'orderId' when calling deleteOrder");
}
// create path and map variables
final Map<String, Object> uriVariables = new HashMap<String, Object>();
uriVariables.put("orderId", orderId);
String path = UriComponentsBuilder.fromPath("/store/order/{orderId}").buildAndExpand(uriVariables).toUriString();
final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
final HttpHeaders headerParams = new HttpHeaders();
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
final String[] accepts = { "application/xml", "application/json" };
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {};
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
String[] authNames = new String[] {};
ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {
};
apiClient.invokeAPI(path, HttpMethod.DELETE, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
use of org.springframework.core.ParameterizedTypeReference in project tutorials by eugenp.
the class StoreApi method placeOrder.
/**
* Place an order for a pet
*
* <p><b>200</b> - successful operation
* <p><b>400</b> - Invalid Order
* @param body order placed for purchasing the pet
* @return Order
* @throws RestClientException if an error occurs while attempting to invoke the API
*/
public Order placeOrder(Order body) throws RestClientException {
Object postBody = body;
// verify the required parameter 'body' is set
if (body == null) {
throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling placeOrder");
}
String path = UriComponentsBuilder.fromPath("/store/order").build().toUriString();
final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
final HttpHeaders headerParams = new HttpHeaders();
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
final String[] accepts = { "application/xml", "application/json" };
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {};
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
String[] authNames = new String[] {};
ParameterizedTypeReference<Order> returnType = new ParameterizedTypeReference<Order>() {
};
return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
use of org.springframework.core.ParameterizedTypeReference in project tutorials by eugenp.
the class UserApi method createUsersWithListInput.
/**
* Creates list of users with given input array
*
* <p><b>0</b> - successful operation
* @param body List of user object
* @throws RestClientException if an error occurs while attempting to invoke the API
*/
public void createUsersWithListInput(List<User> body) throws RestClientException {
Object postBody = body;
// verify the required parameter 'body' is set
if (body == null) {
throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling createUsersWithListInput");
}
String path = UriComponentsBuilder.fromPath("/user/createWithList").build().toUriString();
final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
final HttpHeaders headerParams = new HttpHeaders();
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
final String[] accepts = { "application/xml", "application/json" };
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {};
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
String[] authNames = new String[] {};
ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {
};
apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
use of org.springframework.core.ParameterizedTypeReference in project tutorials by eugenp.
the class UserApi method createUser.
/**
* Create user
* This can only be done by the logged in user.
* <p><b>0</b> - successful operation
* @param body Created user object
* @throws RestClientException if an error occurs while attempting to invoke the API
*/
public void createUser(User body) throws RestClientException {
Object postBody = body;
// verify the required parameter 'body' is set
if (body == null) {
throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling createUser");
}
String path = UriComponentsBuilder.fromPath("/user").build().toUriString();
final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
final HttpHeaders headerParams = new HttpHeaders();
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
final String[] accepts = { "application/xml", "application/json" };
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = {};
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
String[] authNames = new String[] {};
ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {
};
apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
use of org.springframework.core.ParameterizedTypeReference in project spring-integration by spring-projects.
the class WebFluxRequestExecutingMessageHandler method exchange.
@Override
protected Object exchange(Supplier<URI> uriSupplier, HttpMethod httpMethod, HttpEntity<?> httpRequest, Object expectedResponseType, Message<?> requestMessage) {
WebClient.RequestBodySpec requestSpec = this.webClient.method(httpMethod).uri(b -> uriSupplier.get()).headers(headers -> headers.putAll(httpRequest.getHeaders()));
if (httpRequest.hasBody()) {
requestSpec.body(BodyInserters.fromObject(httpRequest.getBody()));
}
Mono<ClientResponse> responseMono = requestSpec.exchange().flatMap(response -> {
HttpStatus httpStatus = response.statusCode();
if (httpStatus.isError()) {
return response.body(BodyExtractors.toDataBuffers()).reduce(DataBuffer::write).map(dataBuffer -> {
byte[] bytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(bytes);
DataBufferUtils.release(dataBuffer);
return bytes;
}).defaultIfEmpty(new byte[0]).map(bodyBytes -> {
throw new WebClientResponseException("ClientResponse has erroneous status code: " + httpStatus.value() + " " + httpStatus.getReasonPhrase(), httpStatus.value(), httpStatus.getReasonPhrase(), response.headers().asHttpHeaders(), bodyBytes, response.headers().contentType().map(MimeType::getCharset).orElse(StandardCharsets.ISO_8859_1));
});
} else {
return Mono.just(response);
}
});
if (isExpectReply()) {
return responseMono.flatMap(response -> {
ResponseEntity.BodyBuilder httpEntityBuilder = ResponseEntity.status(response.statusCode()).headers(response.headers().asHttpHeaders());
Mono<?> bodyMono;
if (expectedResponseType != null) {
if (this.replyPayloadToFlux) {
BodyExtractor<? extends Flux<?>, ReactiveHttpInputMessage> extractor;
if (expectedResponseType instanceof ParameterizedTypeReference<?>) {
extractor = BodyExtractors.toFlux((ParameterizedTypeReference<?>) expectedResponseType);
} else {
extractor = BodyExtractors.toFlux((Class<?>) expectedResponseType);
}
Flux<?> flux = response.body(extractor);
bodyMono = Mono.just(flux);
} else {
BodyExtractor<? extends Mono<?>, ReactiveHttpInputMessage> extractor;
if (expectedResponseType instanceof ParameterizedTypeReference<?>) {
extractor = BodyExtractors.toMono((ParameterizedTypeReference<?>) expectedResponseType);
} else {
extractor = BodyExtractors.toMono((Class<?>) expectedResponseType);
}
bodyMono = response.body(extractor);
}
} else if (this.bodyExtractor != null) {
Object body = response.body(this.bodyExtractor);
if (body instanceof Mono) {
bodyMono = (Mono<?>) body;
} else {
bodyMono = Mono.just(body);
}
} else {
bodyMono = Mono.empty();
}
return bodyMono.map(httpEntityBuilder::body).defaultIfEmpty(httpEntityBuilder.build());
}).map(this::getReply);
} else {
responseMono.subscribe(v -> {
}, ex -> sendErrorMessage(requestMessage, ex));
return null;
}
}
Aggregations