当前位置: 首页>>代码示例>>Java>>正文


Java HttpServletResponseWrapper类代码示例

本文整理汇总了Java中javax.servlet.http.HttpServletResponseWrapper的典型用法代码示例。如果您正苦于以下问题:Java HttpServletResponseWrapper类的具体用法?Java HttpServletResponseWrapper怎么用?Java HttpServletResponseWrapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpServletResponseWrapper类属于javax.servlet.http包,在下文中一共展示了HttpServletResponseWrapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doGet

import javax.servlet.http.HttpServletResponseWrapper; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
    Cookie cookie = new Cookie("name", unknown());
    cookie.setValue(req.getParameter("p") + "x");
    resp.setHeader("header", req.getParameter("h1"));
    resp.addHeader("header", unknown());
    callCookieSink(req.getParameter("h2"));
    String encoded = ESAPI.encoder().encodeForURL(req.getParameter("h3"));
    resp.addHeader("header", ESAPI.encoder().decodeFromURL(encoded));
    
    // false positives
    String safe = "x".concat("y");
    Cookie safeCookie = new Cookie("name", safe);
    safeCookie.setValue(safe + "x");
    resp.setHeader("header", safe);
    resp.addHeader("header", encoded.concat(safe));


    HttpServletResponseWrapper resWrapper = new HttpServletResponseWrapper(resp);
    resWrapper.setHeader("header2",req.getParameter("a"));
    resWrapper.addHeader("header3",req.getParameter("b"));
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:23,代码来源:ResponseSplittingServlet.java

示例2: doOptions

import javax.servlet.http.HttpServletResponseWrapper; //导入依赖的package包/类
/**
 * Delegate OPTIONS requests to {@link #processRequest}, if desired.
 * <p>Applies HttpServlet's standard OPTIONS processing otherwise,
 * and also if there is still no 'Allow' header set after dispatching.
 * @see #doService
 */
