/** * Apply the given remote invocation to the given target object, wrapping * the invocation result in a serializable RemoteInvocationResult object. * The default implementation creates a plain RemoteInvocationResult. * <p>Can be overridden in subclasses for custom invocation behavior, * for example to return additional context information. Note that this * is not covered by the RemoteInvocationExecutor strategy! * @param invocation the remote invocation * @param targetObject the target object to apply the invocation to * @return the invocation result * @see #invoke */ protected RemoteInvocationResult invokeAndCreateResult(RemoteInvocation invocation, Object targetObject) { try { Object value = invoke(invocation, targetObject); return new RemoteInvocationResult(value); } catch (Throwable ex) { return new RemoteInvocationResult(ex); } }
/** * Recreate the invocation result contained in the given RemoteInvocationResult object. * <p>The default implementation calls the default {@code recreate()} method. * This can be overridden in subclass to provide custom recreation, potentially * processing the returned result object. * @param result the RemoteInvocationResult to recreate * @return a return value if the invocation result is a successful return * @throws Throwable if the invocation result is an exception * @see RemoteInvocationResult#recreate() */ protected Object recreateRemoteInvocationResult(RemoteInvocationResult result) throws Throwable { return result.recreate(); }
@Override @Nullable public Object invoke(MethodInvocation methodInvocation) throws Throwable { if (AopUtils.isToStringMethod(methodInvocation.getMethod())) { return "JMS invoker proxy for queue [" + this.queue + "]"; } RemoteInvocation invocation = createRemoteInvocation(methodInvocation); RemoteInvocationResult result; try { result = executeRequest(invocation); } catch (JMSException ex) { throw convertJmsInvokerAccessException(ex); } try { return recreateRemoteInvocationResult(result); } catch (Throwable ex) { if (result.hasInvocationTargetException()) { throw ex; } else { throw new RemoteInvocationFailureException("Invocation of method [" + methodInvocation.getMethod() + "] failed in JMS invoker remote service at queue [" + this.queue + "]", ex); } } }
/** * {@inheritDoc} */ @Override protected void writeRemoteInvocationResult(HttpServletRequest request, HttpServletResponse response, RemoteInvocationResult result, OutputStream os) throws IOException { try (Output output = new Output(os)) { if (!result.hasException()) { Object value = result.getValue(); result = new RemoteInvocationResult(value); } ISerializer serializer = serializationManagerProvider.createSerializer(); serializer.serialize(result, output); } catch (SerializationException e) { throw new IOException(e); } }
@Override protected void processNormalExit(Operation op, Object returnValue) { RemoteInvocationResult result=(RemoteInvocationResult) returnValue; Throwable remoteError=result.getException(); if (remoteError != null) { op.put(REMOTE_EXCEPTION, StringFormatterUtils.formatStackTrace(remoteError)); } else { op.put(OperationFields.RETURN_VALUE, StringFormatterUtils.formatObject(result.getValue())); } } }
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 { coll.add(newValue); } } else if (value instanceof Map && newValue instanceof Map) { Map map = (Map) value; map.putAll((Map) newValue); } return currentResult; }
@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); } }
/** * Apply the given remote invocation to the given target object, wrapping * the invocation result in a serializable RemoteInvocationResult object. * The default implementation creates a plain RemoteInvocationResult. * <p>Can be overridden in subclasses for custom invocation behavior, * for example to return additional context information. Note that this * is not covered by the RemoteInvocationExecutor strategy! * @param invocation the remote invocation * @param targetObject the target object to apply the invocation to * @return the invocation result * @see #invoke */ protected RemoteInvocationResult invokeAndCreateResult(RemoteInvocation invocation, Object targetObject) { try { Object value = invoke(invocation, targetObject); return new RemoteInvocationResult(value); } catch (Throwable ex) { return new RemoteInvocationResult(ex); } }
/** * Recreate the invocation result contained in the given RemoteInvocationResult object. * <p>The default implementation calls the default {@code recreate()} method. * This can be overridden in subclass to provide custom recreation, potentially * processing the returned result object. * @param result the RemoteInvocationResult to recreate * @return a return value if the invocation result is a successful return * @throws Throwable if the invocation result is an exception * @see RemoteInvocationResult#recreate() */ protected Object recreateRemoteInvocationResult(RemoteInvocationResult result) throws Throwable { return result.recreate(); }
@Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { if (AopUtils.isToStringMethod(methodInvocation.getMethod())) { return "HTTP invoker proxy for service URL [" + getServiceUrl() + "]"; } RemoteInvocation invocation = createRemoteInvocation(methodInvocation); RemoteInvocationResult result; try { result = executeRequest(invocation, methodInvocation); } catch (Throwable ex) { RemoteAccessException rae = convertHttpInvokerAccessException(ex); throw (rae != null ? rae : ex); } try { return recreateRemoteInvocationResult(result); } catch (Throwable ex) { if (result.hasInvocationTargetException()) { throw ex; } else { throw new RemoteInvocationFailureException("Invocation of method [" + methodInvocation.getMethod() + "] failed in HTTP invoker remote service at [" + getServiceUrl() + "]", ex); } } }
@Bean public HttpInvokerProxyFactoryBean myService() { String name = env.getProperty("testbean.name"); HttpInvokerProxyFactoryBean factory = new HttpInvokerProxyFactoryBean(); factory.setServiceUrl("/svc/" + name); factory.setServiceInterface(MyService.class); factory.setHttpInvokerRequestExecutor((config, invocation) -> new RemoteInvocationResult()); return factory; } }
/** * Recreate the invocation result contained in the given {@link RemoteInvocationResult} * object. * <p>The default implementation calls the default {@code recreate()} method. * <p>Can be overridden in subclasses to provide custom recreation, potentially * processing the returned result object. * @param result the RemoteInvocationResult to recreate * @return a return value if the invocation result is a successful return * @throws Throwable if the invocation result is an exception * @see org.springframework.remoting.support.RemoteInvocationResult#recreate() */ @Nullable protected Object recreateRemoteInvocationResult(RemoteInvocationResult result) throws Throwable { return result.recreate(); }
@Override public Object invoke(MethodInvocation methodInvocation) throws Throwable { if (AopUtils.isToStringMethod(methodInvocation.getMethod())) { return "HTTP invoker proxy for service URL [" + getServiceUrl() + "]"; } RemoteInvocation invocation = createRemoteInvocation(methodInvocation); RemoteInvocationResult result; try { result = executeRequest(invocation, methodInvocation); } catch (Throwable ex) { RemoteAccessException rae = convertHttpInvokerAccessException(ex); throw (rae != null ? rae : ex); } try { return recreateRemoteInvocationResult(result); } catch (Throwable ex) { if (result.hasInvocationTargetException()) { throw ex; } else { throw new RemoteInvocationFailureException("Invocation of method [" + methodInvocation.getMethod() + "] failed in HTTP invoker remote service at [" + getServiceUrl() + "]", ex); } } }
@Bean public HttpInvokerProxyFactoryBean myService() { HttpInvokerProxyFactoryBean factory = new HttpInvokerProxyFactoryBean(); factory.setServiceUrl("/svc/dummy"); factory.setServiceInterface(MyService.class); factory.setHttpInvokerRequestExecutor((config, invocation) -> new RemoteInvocationResult()); return factory; }
/** * Recreate the invocation result contained in the given RemoteInvocationResult * object. The default implementation calls the default recreate method. * <p>Can be overridden in subclass to provide custom recreation, potentially * processing the returned result object. * @param result the RemoteInvocationResult to recreate * @return a return value if the invocation result is a successful return * @throws Throwable if the invocation result is an exception * @see org.springframework.remoting.support.RemoteInvocationResult#recreate() */ protected Object recreateRemoteInvocationResult(RemoteInvocationResult result) throws Throwable { return result.recreate(); }
@Override @Nullable public Object invoke(MethodInvocation methodInvocation) throws Throwable { if (AopUtils.isToStringMethod(methodInvocation.getMethod())) { return "JMS invoker proxy for queue [" + this.queue + "]"; } RemoteInvocation invocation = createRemoteInvocation(methodInvocation); RemoteInvocationResult result; try { result = executeRequest(invocation); } catch (JMSException ex) { throw convertJmsInvokerAccessException(ex); } try { return recreateRemoteInvocationResult(result); } catch (Throwable ex) { if (result.hasInvocationTargetException()) { throw ex; } else { throw new RemoteInvocationFailureException("Invocation of method [" + methodInvocation.getMethod() + "] failed in JMS invoker remote service at queue [" + this.queue + "]", ex); } } }
@Override protected RemoteInvocationResult create(Kryo kryo, Input input, Class<RemoteInvocationResult> type) { return new RemoteInvocationResult(null); } });
/** * Recreate the invocation result contained in the given RemoteInvocationResult object. * <p>The default implementation calls the default {@code recreate()} method. * This can be overridden in subclass to provide custom recreation, potentially * processing the returned result object. * @param result the RemoteInvocationResult to recreate * @return a return value if the invocation result is a successful return * @throws Throwable if the invocation result is an exception * @see RemoteInvocationResult#recreate() */ protected Object recreateRemoteInvocationResult(RemoteInvocationResult result) throws Throwable { return result.recreate(); }
public Object invoke(MethodInvocation methodInvocation) throws Throwable { if (AopUtils.isToStringMethod(methodInvocation.getMethod())) { return "JMS invoker proxy for queue [" + this.queue + "]"; } RemoteInvocation invocation = createRemoteInvocation(methodInvocation); RemoteInvocationResult result; try { result = executeRequest(invocation); } catch (JMSException ex) { throw convertJmsInvokerAccessException(ex); } try { return recreateRemoteInvocationResult(result); } catch (Throwable ex) { if (result.hasInvocationTargetException()) { throw ex; } else { throw new RemoteInvocationFailureException("Invocation of method [" + methodInvocation.getMethod() + "] failed in JMS invoker remote service at queue [" + this.queue + "]", ex); } } }
/** * Apply the given remote invocation to the given target object, wrapping * the invocation result in a serializable RemoteInvocationResult object. * The default implementation creates a plain RemoteInvocationResult. * <p>Can be overridden in subclasses for custom invocation behavior, * for example to return additional context information. Note that this * is not covered by the RemoteInvocationExecutor strategy! * @param invocation the remote invocation * @param targetObject the target object to apply the invocation to * @return the invocation result * @see #invoke */ protected RemoteInvocationResult invokeAndCreateResult(RemoteInvocation invocation, Object targetObject) { try { Object value = invoke(invocation, targetObject); return new RemoteInvocationResult(value); } catch (Throwable ex) { return new RemoteInvocationResult(ex); } }