Example usage for org.springframework.remoting.support RemoteInvocationResult getException

List of usage examples for org.springframework.remoting.support RemoteInvocationResult getException

Introduction

In this page you can find the example usage for org.springframework.remoting.support RemoteInvocationResult getException.

Prototype

@Nullable
public Throwable getException() 

Source Link

Document

Return the exception thrown by an unsuccessful invocation of the target method, if any.

Usage

From source file:com.seajas.search.utilities.remoting.JsonInvokerServiceExporter.java

@Override
protected void writeRemoteInvocationResult(HttpExchange exchange, RemoteInvocationResult result,
        OutputStream os) throws IOException {
    Object content = result.getException();
    if (content == null)
        content = result.getValue();/*from  w w  w.jav  a  2  s  . c o  m*/
    String type = content == null ? null : content.getClass().getName();

    JsonGenerator generator = factory.createJsonGenerator(os);
    generator.setCodec(codec);

    generator.writeStartObject();
    generator.writeFieldName("type");
    generator.writeString(type);
    generator.writeFieldName("content");
    generator.writeObject(content);
    generator.writeEndObject();
    generator.close();
}

From source file:com.seajas.search.utilities.remoting.JsonHttpSupport.java

@Test
public void resultError() throws Exception {
    Throwable error = new RuntimeException("test");
    RemoteInvocationResult result = new RemoteInvocationResult(error);

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    exporter.writeRemoteInvocationResult(null, result, buffer);
    ByteArrayInputStream stream = new ByteArrayInputStream(buffer.toByteArray());
    RemoteInvocationResult deserialized = executor.readRemoteInvocationResult(stream, null);
    assertNull(deserialized.getValue());
    assertNotNull(deserialized.getException());
    assertEquals(error.getClass(), deserialized.getException().getClass());
    assertEquals(error.getMessage(), deserialized.getException().getMessage());
}

From source file:com.seajas.search.utilities.remoting.JsonHttpSupport.java

@Test
public void resultValue() throws Exception {
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("a", null);
    map.put("b", "text");
    // stack overflow: map.put("c", map);
    RemoteInvocationResult result = new RemoteInvocationResult(map);

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    exporter.writeRemoteInvocationResult(null, result, buffer);
    ByteArrayInputStream stream = new ByteArrayInputStream(buffer.toByteArray());
    RemoteInvocationResult deserialized = executor.readRemoteInvocationResult(stream, null);
    assertEquals(result.getValue(), deserialized.getValue());
    assertNull(deserialized.getException());
}

From source file:org.piraso.replacer.spring.remoting.PirasoHttpInvokerProxyFactoryBean.java

@Override
protected RemoteInvocationResult executeRequest(RemoteInvocation invocation,
        MethodInvocation originalInvocation) throws Exception {
    ElapseTimeEntry elapseTime = null;//from  ww w.ja  v a  2s  . c  om

    if (context.isMonitored()) {
        try {
            if (pref.isEnabled(SpringPreferenceEnum.REMOTING_ELAPSE_TIME_ENABLED)) {
                elapseTime = new ElapseTimeEntry();
                elapseTime.start();
            }

            if (pref.isEnabled(SpringPreferenceEnum.REMOTING_METHOD_CALL_ENABLED)) {
                String declaringClass = originalInvocation.getMethod().getDeclaringClass().getName();
                String methodName = originalInvocation.getMethod().getName();

                Level level = Level.get(SpringPreferenceEnum.REMOTING_ENABLED.getPropertyName());
                SpringRemotingStartEntry entry = new SpringRemotingStartEntry(
                        "START (" + methodName + "): " + originalInvocation.getMethod().toGenericString(),
                        invocation);
                entry.setMethodName(methodName);
                entry.setMethodSignature(originalInvocation.getMethod().toGenericString());
                entry.setUrl(getServiceUrl());
                entry.setServiceInterface(getServiceInterface().getName());

                if (pref.isStackTraceEnabled()) {
                    entry.setStackTrace(EntryUtils.toEntry(Thread.currentThread().getStackTrace()));
                }

                ContextLogDispatcher.forward(level, new GroupChainId(declaringClass), entry);
            }
        } catch (Exception e) {
            LOG.warn(e.getMessage(), e);
        }
    }

    RemoteInvocationResult result = super.executeRequest(invocation, originalInvocation);

    if (context.isMonitored()) {
        try {
            String declaringClass = originalInvocation.getMethod().getDeclaringClass().getName();
            String methodName = originalInvocation.getMethod().getName();

            if (elapseTime != null) {
                elapseTime.stop();

                Level level = Level.get(SpringPreferenceEnum.REMOTING_ENABLED.getPropertyName());
                MessageEntry entry = new MessageEntry("Elapse Time", elapseTime);

                ContextLogDispatcher.forward(level, new GroupChainId(declaringClass), entry);
            }

            if (context.isMonitored() && pref.isEnabled(SpringPreferenceEnum.REMOTING_METHOD_CALL_ENABLED)) {
                Level level = Level.get(SpringPreferenceEnum.REMOTING_ENABLED.getPropertyName());
                SpringRemotingEndEntry entry = new SpringRemotingEndEntry(
                        "END (" + methodName + "): Returned Value ", result);
                entry.setMethodName(methodName);
                entry.setUrl(getServiceUrl());
                entry.setServiceInterface(getServiceInterface().getName());

                if (result.getException() != null) {
                    entry.setThrown(new ThrowableEntry(result.getException()));
                }

                ContextLogDispatcher.forward(level, new GroupChainId(declaringClass), entry);
            }
        } catch (Exception e) {
            LOG.warn(e.getMessage(), e);
        }
    }

    return result;
}