Search in sources :

Example 1 with CheckInModelException

use of org.eclipse.vorto.core.api.repository.CheckInModelException in project vorto by eclipse.

the class RestClient method executePost.

public <Result> Result executePost(String query, HttpEntity content, final Function<String, Result> responseConverter) throws ClientProtocolException, IOException {
    ProxyConfiguration proxyProvider = getProxyConfiguration();
    CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(proxyProvider.credentialsProvider).build();
    HttpUriRequest request = RequestBuilder.post().setConfig(proxyProvider.requestConfig).setUri(createQuery(query)).addHeader(createSecurityHeader()).setEntity(content).build();
    return client.execute(request, new DefaultResponseHandler<Result>() {

        @Override
        public Result handleSuccess(HttpResponse response) throws ClientProtocolException, IOException {
            return responseConverter.apply(IOUtils.toString(response.getEntity().getContent()));
        }

        @Override
        protected Result handleFailure(HttpResponse response) throws ClientProtocolException, IOException {
            throw new CheckInModelException("Error in uploading file to remote repository");
        }
    });
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException) CheckInModelException(org.eclipse.vorto.core.api.repository.CheckInModelException)

Aggregations

IOException (java.io.IOException)1 HttpResponse (org.apache.http.HttpResponse)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 CheckInModelException (org.eclipse.vorto.core.api.repository.CheckInModelException)1