diff --git a/src/main/java/org/verapdf/rest/resources/ValidateResource.java b/src/main/java/org/verapdf/rest/resources/ValidateResource.java index b218dbd9..ec1487ec 100644 --- a/src/main/java/org/verapdf/rest/resources/ValidateResource.java +++ b/src/main/java/org/verapdf/rest/resources/ValidateResource.java @@ -1,5 +1,5 @@ /** - * + * */ package org.verapdf.rest.resources; @@ -100,9 +100,8 @@ public static InputStream validateXml(@PathParam("profileId") String profileId, @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces({ MediaType.APPLICATION_XML }) public static InputStream validateXml(@PathParam("profileId") String profileId, - @FormDataParam("url") String urlLink) - throws VeraPDFException, IOException { - InputStream uploadedInputStream = new URL(urlLink).openStream(); + @FormDataParam("url") String urlLink) throws VeraPDFException { + InputStream uploadedInputStream = getInputStreamByUrlLink(urlLink); return validate(uploadedInputStream, profileId, FormatOption.XML); } @@ -141,9 +140,8 @@ public static InputStream validateJson(@PathParam("profileId") String profileId, @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces({ MediaType.APPLICATION_JSON }) public static InputStream validateJson(@PathParam("profileId") String profileId, - @FormDataParam("url") String urlLink) - throws VeraPDFException, IOException { - InputStream uploadedInputStream = new URL(urlLink).openStream(); + @FormDataParam("url") String urlLink) throws VeraPDFException { + InputStream uploadedInputStream = getInputStreamByUrlLink(urlLink); return validate(uploadedInputStream, profileId, FormatOption.JSON); } @@ -180,9 +178,8 @@ public static InputStream validateHtml(@PathParam("profileId") String profileId, @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces({ MediaType.TEXT_HTML }) public static InputStream validateHtml(@PathParam("profileId") String profileId, - @FormDataParam("url") String urlLink) - throws VeraPDFException, IOException { - InputStream uploadedInputStream = new URL(urlLink).openStream(); + @FormDataParam("url") String urlLink) throws VeraPDFException { + InputStream uploadedInputStream = getInputStreamByUrlLink(urlLink); return validate(uploadedInputStream, profileId, FormatOption.HTML); } @@ -286,6 +283,18 @@ private static MessageDigest getDigest() { } } + private static InputStream getInputStreamByUrlLink(String urlLink) throws VeraPDFException { + try { + return new URL(urlLink).openStream(); + } catch (IOException e) { + if (urlLink.isEmpty()) { + throw new VeraPDFException("URL is empty"); + } else { + throw new VeraPDFException("URL is incorrect: " + urlLink); + } + } + } + private static ProcessorConfig createProcessorConfig(ValidatorConfig validatorConfig) { VeraAppConfig veraAppConfig = configManager.getApplicationConfig(); return ProcessorFactory.fromValues(validatorConfig, configManager.getFeaturesConfig(),