@Override public Object deserialize(String message) throws org.atmosphere.gwt20.server.SerializationException { try { return GwtRpcUtil.deserialize(message); } catch (SerializationException ex) { throw new org.atmosphere.gwt20.server.SerializationException(ex.getMessage(), ex); } }
@Override public String serialize(Object message) throws org.atmosphere.gwt20.server.SerializationException { try { return GwtRpcUtil.serialize(message); } catch (SerializationException ex) { throw new org.atmosphere.gwt20.server.SerializationException(ex.getMessage(), ex); } } };
@Override public Object deserialize(String data) throws SerializationException { try { // TODO not the most neat implementation return provider.mapper.readValue(data, Map.class); } catch (IOException ex) { throw new SerializationException("Failed to deserialize data", ex); } } }
@Override public Action inspect(AtmosphereResource r) { boolean jersey = isHandledByJersey(r); r.setSerializer(new GwtRpcSerializer(r)); String data = GwtRpcUtil.readerToString(r.getRequest().getReader()); if (logger.isDebugEnabled()) { logger.debug("Received message from client: " + data); r.getRequest().setAttribute(Constants.MESSAGE_OBJECT, GwtRpcUtil.deserialize(data)); } catch (IOException ex) { logger.error("Failed to read request data", ex);
@Override public Object readFrom(Class<Object> type, Type type1, Annotation[] antns, MediaType mt, MultivaluedMap<String, String> headers, InputStream in) throws IOException, WebApplicationException { try { String charset = mt.getParameters().get("charset"); if (charset == null || charset.isEmpty()) { charset = "UTF-8"; } String data = GwtRpcUtil.streamToString(in, charset); if (data.isEmpty()) { throw new WebApplicationException(Response.Status.NO_CONTENT); } return GwtRpcUtil.deserialize(data); } catch (SerializationException ex) { logger.error("Failed to deserialize RPC data", ex); throw new WebApplicationException(ex, Response.Status.BAD_REQUEST); } } }
@Override public void write(OutputStream out, Object o) throws IOException { String payload; try { payload = GwtRpcUtil.serialize(o); } catch (SerializationException ex) { throw new IOException("Failed to deserialize message"); } if (logger.isTraceEnabled()) { logger.trace("Writing to outputstream with encoding: " + outputEncoding + " data: " + payload); } out.write(payload.getBytes(outputEncoding)); out.flush(); }
public static String streamToString(InputStream in, String charset) throws IOException, UnsupportedEncodingException { return readerToString(new BufferedReader(new InputStreamReader(in, charset))); // a possible other way // Scanner s = new Scanner(in, charset).useDelimiter("\\A"); // String data = s.hasNext() ? s.next() : ""; }
@Override public Set<String> getClientFieldNamesForEnhancedClass(Class<?> clazz) { if (hasJpaAnnotation(clazz) || hasJdoAnnotation(clazz)) { Set<String> fieldNames = new TreeSet<String>(); for (Field f : clazz.getDeclaredFields()) { fieldNames.add(f.getName()); } return fieldNames; } else { return null; } }
public static Object deserialize(String data) throws SerializationException { ServerSerializationStreamReader reader = new ServerSerializationStreamReader(Thread.currentThread().getContextClassLoader(), GwtRpcUtil.getSerializationPolicyProvider()); reader.prepareToRead(data); return reader.readObject(); }
public static String serialize(Object message) throws SerializationException { ServerSerializationStreamWriter streamWriter = new ServerSerializationStreamWriter(GwtRpcUtil.getSerializationPolicy()); streamWriter.prepareToWrite(); streamWriter.writeObject(message); return streamWriter.toString(); }
@Override public void writeTo(Object t, Class<?> type, Type type1, Annotation[] antns, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream out) throws IOException, WebApplicationException { try { List ct = Collections.singletonList(Constants.GWT_RPC_MEDIA_TYPE + "; charset=UTF-8"); if (!ct.equals(headers.get("Content-Type"))) { headers.put("Content-Type", ct); } if (t instanceof String && ((String) t).isEmpty()) { out.flush(); return; } String data = GwtRpcUtil.serialize(t); out.write(data.getBytes("UTF-8")); out.flush(); } catch (SerializationException ex) { logger.error("Failed to serialize message", ex); } }
@Override public String serialize(Object data) throws SerializationException { try { return provider.mapper.writeValueAsString(data); } catch (IOException ex) { throw new SerializationException("Failed to serialize data", ex); } }