private URL prepareURL(String location) throws InfrastructureException { URI uri; try { uri = new URI(location); } catch (URISyntaxException e) { LOG.debug(e.getLocalizedMessage(), e); throw new InfrastructureException( "Location of recipe downloading is not supported because it is not a valid URI"); } // if URI to this server add token to access protected API boolean addToken = isTokenNeeded(uri); UriBuilder uriBuilder = makeURIAbsolute(uri); if (addToken) { addToken(uriBuilder); } try { return uriBuilder.build().toURL(); } catch (MalformedURLException e) { LOG.debug(e.getLocalizedMessage(), e); throw new InfrastructureException("Constructing URL for downloading recipe failed"); } }
private String retrieveContent(Recipe recipe) throws InfrastructureException { if (recipe.getContent() != null && !recipe.getContent().isEmpty()) { // no downloading is needed return recipe.getContent(); } if (recipe.getLocation() == null || recipe.getLocation().isEmpty()) { throw new IllegalArgumentException("Neither content nor location are present in recipe"); } URL url = prepareURL(recipe.getLocation()); return downloadContent(url); }
/** * Returns content of recipe either by getting it from provided {@link Recipe} object or by * retrieving it from location set in provided recipe. * * @param recipe recipe of {@link org.eclipse.che.api.core.model.workspace.config.Environment} * @return recipe content * @throws NullPointerException when recipe is null * @throws IllegalArgumentException when both recipe content and location are null or empty */ public InternalRecipe getRecipe(Recipe recipe) throws InfrastructureException { Objects.requireNonNull(recipe, "Recipe should not be null"); Objects.requireNonNull(recipe.getType(), "Recipe type should not be null"); return new InternalRecipe(recipe.getType(), recipe.getContentType(), retrieveContent(recipe)); }
recipe = recipeRetriever.getRecipe(sourceEnv.getRecipe());