Search in sources :

Example 1 with IRIValidator

use of org.apache.jena.fuseki.validation.IRIValidator in project jena by apache.

the class SPARQLServer method buildServer.

// Later : private and in constructor.
private ServletContextHandler buildServer(String jettyConfig, boolean enableCompression) {
    if (jettyConfig != null) {
        // --jetty-config=jetty-fuseki.xml
        // for detailed configuration of the server using Jetty features.
        server = configServer(jettyConfig);
    } else
        server = defaultServerConfig(serverConfig.port, serverConfig.loopback);
    // Keep the server to a maximum number of threads.
    // server.setThreadPool(new QueuedThreadPool(ThreadPoolSize)) ;
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setErrorHandler(new FusekiErrorHandler());
    context.addEventListener(new FusekiServletContextListener(this));
    // Increase form size.
    context.getServletContext().getContextHandler().setMaxFormContentSize(10 * 1000 * 1000);
    // Wire up authentication if appropriate
    if (jettyConfig == null && serverConfig.authConfigFile != null) {
        Constraint constraint = new Constraint();
        constraint.setName(Constraint.__BASIC_AUTH);
        constraint.setRoles(new String[] { "fuseki" });
        constraint.setAuthenticate(true);
        ConstraintMapping mapping = new ConstraintMapping();
        mapping.setConstraint(constraint);
        mapping.setPathSpec("/*");
        IdentityService identService = new DefaultIdentityService();
        ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
        securityHandler.addConstraintMapping(mapping);
        securityHandler.setIdentityService(identService);
        HashLoginService loginService = new HashLoginService("Fuseki Authentication", serverConfig.authConfigFile);
        loginService.setIdentityService(identService);
        securityHandler.setLoginService(loginService);
        securityHandler.setAuthenticator(new BasicAuthenticator());
        context.setSecurityHandler(securityHandler);
        serverLog.debug("Basic Auth Configuration = " + serverConfig.authConfigFile);
    }
    // Wire up context handler to server
    server.setHandler(context);
    // Constants. Add RDF types.
    MimeTypes mt = new MimeTypes();
    mt.addMimeMapping("rdf", WebContent.contentTypeRDFXML + ";charset=utf-8");
    mt.addMimeMapping("ttl", WebContent.contentTypeTurtle + ";charset=utf-8");
    mt.addMimeMapping("nt", WebContent.contentTypeNTriples + ";charset=ascii");
    mt.addMimeMapping("nq", WebContent.contentTypeNQuads + ";charset=ascii");
    mt.addMimeMapping("trig", WebContent.contentTypeTriG + ";charset=utf-8");
    // mt.addMimeMapping("tpl", "text/html;charset=utf-8") ;
    context.setMimeTypes(mt);
    server.setHandler(context);
    serverLog.debug("Pages = " + serverConfig.pages);
    boolean installManager = true;
    boolean installServices = true;
    String validationRoot = "/validate";
    if (installManager || installServices) {
        // TODO Respect port.
        if (serverConfig.pagesPort != serverConfig.port)
            serverLog.warn("Not supported yet - pages on a different port to services");
        if (serverConfig.pages != null) {
            if (!FileOps.exists(serverConfig.pages))
                serverLog.warn("No pages directory - " + serverConfig.pages);
            String base = serverConfig.pages;
            Map<String, Object> data = new HashMap<>();
            data.put("mgt", new MgtFunctions());
            SimpleVelocityServlet templateEngine = new SimpleVelocityServlet(base, data);
            addServlet(context, templateEngine, "*.tpl", false);
        }
    }
    if (installManager) {
        // Action when control panel selects a dataset.
        HttpServlet datasetChooser = new ActionDataset();
        addServlet(context, datasetChooser, PageNames.actionDatasetNames, false);
    }
    if (installServices) {
        // Validators
        HttpServlet validateQuery = new QueryValidator();
        HttpServlet validateUpdate = new UpdateValidator();
        HttpServlet validateData = new DataValidator();
        HttpServlet validateIRI = new IRIValidator();
        HttpServlet dumpService = new DumpServlet();
        HttpServlet generalQueryService = new SPARQL_QueryGeneral();
        addServlet(context, validateQuery, validationRoot + "/query", false);
        addServlet(context, validateUpdate, validationRoot + "/update", false);
        addServlet(context, validateData, validationRoot + "/data", false);
        addServlet(context, validateIRI, validationRoot + "/iri", false);
        // general query processor.
        addServlet(context, generalQueryService, HttpNames.ServiceGeneralQuery, enableCompression);
    }
    if (installManager || installServices) {
        String[] files = { "fuseki.html", "index.html" };
        context.setWelcomeFiles(files);
        addContent(context, "/", serverConfig.pages);
    }
    return context;
}
Also used : Constraint(org.eclipse.jetty.util.security.Constraint) MgtFunctions(org.apache.jena.fuseki.mgt.MgtFunctions) BasicAuthenticator(org.eclipse.jetty.security.authentication.BasicAuthenticator) IRIValidator(org.apache.jena.fuseki.validation.IRIValidator) ActionDataset(org.apache.jena.fuseki.mgt.ActionDataset) HttpServlet(javax.servlet.http.HttpServlet) MimeTypes(org.eclipse.jetty.http.MimeTypes) UpdateValidator(org.apache.jena.fuseki.validation.UpdateValidator) QueryValidator(org.apache.jena.fuseki.validation.QueryValidator) DataValidator(org.apache.jena.fuseki.validation.DataValidator) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 2 with IRIValidator

