Support standard processing of the render phase of a request.

@throws IOException IO Exception
422179
public void render() throws IOException {
		if (isDisposed()) {
			LOG.debug("Skipping render phase.");
			return;
		}

		try {
			// Check user context has been prepared
			if (getNewConversation() == null) {
				throw new IllegalStateException(
						"User context has not been prepared before the render phase");
			}

			prepareRender();

			UIContext uic = getUIContext();
			if (uic == null) {
				throw new IllegalStateException("No user context set for the render phase.");
			}

			UIContextHolder.pushContext(uic);
			prepareRequest();

			// Handle errors from the action phase now.
			if (havePropogatedError()) {
				handleError(getPropogatedError());
				return;
			}

			WComponent uiComponent = getUI();

			if (uiComponent == null) {
				throw new SystemException("No UI Component exists.");
			}

			Environment environment = uiComponent.getEnvironment();

			if (environment == null) {
				throw new SystemException("No WEnvironment exists.");
			}

			getInterceptor().attachResponse(getResponse());
			getInterceptor().preparePaint(getRequest());

			String contentType = getUI().getHeaders().getContentType();
			Response response = getResponse();
			response.setContentType(contentType);

			addGenericHeaders(uic, getUI());

			PrintWriter writer = getPrintWriter();
			getInterceptor().paint(new WebXmlRenderContext(writer, uic.getLocale()));

			// The following only matters for a Portal context
			String title = uiComponent instanceof WApplication ? ((WApplication) uiComponent).
					getTitle() : null;

			if (title != null) {
				setTitle(title);
			}
		} catch (Escape esc) {
			LOG.debug("Escape performed during render phase.");
			handleEscape(esc);
		} catch (Throwable t) {
			// We try not to let any exception propagate to container.
			String message = "Caught exception during render phase.";
			LOG.error(message, t);
			handleError(t);
		} finally {
			UIContextHolder.reset();
			dispose();
		}
	}
939856
public void handleError(final Throwable error) throws IOException {

		LOG.debug("Start handleError...");

		// Should the session be removed upon error?
		boolean terminate = ConfigurationProperties.getTerminateSessionOnError();
		// If we are unfriendly, terminate the session
		if (terminate) {
			invalidateSession();
		}

		// Are we in developer friendly error mode?
		boolean friendly = ConfigurationProperties.getDeveloperErrorHandling();

		FatalErrorPageFactory factory = Factory.newInstance(FatalErrorPageFactory.class);
		WComponent errorPage = factory.createErrorPage(friendly, error);

		String html = renderErrorPageToHTML(errorPage);

		// Setup the response
		Response response = getResponse();
		response.setContentType(WebUtilities.CONTENT_TYPE_HTML);

		// Make sure not cached
		getResponse().setHeader("Cache-Control", CacheType.NO_CACHE.getSettings());
		getResponse().setHeader("Pragma", "no-cache");
		getResponse().setHeader("Expires", "-1");

		getPrintWriter().println(html);

		LOG.debug("End handleError");
	}
806429
private void processSavedViewState() throws IOException
   {
      DirectoryEntry dir = (DirectoryEntry) m_viewDir.getEntry("CEdl");
      VarMeta varMeta = new VarMeta9(new DocumentInputStream(((DocumentEntry) dir.getEntry("VarMeta"))));
      Var2Data varData = new Var2Data(varMeta, new DocumentInputStream(((DocumentEntry) dir.getEntry("Var2Data"))));
      //System.out.println(varMeta);
      //System.out.println(varData);

      InputStream is = m_inputStreamFactory.getInstance(dir, "FixedData");
      byte[] fixedData = new byte[is.available()];
      is.read(fixedData);
      //System.out.println(ByteArrayHelper.hexdump(fixedData, false, 16, ""));

      ViewStateReader reader = new ViewStateReader9();
      reader.process(m_file, varData, fixedData);
   }
207112
public void render(OutputStream outputStream, Format format, int dpi) throws PrintingException {
		try {
			if (baos == null) {
				prepare();
			}
			writeDocument(outputStream, format, dpi);
		} catch (Exception e) { // NOSONAR
			throw new PrintingException(e, PrintingException.DOCUMENT_RENDER_PROBLEM);
		}
	}
1047868
@Override
	protected void preparePaintComponent(final Request request) {
		super.preparePaintComponent(request);
		if (!isInitialised()) {
			table.setBean(ExampleDataUtil.createExampleData());
			setInitialised(true);
		}
	}
