Example usage for com.google.gwt.user.client.rpc.impl AbstractSerializationStream DEFAULT_FLAGS

List of usage examples for com.google.gwt.user.client.rpc.impl AbstractSerializationStream DEFAULT_FLAGS

Introduction

In this page you can find the example usage for com.google.gwt.user.client.rpc.impl AbstractSerializationStream DEFAULT_FLAGS.

Prototype

int DEFAULT_FLAGS

To view the source code for com.google.gwt.user.client.rpc.impl AbstractSerializationStream DEFAULT_FLAGS.

Click Source Link

Document

The default flags to be used by serialization streams.

Usage

From source file:com.brightedu.server.util.MyRPC.java

License:Apache License

/**
 * Returns a string that encodes an exception. If method is not
 * <code>null</code>, it is an error if the exception is not in the method's
 * list of checked exceptions.//from   w  w  w .ja  v  a 2  s.  co m
 * 
 * <p>
 * If the serializationPolicy parameter is not <code>null</code>, it is used
 * to determine what types can be encoded as part of this response. If this
 * parameter is <code>null</code>, then only subtypes of
 * {@link com.google.gwt.user.client.rpc.IsSerializable IsSerializable} or
 * types which have custom field serializers may be encoded.
 * </p>
 * 
 * @param serviceMethod
 *            the method that threw the exception, may be <code>null</code>
 * @param cause
 *            the {@link Throwable} that was thrown
 * @param serializationPolicy
 *            determines the serialization policy to be used
 * @return a string that encodes the exception
 * 
 * @throws NullPointerException
 *             if the the cause or the serializationPolicy are
 *             <code>null</code>
 * @throws SerializationException
 *             if the result cannot be serialized
 * @throws UnexpectedException
 *             if the result was an unexpected exception (a checked
 *             exception not declared in the serviceMethod's signature)
 */
public static String encodeResponseForFailure(Method serviceMethod, Throwable cause,
        SerializationPolicy serializationPolicy) throws SerializationException {
    return encodeResponseForFailure(serviceMethod, cause, serializationPolicy,
            AbstractSerializationStream.DEFAULT_FLAGS);
}

From source file:com.brightedu.server.util.MyRPC.java

License:Apache License

/**
 * Returns a string that encodes the object. It is an error to try to encode
 * an object that is not assignable to the service method's return type.
 * //from  w ww.  j ava2  s .  c o m
 * <p>
 * If the serializationPolicy parameter is not <code>null</code>, it is used
 * to determine what types can be encoded as part of this response. If this
 * parameter is <code>null</code>, then only subtypes of
 * {@link com.google.gwt.user.client.rpc.IsSerializable IsSerializable} or
 * types which have custom field serializers may be encoded.
 * </p>
 * 
 * @param serviceMethod
 *            the method whose result we are encoding
 * @param object
 *            the instance that we wish to encode
 * @param serializationPolicy
 *            determines the serialization policy to be used
 * @return a string that encodes the object, if the object is compatible
 *         with the service method's declared return type
 * 
 * @throws IllegalArgumentException
 *             if the result is not assignable to the service method's
 *             return type
 * @throws NullPointerException
 *             if the serviceMethod or the serializationPolicy are
 *             <code>null</code>
 * @throws SerializationException
 *             if the result cannot be serialized
 */
public static String encodeResponseForSuccess(Method serviceMethod, Object object,
        SerializationPolicy serializationPolicy) throws SerializationException {
    return encodeResponseForSuccess(serviceMethod, object, serializationPolicy,
            AbstractSerializationStream.DEFAULT_FLAGS);
}

From source file:com.brightedu.server.util.MyRPC.java

License:Apache License

/**
 * Returns a string that encodes the result of calling a service method,
 * which could be the value returned by the method or an exception thrown by
 * it.//from   w ww  . j ava  2s  . c o  m
 * 
 * <p>
 * If the serializationPolicy parameter is not <code>null</code>, it is used
 * to determine what types can be encoded as part of this response. If this
 * parameter is <code>null</code>, then only subtypes of
 * {@link com.google.gwt.user.client.rpc.IsSerializable IsSerializable} or
 * types which have custom field serializers may be encoded.
 * </p>
 * 
 * <p>
 * This method does no security checking; security checking must be done on
 * the method prior to this invocation.
 * </p>
 * 
 * @param target
 *            instance on which to invoke the serviceMethod
 * @param serviceMethod
 *            the method to invoke
 * @param args
 *            arguments used for the method invocation
 * @param serializationPolicy
 *            determines the serialization policy to be used
 * @return a string which encodes either the method's return or a checked
 *         exception thrown by the method
 * 
 * @throws NullPointerException
 *             if the serviceMethod or the serializationPolicy are
 *             <code>null</code>
 * @throws SecurityException
 *             if the method cannot be accessed or if the number or type of
 *             actual and formal arguments differ
 * @throws SerializationException
 *             if an object could not be serialized by the stream
 * @throws UnexpectedException
 *             if the serviceMethod throws a checked exception that is not
 *             declared in its signature
 */
