org.springframework.remoting.support.RemoteInvocationResult Java Examples
The following examples show how to use
org.springframework.remoting.support.RemoteInvocationResult.
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: HttpComponentsHttpInvokerRequestExecutor.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Execute the given request through the HttpClient. * <p>This method implements the basic processing workflow: * The actual work happens in this class's template methods. * @see #createHttpPost * @see #setRequestBody * @see #executeHttpPost * @see #validateResponse * @see #getResponseBody */ @Override protected RemoteInvocationResult doExecuteRequest( HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws IOException, ClassNotFoundException { HttpPost postMethod = createHttpPost(config); setRequestBody(config, postMethod, baos); try { HttpResponse response = executeHttpPost(config, getHttpClient(), postMethod); validateResponse(config, response); InputStream responseBody = getResponseBody(config, response); return readRemoteInvocationResult(responseBody, config.getCodebaseUrl()); } finally { postMethod.releaseConnection(); } }
Example #2
Source File: HttpComponentsHttpInvokerRequestExecutor.java From java-technology-stack with MIT License | 6 votes |
/** * Execute the given request through the HttpClient. * <p>This method implements the basic processing workflow: * The actual work happens in this class's template methods. * @see #createHttpPost * @see #setRequestBody * @see #executeHttpPost * @see #validateResponse * @see #getResponseBody */ @Override protected RemoteInvocationResult doExecuteRequest( HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws IOException, ClassNotFoundException { HttpPost postMethod = createHttpPost(config); setRequestBody(config, postMethod, baos); try { HttpResponse response = executeHttpPost(config, getHttpClient(), postMethod); validateResponse(config, response); InputStream responseBody = getResponseBody(config, response); return readRemoteInvocationResult(responseBody, config.getCodebaseUrl()); } finally { postMethod.releaseConnection(); } }
Example #3
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 #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: HttpServiceProxy.java From cuba with Apache License 2.0 | 6 votes |
@Override protected Object recreateRemoteInvocationResult(RemoteInvocationResult result) throws Throwable { Throwable throwable = result.getException(); if (throwable != null) { if (throwable instanceof InvocationTargetException) throwable = ((InvocationTargetException) throwable).getTargetException(); if (throwable instanceof RemoteException) { Exception exception = ((RemoteException) throwable).getFirstCauseException(); // This is a checked exception declared in a service method // or runtime exception supported by client if (exception != null) { RemoteInvocationUtils.fillInClientStackTraceIfPossible(exception); throw exception; } } } return super.recreateRemoteInvocationResult(result); }
Example #6
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 #7
Source File: HttpComponentsHttpInvokerRequestExecutor.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Execute the given request through the HttpClient. * <p>This method implements the basic processing workflow: * The actual work happens in this class's template methods. * @see #createHttpPost * @see #setRequestBody * @see #executeHttpPost * @see #validateResponse * @see #getResponseBody */ @Override protected RemoteInvocationResult doExecuteRequest( HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws IOException, ClassNotFoundException { HttpPost postMethod = createHttpPost(config); setRequestBody(config, postMethod, baos); try { HttpResponse response = executeHttpPost(config, getHttpClient(), postMethod); validateResponse(config, response); InputStream responseBody = getResponseBody(config, response); return readRemoteInvocationResult(responseBody, config.getCodebaseUrl()); } finally { postMethod.releaseConnection(); } }
Example #8
Source File: SimpleHttpInvokerServiceExporter.java From java-technology-stack with MIT License | 5 votes |
/** * Write the given RemoteInvocationResult to the given HTTP response. * @param exchange current HTTP request/response * @param result the RemoteInvocationResult object * @throws java.io.IOException in case of I/O failure */ protected void writeRemoteInvocationResult(HttpExchange exchange, RemoteInvocationResult result) throws IOException { exchange.getResponseHeaders().set("Content-Type", getContentType()); exchange.sendResponseHeaders(200, 0); writeRemoteInvocationResult(exchange, result, exchange.getResponseBody()); }
Example #9
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 #10
Source File: HttpInvokerFactoryBeanIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
@Bean public HttpInvokerProxyFactoryBean myService() { HttpInvokerProxyFactoryBean factory = new HttpInvokerProxyFactoryBean(); factory.setServiceUrl("/svc/dummy"); factory.setServiceInterface(MyService.class); factory.setHttpInvokerRequestExecutor((config, invocation) -> new RemoteInvocationResult()); return factory; }
Example #11
Source File: AbstractHttpInvokerRequestExecutor.java From java-technology-stack 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 #12
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 #13
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 #14
Source File: SimpleHttpInvokerServiceExporter.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Write the given RemoteInvocationResult to the given HTTP response. * @param exchange current HTTP request/response * @param result the RemoteInvocationResult object * @throws java.io.IOException in case of I/O failure */ protected void writeRemoteInvocationResult(HttpExchange exchange, RemoteInvocationResult result) throws IOException { exchange.getResponseHeaders().set("Content-Type", getContentType()); exchange.sendResponseHeaders(200, 0); writeRemoteInvocationResult(exchange, result, exchange.getResponseBody()); }
Example #15
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 #16
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 #17
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 #18
Source File: HttpInvokerServiceExporter.java From java-technology-stack with MIT License | 5 votes |
/** * Write the given RemoteInvocationResult to the given HTTP response. * @param request current HTTP request * @param response current HTTP response * @param result the RemoteInvocationResult object * @throws IOException in case of I/O failure */ protected void writeRemoteInvocationResult( HttpServletRequest request, HttpServletResponse response, RemoteInvocationResult result) throws IOException { response.setContentType(getContentType()); writeRemoteInvocationResult(request, response, result, response.getOutputStream()); }
Example #19
Source File: AbstractHttpInvokerRequestExecutor.java From spring4-understanding with Apache License 2.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 lams with GNU General Public License v2.0 | 5 votes |
/** * Write the given RemoteInvocationResult to the given HTTP response. * @param request current HTTP request * @param response current HTTP response * @param result the RemoteInvocationResult object * @throws IOException in case of I/O failure */ protected void writeRemoteInvocationResult( HttpServletRequest request, HttpServletResponse response, RemoteInvocationResult result) throws IOException { response.setContentType(getContentType()); writeRemoteInvocationResult(request, response, result, response.getOutputStream()); }
Example #21
Source File: SimpleHttpInvokerRequestExecutor.java From java-technology-stack with MIT License | 5 votes |
/** * Execute the given request through a standard {@link HttpURLConnection}. * <p>This method implements the basic processing workflow: * The actual work happens in this class's template methods. * @see #openConnection * @see #prepareConnection * @see #writeRequestBody * @see #validateResponse * @see #readResponseBody */ @Override protected RemoteInvocationResult doExecuteRequest( HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws IOException, ClassNotFoundException { HttpURLConnection con = openConnection(config); prepareConnection(con, baos.size()); writeRequestBody(config, con, baos); validateResponse(config, con); InputStream responseBody = readResponseBody(config, con); return readRemoteInvocationResult(responseBody, config.getCodebaseUrl()); }
Example #22
Source File: HttpInvokerFactoryBeanIntegrationTests.java From java-technology-stack with MIT License | 5 votes |
@Bean public HttpInvokerProxyFactoryBean myService() { HttpInvokerProxyFactoryBean factory = new HttpInvokerProxyFactoryBean(); factory.setServiceUrl("/svc/dummy"); factory.setServiceInterface(MyService.class); factory.setHttpInvokerRequestExecutor((config, invocation) -> new RemoteInvocationResult()); return factory; }
Example #23
Source File: SimpleHttpInvokerRequestExecutor.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Execute the given request through a standard J2SE HttpURLConnection. * <p>This method implements the basic processing workflow: * The actual work happens in this class's template methods. * @see #openConnection * @see #prepareConnection * @see #writeRequestBody * @see #validateResponse * @see #readResponseBody */ @Override protected RemoteInvocationResult doExecuteRequest( HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws IOException, ClassNotFoundException { HttpURLConnection con = openConnection(config); prepareConnection(con, baos.size()); writeRequestBody(config, con, baos); validateResponse(config, con); InputStream responseBody = readResponseBody(config, con); return readRemoteInvocationResult(responseBody, config.getCodebaseUrl()); }
Example #24
Source File: HttpInvokerTests.java From spring4-understanding with Apache License 2.0 | 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 #25
Source File: SimpleHttpInvokerServiceExporter.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Write the given RemoteInvocationResult to the given HTTP response. * @param exchange current HTTP request/response * @param result the RemoteInvocationResult object * @throws java.io.IOException in case of I/O failure */ protected void writeRemoteInvocationResult(HttpExchange exchange, RemoteInvocationResult result) throws IOException { exchange.getResponseHeaders().set("Content-Type", getContentType()); exchange.sendResponseHeaders(200, 0); writeRemoteInvocationResult(exchange, result, exchange.getResponseBody()); }
Example #26
Source File: JmsInvokerServiceExporter.java From java-technology-stack 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 #27
Source File: JmsInvokerServiceExporter.java From java-technology-stack with MIT License | 5 votes |
/** * Send the given RemoteInvocationResult as a JMS message to the originator. * @param requestMessage current request message * @param session the JMS Session to use * @param result the RemoteInvocationResult object * @throws javax.jms.JMSException if thrown by trying to send the message */ protected void writeRemoteInvocationResult( Message requestMessage, Session session, RemoteInvocationResult result) throws JMSException { Message response = createResponseMessage(requestMessage, session, result); MessageProducer producer = session.createProducer(requestMessage.getJMSReplyTo()); try { producer.send(response); } finally { JmsUtils.closeMessageProducer(producer); } }
Example #28
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 #29
Source File: SimpleHttpInvokerServiceExporter.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(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 #30
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); } }