Search in sources :

Example 1 with BadRequestException

use of com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException in project Plan by plan-player-analytics.

the class QueryFilters method apply.

private Filter.Result apply(Filter.Result current, InputFilterDto inputFilterDto) {
    String kind = inputFilterDto.getKind();
    Filter filter = getFilter(kind).orElseThrow(() -> new BadRequestException("Filter kind not supported: '" + kind + "'"));
    return getResult(current, filter, inputFilterDto);
}
Also used : PluginGroupsFilter(com.djrapitops.plan.storage.database.queries.filter.filters.PluginGroupsFilter) AllPlayersFilter(com.djrapitops.plan.storage.database.queries.filter.filters.AllPlayersFilter) BadRequestException(com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException)

Example 2 with BadRequestException

use of com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException in project Plan by plan-player-analytics.

the class RegisterResolver method getResponse.

public Response getResponse(Request request) {
    URIQuery query = request.getQuery();
    Optional<String> checkCode = query.get("code");
    if (checkCode.isPresent()) {
        return Response.builder().setStatus(200).setJSONContent(Collections.singletonMap("success", !RegistrationBin.contains(checkCode.get()))).build();
    }
    URIQuery form = RequestBodyConverter.formBody(request);
    String username = getUser(form, query);
    boolean alreadyExists = dbSystem.getDatabase().query(WebUserQueries.fetchUser(username)).isPresent();
    if (alreadyExists)
        throw new BadRequestException("User already exists!");
    String password = getPassword(form, query);
    try {
        String code = RegistrationBin.addInfoForRegistration(username, password);
        return Response.builder().setStatus(200).setJSONContent(Maps.builder(String.class, Object.class).put("success", true).put("code", code).build()).build();
    } catch (PassEncryptUtil.CannotPerformOperationException e) {
        throw new IllegalStateException(e);
    }
}
Also used : BadRequestException(com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException) PassEncryptUtil(com.djrapitops.plan.utilities.PassEncryptUtil) URIQuery(com.djrapitops.plan.delivery.web.resolver.request.URIQuery)

Example 3 with BadRequestException

use of com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException in project Plan by plan-player-analytics.

the class GraphsJSONResolver method getResponse.

private Response getResponse(Request request) {
    String type = request.getQuery().get("type").orElseThrow(() -> new BadRequestException("'type' parameter was not defined."));
    DataID dataID = getDataID(type);
    return Response.builder().setMimeType(MimeType.JSON).setJSONContent(getGraphJSON(request, dataID).json).build();
}
Also used : DataID(com.djrapitops.plan.delivery.webserver.cache.DataID) BadRequestException(com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException)

Example 4 with BadRequestException

use of com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException in project Plan by plan-player-analytics.

the class QueryJSONResolver method buildAndStoreResponse.

private Response buildAndStoreResponse(ViewDto view, Filter.Result result, List<Filter.ResultPath> resultPath) {
    try {
        long timestamp = System.currentTimeMillis();
        Map<String, Object> json = Maps.builder(String.class, Object.class).put("path", resultPath).put("view", view).put("timestamp", timestamp).build();
        if (!result.isEmpty()) {
            json.put("data", getDataFor(result.getResultUserIds(), view));
        }
        JSONStorage.StoredJSON stored = jsonStorage.storeJson("query", json, timestamp);
        return Response.builder().setMimeType(MimeType.JSON).setJSONContent(stored.json).build();
    } catch (ParseException e) {
        throw new BadRequestException("'view' date format was incorrect (expecting afterDate dd/mm/yyyy, afterTime hh:mm, beforeDate dd/mm/yyyy, beforeTime hh:mm}): " + e.getMessage());
    }
}
Also used : BadRequestException(com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException) ParseException(java.text.ParseException) JSONStorage(com.djrapitops.plan.delivery.webserver.cache.JSONStorage)

Example 5 with BadRequestException

use of com.djrapitops.plan.delivery.web.resolver.exception.BadRequestException 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)11 WebUser (com.djrapitops.plan.delivery.web.resolver.request.WebUser)3 JSONStorage (com.djrapitops.plan.delivery.webserver.cache.JSONStorage)3 ParseException (java.text.ParseException)3 GraphJSONCreator (com.djrapitops.plan.delivery.rendering.json.graphs.GraphJSONCreator)2 MimeType (com.djrapitops.plan.delivery.web.resolver.MimeType)2 Resolver (com.djrapitops.plan.delivery.web.resolver.Resolver)2 Response (com.djrapitops.plan.delivery.web.resolver.Response)2 Request (com.djrapitops.plan.delivery.web.resolver.request.Request)2 URIQuery (com.djrapitops.plan.delivery.web.resolver.request.URIQuery)2 DataID (com.djrapitops.plan.delivery.webserver.cache.DataID)2 ServerUUID (com.djrapitops.plan.identification.ServerUUID)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2 DateMap (com.djrapitops.plan.delivery.domain.DateMap)1 InputFilterDto (com.djrapitops.plan.delivery.domain.datatransfer.InputFilterDto)1 InputQueryDto (com.djrapitops.plan.delivery.domain.datatransfer.InputQueryDto)1 ViewDto (com.djrapitops.plan.delivery.domain.datatransfer.ViewDto)1 Formatter (com.djrapitops.plan.delivery.formatting.Formatter)1 Formatters (com.djrapitops.plan.delivery.formatting.Formatters)1