public static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args,
        SerializationPolicy serializationPolicy) throws SerializationException {
    return invokeAndEncodeResponse(target, serviceMethod, args, serializationPolicy,
            AbstractSerializationStream.DEFAULT_FLAGS);
}

From source file:com.foo.server.rpc230.CustomRPC.java

License:Apache License

/**
 * Returns a string that encodes an exception. If method is not
 * <code>null</code>, it is an error if the exception is not in the method's
 * list of checked exceptions.//from  ww  w .  j  ava  2 s . c o m
 * 
 * <p>
 * If the serializationPolicy parameter is not <code>null</code>, it is used
 * to determine what types can be encoded as part of this response. If this
 * parameter is <code>null</code>, then only subtypes of
 * {@link com.google.gwt.user.client.rpc.IsSerializable IsSerializable} or
 * types which have custom field serializers may be encoded.
 * </p>
 * 
 * @param serviceMethod
 *            the method that threw the exception, may be <code>null</code>
 * @param cause
 *            the {@link Throwable} that was thrown
 * @param serializationPolicy
 *            determines the serialization policy to be used
 * @return a string that encodes the exception
 * 
 * @throws NullPointerException
 *             if the the cause or the serializationPolicy are
 *             <code>null</code>
 * @throws SerializationException
 *             if the result cannot be serialized
 * @throws UnexpectedException
 *             if the result was an unexpected exception (a checked
 *             exception not declared in the serviceMethod's signature)
 */
public static String encodeResponseForFailure(Method serviceMethod, Throwable cause,
        SerializationPolicy serializationPolicy) throws SerializationException {
    return encodeResponseForFailure(serviceMethod, cause,
            new ServerSerializationStreamWriterSenasa(serializationPolicy),
            AbstractSerializationStream.DEFAULT_FLAGS);
}

From source file:com.foo.server.rpc230.CustomRPC.java

License:Apache License

/**
 * Returns a string that encodes the object. It is an error to try to encode
 * an object that is not assignable to the service method's return type.
 * /*from  w  w  w.  j  av  a2s  .co  m*/
 * <p>
 * If the serializationPolicy parameter is not <code>null</code>, it is used
 * to determine what types can be encoded as part of this response. If this
 * parameter is <code>null</code>, then only subtypes of
 * {@link com.google.gwt.user.client.rpc.IsSerializable IsSerializable} or
 * types which have custom field serializers may be encoded.
 * </p>
 * 
 * @param serviceMethod
 *            the method whose result we are encoding
 * @param object
 *            the instance that we wish to encode
 * @param serializationPolicy
 *            determines the serialization policy to be used
 * @return a string that encodes the object, if the object is compatible
 *         with the service method's declared return type
 * 
 * @throws IllegalArgumentException
 *             if the result is not assignable to the service method's
 *             return type
 * @throws NullPointerException
 *             if the serviceMethod or the serializationPolicy are
 *             <code>null</code>
 * @throws SerializationException
 *             if the result cannot be serialized
 */
public static String encodeResponseForSuccess(Method serviceMethod, Object object,
        SerializationPolicy serializationPolicy) throws SerializationException {
    return encodeResponseForSuccess(serviceMethod, object,
            new ServerSerializationStreamWriterSenasa(serializationPolicy),
            AbstractSerializationStream.DEFAULT_FLAGS);
}

From source file:com.foo.server.rpc230.CustomRPC.java

License:Apache License

/**
 * Returns a string that encodes the result of calling a service method,
 * which could be the value returned by the method or an exception thrown by
 * it.//from w  w w  . j  av  a2s.c o  m
 * 
 * <p>
 * If the serializationPolicy parameter is not <code>null</code>, it is used
 * to determine what types can be encoded as part of this response. If this
 * parameter is <code>null</code>, then only subtypes of
 * {@link com.google.gwt.user.client.rpc.IsSerializable IsSerializable} or
 * types which have custom field serializers may be encoded.
 * </p>
 * 
 * <p>
 * This method does no security checking; security checking must be done on
 * the method prior to this invocation.
 * </p>
 * 
 * @param target
 *            instance on which to invoke the serviceMethod
 * @param serviceMethod
 *            the method to invoke
 * @param args
 *            arguments used for the method invocation
 * @param serializationPolicy
 *            determines the serialization policy to be used
 * @return a string which encodes either the method's return or a checked
 *         exception thrown by the method
 * 
 * @throws NullPointerException
 *             if the serviceMethod or the serializationPolicy are
 *             <code>null</code>
 * @throws SecurityException
 *             if the method cannot be accessed or if the number or type of
 *             actual and formal arguments differ
 * @throws SerializationException
 *             if an object could not be serialized by the stream
 * @throws UnexpectedException
 *             if the serviceMethod throws a checked exception that is not
 *             declared in its signature
 */