@Override
protected void doOptions(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

	if (this.dispatchOptionsRequest || CorsUtils.isPreFlightRequest(request)) {
		processRequest(request, response);
		if (response.containsHeader("Allow")) {
			// Proper OPTIONS response coming from a handler - we're done.
			return;
		}
	}

	// Use response wrapper for Servlet 2.5 compatibility where
	// the getHeader() method does not exist
	super.doOptions(request, new HttpServletResponseWrapper(response) {
		@Override
		public void setHeader(String name, String value) {
			if ("Allow".equals(name)) {
				value = (StringUtils.hasLength(value) ? value + ", " : "") + RequestMethod.PATCH.name();
			}
			super.setHeader(name, value);
		}
	});
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:FrameworkServlet.java

示例3: decoratedNativeRequest

import javax.servlet.http.HttpServletResponseWrapper; //导入依赖的package包/类
@Test
public void decoratedNativeRequest() {
	HttpServletRequest decoratedRequest = new HttpServletRequestWrapper(servletRequest);
	HttpServletResponse decoratedResponse = new HttpServletResponseWrapper(servletResponse);
	ServletWebRequest request = new ServletWebRequest(decoratedRequest, decoratedResponse);
	assertSame(decoratedRequest, request.getNativeRequest());
	assertSame(decoratedRequest, request.getNativeRequest(ServletRequest.class));
	assertSame(decoratedRequest, request.getNativeRequest(HttpServletRequest.class));
	assertSame(servletRequest, request.getNativeRequest(MockHttpServletRequest.class));
	assertNull(request.getNativeRequest(MultipartRequest.class));
	assertSame(decoratedResponse, request.getNativeResponse());
	assertSame(decoratedResponse, request.getNativeResponse(ServletResponse.class));
	assertSame(decoratedResponse, request.getNativeResponse(HttpServletResponse.class));
	assertSame(servletResponse, request.getNativeResponse(MockHttpServletResponse.class));
	assertNull(request.getNativeResponse(MultipartRequest.class));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:ServletWebRequestTests.java

示例4: doFilterInternal

import javax.servlet.http.HttpServletResponseWrapper; //导入依赖的package包/类
@Override
protected void doFilterInternal(HttpServletRequest request,
		HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {

	filterChain.doFilter(new HttpServletRequestWrapper(request) {
		@Override
		public Principal getUserPrincipal() {
			return new Principal() {
				@Override
				public String getName() {
					return PRINCIPAL_NAME;
				}
			};
		}
	}, new HttpServletResponseWrapper(response));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:FilterTests.java

示例5: fetchCacheProxyResponse

import javax.servlet.http.HttpServletResponseWrapper; //导入依赖的package包/类
/**
 * Fetch the response wrapper of type CacheProxyResponse if one can be
 * found.
 * 
 * @param servletResponse
 *            the current servlet response.
 * @return the response wrapper of type CacheProxyResponse if one can be
 *         found.
 */
private static CacheProxyResponse fetchCacheProxyResponse(
		ServletResponse servletResponse) {
	CacheProxyResponse cachedResponse = null;
	ServletResponse findResponse = servletResponse;

	while (findResponse instanceof HttpServletResponseWrapper) {
		if (findResponse instanceof CacheProxyResponse) {
			cachedResponse = (CacheProxyResponse) findResponse;
			break;
		}
		HttpServletResponseWrapper wrapper = (HttpServletResponseWrapper) findResponse;
		findResponse = wrapper.getResponse();
	}
	return cachedResponse;
}
 
开发者ID:dd00f,项目名称:ibm-performance-monitor,代码行数:25,代码来源:WasCacheHitCheckServletFilter.java

示例6: notAnErrorButNotOK

import javax.servlet.http.HttpServletResponseWrapper; //导入依赖的package包/类
@Test
public void notAnErrorButNotOK() throws Exception {
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			((HttpServletResponse) response).setStatus(201);
			super.doFilter(request, response);
			response.flushBuffer();
		}
	};
	this.filter.doFilter(this.request, this.response, this.chain);
	assertThat(((HttpServletResponse) this.chain.getResponse()).getStatus())
			.isEqualTo(201);
	assertThat(((HttpServletResponse) ((HttpServletResponseWrapper) this.chain
			.getResponse()).getResponse()).getStatus()).isEqualTo(201);
	assertThat(this.response.isCommitted()).isTrue();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:ErrorPageFilterTests.java

示例7: unauthorizedWithErrorPath

import javax.servlet.http.HttpServletResponseWrapper; //导入依赖的package包/类
@Test
public void unauthorizedWithErrorPath() throws Exception {
	this.filter.addErrorPages(new ErrorPage("/error"));
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			((HttpServletResponse) response).sendError(401, "UNAUTHORIZED");
			super.doFilter(request, response);
		}
	};
	this.filter.doFilter(this.request, this.response, this.chain);
	assertThat(this.chain.getRequest()).isEqualTo(this.request);
	HttpServletResponseWrapper wrapper = (HttpServletResponseWrapper) this.chain
			.getResponse();
	assertThat(wrapper.getResponse()).isEqualTo(this.response);
	assertThat(this.response.isCommitted()).isTrue();
	assertThat(wrapper.getStatus()).isEqualTo(401);
	// The real response has to be 401 as well...
	assertThat(this.response.getStatus()).isEqualTo(401);
	assertThat(this.response.getForwardedUrl()).isEqualTo("/error");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:23,代码来源:ErrorPageFilterTests.java

示例8: responseUncommittedWithoutErrorPage

import javax.servlet.http.HttpServletResponseWrapper; //导入依赖的package包/类
@Test
public void responseUncommittedWithoutErrorPage() throws Exception {
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			((HttpServletResponse) response).sendError(400, "BAD");
			super.doFilter(request, response);
		}
	};
	this.filter.doFilter(this.request, this.response, this.chain);
	assertThat(this.chain.getRequest()).isEqualTo(this.request);
	assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getResponse())
			.isEqualTo(this.response);
	assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
			.isEqualTo(400);
	assertThat(this.response.getForwardedUrl()).isNull();
	assertThat(this.response.isCommitted()).isTrue();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:ErrorPageFilterTests.java

示例9: globalError

import javax.servlet.http.HttpServletResponseWrapper; //导入依赖的package包/类
@Test
public void globalError() throws Exception {
	this.filter.addErrorPages(new ErrorPage("/error"));
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			((HttpServletResponse) response).sendError(400, "BAD");
			super.doFilter(request, response);
		}
	};
	this.filter.doFilter(this.request, this.response, this.chain);
	assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
			.isEqualTo(400);
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE))
			.isEqualTo(400);
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE))
			.isEqualTo("BAD");
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI))
			.isEqualTo("/test/path");
	assertThat(this.response.isCommitted()).isTrue();
	assertThat(this.response.getForwardedUrl()).isEqualTo("/error");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:24,代码来源:ErrorPageFilterTests.java

示例10: statusError

