Search in sources :

Example 1 with SerializationException

use of com.haulmont.cuba.core.sys.serialization.SerializationException in project cuba by cuba-platform.

the class HttpServiceExporter method handleRequest.

/*
     * In base implementation, exceptions which are thrown during reading remote invocation request, are not handled.
     * Client gets useless HTTP status 500 in this case.
     *
     * This implementation passes some known exceptions to client.
     */
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (!ServiceExportHelper.exposeServices()) {
        logger.debug("Services are not exposed due to 'cuba.doNotExposeRemoteServices' is set to true");
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    RemoteInvocationResult result;
    RemoteInvocation invocation = null;
    try {
        invocation = readRemoteInvocation(request);
        result = invokeAndCreateResult(invocation, getProxy());
    } catch (OptionalDataException | ClassCastException e) {
        // typical binary incompatibility exceptions
        logger.error("Failed to read remote invocation request", e);
        result = new RemoteInvocationResult(e);
    } catch (ClassNotFoundException ex) {
        throw new NestedServletException("Class not found during deserialization", ex);
    }
    try {
        writeRemoteInvocationResult(request, response, result);
    } catch (SerializationException e) {
        String serviceName = null;
        if (getServiceInterface() != null) {
            serviceName = getServiceInterface().getSimpleName();
        }
        String methodName = null;
        String paramTypes = null;
        if (invocation != null) {
            methodName = invocation.getMethodName();
            if (invocation.getParameterTypes() != null) {
                paramTypes = Joiner.on(",").join(invocation.getParameterTypes());
            }
        }
        throw new NestedServletException(String.format("Failed to write result for service [%s.%s(%s)]", serviceName, methodName, paramTypes), e);
    }
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) NestedServletException(org.springframework.web.util.NestedServletException) SerializationException(com.haulmont.cuba.core.sys.serialization.SerializationException) RemoteInvocationResult(org.springframework.remoting.support.RemoteInvocationResult) OptionalDataException(java.io.OptionalDataException)

Aggregations

SerializationException (com.haulmont.cuba.core.sys.serialization.SerializationException)1 OptionalDataException (java.io.OptionalDataException)1 RemoteInvocation (org.springframework.remoting.support.RemoteInvocation)1 RemoteInvocationResult (org.springframework.remoting.support.RemoteInvocationResult)1 NestedServletException (org.springframework.web.util.NestedServletException)1