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

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

Introduction

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

Prototype

public IncompatibleRemoteServiceException(String msg, Throwable cause) 

Source Link

Document

Constructs an instance with the specified message and cause.

Usage

From source file:com.seanchenxi.resteasy.autobean.client.BaseResponseHandler.java

License:Apache License

@Override
protected void handleResponse(Response response, Class<T> clazz, AsyncCallback<T> callback,
        String resourceName) {//from   w ww  . j  a v  a  2  s . c  o m
    T result = null;
    Throwable caught = null;
    try {
        RESTResponse restResponse = REST.decodeResponse(response.getText());
        int statusCode = response.getStatusCode();
        if (statusCode != Response.SC_OK) {
            caught = new StatusCodeException(statusCode, response.getText());
        } else if (restResponse == null) {
            caught = new InvocationException(
                    "No response payload from " + uri + " of resource " + resourceName);
        } else if (REST.isReturnValue(restResponse)) {
            if (!Void.class.equals(clazz)) {
                Splittable data = StringQuoter.split(restResponse.getPayload());
                if (data != null)
                    result = (T) REST.decodeData(clazz, data);
            }
        } else if (REST.isThrowable(restResponse)) {
            caught = REST.decodeThrowable(restResponse.getPayload());
        } else {
            caught = new InvocationException(restResponse + " from " + uri + " of resource " + resourceName);
        }
    } catch (SerializationException e) {
        caught = new IncompatibleRemoteServiceException(
                "The response: \n{" + response.getText() + "}\n could not be deserialized", e);
    } catch (Throwable e) {
        caught = e;
    }

    if (caught != null) {
        callback.onFailure(caught);
    } else {
        callback.onSuccess(result);
    }
}

From source file:org.cruxframework.crux.core.server.dispatch.RemoteServiceServlet.java

License:Apache License

/**
 * @param rpcRequest//  w w  w  .j a  va  2  s .  c  o  m
 * @param handler
 * @return
 * @throws IncompatibleRemoteServiceException
 */
protected boolean checkSynchonizerToken(RPCRequest rpcRequest, CruxSynchronizerTokenHandler handler)
        throws IncompatibleRemoteServiceException {
    Method method = rpcRequest.getMethod();
    if (method.getAnnotation(UseSynchronizerToken.class) != null) {
        String methodFullSignature = handler.getMethodDescription(method);
        if (!handler.isMethodRunning(methodFullSignature)) {
            try {
                handler.startMethod(methodFullSignature);
                return true;
            } catch (InvalidTokenException e) {
                throw new IncompatibleRemoteServiceException(e.getLocalizedMessage(), e);
            }
        } else {
            throw new IncompatibleRemoteServiceException("Invalid Synchronizer Token for method ["
                    + methodFullSignature + "]. Possible CSRF attack.");
        }
    }
    return false;
}

From source file:org.cruxframework.crux.core.server.dispatch.RemoteServiceServlet.java

License:Apache License

/**
 * Return the service that will handle this request
 * @param encodedRequest/*w  w  w  .  jav  a2  s  .c  o  m*/
 * @return
 * @throws IncompatibleRemoteServiceException
 */
protected Object getServiceForRequest(String encodedRequest) throws IncompatibleRemoteServiceException {
    try {
        if (!ServiceFactoryInitializer.isFactoryInitialized()) {
            ServiceFactoryInitializer.initialize(getServletContext());
        }

        // We don't need to verify or parse the encodedRequest because it will be already done by
        // RPC.decodeRequest. So, just read the interface name directly
        String serviceIntfName = RegexpPatterns.REGEXP_PIPE.split(encodedRequest)[5];
        Object service = ServiceFactoryInitializer.getServiceFactory().getService(serviceIntfName);
        if (service instanceof RequestAware) {
            ((RequestAware) service).setRequest(getThreadLocalRequest());
        }
        if (service instanceof ResponseAware) {
            ((ResponseAware) service).setResponse(getThreadLocalResponse());
        }
        if (service instanceof SessionAware) {
            ((SessionAware) service).setSession(getThreadLocalRequest().getSession());
        }
        return service;
    } catch (Throwable e) {
        throw new IncompatibleRemoteServiceException(e.getLocalizedMessage(), e);
    }
}

From source file:org.slim3.gwt.server.rpc.GWTServiceServlet.java

License:Apache License

