Search in sources :

Example 6 with ParameterizedTypeReference

use of org.springframework.core.ParameterizedTypeReference in project tutorials by eugenp.

the class PetApi method findPetsByStatus.

/**
 * Finds Pets by status
 * Multiple status values can be provided with comma separated strings
 * <p><b>200</b> - successful operation
 * <p><b>400</b> - Invalid status value
 * @param status Status values that need to be considered for filter
 * @return List&lt;Pet&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public List<Pet> findPetsByStatus(List<String> status) throws RestClientException {
    Object postBody = null;
    // verify the required parameter 'status' is set
    if (status == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'status' when calling findPetsByStatus");
    }
    String path = UriComponentsBuilder.fromPath("/pet/findByStatus").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>();
    queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("multi".toUpperCase()), "status", status));
    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[] { "petstore_auth" };
    ParameterizedTypeReference<List<Pet>> returnType = new ParameterizedTypeReference<List<Pet>>() {
    };
    return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) MediaType(org.springframework.http.MediaType) ArrayList(java.util.ArrayList) List(java.util.List) Pet(com.baeldung.petstore.client.model.Pet)

Example 7 with ParameterizedTypeReference

use of org.springframework.core.ParameterizedTypeReference in project tutorials by eugenp.

the class PetApi method deletePet.

/**
 * Deletes a pet
 *
 * <p><b>400</b> - Invalid ID supplied
 * <p><b>404</b> - Pet not found
 * @param petId Pet id to delete
 * @param apiKey The apiKey parameter
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public void deletePet(Long petId, String apiKey) throws RestClientException {
    Object postBody = null;
    // verify the required parameter 'petId' is set
    if (petId == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'petId' when calling deletePet");
    }
    // create path and map variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("petId", petId);
    String path = UriComponentsBuilder.fromPath("/pet/{petId}").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>();
    if (apiKey != null)
        headerParams.add("api_key", apiClient.parameterToString(apiKey));
    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[] { "petstore_auth" };
    ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {
    };
    apiClient.invokeAPI(path, HttpMethod.DELETE, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HashMap(java.util.HashMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) MediaType(org.springframework.http.MediaType)

Example 8 with ParameterizedTypeReference

use of org.springframework.core.ParameterizedTypeReference in project tutorials by eugenp.

the class PetApi method findPetsByTags.

/**
 * Finds Pets by tags
 * Muliple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
 * <p><b>200</b> - successful operation
 * <p><b>400</b> - Invalid tag value
 * @param tags Tags to filter by
 * @return List&lt;Pet&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public List<Pet> findPetsByTags(List<String> tags) throws RestClientException {
    Object postBody = null;
    // verify the required parameter 'tags' is set
    if (tags == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'tags' when calling findPetsByTags");
    }
    String path = UriComponentsBuilder.fromPath("/pet/findByTags").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>();
    queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("multi".toUpperCase()), "tags", tags));
    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[] { "petstore_auth" };
    ParameterizedTypeReference<List<Pet>> returnType = new ParameterizedTypeReference<List<Pet>>() {
    };
    return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) MediaType(org.springframework.http.MediaType) ArrayList(java.util.ArrayList) List(java.util.List) Pet(com.baeldung.petstore.client.model.Pet)

Example 9 with ParameterizedTypeReference

use of org.springframework.core.ParameterizedTypeReference in project tutorials by eugenp.

the class PetApi method getPetById.

/**
 * Find pet by ID
 * Returns a single pet
 * <p><b>200</b> - successful operation
 * <p><b>400</b> - Invalid ID supplied
 * <p><b>404</b> - Pet not found
 * @param petId ID of pet to return
 * @return Pet
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public Pet getPetById(Long petId) throws RestClientException {
    Object postBody = null;
    // verify the required parameter 'petId' is set
    if (petId == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'petId' when calling getPetById");
    }
    // create path and map variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("petId", petId);
    String path = UriComponentsBuilder.fromPath("/pet/{petId}").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[] { "api_key" };
    ParameterizedTypeReference<Pet> returnType = new ParameterizedTypeReference<Pet>() {
    };
    return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HashMap(java.util.HashMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) MediaType(org.springframework.http.MediaType) Pet(com.baeldung.petstore.client.model.Pet)

Example 10 with ParameterizedTypeReference

use of org.springframework.core.ParameterizedTypeReference in project tutorials by eugenp.

the class StoreApi method getOrderById.

/**
 * Find purchase order by ID
 * For valid response try integer IDs with value &gt;&#x3D; 1 and &lt;&#x3D; 10. Other values will generated exceptions
 * <p><b>200</b> - successful operation
 * <p><b>400</b> - Invalid ID supplied
 * <p><b>404</b> - Order not found
 * @param orderId ID of pet that needs to be fetched
 * @return Order
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public Order getOrderById(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 getOrderById");
    }
    // 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<Order> returnType = new ParameterizedTypeReference<Order>() {
    };
    return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
Also used : Order(com.baeldung.petstore.client.model.Order) HttpHeaders(org.springframework.http.HttpHeaders) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HashMap(java.util.HashMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) MediaType(org.springframework.http.MediaType)

Aggregations

ParameterizedTypeReference (org.springframework.core.ParameterizedTypeReference)57 MediaType (org.springframework.http.MediaType)29 HttpHeaders (org.springframework.http.HttpHeaders)25 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)22 List (java.util.List)20 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)18 Test (org.junit.jupiter.api.Test)16 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)12 URI (java.net.URI)11 Test (org.junit.Test)10 MockHttpInputMessage (org.springframework.http.MockHttpInputMessage)8 URISyntaxException (java.net.URISyntaxException)7 MockHttpOutputMessage (org.springframework.http.MockHttpOutputMessage)7 DataBuffer (org.springframework.core.io.buffer.DataBuffer)6 HttpEntity (org.springframework.http.HttpEntity)6 Resources (org.springframework.hateoas.Resources)5 Traverson (org.springframework.hateoas.client.Traverson)5 IOException (java.io.IOException)4 DefaultDataBuffer (org.springframework.core.io.buffer.DefaultDataBuffer)4