@Override
public Action inspect(AtmosphereResource r) {
final AtmosphereRequest request = r.getRequest();
final AtmosphereResponse response = r.getResponse();
final AtmosphereHandler atmosphereHandler = r.getAtmosphereHandler();
try {
// find the transport
String path = request.getPathInfo();
if (path == null || path.length() == 0 || "/".equals(path)) {
logger.debug("Not a SocketIO client");
return Action.CONTINUE;
}
if (path.startsWith("/")) {
path = path.substring(1);
}
String[] parts = path.split("/");
String protocol = null;
String version = null;
// find protocol's version
if (parts.length == 0) {
logger.debug("Not a SocketIO protocol supported");
return Action.CONTINUE;
} else if (parts.length == 1) {
// is protocol's version ?
if (parts[0].length() == 1) {
version = parts[0];
// must be a digit
if (!Character.isDigit(version.charAt(0))) {
version = null;
}
} else {
protocol = parts[0];
}
} else {
// ex :[1, xhr-polling, 7589995670715459]
version = parts[0];
protocol = parts[1];
// must be a digit
if (!Character.isDigit(version.charAt(0))) {
version = null;
protocol = null;
}
}
if (protocol == null && version == null) {
logger.debug("Not a SocketIO protocol supported");
return Action.CONTINUE;
} else if (protocol == null && version != null) {
// create a session and send the available transports to the client
response.setStatus(200);
response.setContentType("plain/text");
SocketIOSession session = getSessionManager(version).createSession((AtmosphereResourceImpl) r, atmosphereHandler);
response.getWriter().print(session.getSessionId() + ":" + (heartbeatTimeout/1000) + ":" + (timeout/1000) + ":" + availableTransports);
return Action.CANCELLED;
} else if (protocol != null && version == null) {
version = "0";
}
final Transport transport = transports.get(protocol + "-" + version);
if (transport != null) {
if (!SocketIOAtmosphereHandler.class.isAssignableFrom(atmosphereHandler.getClass())) {
response.asyncIOWriter(new AsyncIOWriterAdapter() {
@Override
public AsyncIOWriter write(AtmosphereResponse r, String data) throws IOException {
SocketIOSessionOutbound outbound = (SocketIOSessionOutbound)
request.getAttribute(SocketIOAtmosphereHandler.SOCKETIO_SESSION_OUTBOUND);