Skip to content

Commit

Permalink
Merge pull request #100 from swagger-api/issue-99
Browse files Browse the repository at this point in the history
check for url
  • Loading branch information
fehguy committed Jan 10, 2017
2 parents ab737cd + 6b86a13 commit c7c2d84
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/java/io/swagger/validator/services/ValidatorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.swagger.validator.models.SchemaValidationError;
import io.swagger.validator.models.ValidationResponse;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.StatusLine;
import org.apache.http.client.config.RequestConfig;
Expand Down Expand Up @@ -117,10 +118,18 @@ public ValidationResponse debugByUrl(HttpServletRequest request, HttpServletResp
ValidationResponse output = new ValidationResponse();
String content;

if(StringUtils.isBlank(url)) {
ProcessingMessage pm = new ProcessingMessage();
pm.setLogLevel(LogLevel.ERROR);
pm.setMessage("No valid URL specified");
output.addValidationMessage(new SchemaValidationError(pm.asJson()));
return output;
}

// read the spec contents, bail if it fails
try {
content = getUrlContents(url);
} catch (IOException e) {
} catch (Exception e) {
ProcessingMessage pm = new ProcessingMessage();
pm.setLogLevel(LogLevel.ERROR);
pm.setMessage("Can't read from file " + url);
Expand Down Expand Up @@ -320,8 +329,8 @@ private String getUrlContents(String urlString) throws IOException {

RequestConfig.Builder requestBuilder = RequestConfig.custom();
requestBuilder = requestBuilder
.setConnectTimeout(2000)
.setSocketTimeout(2000);
.setConnectTimeout(5000)
.setSocketTimeout(5000);

HttpGet getMethod = new HttpGet(urlString);
getMethod.setConfig(requestBuilder.build());
Expand Down

0 comments on commit c7c2d84

Please sign in to comment.