Search in sources :

Example 96 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 97 with HttpServlet

use of javax.servlet.http.HttpServlet in project tomcat by apache.

the class TestExpiresFilter method testSkipBecauseExpiresIsDefined.

@Test
public void testSkipBecauseExpiresIsDefined() throws Exception {
    HttpServlet servlet = new HttpServlet() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/xml; charset=utf-8");
            response.addDateHeader("Expires", System.currentTimeMillis());
            response.getWriter().print("Hello world");
        }
    };
    validate(servlet, null);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 98 with HttpServlet

use of javax.servlet.http.HttpServlet in project tomcat by apache.

the class TestExpiresFilter method testUseDefaultConfiguration2.

@Test
public void testUseDefaultConfiguration2() throws Exception {
    HttpServlet servlet = new HttpServlet() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("image/jpeg");
            response.addHeader("Cache-Control", "private");
            response.getWriter().print("Hello world");
        }
    };
    validate(servlet, Integer.valueOf(1 * 60));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 99 with HttpServlet

use of javax.servlet.http.HttpServlet in project tomcat by apache.

the class TestExpiresFilter method testNullContentType.

@Test
public void testNullContentType() throws Exception {
    HttpServlet servlet = new HttpServlet() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType(null);
        }
    };
    validate(servlet, Integer.valueOf(1 * 60));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 100 with HttpServlet

use of javax.servlet.http.HttpServlet in project tomcat by apache.

the class TestExpiresFilter method testSkipBecauseCacheControlMaxAgeIsDefined.

@Test
public void testSkipBecauseCacheControlMaxAgeIsDefined() throws Exception {
    HttpServlet servlet = new HttpServlet() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/xml; charset=utf-8");
            response.addHeader("Cache-Control", "private, max-age=232");
            response.getWriter().print("Hello world");
        }
    };
    validate(servlet, Integer.valueOf(232));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Aggregations

HttpServlet (javax.servlet.http.HttpServlet)169 HttpServletRequest (javax.servlet.http.HttpServletRequest)150 HttpServletResponse (javax.servlet.http.HttpServletResponse)150 IOException (java.io.IOException)130 ServletException (javax.servlet.ServletException)127 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 DataFrame (org.eclipse.jetty.http2.frames.DataFrame)22