Package eirb.pub.app.server.utils
Class UtilHttp
java.lang.Object
eirb.pub.app.server.utils.UtilHttp
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.hc.client5.http.async.methods.SimpleHttpResponseexecuteRequest(org.apache.hc.client5.http.classic.methods.HttpUriRequest httpUriRequest) Execute Http request synchronously with a timeoutstatic CompletableFuture<org.apache.hc.client5.http.async.methods.SimpleHttpResponse> executeRequestAsync(org.apache.hc.client5.http.classic.methods.HttpUriRequest httpUriRequest) static CompletableFuture<org.apache.hc.client5.http.async.methods.SimpleHttpResponse> executeRequestAsync(org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient httpClient, org.apache.hc.client5.http.classic.methods.HttpUriRequest httpUriRequest) Executes the given HTTP request asynchronously and returns a future representing the result.static org.json.JSONObjectexecuteRequestJSON(org.apache.hc.client5.http.classic.methods.HttpUriRequest httpUriRequest) Execute Http request synchronously with a timeoutstatic CompletableFuture<org.json.JSONObject> executeRequestJSONAsync(org.apache.hc.client5.http.classic.methods.HttpUriRequest httpUriRequest) Executes the given HTTP request asynchronously and returns a future representing the result in JSONFormat.
-
Method Details
-
executeRequestAsync
public static CompletableFuture<org.apache.hc.client5.http.async.methods.SimpleHttpResponse> executeRequestAsync(org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient httpClient, org.apache.hc.client5.http.classic.methods.HttpUriRequest httpUriRequest) throws IOException Executes the given HTTP request asynchronously and returns a future representing the result.The returned
CompletableFuturewill:- Complete normally with the HTTP response if the request succeeds (HTTP 200).
- Complete exceptionally with:
BadRequestExceptionif the request is malformed (HTTP 400),AuthenticationExceptionif authentication fails (HTTP 401),ForbiddenAccessExceptionif access is forbidden (HTTP 403),NotFoundExceptionif the resource is not found (HTTP 404),ServerExceptionfor any other unexpected server error,IOExceptionif the request fails due to I/O issues.
- Parameters:
httpClient- The HTTP client to use.httpUriRequest- The HTTP request to execute.- Returns:
- A
CompletableFuturerepresenting the asynchronous result of the request. - Throws:
IOException
-
executeRequestAsync
public static CompletableFuture<org.apache.hc.client5.http.async.methods.SimpleHttpResponse> executeRequestAsync(org.apache.hc.client5.http.classic.methods.HttpUriRequest httpUriRequest) throws IOException - Throws:
IOException
-
executeRequestJSONAsync
public static CompletableFuture<org.json.JSONObject> executeRequestJSONAsync(org.apache.hc.client5.http.classic.methods.HttpUriRequest httpUriRequest) throws IOException Executes the given HTTP request asynchronously and returns a future representing the result in JSONFormat.The returned
CompletableFuturewill:- Complete normally with the HTTP response if the request succeeds (HTTP 200).
- Complete exceptionally with:
BadRequestExceptionif the request is malformed (HTTP 400),AuthenticationExceptionif authentication fails (HTTP 401),ForbiddenAccessExceptionif access is forbidden (HTTP 403),NotFoundExceptionif the resource is not found (HTTP 404),ServerExceptionfor any other unexpected server error,IOExceptionif the request fails due to I/O issues.
- Parameters:
httpUriRequest- The HTTP request to execute.- Returns:
- A
CompletableFuturerepresenting the asynchronous result of the request. - Throws:
IOException
-
executeRequest
public static org.apache.hc.client5.http.async.methods.SimpleHttpResponse executeRequest(org.apache.hc.client5.http.classic.methods.HttpUriRequest httpUriRequest) throws TimeoutException, ServerException, IOException Execute Http request synchronously with a timeout- Parameters:
httpUriRequest- request to execute- Returns:
- the request response
- Throws:
ServerException- can be 400, 401, 500 error from the serverIOException- if the connection was interruptedTimeoutException- if the timeout was reached
-
executeRequestJSON
public static org.json.JSONObject executeRequestJSON(org.apache.hc.client5.http.classic.methods.HttpUriRequest httpUriRequest) throws ServerException, IOException, TimeoutException Execute Http request synchronously with a timeout- Parameters:
httpUriRequest- request to execute- Returns:
- the request response as JSON
- Throws:
ServerException- can be 400, 401, 500 error from the serverIOException- if the connection was interruptedTimeoutException- if the timeout was reached
-