Search in sources :

Example 1 with SuccessStatusJson

use of io.kamax.mxisd.http.io.identity.SuccessStatusJson in project mxisd by kamax-io.

the class SessionValidationPostHandler method handleRequest.

@Override
public void handleRequest(HttpServerExchange exchange) throws IOException {
    log.info("Handling POST request to validate session");
    String sid;
    String secret;
    String token;
    String contentType = getContentType(exchange).orElseThrow(() -> new IllegalArgumentException("Content type header is not set"));
    if (StringUtils.equals(contentType, "application/json")) {
        // FIXME use MIME parsing tools
        log.info("Parsing as JSON data");
        JsonObject body = parseJsonObject(exchange);
        sid = GsonUtil.getStringOrThrow(body, "sid");
        secret = GsonUtil.getStringOrThrow(body, "client_secret");
        token = GsonUtil.getStringOrThrow(body, "token");
    } else if (StringUtils.equals(contentType, "application/x-www-form-urlencoded")) {
        // FIXME use MIME parsing tools
        log.info("Parsing as Form data");
        FormData data = factory.createParser(exchange).parseBlocking();
        sid = getOrThrow(data, "sid");
        secret = getOrThrow(data, "client_secret");
        token = getOrThrow(data, "token");
    } else {
        log.info("Unsupported Content type: {}", contentType);
        throw new IllegalArgumentException("Unsupported Content type: " + contentType);
    }
    handleRequest(sid, secret, token);
    respondJson(exchange, new SuccessStatusJson(true));
}
Also used : FormData(io.undertow.server.handlers.form.FormData) SuccessStatusJson(io.kamax.mxisd.http.io.identity.SuccessStatusJson) JsonObject(com.google.gson.JsonObject)

Aggregations

JsonObject (com.google.gson.JsonObject)1 SuccessStatusJson (io.kamax.mxisd.http.io.identity.SuccessStatusJson)1 FormData (io.undertow.server.handlers.form.FormData)1