Package javax.servlet

Examples of javax.servlet.ServletOutputStream


            setMaxAge(response, EXPIRES_1_HOUR);

            thumbnailData = thumbnail.getThumbnailData();
            if (thumbnailData != null) {
                LOGGER.debug("Cache hit for: %s (raw) %d x %d", artifactVertex.getId(), boundaryDims[0], boundaryDims[1]);
                ServletOutputStream out = response.getOutputStream();
                out.write(thumbnailData);
                out.close();
                return;
            }
        }

        LOGGER.info("Cache miss for: %s (raw) %d x %d", artifactVertex.getId(), boundaryDims[0], boundaryDims[1]);
        StreamingPropertyValue rawPropertyValue = LumifyProperties.RAW.getPropertyValue(artifactVertex);
        if (rawPropertyValue == null) {
            respondWithNotFound(response);
            return;
        }

        InputStream in = rawPropertyValue.getInputStream();
        try {
            thumbnail = artifactThumbnailRepository.createThumbnail(artifactVertex, "raw", in, boundaryDims, user);

            String format = thumbnail.getFormat();
            response.setContentType("image/" + format);
            response.addHeader("Content-Disposition", "inline; filename=thumbnail" + boundaryDims[0] + "." + format);
            setMaxAge(response, EXPIRES_1_HOUR);

            thumbnailData = thumbnail.getThumbnailData();
        } finally {
            in.close();
        }
        ServletOutputStream out = response.getOutputStream();
        out.write(thumbnailData);
        out.close();
    }
View Full Code Here


            imageData = getMarkerImage(new ByteArrayInputStream(glyphIcon), scale, selected, heading, isMapGlyphIcon);
            imageCache.put(cacheKey, imageData);
        }

        response.setHeader("Cache-Control", "max-age=" + (5 * 60));
        ServletOutputStream out = response.getOutputStream();
        out.write(imageData);
        out.close();
    }
View Full Code Here

            setMaxAge(response, EXPIRES_1_HOUR);

            byte[] thumbnailData = artifactThumbnailRepository.getThumbnailData(artifactVertex.getId(), "poster-frame", boundaryDims[0], boundaryDims[1], user);
            if (thumbnailData != null) {
                LOGGER.debug("Cache hit for: %s (poster-frame) %d x %d", graphVertexId, boundaryDims[0], boundaryDims[1]);
                ServletOutputStream out = response.getOutputStream();
                out.write(thumbnailData);
                out.close();
                return;
            }
        }

        StreamingPropertyValue rawPosterFrameValue = RAW_POSTER_FRAME.getPropertyValue(artifactVertex);
        if (rawPosterFrameValue == null) {
            LOGGER.warn("Could not find raw poster from for artifact: %s", artifactVertex.getId());
            respondWithNotFound(response);
            return;
        }

        InputStream in = rawPosterFrameValue.getInputStream();
        try {
            if (widthStr != null) {
                LOGGER.info("Cache miss for: %s (poster-frame) %d x %d", graphVertexId, boundaryDims[0], boundaryDims[1]);

                response.setContentType("image/jpeg");
                response.addHeader("Content-Disposition", "inline; filename=thumbnail" + boundaryDims[0] + ".jpg");
                setMaxAge(response, EXPIRES_1_HOUR);

                byte[] thumbnailData = artifactThumbnailRepository.createThumbnail(artifactVertex, "poster-frame", in, boundaryDims, user).getThumbnailData();
                ServletOutputStream out = response.getOutputStream();
                out.write(thumbnailData);
                out.close();
            } else {
                response.setContentType("image/png");
                IOUtils.copy(in, response.getOutputStream());
            }
        } finally {
View Full Code Here

        }

        // TODO change content type if we use this route for more than getting glyph icons
        response.setContentType("image/png");
        response.setHeader("Cache-Control", "max-age=" + (5 * 60));
        ServletOutputStream out = response.getOutputStream();
        out.write(rawImg);
        out.close();
    }
