Search in sources :

Example 1 with ForbiddenException

use of com.djrapitops.plan.exceptions.connection.ForbiddenException in project Plan by plan-player-analytics.

the class HttpsServerTest method testAccess.

default void testAccess(String address, String cookie) throws IOException, KeyManagementException, NoSuchAlgorithmException {
    HttpURLConnection connection = null;
    try {
        connection = connector.getConnection("GET", address);
        connection.setRequestProperty("Cookie", cookie);
        int responseCode = connection.getResponseCode();
        switch(responseCode) {
            case 200:
            case 302:
                return;
            case 400:
                throw new BadRequestException("Bad Request: " + address);
            case 403:
                throw new ForbiddenException(address + " returned 403");
            case 404:
                throw new NotFoundException(address + " returned a 404, ensure that your server is connected to an up to date Plan server.");
            case 500:
                // Not supported
                throw new IllegalStateException();
            default:
                throw new WebException(address + "| Wrong response code " + responseCode);
        }
    } finally {
        connection.disconnect();
    }
}
Also used : ForbiddenException(com.djrapitops.plan.exceptions.connection.ForbiddenException) HttpURLConnection(java.net.HttpURLConnection) WebException(com.djrapitops.plan.exceptions.connection.WebException) BadRequestException(com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException) NotFoundException(com.djrapitops.plan.delivery.web.resolver.exception.NotFoundException)

Aggregations

BadRequestException (com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException)1 NotFoundException (com.djrapitops.plan.delivery.web.resolver.exception.NotFoundException)1 ForbiddenException (com.djrapitops.plan.exceptions.connection.ForbiddenException)1 WebException (com.djrapitops.plan.exceptions.connection.WebException)1 HttpURLConnection (java.net.HttpURLConnection)1