use of edu.umass.cs.reconfiguration.reconfigurationutils.RequestParseException in project GNS by MobilityFirst.
the class GNSApp method getRequest.
// For InterfaceApplication
/**
*
* @param string
* @return the request
* @throws RequestParseException
*/
@Override
public Request getRequest(String string) throws RequestParseException {
GNSConfig.getLogger().log(Level.FINEST, ">>>>>>>>>>>>>>> GET REQUEST: {0}", string);
// Special case handling of NoopPacket packets
if (Request.NO_OP.equals(string)) {
//new NoopPacket();
throw new RuntimeException("Should never be here");
}
try {
long t = System.nanoTime();
JSONObject json = new JSONObject(string);
if (Util.oneIn(1000)) {
DelayProfiler.updateDelayNano("jsonificationApp", t);
}
Request request = (Request) Packet.createInstance(json, nodeConfig);
return request;
} catch (JSONException e) {
throw new RequestParseException(e);
}
}
use of edu.umass.cs.reconfiguration.reconfigurationutils.RequestParseException in project GNS by MobilityFirst.
the class GNSAppUtil method getRequestStatic.
/**
* This method avoids an unnecessary restringification (as is the case with
* {@link GNSApp#getRequest(String)} above) by decoding the JSON, stamping it with
* the sender information, and then creating a packet out of it.
*
* @param msgBytes
* @param header
* @param unstringer
* @return Request constructed from msgBytes.
* @throws RequestParseException
*/
public static Request getRequestStatic(byte[] msgBytes, NIOHeader header, Stringifiable<String> unstringer) throws RequestParseException {
Request request = null;
try {
long t = System.nanoTime();
if (JSONPacket.couldBeJSON(msgBytes)) {
JSONObject json = new JSONObject(new String(msgBytes, NIOHeader.CHARSET));
MessageExtractor.stampAddressIntoJSONObject(header.sndr, header.rcvr, json);
request = (Request) Packet.createInstance(json, unstringer);
} else {
// parse non-JSON byteified form
return fromBytes(msgBytes);
}
if (Util.oneIn(100)) {
DelayProfiler.updateDelayNano("getRequest." + request.getRequestType(), t);
}
} catch (JSONException | UnsupportedEncodingException e) {
throw new RequestParseException(e);
}
return request;
}
Aggregations