/** * 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); } }
/** * 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); } }
@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; } }
@Bean public HttpInvokerProxyFactoryBean myService() { HttpInvokerProxyFactoryBean factory = new HttpInvokerProxyFactoryBean(); factory.setServiceUrl("/svc/dummy"); factory.setServiceInterface(MyService.class); factory.setHttpInvokerRequestExecutor((config, invocation) -> new RemoteInvocationResult()); return factory; }
@Override protected RemoteInvocationResult create(Kryo kryo, Input input, Class<RemoteInvocationResult> type) { return new RemoteInvocationResult(null); } });
/** * 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); } }
public Object execute(RemoteInvocation invocation) { try { Object value = invoke(invocation, proxy); return value; } catch (Throwable ex) { ex.printStackTrace(); return new RemoteInvocationResult(ex); } } }
public Object execute(RemoteInvocation invocation) { try { Object value = invoke(invocation, proxy); return value; } catch (Throwable ex) { return new RemoteInvocationResult(ex); } } }
private void returnOrThrow(org.springframework.amqp.core.Message amqpMessage, Channel channel, Message<?> message, Throwable throwableToReturn, Exception exceptionToThrow) throws Exception { // NOSONAR if (!this.returnExceptions) { throw exceptionToThrow; } try { handleResult(new InvocationResult(new RemoteInvocationResult(throwableToReturn), null, null), amqpMessage, channel, message); } catch (ReplyFailureException rfe) { if (void.class.equals(this.handlerAdapter.getReturnType(message.getPayload()))) { throw exceptionToThrow; } else { throw rfe; } } }
private void returnOrThrow(org.springframework.amqp.core.Message amqpMessage, Channel channel, Message<?> message, Throwable throwableToReturn, Exception exceptionToThrow) throws Exception { // NOSONAR if (!this.returnExceptions) { throw exceptionToThrow; } try { handleResult(new InvocationResult(new RemoteInvocationResult(throwableToReturn), null, null), amqpMessage, channel, message); } catch (ReplyFailureException rfe) { if (void.class.equals(this.handlerAdapter.getReturnType(message.getPayload()))) { throw exceptionToThrow; } else { throw rfe; } } }
protected Object doTransform(Object src, String encoding) throws TransformerException { try { if (logger.isDebugEnabled()) { logger.debug("ObjectToRemoteInvocationResult.doTransform(" + src + ")"); } RemoteInvocationResult rval; if (src instanceof RemoteInvocationResult) { rval = (RemoteInvocationResult)src; } else { rval = new RemoteInvocationResult(src); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(rval); oos.close(); return baos.toByteArray(); } catch (Exception e) { throw new TransformerException(this, e); } }
/** * {@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 public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { RemoteInvocationResult result; try { RemoteInvocation invocation = readRemoteInvocation(request); result = invokeAndCreateResult(invocation, getProxy()); } catch (OptionalDataException | ClassCastException e) { // typical binary incompatibility exceptions logger.error("Failed to read remote invocation request", e); result = new RemoteInvocationResult(e); } writeRemoteInvocationResult(request, response, result); } catch (ClassNotFoundException ex) { throw new NestedServletException("Class not found during deserialization", ex); } }
@Override public void onMessage(Message message) { Address replyToAddress = message.getMessageProperties().getReplyToAddress(); if (replyToAddress == null) { throw new AmqpRejectAndDontRequeueException("No replyToAddress in inbound AMQP Message"); } Object invocationRaw = this.messageConverter.fromMessage(message); RemoteInvocationResult remoteInvocationResult; if (!(invocationRaw instanceof RemoteInvocation)) { remoteInvocationResult = new RemoteInvocationResult( new IllegalArgumentException("The message does not contain a RemoteInvocation payload")); } else { RemoteInvocation invocation = (RemoteInvocation) invocationRaw; remoteInvocationResult = invokeAndCreateResult(invocation, getService()); } send(remoteInvocationResult, replyToAddress, message); }
@Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { RemoteInvocation invocation = this.readRemoteInvocation(request); RemoteInvocationResult result = null; if (!validate(invocation.getAttributes())){ String msg="RPC Security Forbidden!"; result=new RemoteInvocationResult(new ServletException(msg)); }else{ result=this.invokeAndCreateResult(invocation, this.getProxy()); } this.writeRemoteInvocationResult(request, response, result); } catch (ClassNotFoundException var5) { throw new NestedServletException("Class not found during deserialization", var5); } } /**