650751
@Override
	protected void render(FacesContext context) throws IOException {

		// Generate the name definition or image element
		StringBuffer results = new StringBuffer(getElementOpen());

		prepareImageUrl(context, results);

		prepareAttribute(results, "name", getAttribute("name"));
		prepareAttribute(results, "align", getAttribute("align"));
		prepareAttribute(results, "border", getAttribute("border"));
		prepareAttribute(results, "value", getAttribute("value"));
		prepareAttribute(results, "accesskey", getAttribute("accesskey"));
		prepareAttribute(results, "tabindex", getAttribute("tabindex"));
		prepareAttribute(results, "disabled", getAttribute("disabled"));
		results.append(prepareStyles());
		results.append(prepareEventHandlers());
		results.append(" />");

		ResponseWriter writer = context.getResponseWriter();
		writer.write(results.toString());
	}
205723
public void flush() throws IOException
    {   
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "flush");
        boolean crlfWrite = false;
        // check for nonblocking
        if(this._listener!= null){
            synchronized(this){

                WebContainerRequestState reqState = WebContainerRequestState.getInstance(false);
                if (reqState!=null && reqState.getAttribute("com.ibm.ws.webcontainer.CRLFWriteinPorgress")!=null){                                      
                    crlfWrite = true;
                }
                if(this.isWriteReadyWork(false) || crlfWrite ){
                    super.flush();
                }
                else{
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                        Tr.debug(tc, "cannot flush, not write ready");
                    
                    return;
                }
            }
        }
        else{
            super.flush();
        }
    }
547771
private void complete() throws IOException
    {
    if( source_ != null)
      {
      try
        {
        thread_.join();
        }
      catch( Exception e)
        {
        logger_.error( "Thread=" + thread_ + " not completed", e);
        }

      IOException failure =
        failure_ == null
        ? null
        : new IOException( "Can't write filter output", failure_);
      
      failure_      = null;
      filterInput_  = null;
      source_       = null;
      target_       = null;
      thread_       = null;

      if( failure != null)
        {
        throw failure;
        }
      }
    }
837120
public void render(OutputStream target, Graph graph) throws IOException {
		
		BufferedImage bi = 
			new BufferedImage(graph.width, graph.height, 
					GraphConfiguration.imageType);
		Graphics2D g2d = bi.createGraphics();
		graph.draw(g2d);
	    ImageIO.write(bi, "png", target);
	}
252462
public String render(Reader in, RenderContext context) throws IOException {
    StringBuffer buffer = new StringBuffer();
    BufferedReader inputReader = new BufferedReader(in);
    String line;
    while ((line = inputReader.readLine()) != null) {
        buffer.append(line);
    }
    return render(buffer.toString(), context);
 }
193591
private void writeObject(ObjectOutputStream out) throws IOException {
        out.defaultWriteObject();
        out.writeInt(severity.getOrdinal());
        out.writeObject(summary);
        out.writeObject(detail);
        out.writeObject(rendered);
    }
519847
private String process() throws IOException
    {
        final StringBuilder out = new StringBuilder();
        final Block parent = this.readLines();
        parent.removeSurroundingEmptyLines();

        this.recurse(parent, false);
        Block block = parent.blocks;
        while (block != null)
        {
            this.emitter.emit(out, block);
            block = block.next;
        }

        return out.toString();
    }
1140774
@FFDCIgnore({ IOException.class })
    private void flushAsyncBuffers() throws IOException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Flushing Async buffers: " + this);
        }
        if (!this.isc.getResponse().isCommitted()) {
            if ((obs != null) && !this.WCheadersWritten) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "obs  ->" + obs);
                }
                obs.alertOSFirstFlush();
            }

            this.isc.getResponse().setCommitted();
        }

        if (this.ignoreFlush) {
            this.ignoreFlush = false;
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Ignoring first flush attempt");
            }
            return;
        }

        final boolean writingBody = (hasBufferedContent());
        // flip the last buffer for the write...
        if (writingBody && null != this.output[this.outputIndex]) {
            this.output[this.outputIndex].flip();
        }
        try {
            WsByteBuffer[] content = (writingBody) ? this.output : null;
            if (isClosed() || this.isClosing) {
                if (!hasFinished) { //if we've already called finishResponseMessage - don't call again
                    // on a closed stream, use the final write api
                    this.isc.finishResponseMessage(content); // check if this also needs to be async
                    this.isClosing = false;
                    this.hasFinished = true;
                }
            } else {
                // else use the partial body api
                // Add the async option.               
                vc = this.isc.sendResponseBody(content, _callback, false);
                if (vc == null) { // then we will have to wait for data to be written, async write in progress
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "wait for data to be written, async write in progress, set ready to false");
                    }
                    synchronized (this._writeReadyLockObj) {
                        this.setWriteReady(false);
                        this.set_internalReady(false);
                    }
                }
                else {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "able to write out, no callback required, vc -->" + vc);
                    }
                }
            }
        } catch (MessageSentException mse) {
            FFDCFilter.processException(mse, getClass().getName(),
                                        "flushAsyncBuffers", new Object[] { this, this.isc });
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                Tr.event(tc, "Invalid state, message-sent-exception received; " + this.isc);
            }
            this.error = new IOException("Invalid state");
            throw this.error;
        } catch (IOException ioe) {
            // no FFDC required
            this.error = ioe;
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Received exception during write: " + ioe);
            }
            throw ioe;
        } finally {
            this.bytesWritten += this.bufferedCount;
            if (this.contentLengthSet) {
                this.bytesRemaining -= this.bufferedCount;
            }
            this.bufferedCount = 0;
            this.outputIndex = 0;
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "finally, this " + this + " ,bytesRemaining -->" + this.bytesRemaining + ", bytesWritten -->" + this.bytesWritten);
            }
            if (writingBody && vc != null) {
                clearBuffersAfterWrite();
            }
        }
    }
