cancel
Showing results for 
Search instead for 
Did you mean: 

Activiti 5.16 REST api returning XML not JSON

joeysr20det
Champ in-the-making
Champ in-the-making
I setup an Activiti 5.16 test environment a couple days ago; I deployed the activiti-explorer.war and activiti-rest.war to a Tomcat 7 instance. Everything appears to be up and running just fine without any errors. I'm attempting to use the REST api and i'm running into issues. I'm calling the management/engine service to get engine info with a basic auth header using kermit for the username and password, and I'm also including Content-Type application/json. Everything works, authentication completes, and I get a response with the name, version, etc… but it's in XML not JSON?

Is there some special switch I need to be using to get JSON or something I need no to do to avoid getting XML?

I'm using the Firefox RESTClient to call:

GET http://mouse:8084/activiti-rest/service/management/engine

using kermit as the username and password, with the Content-Type application/json.

Is there something I'm missing?

Thanks

Joey
6 REPLIES 6

joeysr20det
Champ in-the-making
Champ in-the-making
I just wanted to follow up. If the URL doesn't end with a forward slash it returns XML. If it does end with a forward slash it returns JSON. I don't know if that a standard REST or JSON thing; I haven't seen this kind of functionality before and the guide doesn't mention it (that I've come across).

http://mouse:8084/activiti-rest/service/management/engine

returns XML

http://mouse:8084/activiti-rest/service/management/engine/

return JSON




joeysr20det
Champ in-the-making
Champ in-the-making
Never mind… the JSON you get with a trailer slash is just the standard JSON error block Smiley Happy

Still searching for an answer on this one…..

pmsevestre
Champ in-the-making
Champ in-the-making
Instead of a Content-Type header, try an "Accept" header. Use application/json as the expected data type.

joeysr20det
Champ in-the-making
Champ in-the-making
Cool that worked! I didn't think to even try that. I read the Activiti 5.16 documentation thoroughly and didn't find anything about getting absolutely any other return type than JSON EXCEPT a type of multipart when your downloading a file. I really wouldn't have thought I would have had to explicitly tell Activiti to give me JSON if that's all it says you'll get in the documentation Smiley Happy

Activiti people: Just for the record, I ran into this with Chrome and Firefox with REST plugins and with my Java URL connection. I don't know if this is a bug or maybe desired functionality for different response types.

Thanks pmsevestre!

frederikherema1
Star Contributor
Star Contributor
Is the returned XML actually representing the result you expect (eg. http://mouse:8084/activiti-rest/service/management/engine returns engine details as XML)? This is probably a side-effect of the usage of Restlet as a REST-framework. Since we use Jackson message converters, both JSON and XML can be generated in theory…

joeysr20det
Champ in-the-making
Champ in-the-making
It sure does and it's completely correct. However, I did run into errors with services that returned JSON array because they don't marshall correctly to XML. I suppose if you wanted XML and knew what the service returned (structure wise) you could parse it properly yourself. Anyhow, here are few samples of output from my Activiti 5.16 instance:

GET /activiti-rest/service/management/engine:


    <ProcessEngineInfoResponse>
    <name>default</name>
    <resourceUrl>file:/C:/Users/joey/AppData/Roaming/NetBeans/7.2/apache-tomcat-7.0.27.0_base/webapps/activiti-rest/WEB-INF/classes/activiti-context.xml</resourceUrl>
    <exception/>
    <version>5.16</version>
    </ProcessEngineInfoResponse>

GET /activiti-rest/service/repository/deployments/1506/resources

This one returns an HTTP 500 from Tomcat and the Tomcat log reveals the following. I imagine it's because this service is trying to return a JSON array in XML:


java.io.IOException: javax.xml.stream.XMLStreamException: Trying to output second root, <ArrayList>
at com.fasterxml.jackson.dataformat.xml.util.StaxUtil.throwXmlAsIOException(StaxUtil.java:24)
at com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator._handleStartObject(ToXmlGenerator.java:428)
at com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.writeStartObject(ToXmlGenerator.java:397)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:138)
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:100)
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:21)
at com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:186)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:222)
at com.fasterxml.jackson.dataformat.xml.ser.XmlSerializerProvider.serializeValue(XmlSerializerProvider.java:87)
at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:683)
at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:534)
at org.restlet.ext.jackson.JacksonRepresentation.write(JacksonRepresentation.java:474)
at org.restlet.engine.adapter.ServerCall.writeResponseBody(ServerCall.java:519)
at org.restlet.engine.adapter.ServerCall.sendResponse(ServerCall.java:463)
at org.restlet.ext.servlet.internal.ServletCall.sendResponse(ServletCall.java:430)
at org.restlet.engine.adapter.ServerAdapter.commit(ServerAdapter.java:196)
at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:153)
at org.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:1118)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)