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);
}
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);
}
}
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();
}
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());
}
}
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();
}
}
Aggregations