use of org.apache.jena.fuseki.validation.IRIValidator in project jena by apache.

the class FusekiMain method buildServer.

private static FusekiServer buildServer(FusekiServer.Builder builder, ServerConfig serverConfig) {
    if (serverConfig.jettyConfigFile != null)
        builder.jettyServerConfig(serverConfig.jettyConfigFile);
    builder.port(serverConfig.port);
    builder.loopback(serverConfig.loopback);
    builder.verbose(serverConfig.verboseLogging);
    if (serverConfig.addGeneral != null)
        // Add SPARQL_QueryGeneral as a general servlet, not reached by the service router.
        builder.addServlet(serverConfig.addGeneral, new SPARQL_QueryGeneral());
    if (serverConfig.validators) {
        // Validators.
        builder.addServlet("/$/validate/query", new QueryValidator());
        builder.addServlet("/$/validate/update", new UpdateValidator());
        builder.addServlet("/$/validate/iri", new IRIValidator());
        builder.addServlet("/$/validate/data", new DataValidator());
    }
    if (!serverConfig.empty) {
        if (serverConfig.serverConfig != null)
            // Config file.
            builder.parseConfigFile(serverConfig.serverConfig);
        else
            // One dataset.
            builder.add(serverConfig.datasetPath, serverConfig.dsg, serverConfig.allowUpdate);
    }
    if (serverConfig.contentDirectory != null)
        builder.staticFileBase(serverConfig.contentDirectory);
    if (serverConfig.passwdFile != null)
        builder.passwordFile(serverConfig.passwdFile);
    if (serverConfig.realm != null)
        builder.realm(serverConfig.realm);
    if (serverConfig.httpsKeysDetails != null)
        builder.https(serverConfig.httpsPort, serverConfig.httpsKeysDetails);
    if (serverConfig.authScheme != null)
        builder.auth(serverConfig.authScheme);
    if (serverConfig.withCORS)
        builder.enableCors(true);
    if (serverConfig.withPing)
        builder.enablePing(true);
    if (serverConfig.withStats)
        builder.enableStats(true);
    if (serverConfig.withMetrics)
        builder.enableMetrics(true);
    if (serverConfig.withCompact)
        builder.enableCompact(true);
    return builder.build();
}
Also used : IRIValidator(org.apache.jena.fuseki.validation.IRIValidator) QueryValidator(org.apache.jena.fuseki.validation.QueryValidator) SPARQL_QueryGeneral(org.apache.jena.fuseki.servlets.SPARQL_QueryGeneral) DataValidator(org.apache.jena.fuseki.validation.DataValidator) UpdateValidator(org.apache.jena.fuseki.validation.UpdateValidator)

Aggregations

DataValidator (org.apache.jena.fuseki.validation.DataValidator)2 IRIValidator (org.apache.jena.fuseki.validation.IRIValidator)2 QueryValidator (org.apache.jena.fuseki.validation.QueryValidator)2 UpdateValidator (org.apache.jena.fuseki.validation.UpdateValidator)2 HttpServlet (javax.servlet.http.HttpServlet)1 ActionDataset (org.apache.jena.fuseki.mgt.ActionDataset)1 MgtFunctions (org.apache.jena.fuseki.mgt.MgtFunctions)1 SPARQL_QueryGeneral (org.apache.jena.fuseki.servlets.SPARQL_QueryGeneral)1 MimeTypes (org.eclipse.jetty.http.MimeTypes)1 BasicAuthenticator (org.eclipse.jetty.security.authentication.BasicAuthenticator)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 Constraint (org.eclipse.jetty.util.security.Constraint)1