本文整理汇总了Java中javax.servlet.ServletRequestWrapper类的典型用法代码示例。如果您正苦于以下问题:Java ServletRequestWrapper类的具体用法?Java ServletRequestWrapper怎么用?Java ServletRequestWrapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServletRequestWrapper类属于javax.servlet包,在下文中一共展示了ServletRequestWrapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unwrap
import javax.servlet.ServletRequestWrapper; //导入依赖的package包/类
/** Unwrap a ServletRequest.
*
* @see javax.servlet.ServletRequestWrapper
* @see javax.servlet.http.HttpServletRequestWrapper
* @param request
* @return The core ServletHttpRequest which must be the
* underlying request object
*/
public static ServletHttpRequest unwrap(ServletRequest request)
{
while (!(request instanceof ServletHttpRequest))
{
if (request instanceof ServletRequestWrapper)
{
ServletRequestWrapper wrapper =
(ServletRequestWrapper)request;
request=wrapper.getRequest();
}
else
throw new IllegalArgumentException("Does not wrap ServletHttpRequest");
}
return (ServletHttpRequest)request;
}
示例2: startAsync
import javax.servlet.ServletRequestWrapper; //导入依赖的package包/类
@Override
public AsyncContext startAsync(final ServletRequest servletRequest, final ServletResponse servletResponse) throws IllegalStateException {
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (!servletContext.getDeployment().getDeploymentInfo().isAllowNonStandardWrappers()) {
if (servletRequestContext.getOriginalRequest() != servletRequest) {
if (!(servletRequest instanceof ServletRequestWrapper)) {
throw UndertowServletMessages.MESSAGES.requestWasNotOriginalOrWrapper(servletRequest);
}
}
if (servletRequestContext.getOriginalResponse() != servletResponse) {
if (!(servletResponse instanceof ServletResponseWrapper)) {
throw UndertowServletMessages.MESSAGES.responseWasNotOriginalOrWrapper(servletResponse);
}
}
}
if (!isAsyncSupported()) {
throw UndertowServletMessages.MESSAGES.startAsyncNotAllowed();
} else if (asyncStarted) {
throw UndertowServletMessages.MESSAGES.asyncAlreadyStarted();
}
asyncStarted = true;
return asyncContext = new AsyncContextImpl(exchange, servletRequest, servletResponse, servletRequestContext, true, asyncContext);
}
示例3: run
import javax.servlet.ServletRequestWrapper; //导入依赖的package包/类
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
FormBodyRequestWrapper wrapper = null;
if (request instanceof HttpServletRequestWrapper) {
HttpServletRequest wrapped = (HttpServletRequest) ReflectionUtils
.getField(this.requestField, request);
wrapper = new FormBodyRequestWrapper(wrapped);
ReflectionUtils.setField(this.requestField, request, wrapper);
if (request instanceof ServletRequestWrapper) {
ReflectionUtils.setField(this.servletRequestField, request, wrapper);
}
}
else {
wrapper = new FormBodyRequestWrapper(request);
ctx.setRequest(wrapper);
}
if (wrapper != null) {
ctx.getZuulRequestHeaders().put("content-type", wrapper.getContentType());
}
return null;
}
示例4: getAsyncRequestWrapper
import javax.servlet.ServletRequestWrapper; //导入依赖的package包/类
/**
* Finds and returns the portlet servlet request wrapper that provides async functionality
*
* @return
*/
@Override
public HttpServletRequestWrapper getAsyncRequestWrapper() {
HttpServletPortletRequestWrapper wrapper = null;
// find our wrapper in case it was wrapped again
ServletRequest wreq = prctx.getAsyncServletRequest();
while ((wreq instanceof ServletRequestWrapper) && !(wreq instanceof HttpServletPortletRequestWrapper)) {
wreq = ((ServletRequestWrapper) wreq).getRequest();
}
if (wreq instanceof HttpServletPortletRequestWrapper) {
wrapper = (HttpServletPortletRequestWrapper) wreq;
}
return wrapper;
}
示例5: unwrapRequest
import javax.servlet.ServletRequestWrapper; //导入依赖的package包/类
/**
* Unwrap the request if we have wrapped it.
*/
private void unwrapRequest(State state) {
if (state.wrapRequest == null)
return;
if (state.outerRequest.isAsyncStarted()) {
if (!state.outerRequest.getAsyncContext().hasOriginalRequestAndResponse()) {
return;
}
}
ServletRequest previous = null;
ServletRequest current = state.outerRequest;
while (current != null) {
// If we run into the container request we are done
if ((current instanceof Request)
|| (current instanceof RequestFacade))
break;
// Remove the current request if it is our wrapper
if (current == state.wrapRequest) {
ServletRequest next =
((ServletRequestWrapper) current).getRequest();
if (previous == null)
state.outerRequest = next;
else
((ServletRequestWrapper) previous).setRequest(next);
break;
}
// Advance to the next request in the chain
previous = current;
current = ((ServletRequestWrapper) current).getRequest();
}
}
示例6: service
import javax.servlet.ServletRequestWrapper; //导入依赖的package包/类
@Override
public void service(ServletRequest req, ServletResponse resp)
throws ServletException, IOException {
if (DispatcherType.ASYNC != req.getDispatcherType()) {
AsyncContext asyncContext;
if ("y".equals(req.getParameter(CUSTOM_REQ_RESP))) {
asyncContext = req.startAsync(
new ServletRequestWrapper(req),
new ServletResponseWrapper(resp));
} else {
asyncContext = req.startAsync();
}
if ("y".equals(req.getParameter(EMPTY_DISPATCH))) {
asyncContext.dispatch();
} else {
asyncContext.dispatch("/target");
}
try {
asyncContext.dispatch("/nonExistingServlet");
TestAsyncContextImpl.track("FAIL");
} catch (IllegalStateException e) {
TestAsyncContextImpl.track("OK");
}
} else {
TestAsyncContextImpl.track("DispatchingGenericServletGet-");
}
}
示例7: getWrappedRequest
import javax.servlet.ServletRequestWrapper; //导入依赖的package包/类
public static <T> Optional<T> getWrappedRequest(ServletRequest request, Class<T> requiredType){
if(requiredType.isInstance(request)){
return Optional.of(requiredType.cast(request));
}
if(request instanceof ServletRequestWrapper){
return getWrappedRequest(((ServletRequestWrapper)request).getRequest(), requiredType);
}
return Optional.empty();
}
示例8: getNativeRequest
import javax.servlet.ServletRequestWrapper; //导入依赖的package包/类
/**
* Return an appropriate request object of the specified type, if available,
* unwrapping the given request as far as necessary.
* @param request the servlet request to introspect
* @param requiredType the desired type of request object
* @return the matching request object, or {@code null} if none
* of that type is available
*/
@SuppressWarnings("unchecked")
public static <T> T getNativeRequest(ServletRequest request, Class<T> requiredType) {
if (requiredType != null) {
if (requiredType.isInstance(request)) {
return (T) request;
}
else if (request instanceof ServletRequestWrapper) {
return getNativeRequest(((ServletRequestWrapper) request).getRequest(), requiredType);
}
}
return null;
}
示例9: unwrapRequest
import javax.servlet.ServletRequestWrapper; //导入依赖的package包/类
/**
* Unwrap the request if we have wrapped it.
*/
private void unwrapRequest(State state) {
if (state.wrapRequest == null)
return;
ServletRequest previous = null;
ServletRequest current = state.outerRequest;
while (current != null) {
// If we run into the container request we are done
if ((current instanceof Request)
|| (current instanceof RequestFacade))
break;
// Remove the current request if it is our wrapper
if (current == state.wrapRequest) {
ServletRequest next =
((ServletRequestWrapper) current).getRequest();
if (previous == null)
state.outerRequest = next;
else
((ServletRequestWrapper) previous).setRequest(next);
break;
}
// Advance to the next request in the chain
previous = current;
current = ((ServletRequestWrapper) current).getRequest();
}
}
示例10: unwrapRequest
import javax.servlet.ServletRequestWrapper; //导入依赖的package包/类
/**
* Unwrap the request if we have wrapped it.
*/
private void unwrapRequest() {
if (wrapRequest == null)
return;
ServletRequest previous = null;
ServletRequest current = outerRequest;
while (current != null) {
// If we run into the container request we are done
if ((current instanceof Request)
|| (current instanceof RequestFacade))
break;
// Remove the current request if it is our wrapper
if (current == wrapRequest) {
ServletRequest next =
((ServletRequestWrapper) current).getRequest();
if (previous == null)
outerRequest = next;
else
((ServletRequestWrapper) previous).setRequest(next);
break;
}
// Advance to the next request in the chain
previous = current;
current = ((ServletRequestWrapper) current).getRequest();
}
}
示例11: wrapRequest
import javax.servlet.ServletRequestWrapper; //导入依赖的package包/类
/**
* Create and return a request wrapper that has been inserted in the
* appropriate spot in the request chain.
*/
private ServletRequest wrapRequest() {
// Locate the request we should insert in front of
ServletRequest previous = null;
ServletRequest current = outerRequest;
while (current != null) {
if ("org.apache.catalina.servlets.InvokerHttpRequest".
equals(current.getClass().getName()))
break; // KLUDGE - Make nested RD.forward() using invoker work
if (!(current instanceof ServletRequestWrapper))
break;
if (current instanceof ApplicationHttpRequest)
break;
if (current instanceof ApplicationRequest)
break;
if (current instanceof Request)
break;
previous = current;
current = ((ServletRequestWrapper) current).getRequest();
}
// Instantiate a new wrapper at this point and insert it in the chain
ServletRequest wrapper = null;
if ((current instanceof ApplicationHttpRequest) ||
(current instanceof HttpRequest) ||
(current instanceof HttpServletRequest))
wrapper = new ApplicationHttpRequest((HttpServletRequest) current);
else
wrapper = new ApplicationRequest(current);
if (previous == null)
outerRequest = wrapper;
else
((ServletRequestWrapper) previous).setRequest(wrapper);
wrapRequest = wrapper;
return (wrapper);
}
示例12: unwrapRequest
import javax.servlet.ServletRequestWrapper; //导入依赖的package包/类
/**
* Unwrap the request if we have wrapped it.
*/
private void unwrapRequest(State state) {
if (state.wrapRequest == null)
return;
if (state.outerRequest.isAsyncStarted()) {
if (!state.outerRequest.getAsyncContext().hasOriginalRequestAndResponse()) {
return;
}
}
ServletRequest previous = null;
ServletRequest current = state.outerRequest;
while (current != null) {
// If we run into the container request we are done
if ((current instanceof Request) || (current instanceof RequestFacade))
break;
// Remove the current request if it is our wrapper
if (current == state.wrapRequest) {
ServletRequest next = ((ServletRequestWrapper) current).getRequest();
if (previous == null)
state.outerRequest = next;
else
((ServletRequestWrapper) previous).setRequest(next);
break;
}
// Advance to the next request in the chain
previous = current;
current = ((ServletRequestWrapper) current).getRequest();
}
}
示例13: HttpRequestWrapper
import javax.servlet.ServletRequestWrapper; //导入依赖的package包/类
/**
* Creates request wrapper from original requests.
*
* @param req
* original servlet request
* @param servletContext
*/
public HttpRequestWrapper(HttpServletRequest req, ServletContext servletContext) {
super(req);
this.servletContext = servletContext;
manager = (SessionManager)servletContext.getAttribute(Attributes.SESSION_MANAGER);
ServletRequest originalRequest = req;
while (originalRequest instanceof ServletRequestWrapper) {
if (originalRequest instanceof HttpRequestWrapper) {
break;
}
originalRequest = ((ServletRequestWrapper)originalRequest).getRequest();
}
embeddedRequest = (originalRequest instanceof HttpRequestWrapper) ? (HttpRequestWrapper)originalRequest : null;
}
示例14: testNonHttpRequestPassesThrough
import javax.servlet.ServletRequestWrapper; //导入依赖的package包/类
@Test
public void testNonHttpRequestPassesThrough() throws Exception {
String param = "valid_param";
String value = "should pass through";
ServletRequest servletRequest = new ServletRequestWrapper(request);
request.setParameter(param, value);
filter.doFilter(servletRequest, response, filterChain);
ServletRequest originalRequest = filterChain.getRequest();
assertThat(originalRequest.getParameter(param), equalTo(value));
assertThat(originalRequest, is(originalRequest));
}
示例15: unwrap
import javax.servlet.ServletRequestWrapper; //导入依赖的package包/类
/**
* If the specified request was a forwarded or included request, unwrap it
* and return the original request.
*/
public static HttpServletRequest unwrap(HttpServletRequest req) {
if (req instanceof ServletRequestWrapper) {
ServletRequestWrapper wrapper = (ServletRequestWrapper) req;
req = (HttpServletRequest) wrapper.getRequest(); // unwrap
}
return req;
}