Builds and writes the response into the OutputStream of {@link HttpServletResponse}
. This methods has to be called at the end of a FORM_POST method.
345684
public void buildAndWrite() {

		try {
			RouterController routerController = RequestContextUtils
					.findWebApplicationContext(this.request)
					.getBean(RouterController.class);

			routerController.writeJsonResponse(this.request, this.response,
					this.extDirectResponse, this.jsonView);

		}
		catch (IOException e) {
			LogFactory.getLog(getClass()).error("buildAndWrite", e);
			throw new RuntimeException(e);
		}

	}
868002
public CloseableHttpResponse getCloseableHttpResponse() {
        ContentType resultContentType = null;
        if (this.contentType != null) {
            resultContentType = ContentType.create(this.contentType, characterEncoding);
        }
        if (internalWriter != null) {
            writer.flush();
            httpClientResponse.setEntity(new StringEntity(internalWriter.toString(), resultContentType));
        } else if (internalOutputStream != null) {
            try {
                outputStream.flush();
            } catch (IOException e) {
                // Nothing to do;
            }
            httpClientResponse.setEntity(new ByteArrayEntity(internalOutputStream.toByteArray(), resultContentType));
        }
        if (!capture) {
            // The result has already been written to the response, let's close
            // the response stream
            if (responseWriter != null) {
                responseWriter.close();
            }
            if (responseOutputStream != null) {
                try {
                    responseOutputStream.close();
                } catch (IOException e) {
                    LOG.warn("Could not close servlet output stream: " + e.getMessage());
                }
            }
        }
        return httpClientResponse;
    }
302122
private void sendResponse(final HttpServletResponse res, final CmsSpellcheckingRequest request) throws IOException {

        final PrintWriter pw = res.getWriter();
        final JSONObject response = getJsonFormattedSpellcheckResult(request);
        pw.println(response.toString());
        pw.close();
    }
10489
@Override
	public void write(final OutputStream output) throws IOException
	{
		initialize();
		if (content == null)
		{
			content = new byte[0];
		}
		output.write(content, 0, content.length);
		output.flush();
	}
1137857
private void writeForm(OutputStream out) throws IOException {
		if (CollectionUtil.isNotEmpty(this.form)) {
			StringBuilder builder = StrUtil.builder();
			for (Entry<String, Object> entry : this.form.entrySet()) {
				builder.append("--").append(BOUNDARY).append(StrUtil.CRLF);
				builder.append(StrUtil.format(CONTENT_DISPOSITION_TEMPLATE, entry.getKey()));
				builder.append(entry.getValue()).append(StrUtil.CRLF);
			}
			IoUtil.write(out, this.charset, false, builder);
		}
	}
319166
protected final OutputStream getHTMLOutputStream(WebSiteRequest req, HttpServletResponse resp) throws IOException {
		resp.setContentType("text/html");
		resp.setCharacterEncoding("UTF-8");
		String[] headers=getAdditionalHeaders(req);
		if(headers!=null) {
			int len=headers.length;
			for(int c=0; c<len; c+=2) resp.setHeader(headers[c], headers[c+1]);
		}
		return resp.getOutputStream();
	}
141980
def _writeResponse(self, response, request, status=200):
        
        request.setResponseCode(status)
        if self.encoding is not None:
            mimeType = 'text/xml; charset="%s"' % self.encoding
        else:
            mimeType = "text/xml"

        request.setHeader("Content-Type", mimeType)
        request.setHeader("Content-Length", str(len(response)))
        request.write(response)
        request.finish()
1329314
def write_response(
        self, status_code: Union[int, constants.HttpStatusCode], *,
        headers: Optional[_HeaderType]=None
            ) -> "writers.HttpResponseWriter":
        
        self._writer = self.__delegate.write_response(
            constants.HttpStatusCode(status_code),
            headers=headers)

        return self._writer
846226
public void handlePut(HttpServletRequest request, HttpServletResponse response, String pathInContext, Resource resource) throws ServletException, IOException
    {
        boolean exists = resource != null && resource.exists();
        if (exists && !passConditionalHeaders(request, response, resource))
            return;

        if (pathInContext.endsWith("/"))
        {
            if (!exists)
            {
                if (!resource.getFile().mkdirs())
                    response.sendError(HttpResponse.__403_Forbidden, "Directories could not be created");
                else
                {
                    response.setStatus(HttpResponse.__201_Created);
                    response.flushBuffer();
                }
            }
            else
            {
                response.setStatus(HttpResponse.__200_OK);
                response.flushBuffer();
            }
        }
        else
        {
            try
            {
                int toRead = request.getContentLength();
                InputStream in = request.getInputStream();
                OutputStream out = resource.getOutputStream();
                if (toRead >= 0)
                    IO.copy(in, out, toRead);
                else
                    IO.copy(in, out);
                out.close();

                response.setStatus(exists ? HttpResponse.__200_OK : HttpResponse.__201_Created);
                response.flushBuffer();
            }
            catch (Exception ex)
            {
                log.warn(LogSupport.EXCEPTION, ex);
                response.sendError(HttpResponse.__403_Forbidden, ex.getMessage());
            }
        }
    }
847319
@Override
	final protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setBufferSize(BUFFER_SIZE);
		postCount.incrementAndGet();
		try {
			reportingDoPost(req, resp);
		} catch (ThreadDeath t) {
			throw t;
		} catch (RuntimeException | ServletException | IOException e) {
			getLogger().log(Level.SEVERE, null, e);
			throw e;
		} catch (SQLException t) {
			getLogger().log(Level.SEVERE, null, t);
			throw new ServletException(t);
		}
	}
