@Override public void init() throws TransportInitializationException { this.flashPolicyDomain = getConfig().getString(PARAM_FLASHPOLICY_DOMAIN); this.flashPolicyPorts = getConfig().getString(PARAM_FLASHPOLICY_PORTS); this.flashPolicyServerHost = getConfig().getString(PARAM_FLASHPOLICY_SERVER_HOST); this.flashPolicyServerPort = getConfig().getInt(PARAM_FLASHPOLICY_SERVER_PORT, 843); this.delegate = getConfig().getWebSocketTransport(); if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine( getType() + " configuration:\n" + " - flashPolicyDomain=" + flashPolicyDomain + "\n" + " - flashPolicyPorts=" + flashPolicyPorts + "\n" + " - flashPolicyServerHost=" + flashPolicyServerHost + "\n" + " - flashPolicyServerPort=" + flashPolicyServerPort + "\n" + " - websocket delegate=" + (delegate == null ? "<none>" : delegate.getClass().getName())); if (delegate == null) throw new TransportInitializationException( "No WebSocket transport available for this transport: " + getClass().getName()); if (flashPolicyServerHost != null && flashPolicyDomain != null && flashPolicyPorts != null) { try { startFlashPolicyServer(); } catch (IOException e) { // Ignore } } }
@Override public void handle( HttpServletRequest request, HttpServletResponse response, Transport.InboundFactory inboundFactory, SessionManager sessionFactory) throws IOException { String path = request.getPathInfo(); if (path == null || path.length() == 0 || "/".equals(path)) { response.sendError( HttpServletResponse.SC_BAD_REQUEST, "Invalid " + TransportType.FLASH_SOCKET + " transport request"); return; } if (path.startsWith("/")) path = path.substring(1); String[] parts = path.split("/"); if ("GET".equals(request.getMethod()) && TransportType.FLASH_SOCKET.name().equals(parts[0])) { if (!FLASHFILE_PATH.equals(path)) { delegate.handle(request, response, inboundFactory, sessionFactory); } else { response.setContentType("application/x-shockwave-flash"); InputStream is = this.getClass() .getClassLoader() .getResourceAsStream("com/glines/socketio/" + FLASHFILE_NAME); OutputStream os = response.getOutputStream(); try { IO.copy(is, os); } catch (IOException e) { LOGGER.log(Level.FINE, "Error writing " + FLASHFILE_NAME + ": " + e.getMessage(), e); } } } else { response.sendError( HttpServletResponse.SC_BAD_REQUEST, "Invalid " + TransportType.FLASH_SOCKET + " transport request"); } }