Get wiki page text via REST API

I created a simple rest service that calls org.moqui.impl.WikiServices.get#PublishedWikiPageText and passes the wikiSpaceId and pagePath.
I called it using curl:from the command line and am getting the following error.

 "errorCode" : 500,
  "errors" : "com.fasterxml.jackson.databind.JsonMappingException: The getOutputStream method is not supported for DB resources, use putStream() instead (through reference chain: java.util.HashMap[\"pageReference\"]->org.moqui.impl.context.reference.DbResourceReference[\"outputStream\"])"

I am way out of my depth on DB resources. But reading through this service sounded like what I needed since it has an output parameter “pageText”.

1 Like

Please provide source code and any relevant information, screenshots, etc.

Definitely. I can also show you on community call tomorrow if needed. Some explanation will be helpful.
I have one resource defined that can a) get all blogs, for example to show on a summary page, b) get all blogs for a specific wiki space, and c) once I have a wikiSpaceId and pagePath retrieve the actual content.
Here is the rest service definition:
“sales” is the CRM component I am building. The service used for retrieving a list of blog posts is working fine. I just used a simple entity find for that.
The service call to WikiServices is the one throwing the error.

    <resource name="blogPosts" require-authentication="anonymous-view">
        <method type="get"><service name="sales.SalesServices.get#BlogPosts"/></method>
        <id name="wikiSpaceId">
            <method type="get">
                <service name="sales.SalesServices.get#BlogPosts"/>
            </method>
            <id name="pagePath">
                <method type="get">
                    <service name="org.moqui.impl.WikiServices.get#PublishedWikiPageText"/>
                </method>
            </id>
        </id>
    </resource>

Here is how I am calling it:

curl -X GET -i http://localhost:8080/rest/s1/sales/blogPosts/ZZWR_TMP/Wiki+Page+Path

Here is the stack trace:

Error thrown in Service REST API (500): com.fasterxml.jackson.databind.JsonMappingException: The getOutputStream method is not supported for DB resources, use putStream() instead (through reference chain: java.util.HashMap["pageReference"]->org.moqui.impl.context.reference.DbResourceReference["outputStream"])
com.fasterxml.jackson.databind.JsonMappingException: The getOutputStream method is not supported for DB resources, use putStream() instead (through reference chain: java.util.HashMap["pageReference"]->org.moqui.impl.context.reference.DbResourceReference["outputStream"])
	at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:392) ~[moqui_temp6393091413820938216WEB-INF_lib_jackson-databind-2.13.2.jar.:2.13.2]
	at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:351) ~[moqui_temp6393091413820938216WEB-INF_lib_jackson-databind-2.13.2.jar.:2.13.2]
	at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:316) ~[moqui_temp6393091413820938216WEB-INF_lib_jackson-databind-2.13.2.jar.:2.13.2]
	at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:782) ~[moqui_temp6393091413820938216WEB-INF_lib_jackson-databind-2.13.2.jar.:2.13.2]
	at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178) ~[moqui_temp6393091413820938216WEB-INF_lib_jackson-databind-2.13.2.jar.:2.13.2]
	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:808) ~[moqui_temp6393091413820938216WEB-INF_lib_jackson-databind-2.13.2.jar.:2.13.2]
	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeWithoutTypeInfo(MapSerializer.java:764) ~[moqui_temp6393091413820938216WEB-INF_lib_jackson-databind-2.13.2.jar.:2.13.2]
	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:720) ~[moqui_temp6393091413820938216WEB-INF_lib_jackson-databind-2.13.2.jar.:2.13.2]
	at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:35) ~[moqui_temp6393091413820938216WEB-INF_lib_jackson-databind-2.13.2.jar.:2.13.2]
	at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480) ~[moqui_temp6393091413820938216WEB-INF_lib_jackson-databind-2.13.2.jar.:2.13.2]
	at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319) ~[moqui_temp6393091413820938216WEB-INF_lib_jackson-databind-2.13.2.jar.:2.13.2]
	at com.fasterxml.jackson.databind.ObjectMapper._writeValueAndClose(ObjectMapper.java:4568) ~[moqui_temp6393091413820938216WEB-INF_lib_jackson-databind-2.13.2.jar.:2.13.2]
	at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3821) ~[moqui_temp6393091413820938216WEB-INF_lib_jackson-databind-2.13.2.jar.:2.13.2]
	at org.moqui.impl.context.WebFacadeImpl.sendJsonResponseInternal(WebFacadeImpl.groovy:712) ~[moqui_temp11995651648177304739WEB-INF_lib_moqui-framework-3.0.0-rc8.jar.:3.0.0-rc8]
	at org.moqui.impl.context.WebFacadeImpl.sendJsonResponse(WebFacadeImpl.groovy:675) ~[moqui_temp11995651648177304739WEB-INF_lib_moqui-framework-3.0.0-rc8.jar.:3.0.0-rc8]
	at org.moqui.impl.context.WebFacadeImpl.handleServiceRestCall(WebFacadeImpl.groovy:1101) ~[moqui_temp11995651648177304739WEB-INF_lib_moqui-framework-3.0.0-rc8.jar.:3.0.0-rc8]
	at org.moqui.context.WebFacade$handleServiceRestCall$0.call(Unknown Source) ~[?:?]
	at component___webroot_screen_webroot_rest_xml_transition_s1_actions.run(component___webroot_screen_webroot_rest_xml_transition_s1_actions:8) ~[?:?]
	at org.moqui.impl.actions.XmlAction.run(XmlAction.java:67) ~[moqui_temp11995651648177304739WEB-INF_lib_moqui-framework-3.0.0-rc8.jar.:3.0.0-rc8]
	at org.moqui.impl.screen.ScreenDefinition$TransitionItem.run(ScreenDefinition.groovy:987) ~[moqui_temp11995651648177304739WEB-INF_lib_moqui-framework-3.0.0-rc8.jar.:3.0.0-rc8]
	at org.moqui.impl.screen.ScreenRenderImpl.recursiveRunTransition(ScreenRenderImpl.groovy:749) ~[moqui_temp11995651648177304739WEB-INF_lib_moqui-framework-3.0.0-rc8.jar.:3.0.0-rc8]
	at org.moqui.impl.screen.ScreenRenderImpl.recursiveRunTransition(ScreenRenderImpl.groovy:745) ~[moqui_temp11995651648177304739WEB-INF_lib_moqui-framework-3.0.0-rc8.jar.:3.0.0-rc8]
	at org.moqui.impl.screen.ScreenRenderImpl.internalRender(ScreenRenderImpl.groovy:454) ~[moqui_temp11995651648177304739WEB-INF_lib_moqui-framework-3.0.0-rc8.jar.:3.0.0-rc8]
	at org.moqui.impl.screen.ScreenRenderImpl.render(ScreenRenderImpl.groovy:170) ~[moqui_temp11995651648177304739WEB-INF_lib_moqui-framework-3.0.0-rc8.jar.:3.0.0-rc8]
	at org.moqui.impl.webapp.MoquiServlet.service(MoquiServlet.groovy:118) ~[moqui_temp11995651648177304739WEB-INF_lib_moqui-framework-3.0.0-rc8.jar.:3.0.0-rc8]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[moqui_temp3126128225459437637execlib_javax.servlet-api-3.1.0.jar.:3.1.0]
	at org.eclipse.jetty.servlet.ServletHolder$NotAsync.service(ServletHolder.java:1450) ~[moqui_temp11661744959976421292execlib_jetty-servlet-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799) ~[moqui_temp11661744959976421292execlib_jetty-servlet-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1631) ~[moqui_temp11661744959976421292execlib_jetty-servlet-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:228) ~[moqui_temp10230083386754160190execlib_websocket-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:193) ~[moqui_temp11661744959976421292execlib_jetty-servlet-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1601) ~[moqui_temp11661744959976421292execlib_jetty-servlet-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.moqui.impl.webapp.ElasticRequestLogFilter.doFilter(ElasticRequestLogFilter.groovy:110) ~[moqui_temp11995651648177304739WEB-INF_lib_moqui-framework-3.0.0-rc8.jar.:3.0.0-rc8]
	at org.eclipse.jetty.servlet.FilterHolder.doFilter(FilterHolder.java:193) ~[moqui_temp11661744959976421292execlib_jetty-servlet-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.servlet.ServletHandler$Chain.doFilter(ServletHandler.java:1601) ~[moqui_temp11661744959976421292execlib_jetty-servlet-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:548) ~[moqui_temp11661744959976421292execlib_jetty-servlet-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) ~[moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:600) ~[moqui_temp17217781463160326815execlib_jetty-security-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) ~[moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624) ~[moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) ~[moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1434) ~[moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) ~[moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501) ~[moqui_temp11661744959976421292execlib_jetty-servlet-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594) ~[moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) ~[moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1349) ~[moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:763) ~[moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.Server.handle(Server.java:516) ~[moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:400) ~[moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:645) [moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:392) [moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277) [moqui_temp8759985335529465220execlib_jetty-server-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [moqui_temp10966742692655862941WEB-INF_lib_jetty-io-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) [moqui_temp10966742692655862941WEB-INF_lib_jetty-io-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) [moqui_temp10966742692655862941WEB-INF_lib_jetty-io-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338) [moqui_temp1116335552945224563WEB-INF_lib_jetty-util-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315) [moqui_temp1116335552945224563WEB-INF_lib_jetty-util-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173) [moqui_temp1116335552945224563WEB-INF_lib_jetty-util-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131) [moqui_temp1116335552945224563WEB-INF_lib_jetty-util-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:409) [moqui_temp1116335552945224563WEB-INF_lib_jetty-util-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883) [moqui_temp1116335552945224563WEB-INF_lib_jetty-util-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034) [moqui_temp1116335552945224563WEB-INF_lib_jetty-util-9.4.44.v20210927.jar.:9.4.44.v20210927]
	at java.lang.Thread.run(Thread.java:829) [?:?]
Caused by: java.lang.UnsupportedOperationException: The getOutputStream method is not supported for DB resources, use putStream() instead
	at org.moqui.impl.context.reference.DbResourceReference.getOutputStream(DbResourceReference.groovy:76) ~[moqui_temp11995651648177304739WEB-INF_lib_moqui-framework-3.0.0-rc8.jar.:3.0.0-rc8]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
	at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:689) ~[moqui_temp6393091413820938216WEB-INF_lib_jackson-databind-2.13.2.jar.:2.13.2]
	at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:774) ~[moqui_temp6393091413820938216WEB-INF_lib_jackson-databind-2.13.2.jar.:2.13.2]
	... 63 more

For a quick interpretation of this error: it is happening when attempting to convert the service output to JSON, and the Jackson JSON serializer does not know how to handle the DbResourceReference object. I don’t know why it is trying to get an OutputStream to write to, it probably has code that looks for certain methods and tries calling them, but either way it doesn’t work.

There are two solutions to this that come to mind:

  1. wrap the service or put it in a transition.actions block and remove the ResourceReference so that it does not attempt to JSON serialize the DbResourceReference object
  2. add a plugin for the Jackson JSON serializer (in addition to the few already there) to handle ResourceReference serialization… this might not be the best option because the most natural result of this would be to get the text from the ResourceReference, or maybe Base64 encoded if binary, as a representation of the ResourceReference which is redundant to the pageText in this case
3 Likes

Thanks @jonesde that worked. Below is the wrapper service I created in case anyone is interested. To clarify what you said in option one about removing the ResourceReference… the service in WikiServices has an out parameter:

<parameter name="pageReference" type="org.moqui.resource.ResourceReference"/>

This is what was causing the error. So the wrapper calls the service, puts the results in the map wikiPage, then sets the pageText out parameter. So the only thing that gets returned is the text.

    <service verb="get" noun="PublishedWikiPageText">
        <in-parameters>
            <parameter name="wikiSpaceId" required="true"/>
            <parameter name="pagePath" required="true"/>
        </in-parameters>
        <out-parameters>
            <parameter name="pageText"/>
        </out-parameters>
        <actions>
            <service-call name="org.moqui.impl.WikiServices.get#PublishedWikiPageText" out-map="wikiPage">
                <field-map field-name="wikiSpaceId" from="wikiSpaceId"/>
                <field-map field-name="pagePath" from="pagePath"/>
            </service-call>
            <set field="pageText" from="wikiPage.pageText"/>
        </actions>
    </service>
1 Like