Search in sources :

Example 6 with MimeTypes

use of org.eclipse.jetty.http.MimeTypes 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 7 with MimeTypes

use of org.eclipse.jetty.http.MimeTypes in project jetty.project by eclipse.

the class ResourceHandler method doStart.

/* ------------------------------------------------------------ */
@Override
public void doStart() throws Exception {
    Context scontext = ContextHandler.getCurrentContext();
    _context = (scontext == null ? null : scontext.getContextHandler());
    _mimeTypes = _context == null ? new MimeTypes() : _context.getMimeTypes();
    _resourceService.setContentFactory(new ResourceContentFactory(this, _mimeTypes, _resourceService.getPrecompressedFormats()));
    _resourceService.setWelcomeFactory(this);
    super.doStart();
}
Also used : Context(org.eclipse.jetty.server.handler.ContextHandler.Context) ResourceContentFactory(org.eclipse.jetty.server.ResourceContentFactory) MimeTypes(org.eclipse.jetty.http.MimeTypes)

Example 8 with MimeTypes

use of org.eclipse.jetty.http.MimeTypes in project jetty.project by eclipse.

the class ResourceCacheTest method testMutlipleSources1.

@Test
public void testMutlipleSources1() throws Exception {
    ResourceCollection rc = new ResourceCollection(new String[] { "../jetty-util/src/test/resources/org/eclipse/jetty/util/resource/one/", "../jetty-util/src/test/resources/org/eclipse/jetty/util/resource/two/", "../jetty-util/src/test/resources/org/eclipse/jetty/util/resource/three/" });
    Resource[] r = rc.getResources();
    MimeTypes mime = new MimeTypes();
    CachedContentFactory rc3 = new CachedContentFactory(null, r[2], mime, false, false, CompressedContentFormat.NONE);
    CachedContentFactory rc2 = new CachedContentFactory(rc3, r[1], mime, false, false, CompressedContentFormat.NONE);
    CachedContentFactory rc1 = new CachedContentFactory(rc2, r[0], mime, false, false, CompressedContentFormat.NONE);
    assertEquals("1 - one", getContent(rc1, "1.txt"));
    assertEquals("2 - two", getContent(rc1, "2.txt"));
    assertEquals("3 - three", getContent(rc1, "3.txt"));
    assertEquals("1 - two", getContent(rc2, "1.txt"));
    assertEquals("2 - two", getContent(rc2, "2.txt"));
    assertEquals("3 - three", getContent(rc2, "3.txt"));
    assertEquals(null, getContent(rc3, "1.txt"));
    assertEquals("2 - three", getContent(rc3, "2.txt"));
    assertEquals("3 - three", getContent(rc3, "3.txt"));
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) MimeTypes(org.eclipse.jetty.http.MimeTypes) ResourceCollection(org.eclipse.jetty.util.resource.ResourceCollection) Test(org.junit.Test)

Example 9 with MimeTypes

use of org.eclipse.jetty.http.MimeTypes in project jetty.project by eclipse.

the class ResourceCacheTest method testNoextension.

@Test
public void testNoextension() throws Exception {
    ResourceCollection rc = new ResourceCollection(new String[] { "../jetty-util/src/test/resources/org/eclipse/jetty/util/resource/four/" });
    Resource[] resources = rc.getResources();
    MimeTypes mime = new MimeTypes();
    CachedContentFactory cache = new CachedContentFactory(null, resources[0], mime, false, false, CompressedContentFormat.NONE);
    assertEquals("4 - four", getContent(cache, "four.txt"));
    assertEquals("4 - four (no extension)", getContent(cache, "four"));
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) MimeTypes(org.eclipse.jetty.http.MimeTypes) ResourceCollection(org.eclipse.jetty.util.resource.ResourceCollection) Test(org.junit.Test)

Example 10 with MimeTypes

use of org.eclipse.jetty.http.MimeTypes in project jetty.project by eclipse.

the class TestStaticMimeTypeServlet method init.

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    mimeTypes = new MimeTypes();
    // Some real world, yet not terribly common, mime type mappings.
    mimeTypes.addMimeMapping("bz2", "application/bzip2");
    mimeTypes.addMimeMapping("br", "application/brotli");
    mimeTypes.addMimeMapping("bmp", "image/bmp");
    mimeTypes.addMimeMapping("tga", "application/tga");
    mimeTypes.addMimeMapping("xcf", "image/xcf");
    mimeTypes.addMimeMapping("jp2", "image/jpeg2000");
    // Some of the other gzip mime-types seen in the wild.
    // NOTE: Using oddball extensions just so that the calling request can specify
    //       which strange mime type to use.
    mimeTypes.addMimeMapping("x-gzip", "application/x-gzip");
    mimeTypes.addMimeMapping("x-gunzip", "application/x-gunzip");
    mimeTypes.addMimeMapping("gzipped", "application/gzippped");
    mimeTypes.addMimeMapping("gzip-compressed", "application/gzip-compressed");
    mimeTypes.addMimeMapping("x-compressed", "application/x-compressed");
    mimeTypes.addMimeMapping("x-compress", "application/x-compress");
    mimeTypes.addMimeMapping("gzipdoc", "gzip/document");
}
Also used : MimeTypes(org.eclipse.jetty.http.MimeTypes)

Aggregations

MimeTypes (org.eclipse.jetty.http.MimeTypes)12 Test (org.junit.Test)5 Resource (org.eclipse.jetty.util.resource.Resource)4 ResourceCollection (org.eclipse.jetty.util.resource.ResourceCollection)3 Constraint (org.eclipse.jetty.util.security.Constraint)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URLClassLoader (java.net.URLClassLoader)1 EventListener (java.util.EventListener)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ServletContext (javax.servlet.ServletContext)1 ServletException (javax.servlet.ServletException)1 SessionCookieConfig (javax.servlet.SessionCookieConfig)1 SessionTrackingMode (javax.servlet.SessionTrackingMode)1 JspPropertyGroupDescriptor (javax.servlet.descriptor.JspPropertyGroupDescriptor)1 TaglibDescriptor (javax.servlet.descriptor.TaglibDescriptor)1 HttpServlet (javax.servlet.http.HttpServlet)1