Example usage for com.google.gwt.user.server.rpc.impl LegacySerializationPolicy getInstance

List of usage examples for com.google.gwt.user.server.rpc.impl LegacySerializationPolicy getInstance

Introduction

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

Prototype

public static LegacySerializationPolicy getInstance() 

Source Link

Usage

From source file:com.apress.progwt.server.gwt.RPC1524.java

License:Apache License

/**
 * Returns a default serialization policy.
 * //from ww  w. ja  va  2s  .  com
 * @return the default serialization policy.
 */
public static SerializationPolicy getDefaultSerializationPolicy() {
    return LegacySerializationPolicy.getInstance();
}

From source file:org.jboss.seam.remoting.gwt.GWTRemoteServiceServlet.java

License:Open Source License

/**
 * This is public so that it can be unit tested easily without HTTP.
 *//*from   w ww.j a v a 2  s.c o  m*/
public String processCall(String payload) throws SerializationException {

    // Let subclasses see the serialized request.
    //
    onBeforeRequestDeserialized(payload);

    // Create a stream to deserialize the request.
    //
    ServerSerializationStreamReader streamReader = new ServerSerializationStreamReader(
            Thread.currentThread().getContextClassLoader(), null);

    streamReader.prepareToRead(payload);

    // Read the service interface
    //
    String serviceIntfName = streamReader.readString();

    //    // TODO(mmendez): need a way to check the type signature of the service intf
    //    // Verify that this very servlet implements the specified interface name.
    //    //
    //    if (!isImplementedRemoteServiceInterface(serviceIntfName)) {
    //      // Bad payload, possible hack attempt.
    //      //
    //      throw new SecurityException(
    //          "Blocked attempt to access interface '"
    //              + serviceIntfName
    //              + "', which is either not implemented by this servlet or which doesn't extend RemoteService; this is either misconfiguration or a hack attempt");
    //    }

    // Actually get the service interface, so that we can query its methods.
    //
    //    Class serviceIntf;
    //    try {
    //      serviceIntf = getClassFromName(serviceIntfName);
    //    } catch (ClassNotFoundException e) {
    //      throw new SerializationException("Unknown service interface class '"
    //          + serviceIntfName + "'", e);
    //    }

    // Read the method name.
    //
    String methodName = streamReader.readString();

    // Read the number and names of the parameter classes from the stream.
    // We have to do this so that we can find the correct overload of the
    // method.
    //
    int paramCount = streamReader.readInt();
    Class[] paramTypes = new Class[paramCount];
    for (int i = 0; i < paramTypes.length; i++) {
        String paramClassName = streamReader.readString();
        try {
            paramTypes[i] = getClassOrPrimitiveFromName(paramClassName);
        } catch (ClassNotFoundException e) {
            throw new SerializationException("Unknown parameter " + i + " type '" + paramClassName + "'", e);
        }
    }

    //    // For security, make sure the method is found in the service interface
    //    // and not just one that happens to be defined on this class.
    //    //
    //    Method serviceIntfMethod = findInterfaceMethod(serviceIntf, methodName,
    //        paramTypes, true);

    //    // If it wasn't found, don't continue.
    //    //
    //    if (serviceIntfMethod == null) {
    //      // Bad payload, possible hack attempt.
    //      //
    //      throw new SecurityException(
    //          "Method '"
    //              + methodName
    //              + "' (or a particular overload) on interface '"
    //              + serviceIntfName
    //              + "' was not found, this is either misconfiguration or a hack attempt");
    //    }

    // Deserialize the parameters.
    //
    Object[] args = new Object[paramCount];
    for (int i = 0; i < args.length; i++) {
        args[i] = streamReader.deserializeValue(paramTypes[i]);
    }

    GWTToSeamAdapter adapter = new GWTToSeamAdapter();

    // Make the call via reflection.
    //
    String responsePayload = GENERIC_FAILURE_MSG;
    ServerSerializationStreamWriter streamWriter = new ServerSerializationStreamWriter(
            LegacySerializationPolicy.getInstance());
    Throwable caught = null;
    try {

        //call the component
        ReturnedObject returnedObject = adapter.callWebRemoteMethod(serviceIntfName, methodName, paramTypes,
                args);
        Class returnType = returnedObject.returnType;
        Object returnVal = returnedObject.returnedObject;
        //      Class returnType = serviceIntfMethod.getReturnType();
        //      Object returnVal = serviceIntfMethod.invoke(this, args);
        responsePayload = createResponse(streamWriter, returnType, returnVal, false);
    } catch (IllegalArgumentException e) {
        caught = e;
    } catch (IllegalAccessException e) {
        caught = e;
    } catch (InvocationTargetException e) {
        // Try to serialize the caught exception if the client is expecting it,
        // otherwise log the exception server-side.
        caught = e;
        Throwable cause = e.getCause();
        if (cause != null) {
            // Update the caught exception to the underlying cause
            caught = cause;
            // Serialize the exception back to the client if it's a declared
            // exception
            if (cause instanceof SerializableException) {
                Class thrownClass = cause.getClass();
                responsePayload = createResponse(streamWriter, thrownClass, cause, true);
                // Don't log the exception on the server
                caught = null;
            }
        }
    }

    if (caught != null) {

        responsePayload = GENERIC_FAILURE_MSG;
        ServletContext servletContext = getServletContext();
        // servletContext may be null (for example, when unit testing)
        if (servletContext != null) {
            // Log the exception server side
            servletContext.log("Exception while dispatching incoming RPC call", caught);
        }
    }

    // Let subclasses see the serialized response.
    //
    onAfterResponseSerialized(responsePayload);

    return responsePayload;
}