if (payload_len > mOptions.getMaxFramePayloadSize()) { throw new WebSocketException("frame payload too large"); }
public void verifyServerHandshakeHeaders(HashMap<String, String> headers) { if (!headers.get("Upgrade").toLowerCase(Locale.US).equals("websocket")) { throw new WebSocketException("connection failed: missing header field in server handshake: Upgrade"); } else if (!headers.get("Connection").toLowerCase(Locale.US).equals("upgrade")) { throw new WebSocketException("connection failed: missing header field in server handshake: Connection"); } }
while (!handshakeComplete) { int b = input.read(); if (b == -1) throw new WebSocketException ("Connected closed."); if (pos == buffer.length) throw new WebSocketException ("Invalid handshake."); buffer[pos] = (byte) b; // THIS LINE CAUSES THE EXCEPTION pos += 1; if (buffer[pos - 1] == 0x0A && buffer[pos - 2] == 0x0D) { String line = new String(buffer, "UTF-8"); if (line.trim().equals("")) { handshakeComplete = true; } else { handshakeLines.add(line.trim()); } buffer = new byte[len]; pos = 0; } }
@Override public RemoteEndpoint getRemote() { if (!isOpen()) { throw new WebSocketException("Session has not been opened yet"); } return remote; }
@Override public void run() { failed(new WebSocketException("MUX Not yet supported")); } }
@Override public void run() { failed(new WebSocketException("MUX Not yet supported")); } }
@Override public RemoteEndpoint getRemote() { if (!isOpen()) { throw new WebSocketException("Session has not been opened yet"); } return remote; }
public void connect() throws WebSocketException { try { if (connected) { throw new WebSocketException("already connected"); } socket = createSocket(); input = new DataInputStream(socket.getInputStream()); output = new PrintStream(socket.getOutputStream()); output.write(handshake.getHandshake()); boolean handshakeComplete = false; ArrayList<String> handshakeLines = new ArrayList<String>(); BufferedReader reader = new BufferedReader(input); String handshakeData; while ((handshakeData = reader.readLine()) != null) { if (handshakeData.trim().equals("")) { handshakeComplete = true; break; } handshakeLines.add(handshakeData); } if (!handshakeComplete) throw new WebSocketException ("Failed to establish handshake.");
/** * Default Creator logic */ @Override public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp) { if (registeredSocketClasses.size() < 1) { throw new WebSocketException("No WebSockets have been registered with the factory. Cannot use default implementation of WebSocketCreator."); } if (registeredSocketClasses.size() > 1) { LOG.warn("You have registered more than 1 websocket object, and are using the default WebSocketCreator! Using first registered websocket."); } Class<?> firstClass = registeredSocketClasses.get(0); try { return firstClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new WebSocketException("Unable to create instance of " + firstClass,e); } }
/** * Default Creator logic */ @Override public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp) { if (registeredSocketClasses.size() < 1) { throw new WebSocketException("No WebSockets have been registered with the factory. Cannot use default implementation of WebSocketCreator."); } if (registeredSocketClasses.size() > 1) { LOG.warn("You have registered more than 1 websocket object, and are using the default WebSocketCreator! Using first registered websocket."); } Class<?> firstClass = registeredSocketClasses.get(0); try { return firstClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new WebSocketException("Unable to create instance of " + firstClass,e); } }
/** * Manually add a WebSocket mapping. * * @param pathSpec the pathspec to respond on * @param endpointClass the endpoint class to use for new upgrade requests on the provided * pathspec (can be an {@link org.eclipse.jetty.websocket.api.annotations.WebSocket} annotated * POJO, or implementing {@link org.eclipse.jetty.websocket.api.WebSocketListener}) */ public void addMapping(PathSpec pathSpec, final Class<?> endpointClass) { mappings.put(pathSpec, (req, resp) -> { try { return endpointClass.getDeclaredConstructor().newInstance(); } catch (Exception e) { throw new WebSocketException("Unable to create instance of " + endpointClass.getName(), e); } }); }
/** * Default Creator logic */ @Override public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) { if (registeredSocketClasses.size() < 1) { throw new WebSocketException("No WebSockets have been registered with the factory. Cannot use default implementation of WebSocketCreator."); } if (registeredSocketClasses.size() > 1) { LOG.warn("You have registered more than 1 websocket object, and are using the default WebSocketCreator! Using first registered websocket."); } Class<?> firstClass = registeredSocketClasses.get(0); try { return objectFactory.createInstance(firstClass); } catch (Exception e) { throw new WebSocketException("Unable to create instance of " + firstClass, e); } }
@Override public RemoteEndpoint getRemote() { if(LOG_OPEN.isDebugEnabled()) LOG_OPEN.debug("[{}] {}.getRemote()",policy.getBehavior(),this.getClass().getSimpleName()); ConnectionState state = connection.getIOState().getConnectionState(); if ((state == ConnectionState.OPEN) || (state == ConnectionState.CONNECTED)) { return remote; } throw new WebSocketException("RemoteEndpoint unavailable, current state [" + state + "], expecting [OPEN or CONNECTED]"); }
throw new WebSocketException(err,e);
throw new WebSocketException(err,e);
throw new WebSocketException(err,e);
throw new WebSocketException("Cannot instantiate extension: " + extClass,e);
throw new WebSocketException("Cannot instantiate extension: " + extClass,e);
notifyWebSocketException(new WebSocketException(t));
notifyWebSocketException(new WebSocketException(t));