Search in sources :

Example 1 with FusekiException

use of org.apache.jena.fuseki.FusekiException in project jena by apache.

the class TestMultipleEmbedded method multiple_01.

// Two servers, same port -> bad.
@Test(expected = FusekiException.class)
public void multiple_01() {
    DatasetGraph dsg = dataset();
    int port = FusekiLib.choosePort();
    FusekiEmbeddedServer server1 = FusekiEmbeddedServer.create().setPort(port).add("/ds1", dsg).build();
    // Same port - Bbad.
    FusekiEmbeddedServer server2 = FusekiEmbeddedServer.create().setPort(port).add("/ds2", dsg).build();
    server1.start();
    try {
        server2.start();
    } catch (FusekiException ex) {
        assertTrue(ex.getCause() instanceof java.net.BindException);
        throw ex;
    } finally {
        try {
            server1.stop();
        } catch (Exception ex) {
        }
        try {
            server2.stop();
        } catch (Exception ex) {
        }
    }
}
Also used : FusekiException(org.apache.jena.fuseki.FusekiException) FusekiException(org.apache.jena.fuseki.FusekiException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 2 with FusekiException

use of org.apache.jena.fuseki.FusekiException in project jena by apache.

the class JettyFuseki method configServer.

private void configServer(String jettyConfig) {
    try {
        serverLog.info("Jetty server config file = " + jettyConfig);
        server = new Server();
        XmlConfiguration configuration = new XmlConfiguration(new FileInputStream(jettyConfig));
        configuration.configure(server);
        serverConnector = (ServerConnector) server.getConnectors()[0];
    } catch (Exception ex) {
        serverLog.error("SPARQLServer: Failed to configure server: " + ex.getMessage(), ex);
        throw new FusekiException("Failed to configure a server using configuration file '" + jettyConfig + "'");
    }
}
Also used : Server(org.eclipse.jetty.server.Server) FusekiException(org.apache.jena.fuseki.FusekiException) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) FileInputStream(java.io.FileInputStream) FusekiException(org.apache.jena.fuseki.FusekiException)

Example 3 with FusekiException

use of org.apache.jena.fuseki.FusekiException in project jena by apache.

the class SPARQLServer method configureOneDataset.

private void configureOneDataset(ServletContextHandler context, DatasetRef dsDesc, boolean enableCompression) {
    String datasetPath = dsDesc.name;
    if (datasetPath.equals("/"))
        datasetPath = "";
    else if (!datasetPath.startsWith("/"))
        datasetPath = "/" + datasetPath;
    if (datasetPath.endsWith("/"))
        datasetPath = datasetPath.substring(0, datasetPath.length() - 1);
    dsDesc.init();
    if (DatasetRegistry.get().isRegistered(datasetPath))
        throw new FusekiException("Already registered: " + datasetPath);
    DatasetRegistry.get().put(datasetPath, dsDesc);
    serverLog.info(format("Dataset path = %s", datasetPath));
    HttpServlet sparqlQuery = new SPARQL_QueryDataset();
    HttpServlet sparqlUpdate = new SPARQL_Update();
    HttpServlet sparqlUpload = new SPARQL_Upload();
    HttpServlet sparqlHttpR = new SPARQL_REST_R();
    HttpServlet sparqlHttpRW = new SPARQL_REST_RW();
    HttpServlet sparqlDataset = new SPARQL_UberServlet.AccessByConfig();
    if (!überServlet) {
        // If uberserver, these are unnecessary but can be used.
        // If just means the überservlet isn't handling these operations.
        addServlet(context, datasetPath, sparqlQuery, dsDesc.query, enableCompression);
        addServlet(context, datasetPath, sparqlUpdate, dsDesc.update, false);
        // No point - no results of any size.
        addServlet(context, datasetPath, sparqlUpload, dsDesc.upload, false);
        addServlet(context, datasetPath, sparqlHttpR, dsDesc.readGraphStore, enableCompression);
        addServlet(context, datasetPath, sparqlHttpRW, dsDesc.readWriteGraphStore, enableCompression);
    // This adds direct operations on the dataset itself.
    // addServlet(context, datasetPath, sparqlDataset,
    // ListOfEmptyString, enableCompression) ;
    } else {
        // This is the servlet that analyses requests and dispatches them to
        // the appropriate servlet.
        // SPARQL Query, SPARQL Update -- handles dataset?query=
        // dataset?update=
        // Graph Store Protocol (direct and indirect naming) if enabled.
        // GET/PUT/POST on the dataset itself.
        // It also checks for a request that looks like a service request
        // and passes it
        // on to the service (this takes precedence over direct naming).
        addServlet(context, datasetPath, sparqlDataset, epDataset, enableCompression);
    }
    // Add JMX beans to record daatset and it's services.
    addJMX(dsDesc);
}
Also used : FusekiException(org.apache.jena.fuseki.FusekiException) HttpServlet(javax.servlet.http.HttpServlet)

