Examples of WebSocketException


Examples of org.eclipse.jetty.websocket.api.WebSocketException

            }
            return ext;
        }
        catch (InstantiationException | IllegalAccessException e)
        {
            throw new WebSocketException("Cannot instantiate extension: " + extClass,e);
        }
    }
View Full Code Here

Examples of org.eclipse.jetty.websocket.api.WebSocketException

        if ((state == ConnectionState.OPEN) || (state == ConnectionState.CONNECTED))
        {
            return remote;
        }

        throw new WebSocketException("RemoteEndpoint unavailable, current state [" + state + "], expecting [OPEN or CONNECTED]");
    }
View Full Code Here

Examples of org.eclipse.jetty.websocket.api.WebSocketException

            notifyWebSocketException(e);
        }
        catch (Throwable t)
        {
            LOG.warn(t);
            notifyWebSocketException(new WebSocketException(t));
        }
    }
View Full Code Here

Examples of org.eclipse.jetty.websocket.api.WebSocketException

        }
        catch (Throwable t)
        {
            buffer.position(buffer.limit()); // consume remaining
            reset();
            notifyWebSocketException(new WebSocketException(t));
        }
    }
View Full Code Here

Examples of org.eclipse.jetty.websocket.api.WebSocketException

        if ((state == ConnectionState.OPEN) || (state == ConnectionState.CONNECTED))
        {
            return remote;
        }

        throw new WebSocketException("RemoteEndpoint unavailable, current state [" + state + "], expecting [OPEN or CONNECTED]");
    }
View Full Code Here

Examples of org.eclipse.jetty.websocket.api.WebSocketException

        }

        @Override
        public void run()
        {
            failed(new WebSocketException("MUX Not yet supported"));
        }
View Full Code Here

Examples of org.eclipse.jetty.websocket.api.WebSocketException

    @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 firstClass.newInstance();
        }
        catch (InstantiationException | IllegalAccessException e)
        {
            throw new WebSocketException("Unable to create instance of " + firstClass, e);
        }
    }
View Full Code Here

Examples of org.eclipse.jetty.websocket.api.WebSocketException

        } catch (Throwable t) {

          if (t instanceof WebSocketException) {

            WebSocketException wse = (WebSocketException) t;

            if ("RemoteEndpoint unavailable, current state [CLOSED], expecting [OPEN or CONNECTED]".equals(wse.getMessage())) {
              clientsToRemove.add(socket);
            }
          }

          logger.log(Level.FINE, "Error sending message to client.", t);
View Full Code Here

Examples of org.jwebsocket.kit.WebSocketException

    public void open(String uriString) throws WebSocketException {
        URI uri = null;
        try {
            uri = new URI(uriString);
        } catch (URISyntaxException e) {
            throw new WebSocketException("Error parsing WebSocket URL:" + uriString, e);
        }
        this.url = uri;
        handshake = new WebSocketHandshake(url);
        try {
            socket = createSocket();
            input = socket.getInputStream();
            output = new PrintStream(socket.getOutputStream());

            output.write(handshake.getHandshake());

            boolean handshakeComplete = false;
            boolean header = true;
            int len = 1000;
            byte[] buffer = new byte[len];
            int pos = 0;
            ArrayList<String> handshakeLines = new ArrayList<String>();

            byte[] serverResponse = new byte[16];

            while (!handshakeComplete) {
                status = WebSocketStatus.CONNECTING;
                int b = input.read();
                buffer[pos] = (byte) b;
                pos += 1;

                if (!header) {
                    serverResponse[pos - 1] = (byte) b;
                    if (pos == 16) {
                        handshakeComplete = true;
                    }
                } else if (buffer[pos - 1] == 0x0A && buffer[pos - 2] == 0x0D) {
                    String line = new String(buffer, "UTF-8");
                    if (line.trim().equals("")) {
                        header = false;
                    } else {
                        handshakeLines.add(line.trim());
                    }

                    buffer = new byte[len];
                    pos = 0;
                }
            }

            handshake.verifyServerStatusLine(handshakeLines.get(0));
            handshake.verifyServerResponse(serverResponse);

            handshakeLines.remove(0);

            Map<String, String> headers = new FastMap<String, String>();
            for (String line : handshakeLines) {
                String[] keyValue = line.split(": ", 2);
                headers.put(keyValue[0], keyValue[1]);
            }
            handshake.verifyServerHandshakeHeaders(headers);

            receiver = new WebSocketReceiver(input);

            // TODO: Add event parameter
            // notifyOpened(null);

            receiver.start();
            connected = true;
            status = WebSocketStatus.OPEN;
        } catch (WebSocketException wse) {
            throw wse;
        } catch (IOException ioe) {
            throw new WebSocketException("error while connecting: " + ioe.getMessage(), ioe);
        }
    }
View Full Code Here

Examples of org.jwebsocket.kit.WebSocketException

    }

    @Override
    public void send(byte[] data) throws WebSocketException {
        if (!connected) {
            throw new WebSocketException("error while sending binary data: not connected");
        }
        try {
            if (isBinaryData) {
                output.write(0x80);
                // TODO: what if frame is longer than 255 characters (8bit?) Refer to IETF spec!
                output.write(data.length);
                output.write(data);               
            } else {
                output.write(0x00);
                output.write(data);
                output.write(0xff);
            }
            output.flush();
        } catch (IOException ioe) {
            throw new WebSocketException("error while sending binary data: ", ioe);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.