public Jetty9AsyncSupportWithWebSocket(final AtmosphereConfig config) {
super(config);
String bs = config.getInitParameter(ApplicationConfig.WEBSOCKET_BUFFER_SIZE);
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
if (bs != null) {
policy.setInputBufferSize(Integer.parseInt(bs));
}
String max = config.getInitParameter(ApplicationConfig.WEBSOCKET_IDLETIME);
if (max != null) {
policy.setIdleTimeout(Integer.parseInt(max));
}
try {
// Crazy Jetty API Incompatibility
String serverInfo = config.getServletConfig().getServletContext().getServerInfo();
boolean isJetty91Plus = false;
if (serverInfo != null) {
int version = Integer.valueOf(serverInfo.split("/")[1].substring(0, 3).replace(".", ""));
isJetty91Plus = version > 90;
}
max = config.getInitParameter(ApplicationConfig.WEBSOCKET_MAXTEXTSIZE);
if (max != null) {
//policy.setMaxMessageSize(Integer.parseInt(max));
Method m;
if (isJetty91Plus) {
m = policy.getClass().getMethod("setMaxTextMessageSize", new Class[]{int.class});
} else {
m = policy.getClass().getMethod("setMaxMessageSize", new Class[]{long.class});
}
m.invoke(policy, Integer.parseInt(max));
}
max = config.getInitParameter(ApplicationConfig.WEBSOCKET_MAXBINARYSIZE);
if (max != null) {
//policy.setMaxMessageSize(Integer.parseInt(max));
Method m;
if (isJetty91Plus) {
m = policy.getClass().getMethod("setMaxBinaryMessageSize", new Class[]{int.class});
} else {
m = policy.getClass().getMethod("setMaxMessageSize", new Class[]{long.class});
}
m.invoke(policy, Integer.parseInt(max));
}
} catch (Exception ex) {
logger.warn("", ex);