Search in sources :

Example 1 with RepositoryClientException

use of org.eclipse.vorto.repository.client.RepositoryClientException in project vorto by eclipse.

the class DefaultModelGeneration method getGeneratedOutput.

private GeneratedOutput getGeneratedOutput(HttpResponse response) {
    try {
        String contentDisposition = response.getFirstHeader("Content-Disposition").getValue();
        String filename = contentDisposition.substring(contentDisposition.indexOf("filename = ") + "filename = ".length());
        long length = response.getEntity().getContentLength();
        byte[] content = IOUtils.toByteArray(response.getEntity().getContent());
        return new GeneratedOutput(content, filename, length);
    } catch (IOException e) {
        throw new RepositoryClientException("Error in converting response to GeneratedOutput", e);
    }
}
Also used : RepositoryClientException(org.eclipse.vorto.repository.client.RepositoryClientException) GeneratedOutput(org.eclipse.vorto.repository.api.generation.GeneratedOutput) IOException(java.io.IOException)

Example 2 with RepositoryClientException

use of org.eclipse.vorto.repository.client.RepositoryClientException in project vorto by eclipse.

the class DefaultModelGeneration method getGeneratorUrl.

private String getGeneratorUrl(String baseUrl, ModelId modelId, String generatorKey, Map<String, String> invocationParams) {
    try {
        StringBuilder url = new StringBuilder();
        url.append(baseUrl).append("/rest/generation-router/").append(modelId.getNamespace()).append("/").append(modelId.getName()).append("/").append(modelId.getVersion()).append("/").append(URLEncoder.encode(generatorKey, "utf-8"));
        if (invocationParams != null && !invocationParams.isEmpty()) {
            StringJoiner joiner = new StringJoiner("&");
            invocationParams.forEach((key, value) -> {
                joiner.add(key + "=" + value);
            });
            url.append("?").append(joiner.toString());
        }
        return url.toString();
    } catch (UnsupportedEncodingException e) {
        throw new RepositoryClientException("Error in generating URL for the generator", e);
    }
}
Also used : RepositoryClientException(org.eclipse.vorto.repository.client.RepositoryClientException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StringJoiner(java.util.StringJoiner)

Aggregations

RepositoryClientException (org.eclipse.vorto.repository.client.RepositoryClientException)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 StringJoiner (java.util.StringJoiner)1 GeneratedOutput (org.eclipse.vorto.repository.api.generation.GeneratedOutput)1