Java Code Examples for org.tio.core.ChannelContext#setAttribute()

The following examples show how to use org.tio.core.ChannelContext#setAttribute() . 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: WsClientAioListener.java    From t-io with Apache License 2.0 6 votes vote down vote up
@Override
public void onBeforeClose(
    ChannelContext channelContext, Throwable throwable, String remark, boolean isRemove)
    throws Exception {
  WsClient client = (WsClient) channelContext.getAttribute(WebSocketImpl.clientIntoCtxAttribute);
  if (throwable instanceof SSLHandshakeException && client.uri.getScheme().equals("wss")) {
    log.warn("wss但没有正确的CA证书,更为ws重试");
    ReflectKit.setField(client.uri, "scheme", "ws");
    if (client.uri.getPort() == 443) ReflectKit.setField(client.uri, "port", 80);
    client.construct();
    client.connect();
    return;
  }
  client.ws.clear(1011, remark);
  channelContext.setAttribute(WebSocketImpl.clientIntoCtxAttribute, null);
}
 
Example 2
Source File: HttpServerAioHandler.java    From t-io with Apache License 2.0 5 votes vote down vote up
@Override
public HttpRequest decode(ByteBuffer buffer, int limit, int position, int readableLength, ChannelContext channelContext) throws AioDecodeException {
	HttpRequest request = HttpRequestDecoder.decode(buffer, limit, position, readableLength, channelContext, httpConfig);
	if (request != null) {
		channelContext.setAttribute(REQUEST_KEY, request);
	}
	return request;
}
 
Example 3
Source File: HttpClientAioHandler.java    From t-io with Apache License 2.0 4 votes vote down vote up
@Override
public ClientHttpResponse decode(ByteBuffer buffer, int limit, int position, int readableLength, ChannelContext channelContext) throws AioDecodeException {
	ClientHttpResponse response = HttpResponseDecoder.decode(buffer, limit, position, readableLength, channelContext);
	channelContext.setAttribute(RESPONSE_KEY, response);
	return response;
}