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

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

Introduction

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

Prototype

@Nullable
public Object getValue() 

Source Link

Document

Return the result value returned by a successful invocation of the target method, if any.

Usage

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:org.logicblaze.lingo.DefaultResultJoinStrategy.java

public RemoteInvocationResult mergeResponses(RemoteInvocationResult currentResult,
        RemoteInvocationResult newResult, int responseCount) {
    Object value = currentResult.getValue();
    Object newValue = newResult.getValue();
    if (value instanceof Collection) {
        Collection coll = (Collection) value;
        if (newValue instanceof Collection) {
            coll.addAll((Collection) newValue);
        } else {/*from  w w w .  j  av  a2  s  . c  o  m*/
            coll.add(newValue);
        }
    } else if (value instanceof Map && newValue instanceof Map) {
        Map map = (Map) value;
        map.putAll((Map) newValue);
    }
    return currentResult;
}

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();
    String type = content == null ? null : content.getClass().getName();

    JsonGenerator generator = factory.createJsonGenerator(os);
    generator.setCodec(codec);/*from  w  w w  . j a  v a  2 s  . co m*/

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

From source file:com.springsource.insight.plugin.springweb.remoting.SimpleHttpInvokerRequestExecutorAspectTest.java

@Test
public void testSimpleHttpInvokerRequestExecutor() throws Exception {
    RemoteInvocation invocation = new RemoteInvocation("testSimpleHttpInvokerRequestExecutor",
            new Class[] { Long.class }, new Object[] { Long.valueOf(System.nanoTime()) });
    TestingSimpleHttpInvokerRequestExecutor executor = new TestingSimpleHttpInvokerRequestExecutor(
            invocation.getMethodName());
    HttpInvokerClientConfiguration config = createMockConfiguration(executor.getColor(),
            ArrayUtil.EMPTY_STRINGS);/*from w ww. j av a 2  s  . co m*/
    RemoteInvocationResult result = executor.executeRequest(config, invocation);
    Object value = result.getValue();
    assertNotNull("No result value", value);
    assertTrue("Bad result value type: " + value.getClass().getSimpleName(), value instanceof RemoteInvocation);

    RemoteInvocation resultValue = (RemoteInvocation) value;
    assertEquals("Mismatched result method", invocation.getMethodName(), resultValue.getMethodName());
    assertArrayEquals("Mismatched result signature", invocation.getParameterTypes(),
            resultValue.getParameterTypes());
    assertArrayEquals("Mismatched result arguments", invocation.getArguments(), resultValue.getArguments());

    Operation op = assertRemotingOperation(config);
    assertEquals("Mismatched request method", executor.getMethod(), op.get("method", String.class));

    ExternalResourceDescriptor desc = assertExternalResource(op);
    assertNotNull("No external resource generated", desc);
}

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());
}