Example usage for org.springframework.remoting.support RemoteInvocation RemoteInvocation

List of usage examples for org.springframework.remoting.support RemoteInvocation RemoteInvocation

Introduction

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

Prototype

public RemoteInvocation(String methodName, Class<?>[] parameterTypes, Object[] arguments) 

Source Link

Document

Create a new RemoteInvocation for the given parameters.

Usage

From source file:org.apache.mina.springrpc.RemoteInvocationFactory.java

public static RemoteInvocation createHashCodeRemoteInvocation() {
    return new RemoteInvocation("hashCode", new Class[] {}, new Object[] {});
}

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

@Test
public void invocation() throws Exception {
    String method = "testMethodName";
    Class[] types = new Class[] { Boolean.class, String.class, Number.class };
    Object[] arguments = new Object[] { Boolean.TRUE, null, new Integer(2) };
    RemoteInvocation invocation = new RemoteInvocation(method, types, arguments);

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    executor.writeRemoteInvocation(invocation, buffer);
    ByteArrayInputStream stream = new ByteArrayInputStream(buffer.toByteArray());
    RemoteInvocation deserialized = exporter.readRemoteInvocation(null, stream);
    assertEquals("method", method, deserialized.getMethodName());
    assertArrayEquals("types", types, deserialized.getParameterTypes());
    assertArrayEquals("arguments", arguments, deserialized.getArguments());
}

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

@Override
protected RemoteInvocation readRemoteInvocation(HttpExchange exchange, InputStream is) throws IOException {
    JsonParser parser = factory.createJsonParser(is);
    parser.setCodec(codec);// ww w.ja  v a 2 s .  co m

    System.err.println(parser.nextToken());
    openField("method", parser);
    String method = parser.getText();
    List<Class<?>> types = new ArrayList<Class<?>>();
    for (JsonToken next = openField("types", parser); next != JsonToken.END_ARRAY; next = parser.nextToken()) {
        try {
            types.add(Class.forName(parser.getText()));
        } catch (ClassNotFoundException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
    }
    List<Object> arguments = new ArrayList<Object>();
    openField("arguments", parser);
    for (Class<?> type : types) {
        parser.nextToken();
        arguments.add(parser.readValueAs(type));
    }
    return new RemoteInvocation(method, types.toArray(new Class[types.size()]), arguments.toArray());
}

From source file:ch.there.gson.GsonInvokerServiceExporter.java

@Override
public void handle(HttpExchange exchange) throws IOException {
    Gson gson = GsonFactory.getGson();/*  w  w w  .  j  a  va  2s  .com*/

    try {
        Integer rpcVersion = Integer.valueOf(exchange.getRequestHeaders().getFirst("rpc-version"));
        CallerRemoteApiVersion.setVersion(rpcVersion);
        InputStreamReader reader = new InputStreamReader(exchange.getRequestBody());
        JsonParser parser = new JsonParser();
        JsonObject remote = parser.parse(reader).getAsJsonObject();
        String methodName = remote.get("methodName").getAsString();

        Type collectionType = new TypeToken<Collection<Class<?>>>() {
        }.getType();
        Collection<Class<?>> parameterTypes = gson.fromJson(remote.get("parameterTypes"), collectionType);

        JsonArray args = remote.get("arguments").getAsJsonArray();
        Class<?>[] params = parameterTypes.toArray(new Class[parameterTypes.size()]);

        Object[] arguments = new Object[params.length];

        for (int i = 0; i < params.length; i++) {
            Class<?> clazz = params[i];
            Object argument = gson.fromJson(args.get(i), clazz);
            arguments[i] = argument;
        }

        RemoteInvocation remoteInvocation = new RemoteInvocation(methodName, params, arguments);
        RemoteInvocationResult result = invokeAndCreateResult(remoteInvocation, getProxy());
        writeRemoteInvocationResult(exchange, result);
        exchange.close();
    } catch (Throwable e) {
        e.printStackTrace();
    }

}

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  www. ja v a  2  s.c o 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);
}