Java Code Examples for javax.servlet.ServletRequest#isAsyncStarted()
The following examples show how to use
javax.servlet.ServletRequest#isAsyncStarted() .
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: TestAsyncContextImpl.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void onTimeout(AsyncEvent event) throws IOException { boolean expectedAsyncStarted = true; TestAsyncContextImpl.track("onTimeout-"); if (completeOnTimeout){ event.getAsyncContext().complete(); expectedAsyncStarted = false; } if (dispatchUrl != null) { event.getAsyncContext().dispatch(dispatchUrl); expectedAsyncStarted = false; } ServletRequest req = event.getSuppliedRequest(); asyncStartedCorrect = (expectedAsyncStarted == req.isAsyncStarted()); }
Example 2
Source File: TestAsyncContextImpl.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public void onError(AsyncEvent event) throws IOException { boolean expectedAsyncStarted = true; TestAsyncContextImpl.track("onError-"); if (completeOnError) { event.getAsyncContext().complete(); expectedAsyncStarted = false; } ServletRequest req = event.getSuppliedRequest(); asyncStartedCorrect = (expectedAsyncStarted == req.isAsyncStarted()); }
Example 3
Source File: TestAsyncContextImpl.java From Tomcat8-Source-Read with MIT License | 5 votes |
public void doOnWritePossible() { // Hack to avoid ISE if we try gettign the request after complete/dispatch ServletRequest req = ac.getRequest(); if (useComplete) { ac.complete(); } else { ac.dispatch("/simpleServlet"); } if (req.isAsyncStarted()) { invalidStateDetected = true; } }
Example 4
Source File: ServletOutputStreamImpl.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public void setWriteListener(WriteListener writeListener) { if (writeListener == null) { throw UndertowServletMessages.MESSAGES.listenerCannotBeNull(); } if (listener != null) { throw UndertowServletMessages.MESSAGES.listenerAlreadySet(); } final ServletRequest servletRequest = servletRequestContext.getOriginalRequest(); if (!servletRequest.isAsyncStarted()) { throw UndertowServletMessages.MESSAGES.asyncNotStarted(); } listener = writeListener; listenerCallback = new ListenerCallback(); servletRequestContext.getOriginalRequest().getAsyncContext().addAsyncTask(new Runnable() { @Override public void run() { //TODO: hack to make sure the invocation happens in the callback loop, to prevent recursive callbacks exchange.getIoThread().execute(new Runnable() { @Override public void run() { listenerCallback.onComplete(null, null); } }); } }); }
Example 5
Source File: AWSXRayServletFilter.java From aws-xray-sdk-java with Apache License 2.0 | 5 votes |
@Override public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (logger.isDebugEnabled()) { logger.debug("AWSXRayServletFilter is beginning to process request: " + request.toString()); } Segment segment = preFilter(request, response); try { chain.doFilter(request, response); } catch (Throwable e) { if (segment != null) { segment.addException(e); } throw e; } finally { if (request.isAsyncStarted()) { if (segment != null) { request.setAttribute(AWSXRayServletAsyncListener.ENTITY_ATTRIBUTE_KEY, segment); } else { request.removeAttribute(AWSXRayServletAsyncListener.ENTITY_ATTRIBUTE_KEY); } try { request.getAsyncContext().addListener(listener); if (recorder != null) { recorder.clearTraceEntity(); } } catch (IllegalStateException ise) { // race condition that occurs when async processing finishes before adding the listener postFilter(request, response); } } else { postFilter(request, response); } if (logger.isDebugEnabled()) { logger.debug("AWSXRayServletFilter is finished processing request: " + request.toString()); } } }
Example 6
Source File: ServletOutputStreamImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void setWriteListener(final WriteListener writeListener) { if (writeListener == null) { throw UndertowServletMessages.MESSAGES.listenerCannotBeNull(); } if (listener != null) { throw UndertowServletMessages.MESSAGES.listenerAlreadySet(); } final ServletRequest servletRequest = servletRequestContext.getOriginalRequest(); if (!servletRequest.isAsyncStarted()) { throw UndertowServletMessages.MESSAGES.asyncNotStarted(); } asyncContext = (AsyncContextImpl) servletRequest.getAsyncContext(); listener = writeListener; //we register the write listener on the underlying connection //so we don't have to force the creation of the response channel //under normal circumstances this will break write listener delegation this.internalListener = new WriteChannelListener(); if (this.channel != null) { this.channel.getWriteSetter().set(internalListener); } //we resume from an async task, after the request has been dispatched asyncContext.addAsyncTask(new Runnable() { @Override public void run() { if (channel == null) { servletRequestContext.getExchange().getIoThread().execute(new Runnable() { @Override public void run() { internalListener.handleEvent(null); } }); } else { channel.resumeWrites(); } } }); }
Example 7
Source File: KeycloakSessionServletFilter.java From keycloak with Apache License 2.0 | 4 votes |
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { servletRequest.setCharacterEncoding("UTF-8"); final HttpServletRequest request = (HttpServletRequest)servletRequest; KeycloakSessionFactory sessionFactory = (KeycloakSessionFactory) servletRequest.getServletContext().getAttribute(KeycloakSessionFactory.class.getName()); KeycloakSession session = sessionFactory.create(); Resteasy.pushContext(KeycloakSession.class, session); ClientConnection connection = new ClientConnection() { @Override public String getRemoteAddr() { return request.getRemoteAddr(); } @Override public String getRemoteHost() { return request.getRemoteHost(); } @Override public int getRemotePort() { return request.getRemotePort(); } @Override public String getLocalAddr() { return request.getLocalAddr(); } @Override public int getLocalPort() { return request.getLocalPort(); } }; session.getContext().setConnection(connection); Resteasy.pushContext(ClientConnection.class, connection); KeycloakTransaction tx = session.getTransactionManager(); Resteasy.pushContext(KeycloakTransaction.class, tx); tx.begin(); try { filterChain.doFilter(servletRequest, servletResponse); } finally { if (servletRequest.isAsyncStarted()) { servletRequest.getAsyncContext().addListener(createAsyncLifeCycleListener(session)); } else { closeSession(session); } } }
Example 8
Source File: KeycloakSessionServletFilter.java From keycloak with Apache License 2.0 | 4 votes |
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { servletRequest.setCharacterEncoding("UTF-8"); final HttpServletRequest request = (HttpServletRequest)servletRequest; KeycloakSessionFactory sessionFactory = (KeycloakSessionFactory) servletRequest.getServletContext().getAttribute(KeycloakSessionFactory.class.getName()); KeycloakSession session = sessionFactory.create(); Resteasy.pushContext(KeycloakSession.class, session); ClientConnection connection = new ClientConnection() { @Override public String getRemoteAddr() { return request.getRemoteAddr(); } @Override public String getRemoteHost() { return request.getRemoteHost(); } @Override public int getRemotePort() { return request.getRemotePort(); } @Override public String getLocalAddr() { return request.getLocalAddr(); } @Override public int getLocalPort() { return request.getLocalPort(); } }; session.getContext().setConnection(connection); Resteasy.pushContext(ClientConnection.class, connection); KeycloakTransaction tx = session.getTransactionManager(); Resteasy.pushContext(KeycloakTransaction.class, tx); tx.begin(); try { filterChain.doFilter(servletRequest, servletResponse); } finally { if (servletRequest.isAsyncStarted()) { servletRequest.getAsyncContext().addListener(createAsyncLifeCycleListener(session)); } else { closeSession(session); } } }