當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServletResponse.resetBuffer方法代碼示例

本文整理匯總了Java中javax.servlet.http.HttpServletResponse.resetBuffer方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletResponse.resetBuffer方法的具體用法?Java HttpServletResponse.resetBuffer怎麽用?Java HttpServletResponse.resetBuffer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.http.HttpServletResponse的用法示例。


在下文中一共展示了HttpServletResponse.resetBuffer方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doPost

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    req.setCharacterEncoding("UTF-8");
    Reader r = req.getReader();

    resp.setCharacterEncoding("UTF-8");
    resp.setContentType("text/plain");
    Writer w = resp.getWriter();

    try {
        // Copy one character at a time
        int c = r.read();
        while (c != -1) {
            w.write(c);
            c = r.read();
        }
        w.close();
    } catch (MalformedInputException mie) {
        resp.resetBuffer();
        w.write("FAILED");
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:24,代碼來源:TestInputBuffer.java

示例2: handleInvalidCORS

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * Handles a CORS request that violates specification.
 *
 * @param request
 *            The {@link HttpServletRequest} object.
 * @param response
 *            The {@link HttpServletResponse} object.
 * @param filterChain
 *            The {@link FilterChain} object.
 */
private void handleInvalidCORS(final HttpServletRequest request,
        final HttpServletResponse response, final FilterChain filterChain) {
    String origin = request.getHeader(CorsFilter.REQUEST_HEADER_ORIGIN);
    String method = request.getMethod();
    String accessControlRequestHeaders = request.getHeader(
            REQUEST_HEADER_ACCESS_CONTROL_REQUEST_HEADERS);

    response.setContentType("text/plain");
    response.setStatus(HttpServletResponse.SC_FORBIDDEN);
    response.resetBuffer();

    if (log.isDebugEnabled()) {
        // Debug so no need for i18n
        StringBuilder message =
                new StringBuilder("Invalid CORS request; Origin=");
        message.append(origin);
        message.append(";Method=");
        message.append(method);
        if (accessControlRequestHeaders != null) {
            message.append(";Access-Control-Request-Headers=");
            message.append(accessControlRequestHeaders);
        }
        log.debug(message.toString());
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:36,代碼來源:CorsFilter.java

示例3: handleInvalidCORS

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * Handles a CORS request that violates specification.
 *
 * @param request
 *            The {@link HttpServletRequest} object.
 * @param response
 *            The {@link HttpServletResponse} object.
 * @param filterChain
 *            The {@link FilterChain} object.
 */
private void handleInvalidCORS(final HttpServletRequest request, final HttpServletResponse response,
		final FilterChain filterChain) {
	String origin = request.getHeader(CorsFilter.REQUEST_HEADER_ORIGIN);
	String method = request.getMethod();
	String accessControlRequestHeaders = request.getHeader(REQUEST_HEADER_ACCESS_CONTROL_REQUEST_HEADERS);

	response.setContentType("text/plain");
	response.setStatus(HttpServletResponse.SC_FORBIDDEN);
	response.resetBuffer();

	if (log.isDebugEnabled()) {
		// Debug so no need for i18n
		StringBuilder message = new StringBuilder("Invalid CORS request; Origin=");
		message.append(origin);
		message.append(";Method=");
		message.append(method);
		if (accessControlRequestHeaders != null) {
			message.append(";Access-Control-Request-Headers=");
			message.append(accessControlRequestHeaders);
		}
		log.debug(message.toString());
	}
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:34,代碼來源:CorsFilter.java

示例4: getAttachmentContent

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@RequestMapping(value = "/email/attachment/{id}",method = RequestMethod.GET)
public void getAttachmentContent(@PathVariable("id") Long id, HttpServletResponse response) {

	final AttachmentEntity attachment = attachmentService.findAttachmentById(id);

	if (attachment != null) {
		try {
			ServletOutputStream stream = response.getOutputStream();
			OutputStream out = new BufferedOutputStream(stream);

			response.resetBuffer();
			response.setBufferSize(attachment.getAttachmentContent().getData().length);
			response.setHeader("Content-Length", String.valueOf(attachment.
                       getAttachmentContent().getData().length));

			out.write(attachment.getAttachmentContent().getData());

			out.close();
			stream.close();
		} catch (final IOException e) {
			log.error("Unable to open file", e);
		}
	} else {
		log.error("File does not exist");
	}
}
 
開發者ID:dopse,項目名稱:maildump,代碼行數:27,代碼來源:EmailController.java

示例5: doGet

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    Writer w = resp.getWriter();
    w.write("OK");
    resp.resetBuffer();
    w.write("OK");
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:9,代碼來源:TestOutputBuffer.java

示例6: sendForm

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/** Send the given parameters as a form-encoded response body. */
public static void sendForm(HttpServletResponse response,
        Iterable<? extends Map.Entry> parameters) throws IOException {
    response.resetBuffer();
    response.setContentType(OAuth.FORM_ENCODED + ";charset="
            + OAuth.ENCODING);
    OAuth.formEncode(parameters, response.getOutputStream());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:OAuthServlet.java

示例7: onProxyResponseFailure

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@Override
protected void onProxyResponseFailure(final HttpServletRequest clientRequest, final HttpServletResponse proxyResponse,
		final Response serverResponse, final Throwable failure) {
	_log.warn(failure.toString());

	if (proxyResponse.isCommitted()) {
		// Parent behavior
		super.onProxyResponseFailure(clientRequest, proxyResponse, serverResponse, failure);
	} else {
		proxyResponse.resetBuffer();
		if (failure instanceof TimeoutException) {
			proxyResponse.setStatus(HttpServletResponse.SC_GATEWAY_TIMEOUT);
		} else {

			// Unavailable business server as JSON response
			proxyResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
			proxyResponse.setContentType("application/json");
			try {
				proxyResponse.getOutputStream().write("{\"code\":\"business-down\"}".getBytes(StandardCharsets.UTF_8));
			} catch (final IOException ioe) {
				_log.warn("Broken proxy stream", ioe);
			}
		}
		proxyResponse.setHeader(HttpHeader.CONNECTION.asString(), HttpHeaderValue.CLOSE.asString());
		final AsyncContext asyncContext = clientRequest.getAsyncContext();
		asyncContext.complete();
	}
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:29,代碼來源:BackendProxyServlet.java

示例8: clearBuffer

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
private void clearBuffer(HttpServletResponse response) {
    if (!response.isCommitted()) {
        response.resetBuffer();
    }
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:6,代碼來源:PrepareExceptionValve.java

示例9: printMessage

import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
/**
 * Produces a simple HTTP text/plain response for the specified CORS
 * exception.
 *
 * <p>Note: The CORS filter avoids falling back to the default web
 * container error page (typically a richly-formatted HTML page) to
 * make it easier for XHR debugger tools to identify the cause of
 * failed requests.
 *
 * @param corsException The CORS exception. Must not be {@code null}.
 * @param response      The HTTP servlet response. Must not be
 *                      {@code null}.
 *
 * @throws IOException      On a I/O exception.
 * @throws ServletException On a general request processing exception.
 */
private void printMessage(final CORSException corsException,
			  final HttpServletResponse response)
	throws IOException, ServletException {

	// Set the status code
	response.setStatus(corsException.getHTTPStatusCode());

	// Write the error message
	response.resetBuffer();
	response.setContentType("text/plain");
	PrintWriter out = response.getWriter();
	out.println("Cross-Origin Resource Sharing (CORS) Filter: " + corsException.getMessage());
}
 
開發者ID:sdcuike,項目名稱:cors-filter,代碼行數:30,代碼來源:CORSFilter.java


注:本文中的javax.servlet.http.HttpServletResponse.resetBuffer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。