Follow the addStock method in this sample:
https://github.com/wso2/msf4j/blob/master/samples/stockquote/fatjar/src/main/java/org/wso2/msf4j/example/StockQuoteService.java#L108
Then;
curl -v -X POST -H "Content-Type:application/json" -d
'{"symbol":"GOOG","name":"Google Inc.", "high":190.23, "low":187.45}'
http://localhost:8080/stockquote
On Mon, Aug 1, 2016 at 9:28 PM, Nadeeshaan Gunasinghe <[email protected]>
wrote:
> Hi all,
>
> When I try to execute the following sample [1] service's POST operation I
> could observe the bellow exception.
>
> *java.lang.IllegalArgumentException: argument type mismatch*
> * at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)*
> * at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)*
> * at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)*
> * at java.lang.reflect.Method.invoke(Method.java:497)*
> * at
> org.wso2.msf4j.internal.router.HttpMethodInfo.invoke(HttpMethodInfo.java:108)*
> * at
> org.wso2.msf4j.internal.MSF4JMessageProcessor.dispatchMethod(MSF4JMessageProcessor.java:129)*
> * at
> org.wso2.msf4j.internal.MSF4JMessageProcessor.receive(MSF4JMessageProcessor.java:73)*
> * at
> org.wso2.carbon.transport.http.netty.listener.WorkerPoolDispatchingSourceHandler$1.run(WorkerPoolDispatchingSourceHandler.java:127)*
> * at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)*
> * at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)*
> * at java.lang.Thread.run(Thread.java:745)*
>
> According to the sample service method I am going to capture the json
> payload as an object passed to the method as follows.
>
> @POST
> @Path("/test")
> public Response post(TestPayload testPayloadBody) {
> // TODO: Implementation for HTTP POST request
> System.out.println("POST invoked ====== " +testPayloadBody);
> return Response.ok().entity(testPayloadBody).build();
> }
>
>
> After further debugging the code, could find that the arguments list
> passed at [2] contains a string. But according to the implementation it
> should be a *TestPayload *object. If we observe at [3] the headers Map's
> keys are all in lowercase. In order to get the header from the map, we use
> the constant from* javax.ws.rs.core.Headers, *there the CONTENT_TYPE
> constant is not in all lowercase and Due to this reason *contentTypeHeaderStr
> *becomes null and leads to convert the object to a String by the default
> text formatter, based on the wild card content-type [4].
>
> [1]
> https://drive.google.com/a/wso2.com/folderview?id=0Bx7aKS6MDJqSVDhVSTdWZ1JBVGc&usp=sharing
> [2]
> https://github.com/wso2/msf4j/blob/master/core/src/main/java/org/wso2/msf4j/internal/router/HttpMethodInfo.java#L108
> [3]
> https://github.com/wso2/carbon-messaging/blob/master/components/src/main/java/org/wso2/carbon/messaging/CarbonMessage.java#L162
> [4]
> https://github.com/wso2/msf4j/blob/master/core/src/main/java/org/wso2/msf4j/internal/router/HttpResourceModelProcessor.java#L158
>
> Thanks,
>
> *Nadeeshaan Gunasinghe*
> Software Engineer, WSO2 Inc. http://wso2.com
> +94770596754 | [email protected] | Skype: nadeeshaan.gunasinghe
> <#m_-746156207640328338_>
> <http://www.facebook.com/nadeeshaan.gunasinghe>
> <http://lk.linkedin.com/in/nadeeshaan> <http://twitter.com/Nadeeshaan>
> <http://nadeeshaan.blogspot.com/>
> Get a signature like this: Click here!
> <http://ws-promos.appspot.com/r?rdata=eyJydXJsIjogImh0dHA6Ly93d3cud2lzZXN0YW1wLmNvbS9lbWFpbC1pbnN0YWxsP3dzX25jaWQ9NjcyMjk0MDA4JnV0bV9zb3VyY2U9ZXh0ZW5zaW9uJnV0bV9tZWRpdW09ZW1haWwmdXRtX2NhbXBhaWduPXByb21vXzU3MzI1Njg1NDg3Njk3OTIiLCAiZSI6ICI1NzMyNTY4NTQ4NzY5NzkyIn0=&u=543026424429568>
>
--
*Afkham Azeez*
Director of Architecture; WSO2, Inc.; http://wso2.com
Member; Apache Software Foundation; http://www.apache.org/
* <http://www.apache.org/>*
*email: **[email protected]* <[email protected]>
* cell: +94 77 3320919blog: **http://blog.afkham.org*
<http://blog.afkham.org>
*twitter: **http://twitter.com/afkham_azeez*
<http://twitter.com/afkham_azeez>
*linked-in: **http://lk.linkedin.com/in/afkhamazeez
<http://lk.linkedin.com/in/afkhamazeez>*
*Lean . Enterprise . Middleware*
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev