Search in sources :

Example 6 with RestCallFailedException

use of org.openkilda.exception.RestCallFailedException in project open-kilda by telstra.

the class OAuthService method getHttpResponse.

private HttpResponse getHttpResponse(UrlDto request, AuthConfigDto authDto) {
    try {
        String accessToken = getToken((OauthTwoConfigDto) authDto);
        if (request.getHeader() != null) {
            request.setHeader(request.getHeader() + "\nAuthorization:" + accessToken);
        } else {
            request.setHeader("Authorization:" + accessToken);
        }
        HttpMethod httpMethod = null;
        if (("POST").equalsIgnoreCase(request.getMethodType())) {
            httpMethod = HttpMethod.POST;
        } else if (("PUT").equalsIgnoreCase(request.getMethodType())) {
            httpMethod = HttpMethod.PUT;
        } else if (("DELETE").equalsIgnoreCase(request.getMethodType())) {
            httpMethod = HttpMethod.DELETE;
        } else {
            httpMethod = HttpMethod.GET;
        }
        ApiRequestDto apiRequestDto = new ApiRequestDto(request.getUrl(), httpMethod, request.getHeader(), request.getBody());
        if (request.getParams() != null) {
            prepareRequest.preprocessApiRequest(apiRequestDto, request.getParams());
        }
        return restClientManager.invoke(apiRequestDto);
    } catch (RestCallFailedException | AuthenticationException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : AuthenticationException(org.openkilda.exception.AuthenticationException) RestCallFailedException(org.openkilda.exception.RestCallFailedException) ApiRequestDto(org.openkilda.store.common.model.ApiRequestDto) HttpMethod(org.springframework.http.HttpMethod)

Aggregations

RestCallFailedException (org.openkilda.exception.RestCallFailedException)6 HttpResponse (org.apache.http.HttpResponse)4 IOException (java.io.IOException)3 ExternalSystemException (org.openkilda.exception.ExternalSystemException)3 UnauthorizedException (org.openkilda.exception.UnauthorizedException)3 InvalidResponseException (org.openkilda.integration.exception.InvalidResponseException)3 HttpClient (org.apache.http.client.HttpClient)2 HttpEntityEnclosingRequestBase (org.apache.http.client.methods.HttpEntityEnclosingRequestBase)2 HttpGet (org.apache.http.client.methods.HttpGet)2 HttpPatch (org.apache.http.client.methods.HttpPatch)2 HttpPost (org.apache.http.client.methods.HttpPost)2 HttpPut (org.apache.http.client.methods.HttpPut)2 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)2 StringEntity (org.apache.http.entity.StringEntity)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 RequestContext (org.openkilda.auth.model.RequestContext)2 ApiRequestDto (org.openkilda.store.common.model.ApiRequestDto)2 HttpMethod (org.springframework.http.HttpMethod)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)1