use of com.generallycloud.baseio.codec.http11.future.HttpFuture in project baseio by generallycloud.
the class TestWebSocketRumpetrollServlet method doAccept.
@Override
protected void doAccept(HttpSession session, HttpFuture future) throws Exception {
future.updateWebSocketProtocol();
session.flush(future);
msgAdapter.addClient(getAddress(session.getIoSession()), session.getIoSession());
SocketSession ioSession = session.getIoSession();
JSONObject o = new JSONObject();
o.put("type", "welcome");
o.put("id", ioSession.getSessionId());
WebSocketFuture f = new WebSocketFutureImpl(ioSession.getContext());
f.write(o.toJSONString());
session.flush(f);
}
use of com.generallycloud.baseio.codec.http11.future.HttpFuture in project baseio by generallycloud.
the class DefaultHttpSessionManager method getHttpSession.
@Override
public HttpSession getHttpSession(HttpContext context, SocketSession ioSession, HttpFuture future) {
String sessionId = future.getCookie(COOKIE_NAME_SESSIONID);
if (StringUtil.isNullOrBlank(sessionId)) {
DefaultHttpSession session = new DefaultHttpSession(context, ioSession);
sessionId = session.getSessionId();
Cookie cookie = new Cookie(COOKIE_NAME_SESSIONID, sessionId);
future.addCookie(cookie);
this.sessions.put(sessionId, session);
return session;
}
HttpSession session = sessions.get(sessionId);
if (session == null) {
session = new DefaultHttpSession(context, ioSession, sessionId);
this.sessions.put(sessionId, session);
return session;
}
if (!session.isValidate()) {
sessions.remove(sessionId);
CloseUtil.close(session.getIoSession());
return getHttpSession(context, ioSession, future);
}
session.active(ioSession);
return session;
}
use of com.generallycloud.baseio.codec.http11.future.HttpFuture in project baseio by generallycloud.
the class ClientHTTPProtocolEncoder method encode.
@Override
public void encode(SocketChannel channel, ChannelFuture future) throws IOException {
ByteBufAllocator allocator = channel.getByteBufAllocator();
HttpFuture f = (HttpFuture) future;
ByteBuf buf = allocator.allocate(256);
buf.put(f.getMethod().getBytes());
buf.putByte(SPACE);
buf.put(getRequestURI(f).getBytes());
buf.put(PROTOCOL);
writeHeaders(f, buf);
List<Cookie> cookieList = f.getCookieList();
if (cookieList != null && cookieList.size() > 0) {
buf.put(COOKIE);
for (Cookie c : cookieList) {
writeBuf(buf, c.getName().getBytes());
writeBuf(buf, COLON);
writeBuf(buf, c.getValue().getBytes());
writeBuf(buf, SEMICOLON);
}
buf.position(buf.position() - 1);
}
buf.put(RN);
future.setByteBuf(buf.flip());
}
use of com.generallycloud.baseio.codec.http11.future.HttpFuture in project baseio by generallycloud.
the class TestSimpleHttpClient method main.
public static void main(String[] args) throws Exception {
HttpIOEventHandle eventHandleAdaptor = new HttpIOEventHandle();
// ServerConfiguration c = new ServerConfiguration("localhost",80);
ServerConfiguration c = new ServerConfiguration("generallycloud.com", 443);
SocketChannelContext context = new NioSocketChannelContext(c);
SocketChannelConnector connector = new SocketChannelConnector(context);
SslContext sslContext = SSLUtil.initClient(true);
context.setProtocolFactory(new ClientHTTPProtocolFactory());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
context.setSslContext(sslContext);
SocketSession session = connector.connect();
HttpClient client = new HttpClient(session);
HttpFuture future = new ClientHttpFuture(context, "/test-show-memory");
HttpFuture res = client.request(future, 10000);
System.out.println();
System.out.println(new String(res.getBodyContent()));
System.out.println();
CloseUtil.close(connector);
}
Aggregations