wso2 / msf4j

WSO2 Microservices Framework for Java (MSF4J)
http://wso2.com/products/microservices-framework-for-java/
Apache License 2.0
400 stars 349 forks source link

msf4j @RequestBody not working #553

Open shalini1153 opened 5 years ago

shalini1153 commented 5 years ago

I am trying to write a post request and i am calling this request from angular 5 client

@OPTIONS
@POST
@Path("/post")
@Consumes("application/json")
@Produces("application/json")
public String addStock(@RequestBody JsonObject stock)
{

    return "test";
}

But everytime i call this request from angular i get this error

2018-11-27 18:36:09 WARN MSF4JHttpConnectorListener:243 - Unmapped exception java.lang.IllegalArgumentException: argument type mismatch at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.wso2.msf4j.internal.router.HttpMethodInfo.invokeResource(HttpMethodInfo.java:187) at org.wso2.msf4j.internal.router.HttpMethodInfo.invoke(HttpMethodInfo.java:143) at rg.wso2.msf4j.internal.MSF4JHttpConnectorListener.dispatchMethod(MSF4JHttpConnectorListener.java:218) at org.wso2.msf4j.internal.MSF4JHttpConnectorListener.lambda$onMessage$39(MSF4JHttpConnectorListener.java:129) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

Can anybody suggest on how to implement

thusithathilina commented 5 years ago

RequestBody is not from the Jax-RS specification but from the spring implementation. AFAIK msf4j doesn't support that annotation. If you want to consume the whole message body you can use @Context Request and get the message content manually inside your resource. e.g. https://github.com/wso2/msf4j/blob/master/core/src/test/java/org/wso2/msf4j/service/TestMicroservice.java#L209