1161579
@Override
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    JsonGenerator jg = null;
    String jsonpcb = null;
    PrintWriter writer = null;
    try {

      writer = response.getWriter();

      // "callback" parameter implies JSONP output
      jsonpcb = request.getParameter(CALLBACK_PARAM);
      if (jsonpcb != null) {
        response.setContentType("application/javascript; charset=utf8");
        writer.write(jsonpcb + "(");
      } else {
        response.setContentType("application/json; charset=utf8");
      }

      jg = jsonFactory.createJsonGenerator(writer);
      jg.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
      jg.useDefaultPrettyPrinter();

      int statusCode = renderMBeans(jg, request.getParameterValues("qry"));
      response.setStatus(statusCode);

    } catch (IOException e) {
      writeException(jg, e);
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } catch (MalformedObjectNameException e) {
      writeException(jg, e);
      response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    } finally {
      if (jg != null) {
        jg.close();
      }
      if (jsonpcb != null) {
        writer.write(");");
      }
      if (writer != null) {
        writer.close();
      }
    }

  }
521481
public void finish() throws IOException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
        { // 306998.15
            Tr.debug(tc, "finish");
        }

        if (length == -1 && total != 0)
            length = total;

        //PM71666 - DBCS and application calls out.close(), the length set here is not correct (depending on # of bytes for each character)
        //          It will be more length by the time the data is encoded by the JDK sun.nio.cs.StreamEncoder, so more bytes are
        //          sent to client than specified in content-length.  Those extra will be dropped by the client without any exception.
        if (WCCustomProperties.SET_CONTENT_LENGTH_ON_CLOSE){
            if (!committed)
            {
                // first write on the close/finish path should set an explicit
                // content-length if we can
                if (!_hasFlushed && obs != null)
                {
                    if (!this.response.isCommitted())
                    {
                        setContentLengthHeader(length);
                    }
                    _hasFlushed = true;
                    obs.alertFirstFlush();
                }
                committed = true;
            }
        } //PM71666
        flush();
    }
467044
@Execute
    public void process() throws Exception {
        if (!concatOr(outTca == null, doReset)) {
            return;
        }
        checkNull(inPit, inFlow);
        HashMap<String, Double> regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inPit);
        cols = regionMap.get(CoverageUtilities.COLS).intValue();
        rows = regionMap.get(CoverageUtilities.ROWS).intValue();
        xRes = regionMap.get(CoverageUtilities.XRES);
        yRes = regionMap.get(CoverageUtilities.YRES);

        RenderedImage pitfillerRI = inPit.getRenderedImage();
        WritableRaster pitWR = CoverageUtilities.renderedImage2WritableRaster(pitfillerRI, false);
        RenderedImage flowRI = inFlow.getRenderedImage();
        WritableRaster flowWR = CoverageUtilities.renderedImage2WritableRaster(flowRI, true);

        // Initialize new RasterData and set value
        WritableRaster tca3dWR = CoverageUtilities.createWritableRaster(cols, rows, null, null, doubleNovalue);

        tca3dWR = area3d(pitWR, flowWR, tca3dWR);
        outTca = CoverageUtilities.buildCoverage("tca3d", tca3dWR, regionMap, //$NON-NLS-1$
                inPit.getCoordinateReferenceSystem());

    }
876082
void processHeader(InputStream dataInput) throws IOException {
        int formatVersion = dataInput.read();
        if (formatVersion < 0) {
            throw new EOFException();
        }
        ensureCondition(formatVersion == SERIALIZER_VERSION, "Unsupported format version %d.", formatVersion);
    }