View Full Code Here

            setMaxAge(response, EXPIRES_1_HOUR);

            byte[] thumbnailData = artifactThumbnailRepository.getThumbnailData(artifactVertex.getId(), "video-preview", boundaryDims[0], boundaryDims[1], user);
            if (thumbnailData != null) {
                LOGGER.debug("Cache hit for: %s (video-preview) %d x %d", artifactVertex.getId().toString(), boundaryDims[0], boundaryDims[1]);
                ServletOutputStream out = response.getOutputStream();
                out.write(thumbnailData);
                out.close();
                return;
            }
        }

        StreamingPropertyValue videoPreviewImageValue = VIDEO_PREVIEW_IMAGE.getPropertyValue(artifactVertex);
        if (videoPreviewImageValue == null) {
            LOGGER.warn("Could not find video preview image for artifact: %s", artifactVertex.getId().toString());
            respondWithNotFound(response);
            return;
        }
        InputStream in = videoPreviewImageValue.getInputStream();
        try {
            if (widthStr != null) {
                LOGGER.info("Cache miss for: %s (video-preview) %d x %d", artifactVertex.getId().toString(), boundaryDims[0], boundaryDims[1]);

                response.setContentType("image/jpeg");
                response.addHeader("Content-Disposition", "inline; filename=videoPreview" + boundaryDims[0] + ".jpg");
                setMaxAge(response, EXPIRES_1_HOUR);

                byte[] thumbnailData = artifactThumbnailRepository.createThumbnail(artifactVertex, "video-preview", in, boundaryDims, user).getThumbnailData();
                ServletOutputStream out = response.getOutputStream();
                out.write(thumbnailData);
                out.close();
            } else {
                response.setContentType("image/png");
                IOUtils.copy(in, response.getOutputStream());
            }
        } finally {
View Full Code Here

      httpResponse.setContentType("application/xml");
    }
    httpResponse.setContentLength(data.length);

    try {
      ServletOutputStream os = httpResponse.getOutputStream();
      os.write(data);
      os.flush();
    } catch (IOException e) {
      // Not a lot we can do here ... we've already started sending data
      log.error("Error flushing data", e);
      // Try setting an error response
      try {
View Full Code Here

                     request, this, servletContext), buffer);

            if (!Charset.forName(getCharacterEncoding()).equals(buffer.getCharset()))
               setCharacterEncoding(buffer.getCharset().name());

            ServletOutputStream outputStream = isResponseStreamWrapped() ? wrappedOutputStream : super
                     .getOutputStream();

            if (outputStream != null)
               Streams.copy(new ByteArrayInputStream(buffer.getContents()), outputStream);
