Search in sources :

Example 91 with HttpServlet

use of javax.servlet.http.HttpServlet in project opennms by OpenNMS.

the class Activator method createAndRegisterVaadinResourceServlet.

private void createAndRegisterVaadinResourceServlet() {
    Bundle vaadin = null;
    for (Bundle bundle : bundleContext.getBundles()) {
        if ("com.vaadin.client-compiled".equals(bundle.getSymbolicName())) {
            vaadin = bundle;
            break;
        }
    }
    Dictionary<String, String> props;
    props = new Hashtable<String, String>();
    props.put("alias", VaadinResourceServlet.VAADIN);
    HttpServlet vaadinResourceServlet = new VaadinResourceServlet(vaadin);
    resourceService = bundleContext.registerService(Servlet.class.getName(), vaadinResourceServlet, props);
    bundleContext.registerService(VaadinResourceService.class.getName(), vaadinResourceServlet, null);
}
Also used : Bundle(org.osgi.framework.Bundle) HttpServlet(javax.servlet.http.HttpServlet) VaadinResourceServlet(org.opennms.vaadin.extender.internal.servlet.VaadinResourceServlet) VaadinResourceService(org.opennms.vaadin.extender.VaadinResourceService)

Example 92 with HttpServlet

use of javax.servlet.http.HttpServlet 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 93 with HttpServlet

use of javax.servlet.http.HttpServlet 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 94 with HttpServlet

use of javax.servlet.http.HttpServlet in project spring-framework by spring-projects.

the class ForwardedHeaderFilterTests method setUp.

@Before
@SuppressWarnings("serial")
public void setUp() throws Exception {
    this.request = new MockHttpServletRequest();
    this.request.setScheme("http");
    this.request.setServerName("localhost");
    this.request.setServerPort(80);
    this.filterChain = new MockFilterChain(new HttpServlet() {
    });
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) HttpServlet(javax.servlet.http.HttpServlet) MockFilterChain(org.springframework.mock.web.test.MockFilterChain) Before(org.junit.Before)

Example 95 with HttpServlet

use of javax.servlet.http.HttpServlet in project spring-framework by spring-projects.

the class ForwardedHeaderFilterTests method doWithFiltersAndGetResponse.

@SuppressWarnings("serial")
private MockHttpServletResponse doWithFiltersAndGetResponse(Filter... filters) throws ServletException, IOException {
    MockHttpServletResponse response = new MockHttpServletResponse();
    FilterChain filterChain = new MockFilterChain(new HttpServlet() {
    }, filters);
    filterChain.doFilter(request, response);
    return response;
}
Also used : HttpServlet(javax.servlet.http.HttpServlet) FilterChain(javax.servlet.FilterChain) MockFilterChain(org.springframework.mock.web.test.MockFilterChain) MockFilterChain(org.springframework.mock.web.test.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse)

Aggregations

HttpServlet (javax.servlet.http.HttpServlet)173 HttpServletRequest (javax.servlet.http.HttpServletRequest)152 HttpServletResponse (javax.servlet.http.HttpServletResponse)152 IOException (java.io.IOException)130 ServletException (javax.servlet.ServletException)128 Test (org.junit.Test)117 CountDownLatch (java.util.concurrent.CountDownLatch)68 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)61 InterruptedIOException (java.io.InterruptedIOException)55 ServletOutputStream (javax.servlet.ServletOutputStream)36 AsyncContext (javax.servlet.AsyncContext)34 HttpFields (org.eclipse.jetty.http.HttpFields)32 MetaData (org.eclipse.jetty.http.MetaData)32 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)32 ServletInputStream (javax.servlet.ServletInputStream)31 Session (org.eclipse.jetty.http2.api.Session)30 Stream (org.eclipse.jetty.http2.api.Stream)27 Response (org.eclipse.jetty.client.api.Response)26 HttpContentResponse (org.eclipse.jetty.client.HttpContentResponse)24 HashMap (java.util.HashMap)22