Search in sources :

Example 11 with ErrorResponse

use of it.unibo.arces.wot.sepa.commons.response.ErrorResponse in project SEPA by arces-wot.

the class QueryProcessor method process.

public synchronized Response process(QueryRequest req, int timeout) {
    if (endpointSemaphore != null)
        try {
            endpointSemaphore.acquire();
        } catch (InterruptedException e) {
            return new ErrorResponse(500, e.getMessage());
        }
    // QUERY the endpoint
    long start = System.currentTimeMillis();
    Response ret = endpoint.query(req, timeout);
    long stop = System.currentTimeMillis();
    if (endpointSemaphore != null)
        endpointSemaphore.release();
    logger.debug("* QUERY PROCESSING (" + (stop - start) + " ms) *");
    ProcessorBeans.queryTimings(start, stop);
    return ret;
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Example 12 with ErrorResponse

use of it.unibo.arces.wot.sepa.commons.response.ErrorResponse in project SEPA by arces-wot.

the class SPUNaive method processInternal.

@Override
public Response processInternal(UpdateResponse update, int timeout) {
    logger.debug("* PROCESSING *" + request);
    Response ret;
    try {
        // Query the SPARQL processing service
        ret = queryProcessor.process(request, timeout);
        if (ret.getClass().equals(ErrorResponse.class)) {
            logger.error(ret);
            return ret;
        }
        // Current and previous bindings
        BindingsResults results = ((QueryResponse) ret).getBindingsResults();
        BindingsResults currentBindings = new BindingsResults(results);
        // Initialize the results with the current bindings
        BindingsResults added = new BindingsResults(results.getVariables(), null);
        BindingsResults removed = new BindingsResults(results.getVariables(), null);
        // Create empty bindings if null
        if (lastBindings == null)
            lastBindings = new BindingsResults(null, null);
        logger.debug("Current bindings: " + currentBindings);
        logger.debug("Last bindings: " + lastBindings);
        // Find removed bindings
        long start = System.nanoTime();
        for (Bindings solution : lastBindings.getBindings()) {
            if (!results.contains(solution) && !solution.isEmpty())
                removed.add(solution);
            else
                results.remove(solution);
        }
        long stop = System.nanoTime();
        logger.debug("Removed bindings: " + removed + " found in " + (stop - start) + " ns");
        // Find added bindings
        start = System.nanoTime();
        for (Bindings solution : results.getBindings()) {
            if (!lastBindings.contains(solution) && !solution.isEmpty())
                added.add(solution);
        }
        stop = System.nanoTime();
        logger.debug("Added bindings: " + added + " found in " + (stop - start) + " ns");
        // Update the last bindings with the current ones
        lastBindings = currentBindings;
        // Send notification (or end processing indication)
        if (!added.isEmpty() || !removed.isEmpty())
            ret = new Notification(getUUID(), new ARBindingsResults(added, removed), sequence++);
    } catch (Exception e) {
        ret = new ErrorResponse(500, e.getMessage());
    }
    return ret;
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) UpdateResponse(it.unibo.arces.wot.sepa.commons.response.UpdateResponse) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) QueryResponse(it.unibo.arces.wot.sepa.commons.response.QueryResponse) ARBindingsResults(it.unibo.arces.wot.sepa.commons.sparql.ARBindingsResults) BindingsResults(it.unibo.arces.wot.sepa.commons.sparql.BindingsResults) ARBindingsResults(it.unibo.arces.wot.sepa.commons.sparql.ARBindingsResults) QueryResponse(it.unibo.arces.wot.sepa.commons.response.QueryResponse) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings) Notification(it.unibo.arces.wot.sepa.commons.response.Notification) SEPAProtocolException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Example 13 with ErrorResponse

use of it.unibo.arces.wot.sepa.commons.response.ErrorResponse in project SEPA by arces-wot.

the class UpdateProcessor method process.

public synchronized Response process(UpdateRequest req, int timeout) {
    if (endpointSemaphore != null)
        try {
            endpointSemaphore.acquire();
        } catch (InterruptedException e) {
            return new ErrorResponse(500, e.getMessage());
        }
    // UPDATE the endpoint
    long start = System.currentTimeMillis();
    Response ret = endpoint.update(req, timeout);
    long stop = System.currentTimeMillis();
    if (endpointSemaphore != null)
        endpointSemaphore.release();
    logger.debug("* UPDATE PROCESSING (" + (stop - start) + " ms) *");
    ProcessorBeans.updateTimings(start, stop);
    return ret;
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Example 14 with ErrorResponse

use of it.unibo.arces.wot.sepa.commons.response.ErrorResponse in project SEPA by arces-wot.

the class WebsocketServer method onMessage.

@Override
public void onMessage(WebSocket conn, String message) {
    jmx.onMessage();
    logger.debug("Message from: " + conn.getRemoteSocketAddress() + " [" + message + "]");
    Request req = parseRequest(message);
    if (req == null) {
        logger.debug("Failed to parse: " + message);
        ErrorResponse response = new ErrorResponse(HttpStatus.SC_BAD_REQUEST, "Failed to parse: " + message);
        conn.send(response.toString());
        return;
    }
    scheduler.schedule(req, new WebsocketEventHandler(conn, jmx));
}
Also used : Request(it.unibo.arces.wot.sepa.commons.request.Request) SubscribeRequest(it.unibo.arces.wot.sepa.commons.request.SubscribeRequest) UnsubscribeRequest(it.unibo.arces.wot.sepa.commons.request.UnsubscribeRequest) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Example 15 with ErrorResponse

use of it.unibo.arces.wot.sepa.commons.response.ErrorResponse in project SEPA by arces-wot.

the class Scheduler method schedule.

public synchronized void schedule(Request request, ResponseHandler handler) {
    int token = getToken();
    if (token == -1) {
        try {
            handler.sendResponse(new ErrorResponse(-1, 500, "Request refused: too many pending requests"));
        } catch (IOException e) {
            logger.error("Failed to send response on out of tokens");
        }
        return;
    }
    // Responder
    responders.put(token, handler);
    queue.addRequest(new ScheduledRequest(token, request, handler));
// // Notify observers
// setChanged();
// notifyObservers(new ScheduledRequest(token, request, handler));
}
Also used : IOException(java.io.IOException) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Aggregations

ErrorResponse (it.unibo.arces.wot.sepa.commons.response.ErrorResponse)23 Response (it.unibo.arces.wot.sepa.commons.response.Response)8 JsonParser (com.google.gson.JsonParser)6 IOException (java.io.IOException)6 JsonObject (com.google.gson.JsonObject)5 JsonParseException (com.google.gson.JsonParseException)5 JWTResponse (it.unibo.arces.wot.sepa.commons.response.JWTResponse)4 QueryResponse (it.unibo.arces.wot.sepa.commons.response.QueryResponse)4 HttpEntity (org.apache.http.HttpEntity)4 SEPAProtocolException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException)3 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)3 UpdateRequest (it.unibo.arces.wot.sepa.commons.request.UpdateRequest)3 SubscribeResponse (it.unibo.arces.wot.sepa.commons.response.SubscribeResponse)3 UpdateResponse (it.unibo.arces.wot.sepa.commons.response.UpdateResponse)3 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)3 JOSEException (com.nimbusds.jose.JOSEException)2 BadJOSEException (com.nimbusds.jose.proc.BadJOSEException)2 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)2 SignedJWT (com.nimbusds.jwt.SignedJWT)2 SubscribeRequest (it.unibo.arces.wot.sepa.commons.request.SubscribeRequest)2