Search in sources :

Example 1 with InternalUQRequest

use of it.unibo.arces.wot.sepa.engine.scheduling.InternalUQRequest in project SEPA by arces-wot.

the class SPARQL11Handler method handle.

@Override
public void handle(HttpRequest request, HttpAsyncExchange httpExchange, HttpContext context) throws HttpException, IOException {
    logger.log(Level.getLevel("http"), "@handle " + request + " " + context);
    // CORS
    if (!corsHandling(httpExchange))
        return;
    // Authorize
    ClientAuthorization oauth = null;
    try {
        oauth = authorize(httpExchange.getRequest());
    } catch (SEPASecurityException e1) {
        HttpUtilities.sendFailureResponse(httpExchange, new ErrorResponse(HttpStatus.SC_UNAUTHORIZED, "oauth_exception", e1.getMessage()));
        jmx.authorizingFailed();
        return;
    }
    if (!oauth.isAuthorized()) {
        logger.log(Level.getLevel("oauth"), "*** NOT AUTHORIZED *** " + oauth.getDescription());
        HttpUtilities.sendFailureResponse(httpExchange, new ErrorResponse(HttpStatus.SC_UNAUTHORIZED, oauth.getError(), oauth.getDescription()));
        jmx.authorizingFailed();
        return;
    }
    InternalUQRequest sepaRequest = null;
    try {
        // Parsing SPARQL 1.1 request and attach a token
        sepaRequest = parse(httpExchange, oauth);
    } catch (SPARQL11ProtocolException e) {
        logger.log(Level.getLevel("http"), "Parsing failed: " + httpExchange.getRequest());
        HttpUtilities.sendFailureResponse(httpExchange, new ErrorResponse(e.getCode(), "SPARQL11ProtocolException", "Parsing failed: " + e.getMessage()));
        jmx.parsingFailed();
        return;
    }
    // Schedule request
    Timings.log(sepaRequest);
    ScheduledRequest req = scheduler.schedule(sepaRequest, new SPARQL11ResponseHandler(httpExchange, jmx));
    if (req == null) {
        logger.error("Out of tokens");
        HttpUtilities.sendFailureResponse(httpExchange, new ErrorResponse(429, "too_many_requests", "Too many pending requests"));
        jmx.outOfTokens();
    }
}
Also used : ScheduledRequest(it.unibo.arces.wot.sepa.engine.scheduling.ScheduledRequest) ClientAuthorization(it.unibo.arces.wot.sepa.commons.security.ClientAuthorization) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) InternalUQRequest(it.unibo.arces.wot.sepa.engine.scheduling.InternalUQRequest) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Aggregations

SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)1 ErrorResponse (it.unibo.arces.wot.sepa.commons.response.ErrorResponse)1 ClientAuthorization (it.unibo.arces.wot.sepa.commons.security.ClientAuthorization)1 InternalUQRequest (it.unibo.arces.wot.sepa.engine.scheduling.InternalUQRequest)1 ScheduledRequest (it.unibo.arces.wot.sepa.engine.scheduling.ScheduledRequest)1