When I try to call this service with POSTMAN tool with:
method: POST
HEADERS:
Content-Type: application/json
request body/body content as json:
{“endPoint”:null,“orderId”:“VT1472048925”,“siteId”:null,“transactionInfo”:{“amount”:100,“timeStamp”:“2014-06-24T08:34:25-07:00”,“status”:“RESERVED”,“transactionId”:“101344195”},“errorInfo”:null}
I got server error.
My question is: could you point me some guide on how to create a service controller that will handle this kind of call from client?
The incoming json request body is valid:
{
“orderId”: “VT1472048925”,
“transactionInfo”: {
“amount”: 100,
“timeStamp”: “2014-06-24T08:34:25-07:00”,
“status”: “RESERVED”,
“transactionId”: “101344195”
}
}
It seems that my service can’t handle the json request body. I got this error:
Caused by: java.lang.IllegalArgumentException: Could not parse ‘application/x-www-form-urlencoded, application/json’
at com.google.common.net.MediaType.parse(MediaType.java:629) ~[guava-18.0.jar:na]
at com.enonic.xp.web.impl.serializer.RequestBodyReader.readBody(RequestBodyReader.java:23) ~[na:na]
at com.enonic.xp.web.impl.handler.WebDispatcherServlet.newWebRequest(WebDispatcherServlet.java:84) ~[na:na]
at com.enonic.xp.web.impl.handler.WebDispatcherServlet.service(WebDispatcherServlet.java:59) ~[na:na]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[web-jetty-6.10.1.jar:6.10.1]
at com.enonic.xp.web.impl.dispatch.mapping.ServletDefinitionImpl.service(ServletDefinitionImpl.java:39) ~[na:na]
at com.enonic.xp.web.impl.dispatch.pipeline.ServletPipelineImpl.service(ServletPipelineImpl.java:30) ~[na:na]
at com.enonic.xp.web.impl.dispatch.pipeline.FilterChainImpl.doFilter(FilterChainImpl.java:45) ~[na:na]
at com.enonic.xp.web.impl.dispatch.pipeline.FilterChainImpl.doFilter(FilterChainImpl.java:36) ~[na:na]
at com.enonic.xp.portal.impl.auth.AuthFilter.doHandle(AuthFilter.java:45) ~[na:na]
at com.enonic.xp.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:31) ~[na:na]
at com.enonic.xp.web.filter.BaseWebFilter.doFilter(BaseWebFilter.java:33) ~[na:na]
… 54 common frames omitted
Caused by: java.lang.IllegalStateException: null
at com.google.common.base.Preconditions.checkState(Preconditions.java:158) ~[guava-18.0.jar:na]
at com.google.common.net.MediaType$Tokenizer.consumeCharacter(MediaType.java:665) ~[guava-18.0.jar:na]
at com.google.common.net.MediaType.parse(MediaType.java:604) ~[guava-18.0.jar:na]
… 65 common frames omitted
You are right.
For some reason, the HTTP Tool addon in firefox appended “application/x-www-form-urlencoded” to content type “application/json”
I tried RESTClient addon in firefox and it works.