View Full Code Here

    private PrintWriter printWriter;
    private ServletOutputStream servletOutputStream;

    public TestHttpServletResponse() {
        this.printWriter = new PrintWriter(outputStream);
        this.servletOutputStream = new ServletOutputStream() {
            @Override
            public void write(int i) throws IOException {
                outputStream.write(i);
            }
        };
View Full Code Here

        String cause = e.getCause().getMessage();
        if ( cause != null )
          error += "\n" + cause;
      }
      StringReader is = new StringReader(error);
      ServletOutputStream os = response.getOutputStream();
      response.setContentType("text/plain");
      IOUtils.copy(is, os);
      os.close();
      return true;
    }
   
    if (log.isDebugEnabled()) {
      log.debug("outFormat=" + outFormat+
          " queryResult: contentType=" + queryResult.getContentType()+
          " isEmpty=" +queryResult.isEmpty());
    }
   
    // set the content type now (although this might be changed below)
    // (this should fix 284: "empty reponse with incorrect content type")
    response.setContentType(queryResult.getContentType());
    String result = queryResult.getResult();
   

    if ( queryResult.isEmpty() ) {
      if ( requestedEntity != null  ) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, requestedEntity);
        return true;
      }
     
      if ( ! forceCompletion ) {
        // we have the condition: !forceCompletion AND requestedEntity is null AND query result is empty.
        return false// dispatch NO completed here.
      }
    }
   
    if ( "Application/rdf+xml".equalsIgnoreCase(queryResult.getContentType()) ) {
      // convert to HTML?
      if ( Util.yes(request, "xslt") ) {
        String XSLT_RESOURCE = "rdf.xslt";
        InputStream xslt = getClass().getClassLoader().getResourceAsStream(XSLT_RESOURCE);
        if ( xslt != null ) {
          result = XSLTCreator.create(result, xslt);
        }
        else {
          result = "Cannot find resource: " + XSLT_RESOURCE;
        }
        response.setContentType("text/html");
      }
     
      // put stylesheet at beginning of the result?
      else if ( Util.yes(request, "xslti") ) {
        // what type? I've tried:
        //   type="text/xsl"
        //   type="text/xml"
        //   type="application/xslt+xml"
        // without success.
        //
        String type="application/xslt+xml";
        String xmlHeader = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n";
        xmlHeader += "<?xml-stylesheet type=\"" +type+ "\" href=\"" +
                request.getContextPath()+ "/rdf.xslt" + "\"?>\n";
       
        result = xmlHeader + result;
        response.setContentType("Application/rdf+xml");
      }
      else {
        response.setContentType("Application/rdf+xml");
      }
    }
   
    else if ( "text/html".equalsIgnoreCase(queryResult.getContentType()) ) {
      String queryComm = "\n<!-- Query:\n\n" +Util.toHtmlComment(query)+ "\n-->\n\n";
      String pre, pos = "";
     
      if ( "html-frag".equals(outFormat) ) {
        pre = queryComm;
        pos = "";
      }
      else {
        pre = "<html><head><title>Query result</title>" +
                "<link rel=stylesheet href=\"" +
                request.getContextPath()+ "/main.css\" type=\"text/css\">" +
                "</head><body>\n" +
            queryComm + "\n" +
                "<br/><div align=\"center\">\n"
        ;
       
        /*
         * TODO better to have this piece as a specific "header" parameter
         */
        if (requestedEntity != null) {
          pre += "<b>" + requestedEntity + "</b><br/><br/>\n";
          pos += "<font color=\"gray\" size=\"-2\"><br/>" +OntVersion.getFullTitle()+ "</font>";
        }

       
       
        pos += "</div></body></html>";
      }
      result = pre + result + pos;
      response.setContentType(queryResult.getContentType());
    }
   
    /*
     * The following checks the case when the request was for "html-frag", which
     * is actually dispatched as CSV when using AllegroGraph 4.4. In this
     * case, do the conversion from CSV to the requested HTML:
     */
    else if ("html-frag".equals(outFormat) && Util.contentTypeIsCsv(queryResult.getContentType())) {
      result = Util.csv2html(result);
      response.setContentType("text/html");
    }
   
    /*
     * The following checks the case when there was no explicit outFormat and the
     * dispatch generated a CSV format. if so, do the conversion from CSV to the requested HTML:
     */
    else if (outFormat == null && Util.contentTypeIsCsv(queryResult.getContentType())) {
      result = Util.csv2html(result);
      response.setContentType("text/html");
     
      String queryComm = "\n<!-- Query:\n\n" +Util.toHtmlComment(query)+ "\n-->\n\n";
      String pre = "<html><head><title>Query result</title>" +
          "<link rel=stylesheet href=\"" +
          request.getContextPath()+ "/main.css\" type=\"text/css\">" +
          "</head><body>\n" +
          queryComm
      ;
      String pos = "</body></html>";
     
      result = pre + result + pos;
    }
   
    else {
      response.setContentType(queryResult.getContentType());
    }
   
    ServletOutputStream os = response.getOutputStream();
    IOUtils.write(result, os, "UTF-8");
    os.close();
   
    return true;
  }
View Full Code Here

      log.error("Error loading ontology.", e);
      throw new ServletException("Error loading ontology.", e);
    }
   
    req.response.setContentType("text/plain");
    ServletOutputStream os = req.response.getOutputStream();
    IOUtils.write(ontUri+ " loaded in graph.", os);
    os.close();
  }
View Full Code Here

TOP

Related Classes of javax.servlet.ServletOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.