/**
 * Returns RPC request./*from w w w . ja v  a  2s .c o  m*/
 * 
 * @param encodedRequest
 *            a string that encodes the service interface, the service
 *            method, and the arguments
 * @return RPC request
 * 
 * @throws NullPointerException
 *             if the encodedRequest is <code>null</code>
 * @throws IllegalArgumentException
 *             if the encodedRequest is an empty string
 * @throws IncompatibleRemoteServiceException
 *             if any of the following conditions apply:
 *             <ul>
 *             <li>if the types in the encoded request cannot be
 *             deserialized</li>
 *             <li>if the {@link ClassLoader} acquired from
 *             <code>Thread.currentThread().getContextClassLoader()</code>
 *             cannot load the service interface or any of the types
 *             specified in the encodedRequest</li>
 *             <li>the requested interface is not assignable to
 *             {@link RemoteService}</li>
 *             <li>the service method requested in the encodedRequest is not
 *             a member of the requested service interface</li>
 *             <li>the type parameter is not <code>null</code> and is not
 *             assignable to the requested {@link RemoteService} interface
 *             </ul>
 */
protected S3RPCRequest decodeRequest(String encodedRequest) {
    if (encodedRequest == null) {
        throw new NullPointerException("The encodedRequest parameter cannot be null.");
    }
    if (encodedRequest.length() == 0) {
        throw new IllegalArgumentException("The encodedRequest parameter cannot be empty.");
    }
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    try {
        ServerSerializationStreamReader streamReader = new ServerSerializationStreamReader(classLoader, this);
        streamReader.prepareToRead(encodedRequest);
        String interfaceName = readClassName(streamReader);
        Class<?> serviceClass = getServiceClass(interfaceName);
        Object service = getService(serviceClass);
        SerializationPolicy serializationPolicy = streamReader.getSerializationPolicy();
        String methodName = streamReader.readString();
        int paramCount = streamReader.readInt();
        Class<?>[] parameterTypes = new Class[paramCount];
        for (int i = 0; i < parameterTypes.length; i++) {
            String paramClassName = readClassName(streamReader);
            parameterTypes[i] = getClass(paramClassName);
        }
        try {
            Method method = serviceClass.getMethod(methodName, parameterTypes);
            Object[] parameterValues = new Object[parameterTypes.length];
            for (int i = 0; i < parameterValues.length; i++) {
                parameterValues[i] = streamReader.deserializeValue(parameterTypes[i]);
            }
            return new S3RPCRequest(service,
                    new RPCRequest(method, parameterValues, serializationPolicy, streamReader.getFlags()));

        } catch (NoSuchMethodException e) {
            throw new IncompatibleRemoteServiceException(e.getMessage(), e);
        }
    } catch (SerializationException ex) {
        throw new IncompatibleRemoteServiceException(ex.getMessage(), ex);
    }
}

From source file:org.slim3.gwt.server.rpc.GWTServiceServlet.java

License:Apache License

/**
 * Invokes the service method./*  w ww .j  av  a 2  s .  c  o m*/
 * 
 * @param service
 *            the service
 * @param method
 *            the method
 * @param args
 *            the arguments
 * @return the return value of the method
 * @throws InvocationTargetException
 *             if the method throws an exception
 */
protected Object invoke(Object service, Method method, Object[] args) throws InvocationTargetException {
    Object result = null;
    try {
        result = method.invoke(service, args);
    } catch (IllegalArgumentException e) {
        throw new IncompatibleRemoteServiceException(e.getMessage(), e);
    } catch (IllegalAccessException e) {
        throw new IncompatibleRemoteServiceException(e.getMessage(), e);
    } catch (ClassCastException e) {
        String msg = e.getMessage();
        String[] msgs = StringUtil.split(msg, " ");
        if (msgs.length > 2 && msgs[0].equals(msgs[msgs.length - 1])) {
            msg = "The class(" + msgs[0] + ") is loaded by deferent class loaders.";
        }
        throw new IncompatibleRemoteServiceException(msg, e);
    }
    return result;
}

From source file:org.slim3.gwt.server.rpc.GWTServiceServlet.java

License:Apache License

/**
 * Returns the class specified by the name.
 * // w  w w .  j a  v  a  2  s .com
 * @param className
 *            the class name
 * @return the class
 * @throws NullPointerException
 *             if the className parameter is null
 */
protected Class<?> getClass(String className) throws NullPointerException {
    if (className == null) {
        throw new NullPointerException("The className parameter is null.");
    }
    Class<?> clazz = TYPE_NAMES.get(className);
    if (clazz != null) {
        return clazz;
    }
    try {
        return Class.forName(className, false, Thread.currentThread().getContextClassLoader());
    } catch (ClassNotFoundException e) {
        throw new IncompatibleRemoteServiceException(
                "Could not load the class(" + className + ") in context classloader", e);
    }
}

From source file:org.talend.mdm.webapp.general.gwt.ProxyGWTServiceImpl.java

License:Open Source License

private String getServiceIntfName(String encodedRequest) {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    ServerSerializationStreamReader streamReader = new ServerSerializationStreamReader(classLoader, this);
    try {/*from  ww  w . j  a  va 2 s .com*/
        streamReader.prepareToRead(encodedRequest);
        return streamReader.readString();
    } catch (SerializationException ex) {
        throw new IncompatibleRemoteServiceException(ex.getMessage(), ex);
    }
}