Search in sources :

Example 6 with UpdateRequest

use of it.unibo.arces.wot.sepa.commons.request.UpdateRequest in project SEPA by arces-wot.

the class UpdateProcessorTest method main.

public static void main(String[] args) throws SEPAPropertiesException, SEPAProtocolException {
    SPARQL11Properties properties = new SPARQL11Properties("endpoint.jpar");
    System.out.println(properties.toString());
    processor = new UpdateProcessor(properties, null);
    while (true) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println(processor.process(new UpdateRequest("PREFIX test:<http://sepa/test#> delete {?s ?p ?o} insert {test:s test:p \"" + Math.random() + "\"} where {?s ?p ?o}"), 0));
    }
}
Also used : SPARQL11Properties(it.unibo.arces.wot.sepa.commons.protocol.SPARQL11Properties) UpdateProcessor(it.unibo.arces.wot.sepa.engine.processing.UpdateProcessor) UpdateRequest(it.unibo.arces.wot.sepa.commons.request.UpdateRequest)

Example 7 with UpdateRequest

use of it.unibo.arces.wot.sepa.commons.request.UpdateRequest in project SEPA by arces-wot.

the class UpdateHandler method parse.

@Override
protected Request parse(HttpAsyncExchange exchange) {
    if (!exchange.getRequest().getRequestLine().getMethod().toUpperCase().equals("POST")) {
        logger.error("UNSUPPORTED METHOD: " + exchange.getRequest().getRequestLine().getMethod().toUpperCase());
        HttpUtilities.sendFailureResponse(exchange, HttpStatus.SC_BAD_REQUEST, "Unsupported method: " + exchange.getRequest().getRequestLine().getMethod().toUpperCase());
        return null;
    }
    String body = null;
    HttpEntity entity = ((HttpEntityEnclosingRequest) exchange.getRequest()).getEntity();
    try {
        body = EntityUtils.toString(entity, Charset.forName("UTF-8"));
    } catch (ParseException | IOException e) {
        body = e.getLocalizedMessage();
    }
    Header[] headers = exchange.getRequest().getHeaders("Content-Type");
    if (headers.length != 1) {
        logger.error("Content-Type is missing");
        HttpUtilities.sendFailureResponse(exchange, HttpStatus.SC_BAD_REQUEST, "Content-Type is missing");
        return null;
    }
    if (headers[0].getValue().equals("application/sparql-update")) {
        logger.debug("update via POST directly");
        return new UpdateRequest(body);
    } else if (headers[0].getValue().equals("application/x-www-form-urlencoded")) {
        try {
            Map<String, String> params = HttpUtilities.splitQuery(body);
            if (params.get("update") != null)
                return new UpdateRequest(params.get("update"));
        } catch (UnsupportedEncodingException e1) {
            logger.error(e1.getMessage());
            HttpUtilities.sendFailureResponse(exchange, HttpStatus.SC_BAD_REQUEST, e1.getMessage());
            return null;
        }
    }
    logger.error("Request MUST conform to SPARQL 1.1 Protocol (https://www.w3.org/TR/sparql11-protocol/)");
    HttpUtilities.sendFailureResponse(exchange, HttpStatus.SC_BAD_REQUEST, "Request MUST conform to SPARQL 1.1 Protocol (https://www.w3.org/TR/sparql11-protocol/)");
    return null;
}
Also used : HttpEntity(org.apache.http.HttpEntity) Header(org.apache.http.Header) UpdateRequest(it.unibo.arces.wot.sepa.commons.request.UpdateRequest) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) Map(java.util.Map)

Example 8 with UpdateRequest

use of it.unibo.arces.wot.sepa.commons.request.UpdateRequest in project SEPA by arces-wot.

the class Producer method update.

public Response update(Bindings forcedBindings) {
    if (sparqlUpdate == null || protocolClient == null) {
        logger.fatal("Producer not initialized");
        return new ErrorResponse(-1, 400, "Producer not initialized");
    }
    String sparql = prefixes() + replaceBindings(sparqlUpdate, forcedBindings);
    logger.debug("<UPDATE> " + SPARQL_ID + " ==> " + sparql);
    return protocolClient.update(new UpdateRequest(sparql));
}
Also used : UpdateRequest(it.unibo.arces.wot.sepa.commons.request.UpdateRequest) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Aggregations

UpdateRequest (it.unibo.arces.wot.sepa.commons.request.UpdateRequest)8 ErrorResponse (it.unibo.arces.wot.sepa.commons.response.ErrorResponse)4 QueryRequest (it.unibo.arces.wot.sepa.commons.request.QueryRequest)2 SubscribeRequest (it.unibo.arces.wot.sepa.commons.request.SubscribeRequest)2 UnsubscribeRequest (it.unibo.arces.wot.sepa.commons.request.UnsubscribeRequest)2 Response (it.unibo.arces.wot.sepa.commons.response.Response)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HttpEntity (org.apache.http.HttpEntity)2 ParseException (org.apache.http.ParseException)2 JsonParseException (com.google.gson.JsonParseException)1 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)1 SPARQL11Properties (it.unibo.arces.wot.sepa.commons.protocol.SPARQL11Properties)1 SSLSecurityManager (it.unibo.arces.wot.sepa.commons.protocol.SSLSecurityManager)1 RegistrationRequest (it.unibo.arces.wot.sepa.commons.request.RegistrationRequest)1 Request (it.unibo.arces.wot.sepa.commons.request.Request)1 QueryResponse (it.unibo.arces.wot.sepa.commons.response.QueryResponse)1 SubscribeResponse (it.unibo.arces.wot.sepa.commons.response.SubscribeResponse)1 UpdateResponse (it.unibo.arces.wot.sepa.commons.response.UpdateResponse)1 EngineProperties (it.unibo.arces.wot.sepa.engine.core.EngineProperties)1