org.springframework.remoting.support.RemoteInvocation Java Examples
The following examples show how to use
org.springframework.remoting.support.RemoteInvocation.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RmiProtocol.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException { final RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean(); // RMI needs extra parameter since it uses customized remote invocation object if (url.getParameter(Constants.DUBBO_VERSION_KEY, Version.getProtocolVersion()).equals(Version.getProtocolVersion())) { // Check dubbo version on provider, this feature only support rmiProxyFactoryBean.setRemoteInvocationFactory(new RemoteInvocationFactory() { @Override public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) { return new RmiRemoteInvocation(methodInvocation); } }); } rmiProxyFactoryBean.setServiceUrl(url.toIdentityString()); rmiProxyFactoryBean.setServiceInterface(serviceType); rmiProxyFactoryBean.setCacheStub(true); rmiProxyFactoryBean.setLookupStubOnStartup(true); rmiProxyFactoryBean.setRefreshStubOnConnectFailure(true); rmiProxyFactoryBean.afterPropertiesSet(); return (T) rmiProxyFactoryBean.getObject(); }
Example #2
Source File: JmsInvokerClientInterceptor.java From spring-analysis-note with MIT License | 6 votes |
/** * Execute the given remote invocation, sending an invoker request message * to this accessor's target queue and waiting for a corresponding response. * @param invocation the RemoteInvocation to execute * @return the RemoteInvocationResult object * @throws JMSException in case of JMS failure * @see #doExecuteRequest */ protected RemoteInvocationResult executeRequest(RemoteInvocation invocation) throws JMSException { Connection con = createConnection(); Session session = null; try { session = createSession(con); Queue queueToUse = resolveQueue(session); Message requestMessage = createRequestMessage(session, invocation); con.start(); Message responseMessage = doExecuteRequest(session, queueToUse, requestMessage); if (responseMessage != null) { return extractInvocationResult(responseMessage); } else { return onReceiveTimeout(invocation); } } finally { JmsUtils.closeSession(session); ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory(), true); } }
Example #3
Source File: CubaRemoteInvocationFactory.java From cuba with Apache License 2.0 | 6 votes |
@Override public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) { SecurityContext securityContext = AppContext.getSecurityContext(); CubaRemoteInvocation remoteInvocation = new CubaRemoteInvocation(methodInvocation, securityContext == null ? null : securityContext.getSessionId()); if (securityContext != null) { UserSession session = securityContext.getSession(); if (session instanceof ClientBasedSession && ((ClientBasedSession) session).hasRequestScopedInfo()) { remoteInvocation.setLocale(session.getLocale() != null ? session.getLocale().toLanguageTag() : null); remoteInvocation.setTimeZone(session.getTimeZone()); remoteInvocation.setAddress(session.getAddress()); remoteInvocation.setClientInfo(session.getClientInfo()); } } return remoteInvocation; }
Example #4
Source File: JmsInvokerClientInterceptor.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Execute the given remote invocation, sending an invoker request message * to this accessor's target queue and waiting for a corresponding response. * @param invocation the RemoteInvocation to execute * @return the RemoteInvocationResult object * @throws JMSException in case of JMS failure * @see #doExecuteRequest */ protected RemoteInvocationResult executeRequest(RemoteInvocation invocation) throws JMSException { Connection con = createConnection(); Session session = null; try { session = createSession(con); Queue queueToUse = resolveQueue(session); Message requestMessage = createRequestMessage(session, invocation); con.start(); Message responseMessage = doExecuteRequest(session, queueToUse, requestMessage); if (responseMessage != null) { return extractInvocationResult(responseMessage); } else { return onReceiveTimeout(invocation); } } finally { JmsUtils.closeSession(session); ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory(), true); } }
Example #5
Source File: JmsInvokerClientInterceptor.java From java-technology-stack with MIT License | 6 votes |
/** * Execute the given remote invocation, sending an invoker request message * to this accessor's target queue and waiting for a corresponding response. * @param invocation the RemoteInvocation to execute * @return the RemoteInvocationResult object * @throws JMSException in case of JMS failure * @see #doExecuteRequest */ protected RemoteInvocationResult executeRequest(RemoteInvocation invocation) throws JMSException { Connection con = createConnection(); Session session = null; try { session = createSession(con); Queue queueToUse = resolveQueue(session); Message requestMessage = createRequestMessage(session, invocation); con.start(); Message responseMessage = doExecuteRequest(session, queueToUse, requestMessage); if (responseMessage != null) { return extractInvocationResult(responseMessage); } else { return onReceiveTimeout(invocation); } } finally { JmsUtils.closeSession(session); ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory(), true); } }
Example #6
Source File: RmiBasedExporter.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Redefined here to be visible to RmiInvocationWrapper. * Simply delegates to the corresponding superclass method. */ @Override protected Object invoke(RemoteInvocation invocation, Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { return super.invoke(invocation, targetObject); }
Example #7
Source File: RmiSupportTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void rmiInvokerWithSpecialLocalMethods() throws Exception { String serviceUrl = "rmi://localhost:1090/test"; RmiProxyFactoryBean factory = new RmiProxyFactoryBean() { @Override protected Remote lookupStub() { return new RmiInvocationHandler() { @Override public String getTargetInterfaceName() { return null; } @Override public Object invoke(RemoteInvocation invocation) throws RemoteException { throw new RemoteException(); } }; } }; factory.setServiceInterface(IBusinessBean.class); factory.setServiceUrl(serviceUrl); factory.afterPropertiesSet(); IBusinessBean proxy = (IBusinessBean) factory.getObject(); // shouldn't go through to remote service assertTrue(proxy.toString().contains("RMI invoker")); assertTrue(proxy.toString().contains(serviceUrl)); assertEquals(proxy.hashCode(), proxy.hashCode()); assertTrue(proxy.equals(proxy)); // should go through try { proxy.setName("test"); fail("Should have thrown RemoteAccessException"); } catch (RemoteAccessException ex) { // expected } }
Example #8
Source File: HttpInvokerTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void httpInvokerProxyFactoryBeanAndServiceExporterWithIOException() throws Exception { TestBean target = new TestBean("myname", 99); final HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter(); exporter.setServiceInterface(ITestBean.class); exporter.setService(target); exporter.afterPropertiesSet(); HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean(); pfb.setServiceInterface(ITestBean.class); pfb.setServiceUrl("https://myurl"); pfb.setHttpInvokerRequestExecutor(new HttpInvokerRequestExecutor() { @Override public RemoteInvocationResult executeRequest( HttpInvokerClientConfiguration config, RemoteInvocation invocation) throws IOException { throw new IOException("argh"); } }); pfb.afterPropertiesSet(); ITestBean proxy = (ITestBean) pfb.getObject(); try { proxy.setAge(50); fail("Should have thrown RemoteAccessException"); } catch (RemoteAccessException ex) { // expected assertTrue(ex.getCause() instanceof IOException); } }
Example #9
Source File: AbstractHttpInvokerRequestExecutor.java From spring-analysis-note with MIT License | 5 votes |
@Override public final RemoteInvocationResult executeRequest( HttpInvokerClientConfiguration config, RemoteInvocation invocation) throws Exception { ByteArrayOutputStream baos = getByteArrayOutputStream(invocation); if (logger.isDebugEnabled()) { logger.debug("Sending HTTP invoker request for service at [" + config.getServiceUrl() + "], with size " + baos.size()); } return doExecuteRequest(config, baos); }
Example #10
Source File: HttpInvokerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void httpInvokerWithSpecialLocalMethods() throws Exception { String serviceUrl = "http://myurl"; HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean(); pfb.setServiceInterface(ITestBean.class); pfb.setServiceUrl(serviceUrl); pfb.setHttpInvokerRequestExecutor(new HttpInvokerRequestExecutor() { @Override public RemoteInvocationResult executeRequest( HttpInvokerClientConfiguration config, RemoteInvocation invocation) throws IOException { throw new IOException("argh"); } }); pfb.afterPropertiesSet(); ITestBean proxy = (ITestBean) pfb.getObject(); // shouldn't go through to remote service assertTrue(proxy.toString().indexOf("HTTP invoker") != -1); assertTrue(proxy.toString().indexOf(serviceUrl) != -1); assertEquals(proxy.hashCode(), proxy.hashCode()); assertTrue(proxy.equals(proxy)); // should go through try { proxy.setAge(50); fail("Should have thrown RemoteAccessException"); } catch (RemoteAccessException ex) { // expected assertTrue(ex.getCause() instanceof IOException); } }
Example #11
Source File: SimpleHttpInvokerServiceExporter.java From spring-analysis-note with MIT License | 5 votes |
/** * Reads a remote invocation from the request, executes it, * and writes the remote invocation result to the response. * @see #readRemoteInvocation(HttpExchange) * @see #invokeAndCreateResult(RemoteInvocation, Object) * @see #writeRemoteInvocationResult(HttpExchange, RemoteInvocationResult) */ @Override public void handle(HttpExchange exchange) throws IOException { try { RemoteInvocation invocation = readRemoteInvocation(exchange); RemoteInvocationResult result = invokeAndCreateResult(invocation, getProxy()); writeRemoteInvocationResult(exchange, result); exchange.close(); } catch (ClassNotFoundException ex) { exchange.sendResponseHeaders(500, -1); logger.error("Class not found during deserialization", ex); } }
Example #12
Source File: JmsInvokerServiceExporter.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public void onMessage(Message requestMessage, Session session) throws JMSException { RemoteInvocation invocation = readRemoteInvocation(requestMessage); if (invocation != null) { RemoteInvocationResult result = invokeAndCreateResult(invocation, this.proxy); writeRemoteInvocationResult(requestMessage, session, result); } }
Example #13
Source File: JmsInvokerServiceExporter.java From spring-analysis-note with MIT License | 5 votes |
@Override public void onMessage(Message requestMessage, Session session) throws JMSException { RemoteInvocation invocation = readRemoteInvocation(requestMessage); if (invocation != null) { RemoteInvocationResult result = invokeAndCreateResult(invocation, this.proxy); writeRemoteInvocationResult(requestMessage, session, result); } }
Example #14
Source File: JmsInvokerServiceExporter.java From spring-analysis-note with MIT License | 5 votes |
/** * Read a RemoteInvocation from the given JMS message. * @param requestMessage current request message * @return the RemoteInvocation object (or {@code null} * in case of an invalid message that will simply be ignored) * @throws javax.jms.JMSException in case of message access failure */ @Nullable protected RemoteInvocation readRemoteInvocation(Message requestMessage) throws JMSException { Object content = this.messageConverter.fromMessage(requestMessage); if (content instanceof RemoteInvocation) { return (RemoteInvocation) content; } return onInvalidRequest(requestMessage); }
Example #15
Source File: SimpleHttpInvokerServiceExporter.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Reads a remote invocation from the request, executes it, * and writes the remote invocation result to the response. * @see #readRemoteInvocation(com.sun.net.httpserver.HttpExchange) * @see #invokeAndCreateResult(org.springframework.remoting.support.RemoteInvocation, Object) * @see #writeRemoteInvocationResult(com.sun.net.httpserver.HttpExchange, org.springframework.remoting.support.RemoteInvocationResult) */ @Override public void handle(HttpExchange exchange) throws IOException { try { RemoteInvocation invocation = readRemoteInvocation(exchange); RemoteInvocationResult result = invokeAndCreateResult(invocation, getProxy()); writeRemoteInvocationResult(exchange, result); exchange.close(); } catch (ClassNotFoundException ex) { exchange.sendResponseHeaders(500, -1); logger.error("Class not found during deserialization", ex); } }
Example #16
Source File: RmiInvocationWrapper.java From java-technology-stack with MIT License | 5 votes |
/** * Delegates the actual invocation handling to the RMI exporter. * @see RmiBasedExporter#invoke(org.springframework.remoting.support.RemoteInvocation, Object) */ @Override @Nullable public Object invoke(RemoteInvocation invocation) throws RemoteException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { return this.rmiExporter.invoke(invocation, this.wrappedObject); }
Example #17
Source File: RmiSupportTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void rmiInvokerWithSpecialLocalMethods() throws Exception { String serviceUrl = "rmi://localhost:1090/test"; RmiProxyFactoryBean factory = new RmiProxyFactoryBean() { @Override protected Remote lookupStub() { return new RmiInvocationHandler() { @Override public String getTargetInterfaceName() { return null; } @Override public Object invoke(RemoteInvocation invocation) throws RemoteException { throw new RemoteException(); } }; } }; factory.setServiceInterface(IBusinessBean.class); factory.setServiceUrl(serviceUrl); factory.afterPropertiesSet(); IBusinessBean proxy = (IBusinessBean) factory.getObject(); // shouldn't go through to remote service assertTrue(proxy.toString().contains("RMI invoker")); assertTrue(proxy.toString().contains(serviceUrl)); assertEquals(proxy.hashCode(), proxy.hashCode()); assertTrue(proxy.equals(proxy)); // should go through try { proxy.setName("test"); fail("Should have thrown RemoteAccessException"); } catch (RemoteAccessException ex) { // expected } }
Example #18
Source File: HttpInvokerServiceExporter.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Reads a remote invocation from the request, executes it, * and writes the remote invocation result to the response. * @see #readRemoteInvocation(HttpServletRequest) * @see #invokeAndCreateResult(org.springframework.remoting.support.RemoteInvocation, Object) * @see #writeRemoteInvocationResult(HttpServletRequest, HttpServletResponse, RemoteInvocationResult) */ @Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { RemoteInvocation invocation = readRemoteInvocation(request); RemoteInvocationResult result = invokeAndCreateResult(invocation, getProxy()); writeRemoteInvocationResult(request, response, result); } catch (ClassNotFoundException ex) { throw new NestedServletException("Class not found during deserialization", ex); } }
Example #19
Source File: AbstractHttpInvokerRequestExecutor.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public final RemoteInvocationResult executeRequest( HttpInvokerClientConfiguration config, RemoteInvocation invocation) throws Exception { ByteArrayOutputStream baos = getByteArrayOutputStream(invocation); if (logger.isDebugEnabled()) { logger.debug("Sending HTTP invoker request for service at [" + config.getServiceUrl() + "], with size " + baos.size()); } return doExecuteRequest(config, baos); }
Example #20
Source File: HttpInvokerServiceExporter.java From java-technology-stack with MIT License | 5 votes |
/** * Reads a remote invocation from the request, executes it, * and writes the remote invocation result to the response. * @see #readRemoteInvocation(HttpServletRequest) * @see #invokeAndCreateResult(org.springframework.remoting.support.RemoteInvocation, Object) * @see #writeRemoteInvocationResult(HttpServletRequest, HttpServletResponse, RemoteInvocationResult) */ @Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { RemoteInvocation invocation = readRemoteInvocation(request); RemoteInvocationResult result = invokeAndCreateResult(invocation, getProxy()); writeRemoteInvocationResult(request, response, result); } catch (ClassNotFoundException ex) { throw new NestedServletException("Class not found during deserialization", ex); } }
Example #21
Source File: HttpInvokerServiceExporter.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Reads a remote invocation from the request, executes it, * and writes the remote invocation result to the response. * @see #readRemoteInvocation(HttpServletRequest) * @see #invokeAndCreateResult(org.springframework.remoting.support.RemoteInvocation, Object) * @see #writeRemoteInvocationResult(HttpServletRequest, HttpServletResponse, RemoteInvocationResult) */ @Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { RemoteInvocation invocation = readRemoteInvocation(request); RemoteInvocationResult result = invokeAndCreateResult(invocation, getProxy()); writeRemoteInvocationResult(request, response, result); } catch (ClassNotFoundException ex) { throw new NestedServletException("Class not found during deserialization", ex); } }
Example #22
Source File: SimpleHttpInvokerServiceExporter.java From java-technology-stack with MIT License | 5 votes |
/** * Reads a remote invocation from the request, executes it, * and writes the remote invocation result to the response. * @see #readRemoteInvocation(HttpExchange) * @see #invokeAndCreateResult(RemoteInvocation, Object) * @see #writeRemoteInvocationResult(HttpExchange, RemoteInvocationResult) */ @Override public void handle(HttpExchange exchange) throws IOException { try { RemoteInvocation invocation = readRemoteInvocation(exchange); RemoteInvocationResult result = invokeAndCreateResult(invocation, getProxy()); writeRemoteInvocationResult(exchange, result); exchange.close(); } catch (ClassNotFoundException ex) { exchange.sendResponseHeaders(500, -1); logger.error("Class not found during deserialization", ex); } }
Example #23
Source File: HttpInvokerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void httpInvokerProxyFactoryBeanAndServiceExporterWithIOException() throws Exception { TestBean target = new TestBean("myname", 99); final HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter(); exporter.setServiceInterface(ITestBean.class); exporter.setService(target); exporter.afterPropertiesSet(); HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean(); pfb.setServiceInterface(ITestBean.class); pfb.setServiceUrl("http://myurl"); pfb.setHttpInvokerRequestExecutor(new HttpInvokerRequestExecutor() { @Override public RemoteInvocationResult executeRequest( HttpInvokerClientConfiguration config, RemoteInvocation invocation) throws IOException { throw new IOException("argh"); } }); pfb.afterPropertiesSet(); ITestBean proxy = (ITestBean) pfb.getObject(); try { proxy.setAge(50); fail("Should have thrown RemoteAccessException"); } catch (RemoteAccessException ex) { // expected assertTrue(ex.getCause() instanceof IOException); } }
Example #24
Source File: HttpInvokerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void httpInvokerWithSpecialLocalMethods() throws Exception { String serviceUrl = "http://myurl"; HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean(); pfb.setServiceInterface(ITestBean.class); pfb.setServiceUrl(serviceUrl); pfb.setHttpInvokerRequestExecutor(new HttpInvokerRequestExecutor() { @Override public RemoteInvocationResult executeRequest( HttpInvokerClientConfiguration config, RemoteInvocation invocation) throws IOException { throw new IOException("argh"); } }); pfb.afterPropertiesSet(); ITestBean proxy = (ITestBean) pfb.getObject(); // shouldn't go through to remote service assertTrue(proxy.toString().contains("HTTP invoker")); assertTrue(proxy.toString().contains(serviceUrl)); assertEquals(proxy.hashCode(), proxy.hashCode()); assertTrue(proxy.equals(proxy)); // should go through try { proxy.setAge(50); fail("Should have thrown RemoteAccessException"); } catch (RemoteAccessException ex) { // expected assertTrue(ex.getCause() instanceof IOException); } }
Example #25
Source File: RmiInvocationWrapper.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Delegates the actual invocation handling to the RMI exporter. * @see RmiBasedExporter#invoke(org.springframework.remoting.support.RemoteInvocation, Object) */ @Override public Object invoke(RemoteInvocation invocation) throws RemoteException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { return this.rmiExporter.invoke(invocation, this.wrappedObject); }
Example #26
Source File: RmiSupportTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void rmiInvokerWithSpecialLocalMethods() throws Exception { String serviceUrl = "rmi://localhost:1090/test"; RmiProxyFactoryBean factory = new RmiProxyFactoryBean() { @Override protected Remote lookupStub() { return new RmiInvocationHandler() { @Override public String getTargetInterfaceName() { return null; } @Override public Object invoke(RemoteInvocation invocation) throws RemoteException { throw new RemoteException(); } }; } }; factory.setServiceInterface(IBusinessBean.class); factory.setServiceUrl(serviceUrl); factory.afterPropertiesSet(); IBusinessBean proxy = (IBusinessBean) factory.getObject(); // shouldn't go through to remote service assertTrue(proxy.toString().contains("RMI invoker")); assertTrue(proxy.toString().contains(serviceUrl)); assertEquals(proxy.hashCode(), proxy.hashCode()); assertTrue(proxy.equals(proxy)); // should go through try { proxy.setName("test"); fail("Should have thrown RemoteAccessException"); } catch (RemoteAccessException ex) { // expected } }
Example #27
Source File: ReferenceRemoteInvocationFactory.java From jdal with Apache License 2.0 | 5 votes |
/** * Replace remote clients in arguments with remote references. */ public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) { Object[] arguments = methodInvocation.getArguments(); for (int i = 0; i < arguments.length; i++) { if (arguments[i] instanceof RemoteClient) { arguments[i] = ((RemoteClient) arguments[i]).getRemoteReference(); } } return new RemoteInvocation(methodInvocation); }
Example #28
Source File: HttpInvokerFactoryBeanIntegrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Bean public HttpInvokerProxyFactoryBean myService() { String name = env.getProperty("testbean.name"); HttpInvokerProxyFactoryBean factory = new HttpInvokerProxyFactoryBean(); factory.setServiceUrl("/svc/" + name); factory.setServiceInterface(MyService.class); factory.setHttpInvokerRequestExecutor(new HttpInvokerRequestExecutor() { @Override public RemoteInvocationResult executeRequest(HttpInvokerClientConfiguration config, RemoteInvocation invocation) { return new RemoteInvocationResult(null); } }); return factory; }
Example #29
Source File: RmiInvocationWrapper_Stub.java From BaRMIe with MIT License | 5 votes |
/******************* * Stub to call the remote invoke() method. ******************/ public Object invoke(RemoteInvocation ri) throws RemoteException { try { Object result = this.ref.invoke(this, RmiInvocationHandler.class.getMethod("invoke", new Class[] {RemoteInvocation.class}), new Object[] { ri }, -5752512342587169831L); return result; } catch(RuntimeException | RemoteException ex1) { throw ex1; } catch(Exception ex2) { throw new RemoteException("Unexpected exception.", ex2); } }
Example #30
Source File: RmiBasedExporter.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Redefined here to be visible to RmiInvocationWrapper. * Simply delegates to the corresponding superclass method. */ @Override protected Object invoke(RemoteInvocation invocation, Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { return super.invoke(invocation, targetObject); }