Search in sources :

Example 61 with ServletOutputStream

use of javax.servlet.ServletOutputStream in project jena by apache.

the class ResponseModel method doResponseModel.

public static void doResponseModel(HttpAction action, Model model) {
    HttpServletRequest request = action.request;
    HttpServletResponse response = action.response;
    // Header request type 
    String mimeType = null;
    // TODO Use MediaType throughout.
    MediaType i = ConNeg.chooseContentType(request, DEF.rdfOffer, DEF.acceptRDFXML);
    if (i != null)
        mimeType = i.getContentType();
    String outputField = ResponseOps.paramOutput(request, shortNamesModel);
    if (outputField != null)
        mimeType = outputField;
    String writerMimeType = mimeType;
    if (mimeType == null) {
        Fuseki.requestLog.warn("Can't find MIME type for response");
        String x = WebLib.getAccept(request);
        String msg;
        if (x == null)
            msg = "No Accept: header";
        else
            msg = "Accept: " + x + " : Not understood";
        error(HttpSC.NOT_ACCEPTABLE_406, msg);
    }
    String contentType = mimeType;
    String charset = WebContent.charsetUTF8;
    String forceAccept = ResponseOps.paramForceAccept(request);
    if (forceAccept != null) {
        contentType = forceAccept;
        charset = WebContent.charsetUTF8;
    }
    Lang lang = RDFLanguages.contentTypeToLang(contentType);
    if (lang == null)
        errorBadRequest("Can't determine output content type: " + contentType);
    try {
        ResponseResultSet.setHttpResponse(request, response, contentType, charset);
        response.setStatus(HttpSC.OK_200);
        ServletOutputStream out = response.getOutputStream();
        RDFDataMgr.write(out, model, lang);
        out.flush();
    } catch (Exception ex) {
        slog.info("Exception while writing the response model: " + ex.getMessage(), ex);
        errorOccurred("Exception while writing the response model: " + ex.getMessage(), ex);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletOutputStream(javax.servlet.ServletOutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) MediaType(org.apache.jena.atlas.web.MediaType) Lang(org.apache.jena.riot.Lang)

Example 62 with ServletOutputStream

use of javax.servlet.ServletOutputStream in project jena by apache.

the class ActionPing method doCommon.

protected void doCommon(HttpServletRequest request, HttpServletResponse response) {
    try {
        ServletOps.setNoCache(response);
        response.setContentType(contentTypeTextPlain);
        response.setCharacterEncoding(charsetUTF8);
        response.setStatus(HttpSC.OK_200);
        ServletOutputStream out = response.getOutputStream();
        out.println(DateTimeUtils.nowAsXSDDateTimeString());
    } catch (IOException ex) {
        Fuseki.serverLog.warn("ping :: IOException :: " + ex.getMessage());
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) IOException(java.io.IOException)

Example 63 with ServletOutputStream

use of javax.servlet.ServletOutputStream in project jena by apache.

the class ActionDataset method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    //        request.getRemoteUser() ;
    //        request.getUserPrincipal() ;
    String dataset = FusekiLib.safeParameter(request, "dataset");
    HttpSession session = request.getSession(true);
    session.setAttribute("dataset", dataset);
    // 10 mins
    session.setMaxInactiveInterval(15 * 60);
    boolean known = DatasetRegistry.get().isRegistered(dataset);
    if (!known) {
        response.sendError(HttpSC.BAD_REQUEST_400, "No such dataset: " + dataset);
        return;
    }
    if (true) {
        // Redirect to GET page.
        response.setHeader(HttpNames.hLocation, PageNames.pageAfterLogin);
        response.setStatus(HttpSC.SEE_OTHER_303);
    } else {
        // Welcome style - but HTML inline :-(
        response.setContentType("text/html");
        response.setStatus(HttpSC.OK_200);
        ServletOutputStream out = response.getOutputStream();
        out.print("<p>" + dataset + "(" + known + ")</p>");
        for (String name : DatasetRegistry.get().keys()) {
            out.print("<li>");
            out.print(name);
            out.println("</li>");
        }
        out.println("</ul>");
        out.println("<p><a href=\"info\">Next</a></p>");
    }
//        Cookie cookie = new Cookie("org.apache.jena.fuseki.session", dataset) ;
//        // 24 hours.
//        cookie.setMaxAge(24*60*60) ;
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) HttpSession(javax.servlet.http.HttpSession)

Example 64 with ServletOutputStream

use of javax.servlet.ServletOutputStream in project jena by apache.

the class PingServlet method doCommon.

protected void doCommon(HttpServletRequest request, HttpServletResponse response) {
    try {
        response.setHeader(HttpNames.hCacheControl, "must-revalidate,no-cache,no-store");
        response.setHeader(HttpNames.hPragma, "no-cache");
        response.setContentType(contentTypeTextPlain);
        response.setCharacterEncoding(charsetUTF8);
        response.setStatus(HttpSC.OK_200);
        ServletOutputStream out = response.getOutputStream();
        out.println(DateTimeUtils.nowAsXSDDateTimeString());
    } catch (IOException ex) {
        Fuseki.serverLog.warn("ping :: IOException :: " + ex.getMessage());
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) IOException(java.io.IOException)

Example 65 with ServletOutputStream

use of javax.servlet.ServletOutputStream in project jena by apache.

the class StatsServlet method statsJSON.

private void statsJSON(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    ServletOutputStream out = resp.getOutputStream();
    resp.setContentType(WebContent.contentTypeJSON);
    resp.setCharacterEncoding(WebContent.charsetUTF8);
    /*
         * { "server" : ....   
         *    "datasets" : {
         *       "ds1": { counters... }
         *       GSP stucture?
         *         
         */
    JsonObject obj = new JsonObject();
    JsonObject datasets = new JsonObject();
    JsonObject server = new JsonObject();
    server.put("host", req.getLocalName() + ":" + req.getLocalPort());
    for (String ds : DatasetRegistry.get().keys()) statsJSON(datasets, ds);
    obj.put("server", server);
    obj.put("datasets", datasets);
    JSON.write(out, obj);
    out.flush();
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) JsonObject(org.apache.jena.atlas.json.JsonObject)

Aggregations

ServletOutputStream (javax.servlet.ServletOutputStream)509 IOException (java.io.IOException)212 HttpServletResponse (javax.servlet.http.HttpServletResponse)147 Test (org.junit.Test)112 HttpServletRequest (javax.servlet.http.HttpServletRequest)109 ServletException (javax.servlet.ServletException)91 InputStream (java.io.InputStream)62 File (java.io.File)57 ByteArrayOutputStream (java.io.ByteArrayOutputStream)40 FileInputStream (java.io.FileInputStream)40 CountDownLatch (java.util.concurrent.CountDownLatch)27 WriteListener (javax.servlet.WriteListener)27 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)27 PrintWriter (java.io.PrintWriter)26 HttpServlet (javax.servlet.http.HttpServlet)25 AsyncContext (javax.servlet.AsyncContext)23 ServletInputStream (javax.servlet.ServletInputStream)22 ArrayList (java.util.ArrayList)21 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)20 Date (java.util.Date)18