Package javax.servlet.http

Examples of javax.servlet.http.HttpServletResponse


      writeStock(actx, stock);
    }
  }

  public void writeStock(AsyncContext actx, Stock stock) {
    HttpServletResponse response = (HttpServletResponse) actx.getResponse();
    try {
      PrintWriter writer = response.getWriter();
      writer.write("STOCK#");//make client parsing easier
      writer.write(stock.getSymbol());
      writer.write("#");
      writer.write(stock.getValueAsString());
      writer.write("#");
      writer.write(stock.getLastChangeAsString());
      writer.write("#");
      writer.write(String.valueOf(stock.getCnt()));
      writer.write("\n");
      writer.flush();
      response.flushBuffer();
    } catch (IOException x) {
      try {
        actx.complete();
      } catch (Exception ignore) {/* Ignore */
      }
 
View Full Code Here


  }

  /** Serve a simple <tt>.rtf</tt> file, having fixed content.  */
  @Override  public ResponsePage execute() throws AppException {
    fLogger.fine("Serving response as an .rtf file.");
    HttpServletResponse response = getRequestParser().getResponse();
    try {
      //you need to use call response.getWriter() OR response.getOutputStream()
      PrintWriter out = response.getWriter();
      try {
        //set the content-type response header accordingly
        //one might set this instead in web.xml, using mime-mapping.
        response.setContentType("application/rtf");
        //output some fixed content in RTF file format
        out.println(
          "{\\rtf1\\ansi\\deff0{\\fonttbl{\\f0 Times New Roman;}}" +
          "{\\pard\\fs32\\b NOTE\\par}" +
          "{\\pard\\fs26 Bangalore is rather {\\i hot and sticky} " +
View Full Code Here

     */
    public OutputStreamMessageContext createOutputStreamContext(MessageContext context)
        throws IOException {
        return new AbstractHTTPServerOutputStreamContext(this, context) {
            protected void flushHeaders() throws IOException {
                HttpServletResponse response =
                    (HttpServletResponse)get(HTTPServerInputStreamContext.HTTP_RESPONSE);
               
                Integer i = (Integer)context.get(HTTP_RESPONSE_CODE);
                if (i != null) {
                    response.setStatus(i.intValue());
                }
               
                Map<?, ?> headers = (Map<?, ?>)super.get(HTTP_RESPONSE_HEADERS);
                if (null != headers) {
                    for (Iterator<?> iter = headers.keySet().iterator(); iter.hasNext();) {
                        String header = (String)iter.next();
                        List<?> headerList = (List<?>)headers.get(header);
                        for (Object string : headerList) {
                            response.addHeader(header, (String)string);
                        }
                    }
                }
                origOut.resetOut(new BufferedOutputStream(response.getOutputStream(), 1024));
            }
        };
    }   
View Full Code Here

        throws IOException
    {
        final BinaryFile fileComponent = (BinaryFile)component;
        if (fileComponent.isRendered())
        {
            final HttpServletResponse response = this.getResponse(context);
            final OutputStream stream = response.getOutputStream();

            // - reset the reponse to clear out any any headers (i.e. so
            //   the user doesn't get "unable to open..." when using IE.)
            response.reset();
            final String fileName = fileComponent.getFileName();
            if (fileComponent.isPrompt() && fileName != null && fileName.trim().length() > 0)
            {
                response.addHeader(
                    "Content-disposition",
                    "attachment; filename=\"" + fileName + '"');
            }

            Object value = fileComponent.getValue();
            final String contentType = fileComponent.getContentType();
            // - for IE we need to set the content type, content length and buffer size and
            //   then the flush the response right away because it seems as if there is any lag time
            //   IE just displays a blank page. With mozilla based clients reports display correctly regardless.
            if (contentType != null && contentType.length() > 0)
            {
                response.setContentType(contentType);
            }
            if (value instanceof String)
            {
                value = ((String)value).getBytes();
            }
            if (value instanceof byte[])
            {
                byte[] file = (byte[])value;
                if (file != null)
                {
                    response.setBufferSize(file.length);
                    response.setContentLength(file.length);
                    response.flushBuffer();
                    stream.write(file);
                }
            }
            else if (value instanceof InputStream)
            {
                final InputStream report = (InputStream)value;
                final byte[] buffer = new byte[BUFFER_SIZE];
                response.setBufferSize(BUFFER_SIZE);
                response.flushBuffer();
                for (int ctr = 0; (ctr = report.read(buffer)) > 0;)
                {
                    stream.write(buffer, 0, ctr);
                }
                stream.flush();
View Full Code Here

        throws IOException
    {
        final BinaryFile fileComponent = (BinaryFile)component;
        if (fileComponent.isRendered())
        {
            final HttpServletResponse response = this.getResponse(context);
            final OutputStream stream = response.getOutputStream();
            stream.flush();
            stream.close();
        }
    }
View Full Code Here

  }
 
  private void doRememberMe(User userRecord){
    if(rememberMe == true){
      Cookie passCookie = createPassCookie(userRecord);
      HttpServletResponse res = getServletResponse();
      res.addCookie(passCookie);
    }else{
      ServletUtilities.deleteCookie(getServletResponse(),SessionConstants.REMEMBER_ME);
    }
  }
View Full Code Here

            throws IOException, ServletException {
        Logger.log(Logger.FULL_DEBUG, AUTH_RESOURCES,
                "BaseAuthenticationHandler.StartAuthCheck");

        HttpServletRequest request = (HttpServletRequest) inRequest;
        HttpServletResponse response = (HttpServletResponse) inResponse;

        // Give previous attempts a chance to be validated
        if (!validatePossibleAuthenticationResponse(request, response, pathRequested)) {
            return false;
        } else {
View Full Code Here

    String format = get("format");
    if (StringUtils.isNotBlank(simpleName)) {
      Iterator<CodeMeta> it = entityDao.get(CodeMeta.class, "name", simpleName).iterator();
      if (it.hasNext()) {
        try {
          HttpServletResponse response = getResponse();
          response.setContentType("text/xml");
          response.setCharacterEncoding("UTF-8");
          out = response.getWriter();
          @SuppressWarnings("rawtypes")
          Class baseCodeClass = Class.forName(it.next().getClassName());
          if (BaseCode.class.isAssignableFrom(baseCodeClass)) {
            @SuppressWarnings("unchecked")
            List<? extends BaseCode<?>> baseCodes = baseCodeService.getCodes(baseCodeClass);
View Full Code Here

    }

    private void lazyInit() {
        if (initialized) return;
        initialized = true;
        HttpServletResponse response = (HttpServletResponse) super.getVariable("response");
        ServletOutput output = new ServletOutput(response);
        super.setVariable("out", output.getWriter());
        super.setVariable("sout", output.getOutputStream());
        MarkupBuilder builder = new MarkupBuilder(output.getWriter());
        builder.setExpandEmptyElements(true);
View Full Code Here

        }
    }
   
    public void forward(String path) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) super.getVariable("request");
        HttpServletResponse response = (HttpServletResponse) super.getVariable("response");
        RequestDispatcher dispatcher = request.getRequestDispatcher(path);
        dispatcher.forward(request, response);
    }
View Full Code Here

TOP

Related Classes of javax.servlet.http.HttpServletResponse

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.