Hippo CMS and Spring Rest

Hi Everybody,

I wrote a Rest endpoint using JAX-RS to get Hippo CMS contents. Was wondering if HippoCMS supports to use Spring REST to create these endpoints, instead of JAX-RS ?

Many Thanks !

Yes, you can use Spring REST instead. See the following instruction:

Basically the idea is, the delivery tier framework can be integrated with any external web application framework like the documentation explains with Spring MVC example.
If you follow the instruction to combine your Spring REST endpoints with WebApplicationInvokingPipeline, then the delivery tier framework will pre-process the requests to resolve HstRequestContext, mount, sitemap items, content beans, etc. before invoking your application – Spring REST application in your case.
So, your Spring REST controller can simply use HST APIs, including RequestContextProvider.get() and all the methods in HstRequestContext to use full features of HST.

Regards,

Woonsan

Thank you for the detailed response. :slight_smile: Mine is a Spring Boot + Spring Rest application
Apologies for the newbie question:
In the hosts.yaml file i changed the named pipeline
/restservices:
jcr:primaryType: hst:mount
hst:alias:restservices
hst:ismapped:false
hst:namedpipeline:WebApplicationInvokingPipeline
hst:types:[live]
and when i do HstRequestContext requestContext = RequestContextProvider.get();

it returns a null !

Please could you help with some pointers, I need to look at ?

Many thanks

This is an advanced topic. :slight_smile:

I suppose your spring-rest application is deployed together in /site web application and the endpoint of spring-rest app is ‘filtered’ by HstFilter as well. That’s the basic assumption of the integration approach described in:

Could you confirm it?

Woonsan

Thank you!

My project is exactly like your github reference https://github.com/woonsanko/hippo-on-spring-boot, except that I merged my site and deploy module together ie. my beans and rest services are within the deploy module where the boot application is placed , And, the site (module) is removed.

If the site module is removed, then I’m afraid you cannot use HST API including HstRequestContext, etc. at all.
Basically the listener, filter, servlet, etc, in site’s web.xml initialize the HST container on load. That’s not trivial thing you can replace easily in your boot application itself.

That’s why I keep using site.war and cms.war as-is in my github project. Also that’s why I named the module as ‘spring-boot-deploy’, which doesn’t mean I’m providing a real spring-boot application, but just mean I can deploy the whole apps using spring-boot’s embedded tomcat + runtime environment.

It is of course unfortunate because you cannot leverage spring-boot’s development best practice by having to use site.war and cms.war while keeping the boot app as almost empty. But that’s the limitation and how it is, considering our multi-wars-based (cms.war, site.war and interaction through shared libraries) deployment model at the moment.

So, I guess the easiest solution is to keep your spring-rest code in site.war even if you cannot leverage the full feature of spring-boot.

Or someday (perhaps in v13.x+), you could use HST API directly in the boot application somehow to retrieve documents with content bean mappings, etc.

Regards,

Woonsan

P.S. Good try and valid development case. But we don’t support that model (yet).

1 Like

Thats very informative ! . Thanks a million. The reason why I chose to merge the site and deploy module together is because my spring boot application and my rest services are in different modules and my boot app was not able to scan the rest services. So , I thought I will put them together in the same module.