You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Olaf Heyder (Jira)" <ji...@apache.org> on 2021/12/20 17:27:00 UTC

[jira] [Commented] (CAMEL-17357) Make the AbstractInvocationHandler pass the method name to the exchange

    [ https://issues.apache.org/jira/browse/CAMEL-17357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17462739#comment-17462739 ] 

Olaf Heyder commented on CAMEL-17357:
-------------------------------------

[~davsclaus] Please rethink your decision. How would you implement a _jsonrpc_ Component?

The old Camel 2.x used the _BeanInvocation_ class as a container for the data to be exchanged. And the serialized(!) _BeanInvocation_ object was sent on the wire which was indeed not a good approach.

Why?
 # It is generally considered unsafe as malicious payload can exploit the host system. (see also [here|https://activemq.apache.org/objectmessage]).
 # The Java serialized form of even small objects is very verbose so it takes up a lot of space on the wire, also Java serialization is slow compared to custom marshalling techniques. (see also [here|https://activemq.apache.org/components/artemis/documentation/1.5.0/perf-tuning.html]. Search for "serialized")
 # Both sides (client+server) must talk Java - no platform independence.
 # Implementing serialization correctly can be tricky.

Hence, the _BeanInvocation_ was retired for good reason.

Now let's assume we want to use Camel to talk to a _jsonrpc_ service where the message exchange is text based.

A Java server may implement some interface like this:

 
{code:java}
interface Foo {
    Bar doSomething(Fee p1, Bee p2);
}
{code}
And the server may publish its service using _jsonrpc_ in a platform independent manner. In such a case a client would have to send a request message like this:

 

 
{code:java}
{
  "method" : "doSomething",
  "jsonrpc" : "2.0",
  "id" : "some-correlation-id...",
  "params" : [
    {
      the marshalled Fee object
    },
    {
      the marshalled Bee object
    }
  ]
}
{code}
 

Briefly, the server expects the request message to be a JSON object which it needs to unmarshal before the actual method call.

From a Camel user's point of view I would like to have a proxy of the Foo service in the client. This can easily be achieved even today like this:

 
{code:java}
Foo foo = ProxyHelper.createProxy(jsonrpEndpoint, Foo.class);
{code}
+But only+ as long as the _Endpoint_ (i.e. its {_}Producer{_}) is able to process the _Exchange_ which was prepared by the _AbstractInvocationHandler._ (The producer can delegate the actual conversion to a JSON Converter like the Jackson or gson libraries.)

Today the _AbstractInvocationHandler_ does not attach the name of the method (in case of the example above "doSomething") to the exchange. Hence the producer is not able to do the conversion, because the method name (mandatory for a _jsonrpc_ request) is missing.

 

In other words, I am missing a _jsonrpc_ Component in the Camel toolkit. Therefore I hereby ask for the prerequisite for a Camel'ish solution.

Shall I open a feature request, or can we can go with this one and I send you my _jsonrpc_ Component for review and maybe adding to Camel?

PS: The Consumer of the Endpoint could be configured with a corresponding Converter to unmarshal the response from the server. Even here I imagine a powerful default converter which is able to handle 99% of all possible responses.

> Make the AbstractInvocationHandler pass the method name to the exchange
> -----------------------------------------------------------------------
>
>                 Key: CAMEL-17357
>                 URL: https://issues.apache.org/jira/browse/CAMEL-17357
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-bean
>    Affects Versions: Future
>            Reporter: Olaf Heyder
>            Priority: Major
>
> One purpose of the _CamelInvocationHandler_ (& Friends) is to translate a _java.lang.reflect.Method_ to  an _Exchange_ in order to eventually have the registered _Producer_ process that Exchange. Currently the name of the method gets lost when the Exchange is prepared.
> It would be helpful if the Exchange contained the method name (as a String), e.g. as an appropiate header. In that case it would be possible to write a new Camel Component "{*}jsonrpc{*}". according to Camel's design concept, because the [jsonrpc protocol|https://www.jsonrpc.org/] requires the name of the method in the request message.
> My suggestion is to attach the method name to the Exchange in method
> {{protected Object invokeProxy(final Method method, final ExchangePattern pattern, Object[] args, boolean binding)}}
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)