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