Example usage for javax.websocket DecodeException DecodeException

List of usage examples for javax.websocket DecodeException DecodeException

Introduction

In this page you can find the example usage for javax.websocket DecodeException DecodeException.

Prototype

public DecodeException(String encodedString, String message, Throwable cause) 

Source Link

Usage

From source file:de.hofuniversity.iisys.neo4j.websock.query.encoding.safe.TSafeJsonQueryHandler.java

@Override
public WebsockQuery decode(String arg0) throws DecodeException {
    WebsockQuery query = null;//from  ww  w. ja  v  a  2s . c  o m

    try {
        final JSONObject obj = new JSONObject(arg0);

        if (fDebug) {
            fTotalBytesIn += arg0.getBytes().length;
            fLogger.log(Level.FINEST, "received JSON message: " + arg0.getBytes().length + " bytes\n"
                    + "total bytes received: " + fTotalBytesIn);
        }

        query = JsonConverter.fromJson(obj);
    } catch (JSONException e) {
        e.printStackTrace();
        throw new DecodeException(arg0, "failed to decode JSON", e);
    }

    return query;
}

From source file:de.hofuniversity.iisys.neo4j.websock.query.encoding.safe.TSafeDeflateJsonQueryHandler.java

@Override
public WebsockQuery decode(ByteBuffer buff) throws DecodeException {
    WebsockQuery query = null;//w  w  w .  jav a2 s .  co m

    try {
        //decompress
        final byte[] incoming = buff.array();
        final Inflater inflater = new Inflater(true);
        inflater.setInput(incoming);

        int read = 0;
        int totalSize = 0;
        final List<byte[]> buffers = new LinkedList<byte[]>();

        final byte[] buffer = new byte[BUFFER_SIZE];
        read = inflater.inflate(buffer);
        while (read > 0) {
            totalSize += read;
            buffers.add(Arrays.copyOf(buffer, read));
            read = inflater.inflate(buffer);
        }

        final byte[] data = fuse(buffers, totalSize).array();
        final JSONObject obj = new JSONObject(new String(data));

        if (fDebug) {
            fTotalBytesIn += incoming.length;
            fLogger.log(Level.FINEST, "received compressed JSON message: " + incoming.length + " bytes\n"
                    + "total bytes received: " + fTotalBytesIn);
        }

        query = JsonConverter.fromJson(obj);
    } catch (Exception e) {
        e.printStackTrace();
        throw new DecodeException(buff, "failed to decode JSON", e);
    }

    return query;
}

From source file:de.hofuniversity.iisys.neo4j.websock.query.encoding.unsafe.DeflateJsonQueryHandler.java

@Override
public WebsockQuery decode(ByteBuffer buff) throws DecodeException {
    WebsockQuery query = null;//from   www.j av  a 2s  .c  o m

    try {
        //decompress
        final byte[] incoming = buff.array();
        fInflater.setInput(incoming);

        int totalSize = 0;

        int read = fInflater.inflate(fBuffer);
        while (read > 0) {
            totalSize += read;
            fBuffers.add(Arrays.copyOf(fBuffer, read));
            read = fInflater.inflate(fBuffer);
        }
        //TODO: directly add final slice?
        //      showed negative impact on performance

        final byte[] data = fuse(totalSize).array();

        final JSONObject obj = new JSONObject(new String(data));

        if (fDebug) {
            fTotalBytesIn += incoming.length;
            fLogger.log(Level.FINEST, "received compressed JSON message: " + incoming.length + " bytes\n"
                    + "total bytes received: " + fTotalBytesIn);
        }

        query = JsonConverter.fromJson(obj);
    } catch (Exception e) {
        e.printStackTrace();
        throw new DecodeException(buff, "failed to decode JSON", e);
    }

    return query;
}

From source file:de.hofuniversity.iisys.neo4j.websock.query.encoding.logging.LoggingTSafeJsonQueryHandler.java

@Override
public WebsockQuery decode(final String arg0) throws DecodeException {
    WebsockQuery query = null;/*from w w w  . j a  v  a 2  s.c  o m*/

    try {
        long time = System.nanoTime();
        final JSONObject obj = new JSONObject(arg0);

        if (fDebug) {
            fTotalBytesIn += arg0.getBytes().length;
            fLogger.log(Level.FINEST, "received JSON message: " + arg0.getBytes().length + " bytes\n"
                    + "total bytes received: " + fTotalBytesIn);
        }

        query = JsonConverter.fromJson(obj);

        time = System.nanoTime() - time;

        //retrieve type
        if (LOGGING_ENABLED) {
            String type = null;
            synchronized (QUERY_TYPES) {
                type = QUERY_TYPES.get(query.getId());
            }

            //store size of query
            List<Integer> sizes = null;
            synchronized (LOGGED_IN_SIZES) {
                sizes = LOGGED_IN_SIZES.get(type);

                if (sizes == null) {
                    sizes = new LinkedList<Integer>();
                    LOGGED_IN_SIZES.put(type, sizes);
                }
            }

            synchronized (sizes) {
                sizes.add(arg0.getBytes().length);
            }

            //store time taken
            List<Long> times = null;
            synchronized (LOGGED_IN_TIMES) {
                times = LOGGED_IN_TIMES.get(type);

                if (times == null) {
                    times = new LinkedList<Long>();
                    LOGGED_IN_TIMES.put(type, times);
                }
            }

            synchronized (times) {
                times.add(time);
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
        throw new DecodeException(arg0, "failed to decode JSON", e);
    }

    return query;
}

From source file:ru.schernolyas.websockettest.testproject.ws.EnvelopeDecoder.java

@Override
public Envelope decode(String jsonStr) throws DecodeException {
    Envelope env = new Envelope();
    JSONParser parser = new JSONParser();
    try {//from ww w  .  j  a  va2  s  .c om
        JSONObject jsonData = (JSONObject) parser.parse(jsonStr);
        env.setData(((JSONObject) jsonData.get("data")).toJSONString());
        env.setType((String) jsonData.get("type"));
        env.setSequenceId((String) jsonData.get("sequence_id"));
    } catch (ParseException pe) {
        throw new DecodeException(jsonStr, "Can not parse JSON", pe);
    }
    return env;
}