use of org.apache.jena.fuseki.FusekiException in project jena by apache.
the class ActionBackup method backup.
public static void backup(DatasetGraph dsg, String backupfile) {
if (!backupfile.endsWith(".nq"))
backupfile = backupfile + ".nq";
OutputStream out = null;
try {
if (true) {
// This seems to achive about the same as "gzip -6"
// It's not too expensive in elapsed time but it's not zero cost.
// GZip, large buffer.
out = new FileOutputStream(backupfile + ".gz");
out = new GZIPOutputStream(out, 8 * 1024);
out = new BufferedOutputStream(out);
} else {
out = new FileOutputStream(backupfile);
out = new BufferedOutputStream(out);
}
RDFDataMgr.write(out, dsg, Lang.NQUADS);
out.close();
out = null;
} catch (FileNotFoundException e) {
Log.warn(ActionBackup.class, "File not found: " + backupfile);
throw new FusekiException("File not found: " + backupfile);
} catch (IOException e) {
IO.exception(e);
} finally {
try {
if (out != null)
out.close();
} catch (IOException e) {
/* ignore */
}
}
}
use of org.apache.jena.fuseki.FusekiException in project jena by apache.
the class JettyFuseki method start.
/**
* Initialize the {@link JettyFuseki} instance.
*/
public void start() {
String version = Fuseki.VERSION;
String buildDate = Fuseki.BUILD_DATE;
if (version != null && version.equals("${project.version}"))
version = null;
if (buildDate != null && buildDate.equals("${build.time.xsd}"))
buildDate = DateTimeUtils.nowAsXSDDateTimeString();
if (version != null) {
if (Fuseki.developmentMode && buildDate != null)
serverLog.info(format("%s %s %s", Fuseki.NAME, version, buildDate));
else
serverLog.info(format("%s %s", Fuseki.NAME, version));
}
// This does not get set usefully for Jetty as we use it.
// String jettyVersion = org.eclipse.jetty.server.Server.getVersion() ;
// serverLog.info(format("Jetty %s",jettyVersion)) ;
String host = serverConnector.getHost();
if (host != null)
serverLog.info("Incoming connections limited to " + host);
try {
server.start();
} catch (java.net.BindException ex) {
serverLog.error("SPARQLServer (port=" + serverConnector.getPort() + "): Failed to start server: " + ex.getMessage());
throw new FusekiException("BindException: port=" + serverConnector.getPort() + ": Failed to start server: " + ex.getMessage(), ex);
} catch (Exception ex) {
serverLog.error("SPARQLServer: Failed to start server: " + ex.getMessage(), ex);
throw new FusekiException("Failed to start server: " + ex.getMessage(), ex);
}
String now = DateTimeUtils.nowAsString();
serverLog.info(format("Started %s on port %d", now, serverConnector.getPort()));
}
use of org.apache.jena.fuseki.FusekiException in project jena by apache.
the class JettyFuseki method createWebApp.
public static WebAppContext createWebApp(String contextPath) {
FusekiEnv.setEnvironment();
WebAppContext webapp = new WebAppContext();
webapp.getServletContext().getContextHandler().setMaxFormContentSize(10 * 1000 * 1000);
// Hunt for the webapp for the standalone jar (or development system).
// Note that Path FUSEKI_HOME is not initialized until the webapp starts
// so it is not available here.
String resourceBase3 = null;
String resourceBase4 = null;
if (FusekiEnv.FUSEKI_HOME != null) {
String HOME = FusekiEnv.FUSEKI_HOME.toString();
resourceBase3 = HOME + "/" + resourceBase1;
resourceBase4 = HOME + "/" + resourceBase2;
}
String resourceBase = tryResourceBase(resourceBase1, null);
resourceBase = tryResourceBase(resourceBase2, resourceBase);
resourceBase = tryResourceBase(resourceBase3, resourceBase);
resourceBase = tryResourceBase(resourceBase4, resourceBase);
if (resourceBase == null) {
if (resourceBase3 == null)
Fuseki.serverLog.error("Can't find resourceBase (tried " + resourceBase1 + " and " + resourceBase2 + ")");
else
Fuseki.serverLog.error("Can't find resourceBase (tried " + resourceBase1 + ", " + resourceBase2 + ", " + resourceBase3 + " and " + resourceBase4 + ")");
Fuseki.serverLog.error("Failed to start");
throw new FusekiException("Failed to start");
}
webapp.setDescriptor(resourceBase + "/WEB-INF/web.xml");
webapp.setResourceBase(resourceBase);
webapp.setContextPath(contextPath);
//-- Jetty setup for the ServletContext logger.
// The name of the Jetty-allocated slf4j/log4j logger is
// the display name or, if null, the context path name.
// It is set, without checking for a previous call of setLogger in "doStart"
// which happens during server startup.
// This the name of the ServletContext logger as well
webapp.setDisplayName(Fuseki.servletRequestLogName);
// Normal Java classloader behaviour.
webapp.setParentLoaderPriority(true);
webapp.setErrorHandler(new FusekiErrorHandler());
return webapp;
}
use of org.apache.jena.fuseki.FusekiException in project jena by apache.
the class HttpAction method setRequest.
/** Initialization after action creation during lifecycle setup.
* <p>Sets the action dataset. Setting will replace any existing {@link DataAccessPoint} and {@link DataService},
* as the {@link DatasetGraph} of the current HTTP Action.</p>
*
* <p>Once it has updated its members, the HTTP Action will change its transactional state and
* {@link Transactional} instance according to its base dataset graph.</p>
*
* @param dataAccessPoint {@link DataAccessPoint}
* @param dService {@link DataService}
* @see Transactional
*/
public void setRequest(DataAccessPoint dataAccessPoint, DataService dService) {
this.dataAccessPoint = dataAccessPoint;
if (dataAccessPoint != null)
this.datasetName = dataAccessPoint.getName();
if (this.dataService != null)
throw new FusekiException("Redefinition of DatasetRef in the request action");
this.dataService = dService;
if (dService == null || dService.getDataset() == null)
// Null does not happens for service requests, (it does for admin requests - call setControlRequest)
throw new FusekiException("Null DataService in the request action");
setDataset(dService.getDataset());
}
use of org.apache.jena.fuseki.FusekiException in project jena by apache.
the class SPARQL_Query method setAnyTimeouts.
private void setAnyTimeouts(QueryExecution qexec, HttpAction action) {
// if ( !(action.getDataService().allowTimeoutOverride) )
// return ;
long desiredTimeout = Long.MAX_VALUE;
String timeoutHeader = action.request.getHeader("Timeout");
String timeoutParameter = action.request.getParameter("timeout");
if (timeoutHeader != null) {
try {
desiredTimeout = (int) (Float.parseFloat(timeoutHeader) * 1000);
} catch (NumberFormatException e) {
throw new FusekiException("Timeout header must be a number", e);
}
} else if (timeoutParameter != null) {
try {
desiredTimeout = (int) (Float.parseFloat(timeoutParameter) * 1000);
} catch (NumberFormatException e) {
throw new FusekiException("timeout parameter must be a number", e);
}
}
// desiredTimeout = Math.min(action.getDataService().maximumTimeoutOverride, desiredTimeout) ;
if (desiredTimeout != Long.MAX_VALUE)
qexec.setTimeout(desiredTimeout);
}
Aggregations