javax.servlet.ServletResponseWrapper Java Examples
The following examples show how to use
javax.servlet.ServletResponseWrapper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpServletRequestImpl.java From quarkus-http with Apache License 2.0 | 6 votes |
@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; servletRequestContext.setServletRequest(servletRequest); servletRequestContext.setServletResponse(servletResponse); return asyncContext = new AsyncContextImpl(exchange, servletRequest, servletResponse, servletRequestContext, true, asyncContext); }
Example #2
Source File: HttpServletRequestImpl.java From lams with GNU General Public License v2.0 | 6 votes |
@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; servletRequestContext.setServletRequest(servletRequest); servletRequestContext.setServletResponse(servletResponse); return asyncContext = new AsyncContextImpl(exchange, servletRequest, servletResponse, servletRequestContext, true, asyncContext); }
Example #3
Source File: ApplicationDispatcher.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Unwrap the response if we have wrapped it. */ private void unwrapResponse(State state) { if (state.wrapResponse == null) return; if (state.outerRequest.isAsyncStarted()) { if (!state.outerRequest.getAsyncContext().hasOriginalRequestAndResponse()) { return; } } ServletResponse previous = null; ServletResponse current = state.outerResponse; while (current != null) { // If we run into the container response we are done if ((current instanceof Response) || (current instanceof ResponseFacade)) break; // Remove the current response if it is our wrapper if (current == state.wrapResponse) { ServletResponse next = ((ServletResponseWrapper) current).getResponse(); if (previous == null) state.outerResponse = next; else ((ServletResponseWrapper) previous).setResponse(next); break; } // Advance to the next response in the chain previous = current; current = ((ServletResponseWrapper) current).getResponse(); } }
Example #4
Source File: TestAsyncContextImpl.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { if (req instanceof ServletRequestWrapper && res instanceof ServletResponseWrapper) { TestAsyncContextImpl.track("CustomGenericServletGet-"); } }
Example #5
Source File: TestAsyncContextImpl.java From tomcatsrc with Apache License 2.0 | 5 votes |
@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-"); } }
Example #6
Source File: ApplicationDispatcher.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Create and return a response wrapper that has been inserted in the * appropriate spot in the response chain. */ private ServletResponse wrapResponse(State state) { // Locate the response we should insert in front of ServletResponse previous = null; ServletResponse current = state.outerResponse; while (current != null) { if(state.hresponse == null && (current instanceof HttpServletResponse)) { state.hresponse = (HttpServletResponse)current; if(!state.including) // Forward only needs hresponse return null; } if (!(current instanceof ServletResponseWrapper)) break; if (current instanceof ApplicationHttpResponse) break; if (current instanceof ApplicationResponse) break; previous = current; current = ((ServletResponseWrapper) current).getResponse(); } // Instantiate a new wrapper at this point and insert it in the chain ServletResponse wrapper = null; if ((current instanceof ApplicationHttpResponse) || (current instanceof Response) || (current instanceof HttpServletResponse)) wrapper = new ApplicationHttpResponse((HttpServletResponse) current, state.including); else wrapper = new ApplicationResponse(current, state.including); if (previous == null) state.outerResponse = wrapper; else ((ServletResponseWrapper) previous).setResponse(wrapper); state.wrapResponse = wrapper; return (wrapper); }
Example #7
Source File: ApplicationDispatcher.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Unwrap the response if we have wrapped it. */ private void unwrapResponse(State state) { if (state.wrapResponse == null) return; if (state.outerRequest.isAsyncStarted()) { if (!state.outerRequest.getAsyncContext().hasOriginalRequestAndResponse()) { return; } } ServletResponse previous = null; ServletResponse current = state.outerResponse; while (current != null) { // If we run into the container response we are done if ((current instanceof Response) || (current instanceof ResponseFacade)) break; // Remove the current response if it is our wrapper if (current == state.wrapResponse) { ServletResponse next = ((ServletResponseWrapper) current).getResponse(); if (previous == null) state.outerResponse = next; else ((ServletResponseWrapper) previous).setResponse(next); break; } // Advance to the next response in the chain previous = current; current = ((ServletResponseWrapper) current).getResponse(); } }
Example #8
Source File: WebUtils.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Return an appropriate response object of the specified type, if available, * unwrapping the given response as far as necessary. * @param response the servlet response to introspect * @param requiredType the desired type of response object * @return the matching response object, or {@code null} if none * of that type is available */ @SuppressWarnings("unchecked") public static <T> T getNativeResponse(ServletResponse response, Class<T> requiredType) { if (requiredType != null) { if (requiredType.isInstance(response)) { return (T) response; } else if (response instanceof ServletResponseWrapper) { return getNativeResponse(((ServletResponseWrapper) response).getResponse(), requiredType); } } return null; }
Example #9
Source File: WebUtils.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Return an appropriate response object of the specified type, if available, * unwrapping the given response as far as necessary. * @param response the servlet response to introspect * @param requiredType the desired type of response object * @return the matching response object, or {@code null} if none * of that type is available */ @SuppressWarnings("unchecked") public static <T> T getNativeResponse(ServletResponse response, Class<T> requiredType) { if (requiredType != null) { if (requiredType.isInstance(response)) { return (T) response; } else if (response instanceof ServletResponseWrapper) { return getNativeResponse(((ServletResponseWrapper) response).getResponse(), requiredType); } } return null; }
Example #10
Source File: TestAsyncContextImpl.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { if (req instanceof ServletRequestWrapper && res instanceof ServletResponseWrapper) { TestAsyncContextImpl.track("CustomGenericServletGet-"); } }
Example #11
Source File: TestAsyncContextImpl.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@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-"); } }
Example #12
Source File: ApplicationDispatcher.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Create and return a response wrapper that has been inserted in the * appropriate spot in the response chain. */ private ServletResponse wrapResponse(State state) { // Locate the response we should insert in front of ServletResponse previous = null; ServletResponse current = state.outerResponse; while (current != null) { if(state.hresponse == null && (current instanceof HttpServletResponse)) { state.hresponse = (HttpServletResponse)current; if(!state.including) // Forward only needs hresponse return null; } if (!(current instanceof ServletResponseWrapper)) break; if (current instanceof ApplicationHttpResponse) break; if (current instanceof ApplicationResponse) break; previous = current; current = ((ServletResponseWrapper) current).getResponse(); } // Instantiate a new wrapper at this point and insert it in the chain ServletResponse wrapper = null; if ((current instanceof ApplicationHttpResponse) || (current instanceof Response) || (current instanceof HttpServletResponse)) wrapper = new ApplicationHttpResponse((HttpServletResponse) current, state.including); else wrapper = new ApplicationResponse(current, state.including); if (previous == null) state.outerResponse = wrapper; else ((ServletResponseWrapper) previous).setResponse(wrapper); state.wrapResponse = wrapper; return (wrapper); }
Example #13
Source File: ApplicationDispatcher.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Unwrap the response if we have wrapped it. */ private void unwrapResponse(State state) { if (state.wrapResponse == null) return; if (state.outerRequest.isAsyncStarted()) { if (!state.outerRequest.getAsyncContext().hasOriginalRequestAndResponse()) { return; } } ServletResponse previous = null; ServletResponse current = state.outerResponse; while (current != null) { // If we run into the container response we are done if ((current instanceof Response) || (current instanceof ResponseFacade)) break; // Remove the current response if it is our wrapper if (current == state.wrapResponse) { ServletResponse next = ((ServletResponseWrapper) current).getResponse(); if (previous == null) state.outerResponse = next; else ((ServletResponseWrapper) previous).setResponse(next); break; } // Advance to the next response in the chain previous = current; current = ((ServletResponseWrapper) current).getResponse(); } }
Example #14
Source File: DefaultAsyncContext.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Unwrap the servlet response. * * @param <T> the type. * @param response the response to unwrap. * @return the unwrapped response. */ @SuppressWarnings("unchecked") private <T extends ServletResponse> T unwrapFully(ServletResponse response) { ServletResponse currentResponse = response; while (currentResponse instanceof ServletResponseWrapper) { ServletResponseWrapper wrapper = (ServletResponseWrapper) currentResponse; currentResponse = wrapper.getResponse(); } return (T) currentResponse; }
Example #15
Source File: Response.java From onedev with MIT License | 5 votes |
public static HttpServletResponse unwrap(ServletResponse servletResponse) { if (servletResponse instanceof HttpServletResponseWrapper) { return (HttpServletResponseWrapper)servletResponse; } if (servletResponse instanceof ServletResponseWrapper) { return unwrap(((ServletResponseWrapper)servletResponse).getResponse()); } return (HttpServletResponse)servletResponse; }
Example #16
Source File: ServletUtil.java From spring-boot-protocol with Apache License 2.0 | 5 votes |
/** * unWrapper * @param response response * @return ServletHttpServletResponse */ public static ServletHttpServletResponse unWrapper(ServletResponse response){ if(response instanceof ServletResponseWrapper){ return unWrapper(((ServletResponseWrapper) response).getResponse()); } if(response instanceof ServletHttpServletResponse){ return (ServletHttpServletResponse) response; } return null; }
Example #17
Source File: WebUtils.java From java-technology-stack with MIT License | 5 votes |
/** * Return an appropriate response object of the specified type, if available, * unwrapping the given response as far as necessary. * @param response the servlet response to introspect * @param requiredType the desired type of response object * @return the matching response object, or {@code null} if none * of that type is available */ @SuppressWarnings("unchecked") @Nullable public static <T> T getNativeResponse(ServletResponse response, @Nullable Class<T> requiredType) { if (requiredType != null) { if (requiredType.isInstance(response)) { return (T) response; } else if (response instanceof ServletResponseWrapper) { return getNativeResponse(((ServletResponseWrapper) response).getResponse(), requiredType); } } return null; }
Example #18
Source File: NonStandardResponseWrapper.java From quarkus-http with Apache License 2.0 | 5 votes |
/** * Checks (recursively) if this ServletResponseWrapper wraps a * {@link ServletResponse} of the given class type. * * @param wrappedType the ServletResponse class type to * search for * @return true if this ServletResponseWrapper wraps a * ServletResponse of the given class type, false otherwise * @throws IllegalArgumentException if the given class does not * implement {@link ServletResponse} * @since Servlet 3.0 */ public boolean isWrapperFor(Class<?> wrappedType) { if (!ServletResponse.class.isAssignableFrom(wrappedType)) { throw new IllegalArgumentException("Given class " + wrappedType.getName() + " not a subinterface of " + ServletResponse.class.getName()); } if (wrappedType.isAssignableFrom(response.getClass())) { return true; } else if (response instanceof ServletResponseWrapper) { return ((ServletResponseWrapper) response).isWrapperFor(wrappedType); } else { return false; } }
Example #19
Source File: NonStandardResponseWrapper.java From quarkus-http with Apache License 2.0 | 5 votes |
/** * Checks (recursively) if this ServletResponseWrapper wraps the given * {@link ServletResponse} instance. * * @param wrapped the ServletResponse instance to search for * @return true if this ServletResponseWrapper wraps the * given ServletResponse instance, false otherwise * @since Servlet 3.0 */ public boolean isWrapperFor(ServletResponse wrapped) { if (response == wrapped) { return true; } else if (response instanceof ServletResponseWrapper) { return ((ServletResponseWrapper) response).isWrapperFor(wrapped); } else { return false; } }
Example #20
Source File: WebUtils.java From spring-analysis-note with MIT License | 5 votes |
/** * Return an appropriate response object of the specified type, if available, * unwrapping the given response as far as necessary. * @param response the servlet response to introspect * @param requiredType the desired type of response object * @return the matching response object, or {@code null} if none * of that type is available */ @SuppressWarnings("unchecked") @Nullable public static <T> T getNativeResponse(ServletResponse response, @Nullable Class<T> requiredType) { if (requiredType != null) { if (requiredType.isInstance(response)) { return (T) response; } else if (response instanceof ServletResponseWrapper) { return getNativeResponse(((ServletResponseWrapper) response).getResponse(), requiredType); } } return null; }
Example #21
Source File: TestAsyncContextImpl.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { if (req instanceof ServletRequestWrapper && res instanceof ServletResponseWrapper) { TestAsyncContextImpl.track("CustomGenericServletGet-"); } }
Example #22
Source File: TestAsyncContextImpl.java From Tomcat8-Source-Read with MIT License | 5 votes |
@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-"); } }
Example #23
Source File: ApplicationDispatcher.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Create and return a response wrapper that has been inserted in the * appropriate spot in the response chain. */ private ServletResponse wrapResponse(State state) { // Locate the response we should insert in front of ServletResponse previous = null; ServletResponse current = state.outerResponse; while (current != null) { if(state.hresponse == null && (current instanceof HttpServletResponse)) { state.hresponse = (HttpServletResponse)current; if(!state.including) // Forward only needs hresponse return null; } if (!(current instanceof ServletResponseWrapper)) break; if (current instanceof ApplicationHttpResponse) break; if (current instanceof ApplicationResponse) break; previous = current; current = ((ServletResponseWrapper) current).getResponse(); } // Instantiate a new wrapper at this point and insert it in the chain ServletResponse wrapper = null; if ((current instanceof ApplicationHttpResponse) || (current instanceof Response) || (current instanceof HttpServletResponse)) wrapper = new ApplicationHttpResponse((HttpServletResponse) current, state.including); else wrapper = new ApplicationResponse(current, state.including); if (previous == null) state.outerResponse = wrapper; else ((ServletResponseWrapper) previous).setResponse(wrapper); state.wrapResponse = wrapper; return wrapper; }
Example #24
Source File: ApplicationDispatcher.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
private void checkSameObjects(ServletRequest appRequest, ServletResponse appResponse) throws ServletException { ServletRequest originalRequest = ApplicationFilterChain.getLastServicedRequest(); ServletResponse originalResponse = ApplicationFilterChain.getLastServicedResponse(); // Some forwards, eg from valves will not set original values if (originalRequest == null || originalResponse == null) { return; } boolean same = false; ServletRequest dispatchedRequest = appRequest; //find the request that was passed into the service method while (originalRequest instanceof ServletRequestWrapper && ((ServletRequestWrapper) originalRequest).getRequest()!=null ) { originalRequest = ((ServletRequestWrapper) originalRequest).getRequest(); } //compare with the dispatched request while (!same) { if (originalRequest.equals(dispatchedRequest)) { same = true; } if (!same && dispatchedRequest instanceof ServletRequestWrapper) { dispatchedRequest = ((ServletRequestWrapper) dispatchedRequest).getRequest(); } else { break; } } if (!same) { throw new ServletException(sm.getString( "applicationDispatcher.specViolation.request")); } same = false; ServletResponse dispatchedResponse = appResponse; //find the response that was passed into the service method while (originalResponse instanceof ServletResponseWrapper && ((ServletResponseWrapper) originalResponse).getResponse() != null ) { originalResponse = ((ServletResponseWrapper) originalResponse).getResponse(); } //compare with the dispatched response while (!same) { if (originalResponse.equals(dispatchedResponse)) { same = true; } if (!same && dispatchedResponse instanceof ServletResponseWrapper) { dispatchedResponse = ((ServletResponseWrapper) dispatchedResponse).getResponse(); } else { break; } } if (!same) { throw new ServletException(sm.getString( "applicationDispatcher.specViolation.response")); } }
Example #25
Source File: ApplicationDispatcher.java From tomcatsrc with Apache License 2.0 | 4 votes |
private void checkSameObjects(ServletRequest appRequest, ServletResponse appResponse) throws ServletException { ServletRequest originalRequest = ApplicationFilterChain.getLastServicedRequest(); ServletResponse originalResponse = ApplicationFilterChain.getLastServicedResponse(); // Some forwards, eg from valves will not set original values if (originalRequest == null || originalResponse == null) { return; } boolean same = false; ServletRequest dispatchedRequest = appRequest; //find the request that was passed into the service method while (originalRequest instanceof ServletRequestWrapper && ((ServletRequestWrapper) originalRequest).getRequest()!=null ) { originalRequest = ((ServletRequestWrapper) originalRequest).getRequest(); } //compare with the dispatched request while (!same) { if (originalRequest.equals(dispatchedRequest)) { same = true; } if (!same && dispatchedRequest instanceof ServletRequestWrapper) { dispatchedRequest = ((ServletRequestWrapper) dispatchedRequest).getRequest(); } else { break; } } if (!same) { throw new ServletException(sm.getString( "applicationDispatcher.specViolation.request")); } same = false; ServletResponse dispatchedResponse = appResponse; //find the response that was passed into the service method while (originalResponse instanceof ServletResponseWrapper && ((ServletResponseWrapper) originalResponse).getResponse() != null ) { originalResponse = ((ServletResponseWrapper) originalResponse).getResponse(); } //compare with the dispatched response while (!same) { if (originalResponse.equals(dispatchedResponse)) { same = true; } if (!same && dispatchedResponse instanceof ServletResponseWrapper) { dispatchedResponse = ((ServletResponseWrapper) dispatchedResponse).getResponse(); } else { break; } } if (!same) { throw new ServletException(sm.getString( "applicationDispatcher.specViolation.response")); } }
Example #26
Source File: ApplicationDispatcher.java From Tomcat8-Source-Read with MIT License | 4 votes |
private void checkSameObjects(ServletRequest appRequest, ServletResponse appResponse) throws ServletException { ServletRequest originalRequest = ApplicationFilterChain.getLastServicedRequest(); ServletResponse originalResponse = ApplicationFilterChain.getLastServicedResponse(); // Some forwards, eg from valves will not set original values if (originalRequest == null || originalResponse == null) { return; } boolean same = false; ServletRequest dispatchedRequest = appRequest; //find the request that was passed into the service method while (originalRequest instanceof ServletRequestWrapper && ((ServletRequestWrapper) originalRequest).getRequest()!=null ) { originalRequest = ((ServletRequestWrapper) originalRequest).getRequest(); } //compare with the dispatched request while (!same) { if (originalRequest.equals(dispatchedRequest)) { same = true; } if (!same && dispatchedRequest instanceof ServletRequestWrapper) { dispatchedRequest = ((ServletRequestWrapper) dispatchedRequest).getRequest(); } else { break; } } if (!same) { throw new ServletException(sm.getString( "applicationDispatcher.specViolation.request")); } same = false; ServletResponse dispatchedResponse = appResponse; //find the response that was passed into the service method while (originalResponse instanceof ServletResponseWrapper && ((ServletResponseWrapper) originalResponse).getResponse() != null ) { originalResponse = ((ServletResponseWrapper) originalResponse).getResponse(); } //compare with the dispatched response while (!same) { if (originalResponse.equals(dispatchedResponse)) { same = true; } if (!same && dispatchedResponse instanceof ServletResponseWrapper) { dispatchedResponse = ((ServletResponseWrapper) dispatchedResponse).getResponse(); } else { break; } } if (!same) { throw new ServletException(sm.getString( "applicationDispatcher.specViolation.response")); } }