Get HstSiteMenu in a REST call

I’ve created two separate functionalities; a repo based menu component following the example in hippo-testsuite [1][2], which I expanded on to also return documents in repo folders as part of the menu, and hst site menus exposed over REST following a blog post [3]. Both work fine on their own.

The problem is that the REST response does not show the children of my repo based menu. I’ve attempted to combine what I’ve done for the repo based menu inside the REST methods to populate the children, with no success.

The problem seems that both start with a request context; HstRequest.getRequestContext() for the component, and RequestContextProvider.get() for the REST call, but they are not the same thing. The next step is to get an HstSiteMenu from the request context using getHstSiteMenus().getSiteMenu(), but doing that on the request context returned by RequestContextProvider.get() gives the following error:

WARN http-nio-8080-exec-10 [HstDelegateeFilterBean.doFilter:426] ContainerException for 'Request{ method='GET', scheme='http', host='localhost:8080', requestURI='/web/ebucks/api-manual/hst/repomenus', queryString='_type=json'}': org.hippoecm.hst.core.container.ContainerException: java.lang.IllegalStateException: HstRequestContext#getHstSiteMenus() is not allowed to be invoked without there being a ResolvedSiteMapItem matched and set on this HstRequestContext.

  • What is the high level difference between HstRequestContext returned by HstRequest.getRequestContext() and RequestContextProvider.get()?

  • Is there a way to get HstSiteMenu from the latter?

  • Is there a different or better way to achieve what I’m attempting? Any examples online I might have missed?

[1] https://code.onehippo.org/cms-community/hippo-testsuite/blob/hippo-testsuite-13.1.0/components/src/main/java/org/hippoecm/hst/demo/components/LeftMenu.java
[2] https://code.onehippo.org/cms-community/hippo-testsuite/blob/hippo-testsuite-13.1.0/components/src/main/java/org/hippoecm/hst/demo/util/DemoRepoBasedMenuItem.java
[3] https://developers.bloomreach.com/blog/2015/exposing-hippo-sitemenus-over-rest.html

I have found a possible answer to why it isn’t working (in my current setup I’m not going via sitemap) and hopefully a solution in a Google Groups thread [1].

I will attempt it in the morning and feedback here if it solves my problem.

[1] https://groups.google.com/d/topic/hippo-community/KA87MKDtZTw/discussion