Search in sources :

Example 26 with RemoteInvocation

use of org.springframework.remoting.support.RemoteInvocation in project dubbo by alibaba.

the class HttpProtocol method doRefer.

@SuppressWarnings("unchecked")
@Override
protected <T> T doRefer(final Class<T> serviceType, URL url) throws RpcException {
    final String generic = url.getParameter(GENERIC_KEY);
    final boolean isGeneric = ProtocolUtils.isGeneric(generic) || serviceType.equals(GenericService.class);
    JsonProxyFactoryBean jsonProxyFactoryBean = new JsonProxyFactoryBean();
    JsonRpcProxyFactoryBean jsonRpcProxyFactoryBean = new JsonRpcProxyFactoryBean(jsonProxyFactoryBean);
    jsonRpcProxyFactoryBean.setRemoteInvocationFactory((methodInvocation) -> {
        RemoteInvocation invocation = new JsonRemoteInvocation(methodInvocation);
        if (isGeneric) {
            invocation.addAttribute(GENERIC_KEY, generic);
        }
        return invocation;
    });
    String key = url.setProtocol("http").toIdentityString();
    if (isGeneric) {
        key = key + "/" + GENERIC_KEY;
    }
    jsonRpcProxyFactoryBean.setServiceUrl(key);
    jsonRpcProxyFactoryBean.setServiceInterface(serviceType);
    jsonProxyFactoryBean.afterPropertiesSet();
    return (T) jsonProxyFactoryBean.getObject();
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) GenericService(org.apache.dubbo.rpc.service.GenericService) JsonProxyFactoryBean(com.googlecode.jsonrpc4j.spring.JsonProxyFactoryBean)

Example 27 with RemoteInvocation

use of org.springframework.remoting.support.RemoteInvocation in project fastjson by alibaba.

the class Issue363 method test_for_issue.

public void test_for_issue() throws Exception {
    RemoteInvocation remoteInvocation = new RemoteInvocation();
    remoteInvocation.setMethodName("test");
    remoteInvocation.setParameterTypes(new Class[] { int.class, Date.class, String.class });
    remoteInvocation.setArguments(new Object[] { 1, new Date(), "this is a test" });
    String json = JSON.toJSONString(remoteInvocation);
    remoteInvocation = JSON.parseObject(json, RemoteInvocation.class);
    System.out.println(remoteInvocation);
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) Date(java.util.Date)

Example 28 with RemoteInvocation

use of org.springframework.remoting.support.RemoteInvocation in project gocd by gocd.

the class AgentRemoteInvokerServiceExporterTest method reportCompleted_rejectedForDifferentUUID.

@Test
void reportCompleted_rejectedForDifferentUUID() throws Exception {
    final AgentRuntimeInfo agent = runtimeInfo("other");
    final AgentRemoteInvokerServiceExporter invoker = deserializingWith(new RemoteInvocation("reportCompleted", new Class[] { AgentRuntimeInfo.class, JobIdentifier.class, JobResult.class }, new Object[] { agent, null, null }));
    invoker.handleRequest(req, res);
    verify(target, never()).reportCompleted(any(AgentRuntimeInfo.class), any(JobIdentifier.class), any(JobResult.class));
    assertEquals(SC_FORBIDDEN, res.getStatus());
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) JobResult(com.thoughtworks.go.domain.JobResult) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Test(org.junit.jupiter.api.Test)

Example 29 with RemoteInvocation

use of org.springframework.remoting.support.RemoteInvocation in project gocd by gocd.

the class AgentRemoteInvokerServiceExporterTest method deserializingWith.

private AgentRemoteInvokerServiceExporter deserializingWith(final RemoteInvocation invocation) {
    final AgentRemoteInvokerServiceExporter invoker = new AgentRemoteInvokerServiceExporter(env) {

        @Override
        protected Object getProxyForService() {
            return target;
        }

        @Override
        protected RemoteInvocation readRemoteInvocation(HttpServletRequest request) {
            return invocation;
        }

        @Override
        protected RemoteInvocationResult invokeAndCreateResult(RemoteInvocation invocation, Object targetObject) {
            try {
                invocation.invoke(targetObject);
                return new RemoteInvocationResult(true);
            } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
                e.printStackTrace();
                fail("invoke() failed; should never get here. error: " + e.getMessage());
                return new RemoteInvocationResult(false);
            }
        }

        @Override
        protected void writeRemoteInvocationResult(HttpServletRequest request, HttpServletResponse response, RemoteInvocationResult result) {
            if ((Boolean) result.getValue()) {
                response.setStatus(SC_OK);
            } else {
                response.setStatus(SC_INTERNAL_SERVER_ERROR);
            }
        }
    };
    invoker.prepare();
    return invoker;
}
Also used : MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) RemoteInvocationResult(org.springframework.remoting.support.RemoteInvocationResult) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 30 with RemoteInvocation

use of org.springframework.remoting.support.RemoteInvocation in project gocd by gocd.

the class AgentRemoteInvokerServiceExporterTest method reportCompleted_allowedForSameUUID.

@Test
void reportCompleted_allowedForSameUUID() throws Exception {
    final AgentRuntimeInfo agent = runtimeInfo(AGENT_UUID);
    final AgentRemoteInvokerServiceExporter invoker = deserializingWith(new RemoteInvocation("reportCompleted", new Class[] { AgentRuntimeInfo.class, JobIdentifier.class, JobResult.class }, new Object[] { agent, null, null }));
    invoker.handleRequest(req, res);
    verify(target, only()).reportCompleted(agent, null, null);
    assertEquals(SC_OK, res.getStatus());
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) JobResult(com.thoughtworks.go.domain.JobResult) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Test(org.junit.jupiter.api.Test)

Aggregations

RemoteInvocation (org.springframework.remoting.support.RemoteInvocation)39 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)16 Test (org.junit.jupiter.api.Test)16 RemoteInvocationResult (org.springframework.remoting.support.RemoteInvocationResult)14 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)8 Test (org.junit.Test)8 RemoteAccessException (org.springframework.remoting.RemoteAccessException)7 IOException (java.io.IOException)6 MethodInvocation (org.aopalliance.intercept.MethodInvocation)6 ITestBean (org.springframework.tests.sample.beans.ITestBean)5 JobResult (com.thoughtworks.go.domain.JobResult)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 TestBean (org.springframework.tests.sample.beans.TestBean)4 NestedServletException (org.springframework.web.util.NestedServletException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Method (java.lang.reflect.Method)3 ServletException (javax.servlet.ServletException)3 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)3