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);
}
});
}
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);
}
}
Aggregations