private static final Logger logger = Logger.getLogger(SparqlServlet.class);
public static final String GRAPH = "http://example.org/graph";
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
SparqlEndpoint endpoint = EndpointFactory.createDefaultSparqlEndpoint();
Model model = (Model)this.getServletContext().getAttribute(StartupServlet.MODEL);
endpoint.setDefaultNamedGraph(model);
endpoint.setRequest(req);
endpoint.setResponse(res);
if (endpoint.isQuery()) {
try {
logger.info("Executing SPARQL query...");
endpoint.query();
} catch (Exception e) {
logger.error(e.getMessage());
endpoint.renderError(e);
}
} else {
logger.info("Showing SPARQL form");
endpoint.renderForm("SU4J SPARQL end-point example", "SELECT * WHERE { ?s ?p ?o }");
}
}