List of usage examples for com.google.gwt.user.server.rpc.impl ServerSerializationStreamWriter prepareToWrite
@Override
public void prepareToWrite()
From source file:com.brightedu.server.util.MyRPC.java
License:Apache License
/** * Returns a string that encodes the results of an RPC call. Private * overload that takes a flag signaling the preamble of the response * payload./*from www. j av a2s . c om*/ * * @param object * the object that we wish to send back to the client * @param wasThrown * if true, the object being returned was an exception thrown by * the service method; if false, it was the result of the service * method's invocation * @return a string that encodes the response from a service method * @throws SerializationException * if the object cannot be serialized */ public static String encodeResponse(Class<?> responseClass, Object object, boolean wasThrown, int flags, SerializationPolicy serializationPolicy) throws SerializationException { ServerSerializationStreamWriter stream = new ServerSerializationStreamWriter(serializationPolicy); stream.setFlags(flags); stream.prepareToWrite(); if (responseClass != void.class) { stream.serializeValue(object, responseClass); } String bufferStr = (wasThrown ? "//EX" : "//OK") + stream.toString(); return bufferStr; }
From source file:com.guit.server.guice.GuiceGwtServlet.java
License:Apache License
protected String encodeResponse(Class<?> responseClass, Object object, boolean wasThrown, int flags, SerializationPolicy serializationPolicy) throws SerializationException { ServerSerializationStreamWriter stream = new ServerSerializationStreamWriter(serializationPolicy); stream.setFlags(flags);/* w ww . j a va 2s . co m*/ stream.prepareToWrite(); stream.serializeValue(object, responseClass); return (wasThrown ? "//EX" : "//OK") + stream.toString(); }
From source file:com.seanchenxi.gwt.storage.server.ServerStorageSerializer.java
License:Apache License
public <T> String serialize(Class<? super T> clazz, T instance, SerializationPolicy serializationPolicy) throws SerializationException { if (instance == null) { return null; } else if (String.class.equals(clazz)) { return (String) instance; }//from w ww. ja va 2 s . co m if (serializationPolicy == null) { throw new IllegalArgumentException( "SerializationPolicy is null, please call StorageUtils.PolicyLoader.load(...) before"); } ServerSerializationStreamWriter stream = new ServerSerializationStreamWriter(serializationPolicy); stream.setFlags(AbstractSerializationStream.DEFAULT_FLAGS); stream.prepareToWrite(); if (clazz != void.class) { stream.serializeValue(instance, clazz); } return stream.toString(); }
From source file:de.csenk.gwt.ws.server.filter.serialization.ServerGWTSerializer.java
License:Open Source License
@Override public String serialize(Object obj) throws SerializationException { SerializationPolicy policy = (serializationPolicy == null) ? RPC.getDefaultSerializationPolicy() : serializationPolicy;// w w w. j a v a 2 s. co m ServerSerializationStreamWriter streamWriter = new ServerSerializationStreamWriter(policy); streamWriter.prepareToWrite(); streamWriter.writeString(obj.getClass().getName()); streamWriter.serializeValue(obj, obj.getClass()); return streamWriter.toString(); }
From source file:de.novanic.eventservice.service.connection.strategy.connector.streaming.StreamingServerConnector.java
License:Open Source License
/** * Transforms an event to a String to make it streamable. * @param anEvent event to serialize/* w ww. j a v a2s.c om*/ * @return serialized event (the event as a String) * @throws EventServiceException */ private String serialize(DomainEvent anEvent) throws EventServiceException { try { ServerSerializationStreamWriter theServerSerializationStreamWriter = new ServerSerializationStreamWriter( mySerializationPolicy); theServerSerializationStreamWriter.setFlags(0); theServerSerializationStreamWriter.prepareToWrite(); theServerSerializationStreamWriter.serializeValue(anEvent, DomainEvent.class); return theServerSerializationStreamWriter.toString(); } catch (SerializationException e) { throw new EventServiceException("Error on serializing the event \"" + anEvent + "\" for domain \"" + anEvent.getDomain() + "\"!", e); } }
From source file:net.zschech.gwt.comet.server.impl.CometServletResponseImpl.java
License:Apache License
protected String serialize(Serializable message) throws NotSerializableException, UnsupportedEncodingException { try {/*from w ww . j ava 2 s . com*/ if (clientOracle == null) { ServerSerializationStreamWriter streamWriter = new ServerSerializationStreamWriter( serializationPolicy); streamWriter.prepareToWrite(); streamWriter.writeObject(message); return streamWriter.toString(); } else { ByteArrayOutputStream result = new ByteArrayOutputStream(); RPC.streamResponseForSuccess(clientOracle, result, message); return new String(result.toByteArray(), "UTF-8"); } } catch (SerializationException e) { throw new NotSerializableException("Unable to serialize object, message: " + e.getMessage()); } }
From source file:org.gwtspringhibernate.reference.rlogman.spring.GwtServiceExporter.java
License:Apache License
/** * @param stream/*from w w w . ja va 2 s.c o m*/ * @param responseType * @param responseObj * @param isException * @return */ private String createResponse(ServerSerializationStreamWriter stream, Class responseType, Object responseObj, boolean isException) { stream.prepareToWrite(); if (responseType != void.class) { try { stream.serializeValue(responseObj, responseType); } catch (SerializationException e) { responseObj = e; isException = true; } } String bufferStr = (isException ? "{EX}" : "{OK}") + stream.toString(); return bufferStr; }
From source file:org.jboss.seam.remoting.gwt.GWTRemoteServiceServlet.java
License:Open Source License
/** * @param stream/* w w w . j a va 2 s.c om*/ * @param responseType * @param responseObj * @param isException * @return response */ private String createResponse(ServerSerializationStreamWriter stream, Class responseType, Object responseObj, boolean isException) { stream.prepareToWrite(); if (responseType != void.class) { try { stream.serializeValue(responseObj, responseType); } catch (SerializationException e) { responseObj = e; isException = true; } } String bufferStr = (isException ? "//EX" : "//OK") + stream.toString(); return bufferStr; }
From source file:rocket.remoting.server.comet.CometServerServlet.java
License:Apache License
/** * Uses the GWT serialization sub-system to convert the given object into a * String. This same object will be deserialized on the client using the GWT * deserialization sub-system./*from w w w . ja v a 2s .c o m*/ * * @param command * The command to send. * @param object * Its okay to push null objects. * @return The serialized form of both the command and object. */ protected String serialize(final int command, final Object object) { try { ServerSerializationStreamWriter streamWriter = new ServerSerializationStreamWriter( this.createSerializationPolicy()); streamWriter.prepareToWrite(); streamWriter.writeInt(command); streamWriter.writeObject(object); return streamWriter.toString(); } catch (final SerializationException serializationException) { throw new RuntimeException( "Unable to serialize object, message: " + serializationException.getMessage()); } }
From source file:us.gibb.dev.gwt.server.remote.RPCGilead.java
License:Apache License
/** * Returns a string that encodes the results of an RPC call. Private overload * that takes a flag signaling the preamble of the response payload. * //from w w w .j a va 2s .co m * @param object the object that we wish to send back to the client * @param wasThrown if true, the object being returned was an exception thrown * by the service method; if false, it was the result of the service * method's invocation * @return a string that encodes the response from a service method * @throws SerializationException if the object cannot be serialized */ private static String encodeResponse(Class<?> responseClass, Object object, boolean wasThrown, SerializationPolicy serializationPolicy) throws SerializationException { ServerSerializationStreamWriter stream = new ServerSerializationStreamWriter(serializationPolicy); stream.prepareToWrite(); if (responseClass != void.class) { stream.serializeValue(object, responseClass); } String bufferStr = (wasThrown ? "//EX" : "//OK") + stream.toString(); return bufferStr; }