public static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args,
        ServerSerializationStreamWriterSenasa streamWriter) throws SerializationException {
    return invokeAndEncodeResponse(target, serviceMethod, args, streamWriter,
            AbstractSerializationStream.DEFAULT_FLAGS);
}

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 ww  . ja v  a2 s  .  c  o 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:controllers.GWT2Controller.java

License:Apache License

/**
 * Invoke a Service //www  .ja  va2 s .  com
 * 
 * This way GWT2Service is allowed to use GWT2Chain
 * 
 * @param mod
 * @return
 * @throws Exception 
 */
private static String invoke(GWT2Service service, RPCRequest rpcRequest) throws Exception {
    String responseload = null;

    try {
        // Get GWt2Invoker
        GWT2Invoker invoker = new GWT2Invoker(service, request, response, session, rpcRequest);

        // run 
        boolean run = true;
        Object result = null;
        Object chainResult = null;
        boolean firstcall = true;
        GWT2ChainRuntime chain = null;
        while (run) {
            try {
                if (firstcall) {
                    firstcall = false;
                    // call service
                    result = invoker.invoke();
                    // get a result stop request
                    run = false;
                } else if (chain != null) {
                    // call callback
                    result = chain.getChain().chain(chainResult);
                    // get a result stop request
                    run = false;
                } else {
                    // no callback to call stop process
                    run = false;
                }
            } catch (GWT2ChainAsync casync) {
                // async chain call
                chain = casync;
                chainResult = chainAwait(chain);
            } catch (GWT2ChainSync csync) {
                chain = csync;
                chainResult = chainDo(chain);
            } catch (InvocationTargetException ite) {
                if (ite.getTargetException() instanceof GWT2ChainAsync) {
                    // async chain call
                    chain = (GWT2ChainAsync) ite.getTargetException();
                    chainResult = chainAwait(chain);
                } else if (ite.getTargetException() instanceof GWT2ChainSync) {
                    chain = (GWT2ChainSync) ite.getTargetException();
                    chainResult = chainDo(chain);
                } else
                    throw ite;
            }
        }

        // encode result
        responseload = RPC.encodeResponseForSuccess(rpcRequest.getMethod(), result,
                rpcRequest.getSerializationPolicy(), AbstractSerializationStream.DEFAULT_FLAGS);

        return responseload;

    } catch (Exception ex) {
        if (ex instanceof PlayException)
            // Rethrow the enclosed exception
            throw (PlayException) ex;

        // if not gwt rpc rethrow
        if (!isGWT())
            throw ex;

        try {
            // else encode error
            responseload = RPC.encodeResponseForFailure(rpcRequest.getMethod(), ex,
                    rpcRequest.getSerializationPolicy(), AbstractSerializationStream.DEFAULT_FLAGS);

        } catch (SerializationException e) {
            StackTraceElement element = PlayException.getInterestingStrackTraceElement(e);
            if (element != null) {
                throw new JavaExecutionException(Play.classes.getApplicationClass(element.getClassName()),
                        element.getLineNumber(), e);
            }
            throw new JavaExecutionException(e);
        }
    }

    return responseload;
}

From source file:org.spring4gwt.server.RPCHelper.java

License:Apache License

public static String invokeAndEncodeResponse(Object target, Method serviceMethod, Object[] args,
        SerializationPolicy serializationPolicy) throws SerializationException {
    return invokeAndEncodeResponse(target, serviceMethod, args, serializationPolicy,
            AbstractSerializationStream.DEFAULT_FLAGS);
}

From source file:play.modules.gwt2.GWT2Invoker.java

License:Apache License

/**
 * Invoke a service//w  w w.ja  va 2  s .c  om
 * @param service
 */
public void doJob() {

    result = null;
    try {
        // invoke
        result = invoke();
        // encode result
        responseload = RPC.encodeResponseForSuccess(rpcRequest.getMethod(), result,
                rpcRequest.getSerializationPolicy(), AbstractSerializationStream.DEFAULT_FLAGS);

    } catch (Exception ex) {
        if (ex instanceof PlayException)
            // Rethrow the enclosed exception
            throw (PlayException) ex;

        try {
            if (GWT2ChainRuntime.class.isAssignableFrom(ex.getClass())) {
                responseload = RPC.encodeResponseForFailure(rpcRequest.getMethod(),
                        new JavaExecutionException(
                                "Chain call is not allowed when runngin Service in async mode", ex),
                        rpcRequest.getSerializationPolicy(), AbstractSerializationStream.DEFAULT_FLAGS);
            } else {
                responseload = RPC.encodeResponseForFailure(rpcRequest.getMethod(), ex,
                        rpcRequest.getSerializationPolicy(), AbstractSerializationStream.DEFAULT_FLAGS);
            }
        } catch (SerializationException e) {
            StackTraceElement element = PlayException.getInterestingStrackTraceElement(e);
            if (element != null) {
                throw new JavaExecutionException(Play.classes.getApplicationClass(element.getClassName()),
                        element.getLineNumber(), e);
            }
            throw new JavaExecutionException(e);
        }
    }
}