类org.springframework.web.socket.sockjs.transport.session.AbstractHttpSockJsSession源码实例Demo

下面列出了怎么用org.springframework.web.socket.sockjs.transport.session.AbstractHttpSockJsSession的API类实例代码及写法,或者点击链接到github查看源代码。

@Override
public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response,
		AbstractHttpSockJsSession sockJsSession) throws SockJsException {

	String callback = getCallbackParam(request);
	if (!StringUtils.hasText(callback)) {
		response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
		try {
			response.getBody().write("\"callback\" parameter required".getBytes(StandardCharsets.UTF_8));
		}
		catch (IOException ex) {
			sockJsSession.tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR);
			throw new SockJsTransportFailureException("Failed to write to response", sockJsSession.getId(), ex);
		}
		return;
	}

	super.handleRequestInternal(request, response, sockJsSession);
}
 
@Override
public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response,
		AbstractHttpSockJsSession sockJsSession) throws SockJsException {

	String callback = getCallbackParam(request);
	if (!StringUtils.hasText(callback)) {
		response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
		try {
			response.getBody().write("\"callback\" parameter required".getBytes(StandardCharsets.UTF_8));
		}
		catch (IOException ex) {
			sockJsSession.tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR);
			throw new SockJsTransportFailureException("Failed to write to response", sockJsSession.getId(), ex);
		}
		return;
	}

	super.handleRequestInternal(request, response, sockJsSession);
}
 
@Override
public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response,
		AbstractHttpSockJsSession sockJsSession) throws SockJsException {

	String callback = getCallbackParam(request);
	if (!StringUtils.hasText(callback)) {
		response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
		try {
			response.getBody().write("\"callback\" parameter required".getBytes(UTF8_CHARSET));
		}
		catch (IOException ex) {
			sockJsSession.tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR);
			throw new SockJsTransportFailureException("Failed to write to response", sockJsSession.getId(), ex);
		}
		return;
	}

	super.handleRequestInternal(request, response, sockJsSession);
}
 
@Override
public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response,
		AbstractHttpSockJsSession sockJsSession) throws SockJsException {

	try {
		String callback = getCallbackParam(request);
		if (!StringUtils.hasText(callback)) {
			response.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
			response.getBody().write("\"callback\" parameter required".getBytes(UTF8_CHARSET));
			return;
		}
	}
	catch (Throwable ex) {
		sockJsSession.tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR);
		throw new SockJsTransportFailureException("Failed to send error", sockJsSession.getId(), ex);
	}

	super.handleRequestInternal(request, response, sockJsSession);
}
 
@Override
public final void handleRequest(ServerHttpRequest request, ServerHttpResponse response,
		WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException {

	Assert.notNull(wsSession, "No session");
	AbstractHttpSockJsSession sockJsSession = (AbstractHttpSockJsSession) wsSession;

	handleRequestInternal(request, response, wsHandler, sockJsSession);
}
 
@Override
public final void handleRequest(ServerHttpRequest request, ServerHttpResponse response,
		WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException {

	AbstractHttpSockJsSession sockJsSession = (AbstractHttpSockJsSession) wsSession;

	// https://github.com/sockjs/sockjs-client/issues/130
	// sockJsSession.setAcceptedProtocol(protocol);

	// Set content type before writing
	response.getHeaders().setContentType(getContentType());

	handleRequestInternal(request, response, sockJsSession);
}
 
@Override
public final void handleRequest(ServerHttpRequest request, ServerHttpResponse response,
		WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException {

	Assert.notNull(wsSession, "No session");
	AbstractHttpSockJsSession sockJsSession = (AbstractHttpSockJsSession) wsSession;

	handleRequestInternal(request, response, wsHandler, sockJsSession);
}
 
@Override
public final void handleRequest(ServerHttpRequest request, ServerHttpResponse response,
		WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException {

	AbstractHttpSockJsSession sockJsSession = (AbstractHttpSockJsSession) wsSession;

	// https://github.com/sockjs/sockjs-client/issues/130
	// sockJsSession.setAcceptedProtocol(protocol);

	// Set content type before writing
	response.getHeaders().setContentType(getContentType());

	handleRequestInternal(request, response, sockJsSession);
}
 
@Override
public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response,
		WebSocketHandler wsHandler, AbstractHttpSockJsSession sockJsSession) throws SockJsException {

	super.handleRequestInternal(request, response, wsHandler, sockJsSession);
	try {
		response.getBody().write("ok".getBytes(UTF8_CHARSET));
	}
	catch (IOException ex) {
		throw new SockJsException("Failed to write to the response body", sockJsSession.getId(), ex);
	}
}
 
@Override
public final void handleRequest(ServerHttpRequest request, ServerHttpResponse response,
		WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException {

	Assert.notNull(wsSession, "No session");
	AbstractHttpSockJsSession sockJsSession = (AbstractHttpSockJsSession) wsSession;

	handleRequestInternal(request, response, wsHandler, sockJsSession);
}
 
@Override
public final void handleRequest(ServerHttpRequest request, ServerHttpResponse response,
		WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException {

	AbstractHttpSockJsSession sockJsSession = (AbstractHttpSockJsSession) wsSession;

	String protocol = null;  // https://github.com/sockjs/sockjs-client/issues/130
	sockJsSession.setAcceptedProtocol(protocol);

	// Set content type before writing
	response.getHeaders().setContentType(getContentType());

	handleRequestInternal(request, response, sockJsSession);
}
 
@Override
public boolean checkSessionType(SockJsSession session) {
	return (session instanceof AbstractHttpSockJsSession);
}
 
@Override
public boolean checkSessionType(SockJsSession session) {
	return (session instanceof AbstractHttpSockJsSession);
}
 
 类方法
 同包方法