William Cheng 3de5483aa0
[JAVA] Add apache httpclient library to java clients (#10218)
* Add apache java client option

* Add sample apache client config

* Switch serialization library, use time formatter

* Add pom template for apache dependencies

* Add initial implementation of ApiClient using apache

* Add apache api template

Plus switch to TypeReference to handle generic types

* Add support for sending json data

* Generate test stubs with @Ignore

* Add accept header

* Remove unnecessary builder assignments

* Set responseHeaders instance variable

* Switch to general serialize / deserialize functions

* Handle sending url encoded form data

* Split response processing into new method

* Allow requests without body

* Use general HttpResponse interface

If the method doesn't need to close it

* Use clients connection timeout

* Add constructor accepting custom client

* Handle multipart and direct file uploads

* Support file downloading

Based on the implementation in the jersey client

* Handle missing content disposition

* Raise error if body given for an unexpected method

* Use try with resources for response handling

* Remove unused url parameter encode method

* Handle content type parse exception

* Improve response content type handling

Would have had issues with content type headers containing a charset

* Make all set methods return client

* Add basic readme

* Send content type with files

* Set domain and path on cookies

Otherwise they will be excluded from the request

* Use consistent quoting in error messages

* Add generated apache sample

* Add generated docs changes

* update samples

* rename library, update samples, docs

* update readme

Co-authored-by: Harry White <hwhite@atlassian.com>
2021-08-22 11:17:31 +08:00

14 KiB

UserApi

All URIs are relative to http://petstore.swagger.io:80/v2

Method HTTP request Description
createUser POST /user Create user
createUsersWithArrayInput POST /user/createWithArray Creates list of users with given input array
createUsersWithListInput POST /user/createWithList Creates list of users with given input array
deleteUser DELETE /user/{username} Delete user
getUserByName GET /user/{username} Get user by user name
loginUser GET /user/login Logs user into the system
logoutUser GET /user/logout Logs out current logged in user session
updateUser PUT /user/{username} Updated user

createUser

createUser(body)

Create user

This can only be done by the logged in user.

Example

// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.UserApi;

public class Example {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        defaultClient.setBasePath("http://petstore.swagger.io:80/v2");

        UserApi apiInstance = new UserApi(defaultClient);
        User body = new User(); // User | Created user object
        try {
            apiInstance.createUser(body);
        } catch (ApiException e) {
            System.err.println("Exception when calling UserApi#createUser");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Parameters

Name Type Description Notes
body User Created user object

Return type

null (empty response body)

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: Not defined

HTTP response details

Status code Description Response headers
0 successful operation -

createUsersWithArrayInput

createUsersWithArrayInput(body)

Creates list of users with given input array

Example

// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.UserApi;

public class Example {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        defaultClient.setBasePath("http://petstore.swagger.io:80/v2");

        UserApi apiInstance = new UserApi(defaultClient);
        List<User> body = Arrays.asList(); // List<User> | List of user object
        try {
            apiInstance.createUsersWithArrayInput(body);
        } catch (ApiException e) {
            System.err.println("Exception when calling UserApi#createUsersWithArrayInput");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Parameters

Name Type Description Notes
body List<User> List of user object

Return type

null (empty response body)

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: Not defined

HTTP response details

Status code Description Response headers
0 successful operation -

createUsersWithListInput

createUsersWithListInput(body)

Creates list of users with given input array

Example

// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.UserApi;

public class Example {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        defaultClient.setBasePath("http://petstore.swagger.io:80/v2");

        UserApi apiInstance = new UserApi(defaultClient);
        List<User> body = Arrays.asList(); // List<User> | List of user object
        try {
            apiInstance.createUsersWithListInput(body);
        } catch (ApiException e) {
            System.err.println("Exception when calling UserApi#createUsersWithListInput");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Parameters

Name Type Description Notes
body List<User> List of user object

Return type

null (empty response body)

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: Not defined

HTTP response details

Status code Description Response headers
0 successful operation -

deleteUser

deleteUser(username)

Delete user

This can only be done by the logged in user.

Example

// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.UserApi;

public class Example {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        defaultClient.setBasePath("http://petstore.swagger.io:80/v2");

        UserApi apiInstance = new UserApi(defaultClient);
        String username = "username_example"; // String | The name that needs to be deleted
        try {
            apiInstance.deleteUser(username);
        } catch (ApiException e) {
            System.err.println("Exception when calling UserApi#deleteUser");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Parameters

Name Type Description Notes
username String The name that needs to be deleted

Return type

null (empty response body)

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: Not defined

HTTP response details

Status code Description Response headers
400 Invalid username supplied -
404 User not found -

getUserByName

User getUserByName(username)

Get user by user name

Example

// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.UserApi;

public class Example {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        defaultClient.setBasePath("http://petstore.swagger.io:80/v2");

        UserApi apiInstance = new UserApi(defaultClient);
        String username = "username_example"; // String | The name that needs to be fetched. Use user1 for testing.
        try {
            User result = apiInstance.getUserByName(username);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling UserApi#getUserByName");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Parameters

Name Type Description Notes
username String The name that needs to be fetched. Use user1 for testing.

Return type

User

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/xml, application/json

HTTP response details

Status code Description Response headers
200 successful operation -
400 Invalid username supplied -
404 User not found -

loginUser

String loginUser(username, password)

Logs user into the system

Example

// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.UserApi;

public class Example {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        defaultClient.setBasePath("http://petstore.swagger.io:80/v2");

        UserApi apiInstance = new UserApi(defaultClient);
        String username = "username_example"; // String | The user name for login
        String password = "password_example"; // String | The password for login in clear text
        try {
            String result = apiInstance.loginUser(username, password);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling UserApi#loginUser");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Parameters

Name Type Description Notes
username String The user name for login
password String The password for login in clear text

Return type

String

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/xml, application/json

HTTP response details

Status code Description Response headers
200 successful operation * X-Rate-Limit - calls per hour allowed by the user
* X-Expires-After - date in UTC when token expires
400 Invalid username/password supplied -

logoutUser

logoutUser()

Logs out current logged in user session

Example

// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.UserApi;

public class Example {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        defaultClient.setBasePath("http://petstore.swagger.io:80/v2");

        UserApi apiInstance = new UserApi(defaultClient);
        try {
            apiInstance.logoutUser();
        } catch (ApiException e) {
            System.err.println("Exception when calling UserApi#logoutUser");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Parameters

This endpoint does not need any parameter.

Return type

null (empty response body)

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: Not defined

HTTP response details

Status code Description Response headers
0 successful operation -

updateUser

updateUser(username, body)

Updated user

This can only be done by the logged in user.

Example

// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.UserApi;

public class Example {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        defaultClient.setBasePath("http://petstore.swagger.io:80/v2");

        UserApi apiInstance = new UserApi(defaultClient);
        String username = "username_example"; // String | name that need to be deleted
        User body = new User(); // User | Updated user object
        try {
            apiInstance.updateUser(username, body);
        } catch (ApiException e) {
            System.err.println("Exception when calling UserApi#updateUser");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

Parameters

Name Type Description Notes
username String name that need to be deleted
body User Updated user object

Return type

null (empty response body)

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: Not defined

HTTP response details

Status code Description Response headers
400 Invalid user supplied -
404 User not found -