Example 4 with FusekiException

use of org.apache.jena.fuseki.FusekiException in project jena by apache.

the class ResponseResultSet method doResponseResultSet$.

// If we refactor the conneg into a single function, we can split boolean and result set handling.
// One or the other argument must be null
private static void doResponseResultSet$(HttpAction action, ResultSet resultSet, Boolean booleanResult, Prologue qPrologue, AcceptList contentTypeOffer) {
    HttpServletRequest request = action.request;
    HttpServletResponse response = action.response;
    long id = action.id;
    if (resultSet == null && booleanResult == null) {
        xlog.warn("doResponseResult: Both result set and boolean result are null");
        throw new FusekiException("Both result set and boolean result are null");
    }
    if (resultSet != null && booleanResult != null) {
        xlog.warn("doResponseResult: Both result set and boolean result are set");
        throw new FusekiException("Both result set and boolean result are set");
    }
    String mimeType = null;
    MediaType i = ConNeg.chooseContentType(request, contentTypeOffer, DEF.acceptRSXML);
    if (i != null)
        mimeType = i.getContentType();
    // Override content type
    // Does &output= override?
    // Requested output type by the web form or &output= in the request.
    // Expands short names
    String outputField = ResponseOps.paramOutput(request, shortNamesResultSet);
    if (outputField != null)
        mimeType = outputField;
    // Choose the serializer based on this.
    String serializationType = mimeType;
    // Set the HTTP respose header to this.
    String contentType = mimeType;
    // Stylesheet - change to application/xml.
    final String stylesheetURL = ResponseOps.paramStylesheet(request);
    if (stylesheetURL != null && Objects.equals(serializationType, contentTypeResultsXML))
        contentType = contentTypeXML;
    // Force to text/plain?
    String forceAccept = ResponseOps.paramForceAccept(request);
    if (forceAccept != null)
        contentType = contentTypeTextPlain;
    // Better : dispatch on MediaType
    if (Objects.equals(serializationType, contentTypeResultsXML))
        sparqlXMLOutput(action, contentType, resultSet, stylesheetURL, booleanResult);
    else if (Objects.equals(serializationType, contentTypeResultsJSON))
        jsonOutput(action, contentType, resultSet, booleanResult);
    else if (Objects.equals(serializationType, contentTypeTextPlain))
        textOutput(action, contentType, resultSet, qPrologue, booleanResult);
    else if (Objects.equals(serializationType, contentTypeTextCSV))
        csvOutput(action, contentType, resultSet, booleanResult);
    else if (Objects.equals(serializationType, contentTypeTextTSV))
        tsvOutput(action, contentType, resultSet, booleanResult);
    else if (Objects.equals(serializationType, WebContent.contentTypeResultsThrift))
        thriftOutput(action, contentType, resultSet, booleanResult);
    else
        ServletOps.errorBadRequest("Can't determine output serialization: " + serializationType);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FusekiException(org.apache.jena.fuseki.FusekiException) HttpServletResponse(javax.servlet.http.HttpServletResponse) MediaType(org.apache.jena.atlas.web.MediaType)

Example 5 with FusekiException

use of org.apache.jena.fuseki.FusekiException in project jena by apache.

the class FusekiVocab method iri.

private static String iri(String localname) {
    String uri = NS + localname;
    IRI iri = IRIResolver.parseIRI(uri);
    if (iri.hasViolation(true))
        throw new FusekiException("Bad IRI: " + iri);
    if (!iri.isAbsolute())
        throw new FusekiException("Bad IRI: " + iri);
    return uri;
}
Also used : IRI(org.apache.jena.iri.IRI) FusekiException(org.apache.jena.fuseki.FusekiException)

Aggregations

FusekiException (org.apache.jena.fuseki.FusekiException)14 FileInputStream (java.io.FileInputStream)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 Server (org.eclipse.jetty.server.Server)2 XmlConfiguration (org.eclipse.jetty.xml.XmlConfiguration)2 HttpServlet (javax.servlet.http.HttpServlet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpException (org.apache.jena.atlas.web.HttpException)1 MediaType (org.apache.jena.atlas.web.MediaType)1 IRI (org.apache.jena.iri.IRI)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 Credential (org.eclipse.jetty.util.security.Credential)1 Password (org.eclipse.jetty.util.security.Password)1 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)1 Test (org.junit.Test)1