Example usage for com.google.gwt.user.server.rpc.impl ServerSerializationStreamWriter serializeValue

List of usage examples for com.google.gwt.user.server.rpc.impl ServerSerializationStreamWriter serializeValue

Introduction

In this page you can find the example usage for com.google.gwt.user.server.rpc.impl ServerSerializationStreamWriter serializeValue.

Prototype

public void serializeValue(Object value, Class<?> type) throws SerializationException 

Source Link

Usage

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  w ww .  java 2 s  .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);/*from w ww. ja  va2 s.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;
    }// w w w .  j a  v  a  2  s .c om

    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;//from   w  w w .  j a v a2 s . c  o  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//from   ww  w .  j a  v  a  2 s  .co  m
 * @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:org.gwtspringhibernate.reference.rlogman.spring.GwtServiceExporter.java

License:Apache License

/**
 * @param stream/* ww w  .j av  a  2  s  .c  om*/
 * @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//from  ww  w .  j  a va  2s .  com
 * @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:org.restlet.ext.gwt.ObjectRepresentation.java

License:LGPL

@Override
public String getText() {
    if ((this.object != null) && (super.getText() == null)) {
        try {/*w w  w . j  a  va  2 s .co  m*/
            ServerSerializationStreamWriter objectWriter = new ServerSerializationStreamWriter(
                    getSerializationPolicy());
            objectWriter.serializeValue(this.object, this.targetClass);
            setText("//OK" + objectWriter.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    return super.getText();
}

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 ww  . ja  v a  2  s.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
 */
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;
}