Skip to content

Commit f597f45

Browse files
Experiment with proxy
1 parent 02f5eac commit f597f45

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

app/src/main/java/hexlet/code/controller/UrlCheckController.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public static void check(Context ctx) throws SQLException {
3939
.orElseThrow(() -> new NotFoundResponse("Entity with id = " + urlId + " not found"));
4040
log.info("Got URL ID: {}", urlId);
4141
try {
42+
// Unirest.config().proxy("127.0.0.1", 1080)
4243
HttpResponse<String> response = Unirest.get(url.getName()).asString();
4344
Document document = Jsoup.parse(response.getBody());
4445

@@ -53,18 +54,21 @@ public static void check(Context ctx) throws SQLException {
5354
log.info("urlCheck created");
5455
UrlCheckRepository.save(urlCheck);
5556
log.info("check saved");
57+
ctx.sessionAttribute(FLASH, PAGE_OK);
58+
ctx.sessionAttribute(FLASH_TYPE, FLASH_SUCCESS);
5659
} catch (UnirestException e) {
60+
e.printStackTrace();
61+
log.info("Error in UrlCheckController.check - UnirestException: ", e);
5762
ctx.sessionAttribute(FLASH, URL_BAD);
5863
ctx.sessionAttribute(FLASH_TYPE, FLASH_DANGER);
59-
ctx.redirect(NamedRoutes.urlPath(urlId));
60-
61-
} catch (Exception e) {
64+
// ctx.redirect(NamedRoutes.urlPath(urlId))
65+
} catch (SQLException e) {
66+
e.printStackTrace();
67+
log.info("Error in UrlCheckController.check - SQLException", e);
6268
ctx.sessionAttribute(FLASH, CHECK_ERROR + e.getMessage());
6369
ctx.sessionAttribute(FLASH_TYPE, FLASH_DANGER);
64-
ctx.redirect(NamedRoutes.urlPath(urlId));
70+
// ctx.redirect(NamedRoutes.urlPath(urlId))
6571
}
66-
ctx.sessionAttribute(FLASH, PAGE_OK);
67-
ctx.sessionAttribute(FLASH_TYPE, FLASH_SUCCESS);
6872
ctx.redirect(NamedRoutes.urlPath(urlId));
6973
}
7074
}

0 commit comments

Comments
 (0)