import javax.servlet.http.HttpServletResponseWrapper; //导入依赖的package包/类
@Test
public void statusError() throws Exception {
	this.filter.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400"));
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			((HttpServletResponse) response).sendError(400, "BAD");
			super.doFilter(request, response);
		}
	};
	this.filter.doFilter(this.request, this.response, this.chain);
	assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
			.isEqualTo(400);
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE))
			.isEqualTo(400);
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE))
			.isEqualTo("BAD");
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI))
			.isEqualTo("/test/path");
	assertThat(this.response.isCommitted()).isTrue();
	assertThat(this.response.getForwardedUrl()).isEqualTo("/400");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:24,代码来源:ErrorPageFilterTests.java

示例11: statusErrorWithCommittedResponse

import javax.servlet.http.HttpServletResponseWrapper; //导入依赖的package包/类
@Test
public void statusErrorWithCommittedResponse() throws Exception {
	this.filter.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400"));
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			((HttpServletResponse) response).sendError(400, "BAD");
			response.flushBuffer();
			super.doFilter(request, response);
		}
	};
	this.filter.doFilter(this.request, this.response, this.chain);
	assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
			.isEqualTo(400);
	assertThat(this.response.isCommitted()).isTrue();
	assertThat(this.response.getForwardedUrl()).isNull();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:ErrorPageFilterTests.java

示例12: exceptionError

import javax.servlet.http.HttpServletResponseWrapper; //导入依赖的package包/类
@Test
public void exceptionError() throws Exception {
	this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			super.doFilter(request, response);
			throw new RuntimeException("BAD");
		}
	};
	this.filter.doFilter(this.request, this.response, this.chain);
	assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
			.isEqualTo(500);
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE))
			.isEqualTo(500);
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE))
			.isEqualTo("BAD");
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE))
			.isEqualTo(RuntimeException.class.getName());
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI))
			.isEqualTo("/test/path");
	assertThat(this.response.isCommitted()).isTrue();
	assertThat(this.response.getForwardedUrl()).isEqualTo("/500");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:26,代码来源:ErrorPageFilterTests.java

示例13: subClassExceptionError

import javax.servlet.http.HttpServletResponseWrapper; //导入依赖的package包/类
@Test
public void subClassExceptionError() throws Exception {
	this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			super.doFilter(request, response);
			throw new IllegalStateException("BAD");
		}
	};
	this.filter.doFilter(this.request, this.response, this.chain);
	assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus())
			.isEqualTo(500);
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE))
			.isEqualTo(500);
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE))
			.isEqualTo("BAD");
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE))
			.isEqualTo(IllegalStateException.class.getName());
	assertThat(this.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI))
			.isEqualTo("/test/path");
	assertThat(this.response.isCommitted()).isTrue();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:25,代码来源:ErrorPageFilterTests.java

示例14: responseIsCommittedWhenExceptionIsThrownDuringAsyncDispatch

import javax.servlet.http.HttpServletResponseWrapper; //导入依赖的package包/类
@Test
public void responseIsCommittedWhenExceptionIsThrownDuringAsyncDispatch()
		throws Exception {
	this.filter.addErrorPages(new ErrorPage("/error"));
	setUpAsyncDispatch();
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			super.doFilter(request, response);
			throw new RuntimeException("BAD");
		}
	};
	this.filter.doFilter(this.request, this.response, this.chain);
	assertThat(this.chain.getRequest()).isEqualTo(this.request);
	assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getResponse())
			.isEqualTo(this.response);
	assertThat(this.response.isCommitted()).isTrue();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:ErrorPageFilterTests.java

示例15: responseIsCommittedWhenStatusIs400PlusDuringAsyncDispatch

import javax.servlet.http.HttpServletResponseWrapper; //导入依赖的package包/类
@Test
public void responseIsCommittedWhenStatusIs400PlusDuringAsyncDispatch()
		throws Exception {
	this.filter.addErrorPages(new ErrorPage("/error"));
	setUpAsyncDispatch();
	this.chain = new MockFilterChain() {
		@Override
		public void doFilter(ServletRequest request, ServletResponse response)
				throws IOException, ServletException {
			super.doFilter(request, response);
			((HttpServletResponse) response).sendError(400, "BAD");
		}
	};
	this.filter.doFilter(this.request, this.response, this.chain);
	assertThat(this.chain.getRequest()).isEqualTo(this.request);
	assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getResponse())
			.isEqualTo(this.response);
	assertThat(this.response.isCommitted()).isTrue();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:ErrorPageFilterTests.java


注:本文中的javax.servlet.http.HttpServletResponseWrapper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。