Search in sources :

Example 1 with Attachment

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

the class RestClient method executeGetAttachment.

public Attachment executeGetAttachment(String query) throws ClientProtocolException, IOException {
    ProxyConfiguration proxyProvider = getProxyConfiguration();
    CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(proxyProvider.credentialsProvider).build();
    HttpUriRequest request = RequestBuilder.get().setConfig(proxyProvider.requestConfig).setUri(createQuery(query)).build();
    return client.execute(request, new DefaultResponseHandler<Attachment>() {

        @Override
        public Attachment handleSuccess(HttpResponse response) throws ClientProtocolException, IOException {
            String content_disposition = response.getFirstHeader("Content-Disposition").getValue();
            String filename = content_disposition.substring(content_disposition.indexOf("filename = ") + "filename = ".length());
            long length = response.getEntity().getContentLength();
            String type = response.getEntity().getContentType().toString();
            byte[] content = IOUtils.toByteArray(response.getEntity().getContent());
            return new Attachment(filename, length, type, content);
        }
    });
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpResponse(org.apache.http.HttpResponse) Attachment(org.eclipse.vorto.core.api.repository.Attachment) IOException(java.io.IOException) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 2 with Attachment

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

the class RestModelRepository method generateCode.

@Override
public Attachment generateCode(ModelId model, String serviceKey) {
    try {
        String url = "generation-router/" + model.getNamespace() + "/" + model.getName() + "/" + model.getVersion() + "/" + URLEncoder.encode(serviceKey, "utf-8");
        Attachment result = httpClient.executeGetAttachment(url);
        return result;
    } catch (RepositoryException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException("Error querying remote repository with generateCode request.", e);
    }
}
Also used : Attachment(org.eclipse.vorto.core.api.repository.Attachment) RepositoryException(org.eclipse.vorto.core.api.repository.RepositoryException) CheckInModelException(org.eclipse.vorto.core.api.repository.CheckInModelException) RepositoryException(org.eclipse.vorto.core.api.repository.RepositoryException)

Aggregations

Attachment (org.eclipse.vorto.core.api.repository.Attachment)2 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 RepositoryException (org.eclipse.vorto.core.api.repository.RepositoryException)1