org.springframework.http.server.ServerHttpAsyncRequestControl Java Examples

The following examples show how to use org.springframework.http.server.ServerHttpAsyncRequestControl. 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: AbstractHttpSockJsSession.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Handle all requests, except the first one, to receive messages on a SockJS
 * HTTP transport based session.
 * <p>Long polling-based transports (e.g. "xhr", "jsonp") complete the request
 * after writing any buffered message frames (or the next one). Streaming-based
 * transports ("xhr_streaming", "eventsource", and "htmlfile") leave the
 * response open longer for further streaming of message frames but will also
 * close it eventually after some amount of data has been sent.
 * @param request the current request
 * @param response the current response
 * @param frameFormat the transport-specific SocksJS frame format to use
 */
public void handleSuccessiveRequest(ServerHttpRequest request, ServerHttpResponse response,
		SockJsFrameFormat frameFormat) throws SockJsException {

	synchronized (this.responseLock) {
		try {
			if (isClosed()) {
				response.getBody().write(SockJsFrame.closeFrameGoAway().getContentBytes());
				return;
			}
			this.response = response;
			this.frameFormat = frameFormat;
			ServerHttpAsyncRequestControl control = request.getAsyncRequestControl(response);
			this.asyncRequestControl = control;
			control.start(-1);
			disableShallowEtagHeaderFilter(request);
			handleRequestInternal(request, response, false);
			this.readyToSend = isActive();
		}
		catch (Throwable ex) {
			tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR);
			throw new SockJsTransportFailureException("Failed to handle SockJS receive request", getId(), ex);
		}
	}
}
 
Example #2
Source File: AbstractHttpSockJsSession.java    From spring-analysis-note with MIT License 6 votes vote down vote up
protected void resetRequest() {
	synchronized (this.responseLock) {
		ServerHttpAsyncRequestControl control = this.asyncRequestControl;
		this.asyncRequestControl = null;
		this.readyToSend = false;
		this.response = null;
		updateLastActiveTime();
		if (control != null && !control.isCompleted() && control.isStarted()) {
			try {
				control.complete();
			}
			catch (Throwable ex) {
				// Could be part of normal workflow (e.g. browser tab closed)
				logger.debug("Failed to complete request: " + ex.getMessage());
			}
		}
	}
}
 
Example #3
Source File: AbstractHttpSockJsSession.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Handle all requests, except the first one, to receive messages on a SockJS
 * HTTP transport based session.
 * <p>Long polling-based transports (e.g. "xhr", "jsonp") complete the request
 * after writing any buffered message frames (or the next one). Streaming-based
 * transports ("xhr_streaming", "eventsource", and "htmlfile") leave the
 * response open longer for further streaming of message frames but will also
 * close it eventually after some amount of data has been sent.
 * @param request the current request
 * @param response the current response
 * @param frameFormat the transport-specific SocksJS frame format to use
 */
public void handleSuccessiveRequest(ServerHttpRequest request, ServerHttpResponse response,
		SockJsFrameFormat frameFormat) throws SockJsException {

	synchronized (this.responseLock) {
		try {
			if (isClosed()) {
				response.getBody().write(SockJsFrame.closeFrameGoAway().getContentBytes());
				return;
			}
			this.response = response;
			this.frameFormat = frameFormat;
			ServerHttpAsyncRequestControl control = request.getAsyncRequestControl(response);
			this.asyncRequestControl = control;
			control.start(-1);
			disableShallowEtagHeaderFilter(request);
			handleRequestInternal(request, response, false);
			this.readyToSend = isActive();
		}
		catch (Throwable ex) {
			tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR);
			throw new SockJsTransportFailureException("Failed to handle SockJS receive request", getId(), ex);
		}
	}
}
 
Example #4
Source File: AbstractHttpSockJsSession.java    From java-technology-stack with MIT License 6 votes vote down vote up
protected void resetRequest() {
	synchronized (this.responseLock) {
		ServerHttpAsyncRequestControl control = this.asyncRequestControl;
		this.asyncRequestControl = null;
		this.readyToSend = false;
		this.response = null;
		updateLastActiveTime();
		if (control != null && !control.isCompleted() && control.isStarted()) {
			try {
				control.complete();
			}
			catch (Throwable ex) {
				// Could be part of normal workflow (e.g. browser tab closed)
				logger.debug("Failed to complete request: " + ex.getMessage());
			}
		}
	}
}
 
Example #5
Source File: AbstractHttpSockJsSession.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
protected void resetRequest() {
	synchronized (this.responseLock) {

		ServerHttpAsyncRequestControl control = this.asyncRequestControl;
		this.asyncRequestControl = null;
		this.readyToSend = false;
		this.response = null;

		updateLastActiveTime();

		if (control != null && !control.isCompleted()) {
			if (control.isStarted()) {
				try {
					control.complete();
				}
				catch (Throwable ex) {
					// Could be part of normal workflow (e.g. browser tab closed)
					logger.debug("Failed to complete request: " + ex.getMessage());
				}
			}
		}
	}
}
 
Example #6
Source File: AbstractHttpSockJsSession.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public boolean isActive() {
	ServerHttpAsyncRequestControl control = this.asyncRequestControl;
	return (control != null && !control.isCompleted());
}
 
Example #7
Source File: AbstractHttpSockJsSession.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public boolean isActive() {
	ServerHttpAsyncRequestControl control = this.asyncRequestControl;
	return (control != null && !control.isCompleted());
}
 
Example #8
Source File: AbstractHttpSockJsSession.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isActive() {
	ServerHttpAsyncRequestControl control = this.asyncRequestControl;
	return (control != null && !control.isCompleted());
}