Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
root
Creator II
Creator II

RESTful web service error (POST with json content)

I am trying to call a RESTful service which is created in ESB using tRESTRequest/ tRESTResponse. I am calling the same via tRestClient. I am not sure if the service is able to receive the request or process it. What am I doing wrong? 
Below are some screens:
Client. I am creating a json request and posting it to the service.
0683p000009MDDZ.png
tRestClient config:

0683p000009MD28.png
RESTFUL service job design. I would like to accept a json input.

0683p000009MD4D.png
Output component details:

0683p000009MD9J.png
Here are the log n the output of the trestclient:
Starting job restconsumer at 15:14 27/03/2015.
connecting to socket on port 3854
connected
: net.sf.json.xml.XMLSerializer - Using default type string
: org.apache.cxf.interceptor.LoggingOutInterceptor - Outbound Message
---------------------------
ID: 1
Address: http://localhost:8088/getScore
Http-Method: POST
Content-Type: application/json
Headers: {Content-Type=, Accept=}
--------------------------------------
: org.apache.cxf.interceptor.LoggingInInterceptor - Inbound Message
----------------------------
ID: 1
Response-Code: 400
Encoding: ISO-8859-1
Content-Type: 
Headers: {Content-Length=, Date=, Server=}
--------------------------------------
400|
disconnected
Job restconsumer ended at 15:14 27/03/2015.
Log / output of restservice
Starting job Service at 15:13 27/03/2015.
connecting to socket on port 3529
connected
: org.apache.cxf.endpoint.ServerImpl - Setting the server's publish address to be http://localhost:8088/
: org.eclipse.jetty.server.Server - jetty-8.1.15.v20140411
: org.eclipse.jetty.server.AbstractConnector - Started SelectChannelConnector@localhost:8088
: org.apache.cxf.interceptor.LoggingInInterceptor - Inbound Message
----------------------------
ID: 1
Address: http://localhost:8088/getScore
Encoding: ISO-8859-1
Http-Method: POST
Content-Type: application/json
Headers: {Accept=, Cache-Control=, connection=, Content-Length=, content-type=, Host=, Pragma=, User-Agent=}
--------------------------------------
: org.apache.cxf.jaxrs.provider.AbstractJAXBProvider - Message body is empty
: org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper - javax.ws.rs.BadRequestException
at org.apache.cxf.jaxrs.utils.SpecExceptions.toBadRequestException(SpecExceptions.java:82)
at org.apache.cxf.jaxrs.utils.ExceptionUtils.toBadRequestException(ExceptionUtils.java:109)
at org.apache.cxf.jaxrs.provider.AbstractJAXBProvider.reportEmptyContentLength(AbstractJAXBProvider.java:236)
at org.apache.cxf.jaxrs.provider.json.JSONProvider.readFrom(JSONProvider.java:211)
at org.apache.cxf.jaxrs.provider.dom4j.DOM4JProvider.readFrom(DOM4JProvider.java:71)
at org.apache.cxf.jaxrs.provider.dom4j.DOM4JProvider.readFrom(DOM4JProvider.java:42)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1258)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1205)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:756)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:715)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:252)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:88)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:65)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1088)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1024)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:370)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Unknown Source)
: org.apache.cxf.interceptor.LoggingOutInterceptor - Outbound Message
---------------------------
ID: 1
Response-Code: 400
Content-Type: 
Headers: {Date=, Content-Length=}
--------------------------------------
Labels (6)
6 Replies
Anonymous
Not applicable

Hi plumberg,
I suspect the issue is that you are expecting the body to be a Document. If you change the tRestRequest schema to have "body" as a String and supply the JSON as a string to the "string" output column of the tWriteJSONField component, it should work
Regards
Richard
root
Creator II
Creator II
Author

Thanks. I tried that, still no go.
I tried another method.. used a tRest component instead of tRestClient... and the request did reach the service. I am not sure what I am doing wrong with the tRestClient... Any pointers appreciated
0683p000009MDEC.png
Anonymous
Not applicable

Hi 
: org.apache.cxf.jaxrs.provider.AbstractJAXBProvider - Message body is empty

tRestClient requires a Document as input request, but tWriteJsonField generates a string. You need to use a tXMLMap before tRestClient to generate a Document. In the restful webservice, use a tXMLMap after tRestRequest to extract data from the Document.
Best regards
Shong
Anonymous
Not applicable

The service requires JSON, not XML Shong. In this case it can be supplied as a String. I have tested this out and supplying a JSON String does work. I believe that plumberg may not be selecting the correct "Output Column" in the tWriteJSONField.
root
Creator II
Creator II
Author

The service requires JSON, not XML Shong. In this case it can be supplied as a String. I have tested this out and supplying a JSON String does work. I believe that plumberg may not be selecting the correct "Output Column" in the tWriteJSONField.

Thanks @Rhall. will recheck settings of output.
Anonymous
Not applicable

Yes, @plumberg, if you want to pass a json string to the webservice, change the data type of body column to String on tRestRequest as Rhall suggested.
BR
Shong