/** * Decodes a JSON string to a map (string name -> object) * * @param in - JSON string * @return map representing the string */ public static Map<String, Object> decodeToMap(String in) { //noinspection unchecked return (Map<String, Object>) JSONDecoder.decode(in); }
private static Map getParts(EJValue value) { return ErraiProtocolEnvelopeMarshaller.INSTANCE.demarshall(value, new DecodingSession(MappingContextSingleton.get())); }
@SuppressWarnings("unchecked") public static Message createCommandMessage(QueueSession session, String json) { if (json.length() == 0) return null; Message msg = createWithPartsFromRawMap(ErraiProtocolEnvelopeMarshaller.INSTANCE.demarshall(JSONDecoder.decode(json), new DecodingSession(MappingContextSingleton.get()))) .setResource("Session", session) .setResource("SessionID", session.getSessionId()); msg.setFlag(RoutingFlag.FromRemote); return msg; }
@Override public Metadata unmarshall(final InputStream input) throws IOException { Metadata result = (Metadata) ServerMarshalling.fromJSON(input); return result; }
@Override public void init(FilterConfig filterConfig) throws ServletException { // Initialize server side marshaller MappingContextSingleton.get(); }
@Override public String marshall(final Metadata metadata) throws IOException { String result = ServerMarshalling.toJSON(metadata); return result; } }
public static List<Message> createCommandMessage(QueueSession session, HttpServletRequest request) throws IOException { EJValue value = JSONStreamDecoder.decode(request.getInputStream()); if (value.isObject() != null) { return Collections.singletonList(from(getParts(value), session, request)); } else if (value.isArray() != null) { EJArray arr = value.isArray(); List<Message> messages = new ArrayList<Message>(arr.size()); for (int i = 0; i < arr.size(); i++) { messages.add(from(getParts(arr.get(i)), session, request)); } return messages; } else if (value.isNull()) { return Collections.<Message>emptyList(); } else { throw new RuntimeException("bad payload"); } }
@Override public boolean canMarshal(final String cls) { return hasMarshaller(cls); } };
@Override public boolean canMarshal(final String cls) { return hasMarshaller(cls); } };
public static Message uglyReEncode(String message) { if (message == null) return null; Map<String, Object> parts = ErraiProtocolEnvelopeMarshaller.INSTANCE.demarshall(JSONDecoder.decode(message), new DecodingSession(MappingContextSingleton.get())); return CommandMessage.createWithParts(parts); }
@Override @SuppressWarnings("unchecked") public Graph unmarshall(final Metadata metadata, final InputStream input) throws IOException { Graph result = (Graph) ServerMarshalling.fromJSON(input); return result; }
/** * Decodes a JSON string to a map (string name -> object) * * @param in - JSON string * @return map representing the string */ public static Map<String, Object> decodeToMap(String in) { //noinspection unchecked return (Map<String, Object>) JSONDecoder.decode(in); }
String securityContextJson(final User user) { final String userJson = ServerMarshalling.toJSON(user); return "{\"" + SecurityConstants.DICTIONARY_USER + "\": " + userJson + "}"; }
public static List<Message> createCommandMessage(QueueSession session, InputStream inputStream) throws IOException { EJValue value = JSONStreamDecoder.decode(inputStream); if (value.isObject() != null) { return Collections.singletonList(from(getParts(value), session, null)); } else if (value.isArray() != null) { EJArray arr = value.isArray(); List<Message> messages = new ArrayList<Message>(arr.size()); for (int i = 0; i < arr.size(); i++) { messages.add(from(getParts(arr.get(i)), session, null)); } return messages; } else { throw new RuntimeException("bad payload"); } }
@Override public boolean canMarshal(final String cls) { return hasMarshaller(cls); } };
public static Message decodeAndDemarshall(String json) { Map<String, Object> parts = ErraiProtocolEnvelopeMarshaller.INSTANCE.demarshall(JSONDecoder.decode(json), new DecodingSession(MappingContextSingleton.get())); if (parts == null) return CommandMessage.create(); return CommandMessage.createWithParts(parts); } }
public static Object fromJSON(final InputStream inputStream) throws IOException { return fromJSON(inputStream, Object.class); } }
@Override public EJValue parse(final String input) { return JSONDecoder.decode(input); } });
public static Object fromJSON(final InputStream inputStream) throws IOException { return fromJSON(inputStream, Object.class); } }
@Override public EJValue parse(final String input) { return JSONDecoder.decode(input); } });