private static final String PATH = "/{path";
private final AtmosphereConfigurator configurator;
public JSR356AsyncSupport(AtmosphereConfig config) {
super(config);
ServerContainer container = (ServerContainer) config.getServletContext().getAttribute(ServerContainer.class.getName());
if (container == null) {
throw new IllegalStateException("ServerContainer is null. Make sure you are using JDK7 and your server has websocket support enabled");
}
int pathLength = 5;
String s = config.getInitParameter(ApplicationConfig.JSR356_PATH_MAPPING_LENGTH);
if (s != null) {
pathLength = Integer.valueOf(s);
}
logger.trace("JSR356 Path mapping Size {}", pathLength);
String servletPath = config.getInitParameter(ApplicationConfig.JSR356_MAPPING_PATH);
if (servletPath == null) {
servletPath = IOUtils.guestServletPath(config);
if (servletPath.equals("/") || servletPath.equals("/*")) {
servletPath = PATH +"}";
}
}
logger.info("JSR 356 Mapping path {}", servletPath);
configurator = new AtmosphereConfigurator(config.framework());
StringBuilder b = new StringBuilder(servletPath);
for (int i = 0; i < pathLength; i++) {
try {
container.addEndpoint(ServerEndpointConfig.Builder.create(JSR356Endpoint.class, b.toString()).configurator(configurator).build());
} catch (DeploymentException e) {
logger.warn("Duplicate Servlet Mapping Path {}. Use {} init-param to prevent this message", servletPath, ApplicationConfig.JSR356_MAPPING_PATH);
logger.trace("", e);
servletPath = IOUtils.guestServletPath(config);
logger.warn("Duplicate guess {}", servletPath, e);