javaxpagesxpages-extlibssjs

Getting JSON data from restService in XPages


Is it possible to get the json data from a restService using code instead of using the pathinfo?

looking for something like: getComponent("restService1").get...

<xe:restService id="restService1" pathInfo="rest">
                    <xe:this.service>
                        <xe:jdbcQueryJsonService connectionName="mssql" contentType="application/json">
                            <xe:this.sqlQuery><![CDATA[SELECT * FROM Order]]></xe:this.sqlQuery>
                        </xe:jdbcQueryJsonService>
                    </xe:this.service>
                </xe:restService>

Solution

  • I don't think that this is possible without deeply hacking into the core ExtLib REST services.

    In these services, the output is generated and written to the defined output stream, which is normally the one from the HttpResponse.

    You have two options for this:

    1. Create your own rest service for jdbcQueryJsonService by extending the existing one and add your own method for accessing the output stream
    2. Use reflection to access the private property which holds the outputstream instance

    For both options I don't think that this is worth the effort. It's a lot easier to create your own JDBC connection to the SQL server and transform the result to JSON by your own.

    EDIT:

    Don't forget that you are accessing a component. A component doesn't know something about the output, which is generated by the renderer depending of the current state of the component. While the ExtLib REST Services are a little bit different of the JSF concepts (their output is generated by a servlet), the pattern is the same.

    That's why no XPages / JSF component has such a method.