Example usage for com.google.gwt.user.client.rpc SerializationException SerializationException

List of usage examples for com.google.gwt.user.client.rpc SerializationException SerializationException

Introduction

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

Prototype

public SerializationException(String msg, Throwable cause) 

Source Link

Usage

From source file:com.didactilab.gwt.phprpc.linker.WebClientOracleWriter.java

License:Apache License

public void write(String data) throws SerializationException {
    try {// w  w w.  ja  v  a2  s  .c o m
        byte[] bytes = data.getBytes("UTF-8");
        out.write(bytes);
    } catch (IOException e) {
        throw new SerializationException(e.getMessage(), e);
    }
}

From source file:com.xpn.xwiki.gwt.api.server.XWikiServiceImpl.java

License:Open Source License

/**
 * We override the default processCall method in order to provide XWiki initialization before we handle the request.
 * This allows us to initialize the XWiki Context and the new Container Objects (which are using ThreadLocal
 * variables)./*www  .  ja  v a 2s .co  m*/
 * 
 * @see RemoteServiceServlet#processCall(String)
 */
@Override
public String processCall(String payload) throws SerializationException {
    String result;

    try {
        initXWiki();
        result = super.processCall(payload);
    } catch (Exception e) {
        throw new SerializationException("Failed to initialize XWiki GWT subsystem", e);
    } finally {
        // Perform cleanup here
        cleanupContainerComponent();
    }

    return result;
}

From source file:org.gwtspringhibernate.reference.rlogman.spring.GwtServiceExporter.java

License:Apache License

/**
 * This is public so that it can be unit tested easily without HTTP.
 *///  w ww .j ava 2  s  .co  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(serializableTypeOracle);
    streamReader.prepareToRead(payload);

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

    // TODO(mmendez): need to check the signature
    // 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] = getClassFromName(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]);
    }

    // Make the call via reflection.
    //
    String responsePayload = GENERIC_FAILURE_MSG;
    ServerSerializationStreamWriter streamWriter = new ServerSerializationStreamWriter(serializableTypeOracle);
    Throwable caught = null;
    try {
        Class returnType = serviceIntfMethod.getReturnType();
        /**
         * The method is not invoked from <code>this</code> but from <code>this.proxy</code>;
         * <code>this</code> is the exporter, <code>this.proxy</code> is the actual service
         * implementation
         * @author rlogman@gmail.com
         */
        Object returnVal = serviceIntfMethod.invoke(this.proxy, 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 (isExpectedException(serviceIntfMethod, cause)) {
                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 may be null (for example, when unit testing)
        /**
         * Our logger will not be servlet context's log (we don't have
         * direct access to it at this point)
         * @author rlogman@gmail.com
         */
        if (logger != null) {
            // Log the exception server side
            logger.error("Exception while dispatching incoming RPC call", caught);
        }
    }

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

    return responsePayload;
}

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 w w  .  j a v a2 s  . co 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;
}

From source file:org.liveSense.service.gwt.GWTRPCServlet.java

License:Apache License

/**
 * Exception handler. Doublle exception handling
 * @param phase/*from   ww  w .j  a  v a 2 s .c o m*/
 * @param payload
 * @param e
 * @return
 */
private String processException(String phase, String payload, Throwable e) {
    String ret = "EX";
    try {
        ret = RPC.encodeResponseForFailure(null, e);
        payloadLogger.error(
                ">>> (" + phase + ") User: " + getUser() + " Payload: " + payload + " Return: " + ret, e);
    } catch (Exception ex) {
        try {
            ret = RPC.encodeResponseForFailure(null, new SerializationException("Serialization error", ex));
        } catch (SerializationException e2) {
        }
        payloadLogger.error(
                ">>> (" + phase + ") User: " + getUser() + " Payload: " + payload + " Return: " + ret, ex);
    }
    payloadLogger.info("<<< (" + phase + ") User: " + getUser() + " Return: " + ret);
    return ret;
}