1313059
@Override
    public ServletOutputStream getOutputStream() throws IOException {

        if(_out == null ){
            //create the outputstream 
            _out = new SRTUpgradeOutputStream31();       
            _outbb = new UpgradeOutputByteBufferUtil(this);
            _out.init(_outbb,_req);
        }
        return _out;
    }
516212
@Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        Context context =
                ReadOnlyContext.getContext(Constants.HTTP_REQUEST.REST.uri,
                                           request);
        try {
            // Create a new file upload handler
            ServletFileUpload upload = new ServletFileUpload();

            // Parse the request, looking for "file"
            InputStream in = null;
            FileItemIterator iter = upload.getItemIterator(request);
            while (in == null && iter.hasNext()) {
                FileItemStream item = iter.next();
                logger.info("Got next item: isFormField={} fieldName={}", item.isFormField(), item.getFieldName());
                if (!item.isFormField() && item.getFieldName().equals("file")) {
                    in = item.openStream();
                }
            }
            if (in == null) {
                sendResponse(HttpServletResponse.SC_BAD_REQUEST,
                             "No data sent.",
                             response);
            } else {
                sendResponse(HttpServletResponse.SC_CREATED,
                             m_management.putTempStream(context, in),
                             response);
            }
        } catch (AuthzException ae) {
            throw RootException.getServletException(ae,
                                                    request,
                                                    "Upload",
                                                    EMPTY_STRING_ARRAY);
        } catch (Exception e) {
            e.printStackTrace();
            sendResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e
                    .getClass().getName()
                    + ": " + e.getMessage(), response);
        }
    }
1045522
Response createResponse(final JaxRx impl, final ResourcePath path) {
        final StreamingOutput out = createOutput(impl, path);

        // change media type, dependent on WRAP value
        final boolean wrap =
            path.getValue(QueryParameter.WRAP) == null || path.getValue(QueryParameter.WRAP).equals("yes");
        String type = wrap ? MediaType.APPLICATION_XML : MediaType.TEXT_PLAIN;

        // overwrite type if METHOD or MEDIA-TYPE parameters are specified
        final String op = path.getValue(QueryParameter.OUTPUT);
        if (op != null) {
            final Scanner sc = new Scanner(op);
            sc.useDelimiter(",");
            while (sc.hasNext()) {
                final String[] sp = sc.next().split("=", 2);
                if (sp.length == 1)
                    continue;
                if (sp[0].equals(METHOD)) {
                    for (final String[] m : METHODS)
                        if (sp[1].equals(m[0]))
                            type = m[1];
                } else if (sp[0].equals(MEDIATYPE)) {
                    type = sp[1];
                }
            }
        }

        // check validity of media type
        MediaType mt = null;
        try {
            mt = MediaType.valueOf(type);
        } catch (final IllegalArgumentException ex) {
            throw new JaxRxException(400, ex.getMessage());
        }
        return Response.ok(out, mt).build();

    }
29044
protected void writeResponse(HttpServletResponse response, ApiResponse sresponse) {
        response.setStatus(sresponse.getCode());
        for (Entry<String, String> entry : sresponse.getHeaders()) {
            response.addHeader(entry.getKey(), entry.getValue());
        }
    }
626663
def write_response(
        self, status_code: Union[
            int, constants.HttpStatusCode
        ]=constants.HttpStatusCode.BAD_REQUEST, *,
        headers: Optional[_HeaderType]=None
            ) -> "writers.HttpResponseWriter":
        
        return self._delegate.write_response(
            constants.HttpStatusCode(status_code),
            headers=headers)
788634
public void writeTo(OutputStream out) throws IOException
    {
        int sz=size();

        if (sz<=AJP13ResponsePacket.__MAX_BUF)
            super.writeTo(out);
        else
        {
            int offset=preReserve();
            int data=sz-AJP13ResponsePacket.__DATA_HDR;

            while (data>AJP13ResponsePacket.__MAX_DATA)
            {
                _packet.setDataSize(AJP13ResponsePacket.__MAX_BUF-AJP13ResponsePacket.__HDR_SIZE);
                if (offset>0)
                    System.arraycopy(_buf,0,_buf,offset,AJP13ResponsePacket.__DATA_HDR);
                out.write(_buf,offset,AJP13ResponsePacket.__MAX_BUF);

                data-=AJP13ResponsePacket.__MAX_DATA;
                offset+=AJP13ResponsePacket.__MAX_DATA;
            }

            int len=data+AJP13ResponsePacket.__DATA_HDR;
            _packet.setDataSize(len-AJP13ResponsePacket.__HDR_SIZE);
            if (offset>0)
                System.arraycopy(_buf,0,_buf,offset,AJP13ResponsePacket.__DATA_HDR);
            out.write(_buf,offset,len);
        }
    }
126128
public final synchronized void create( HttpServletRequest request,
                                           HttpServletResponse response,
                                           ServletContext servletContext )
    {
        reinitialize( request, response, servletContext );
        initializeSharedFlowFields( request );

        if ( isNestable() )
        {
            // Initialize a ViewRenderer for exiting the nested page flow.  This is used (currently) as part of popup
            // window support -- when exiting a popup nested page flow, a special view renderer writes out javascript
            // that maps output values to the original window and closes the popup window.
            String vrClassName = request.getParameter( InternalConstants.RETURN_ACTION_VIEW_RENDERER_PARAM );

            if ( vrClassName != null )
            {
                ViewRenderer vr =
                        ( ViewRenderer ) DiscoveryUtils.newImplementorInstance( vrClassName, ViewRenderer.class );

                if ( vr != null )
                {
                    vr.init( request );
                    PageFlowController nestingPageFlow = PageFlowUtils.getCurrentPageFlow(request, servletContext);
                    nestingPageFlow.setReturnActionViewRenderer(vr);
                }
            }
        }

        super.create( request, response, servletContext );
    }