# Access Repository outside a request

**URL:** <https://community.bloomreach.com/t/access-repository-outside-a-request/2215>\
**Category:** Experience Manager (PaaS/OnPrem)\
**Created:** [November 5, 2020, 4:03pm UTC](https://community.bloomreach.com/t/access-repository-outside-a-request/2215 "2020-11-05T16:03:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/thomas/32/753_2.png) [@Thomas](https://community.bloomreach.com/u/Thomas)\
**Post date:** [November 5, 2020, 4:03pm UTC](https://community.bloomreach.com/t/access-repository-outside-a-request/2215/1 "2020-11-05T16:03:32Z")

</div>

Following the documentation I should be able to access the repository by the following line:

`HippoRepository repository = HippoRepositoryFactory.getHippoRepository("vm://");`

But that ends up in a `java.lang.ClassNotFoundException: org.hippoecm.repository.LocalHippoRepository`

What is my mistake?

**Addition:**  
Using  
`HippoRepository repository = HippoRepositoryFactory.getHippoRepository("rmi://localhost:1099/hipporepository");`  
worked !

I guess the repository is running in cms-Application (JVM) , but my code is running in site-application - in a different JVM- correct?

So I had to enable rmi to get this work.  
Are there any aspects against this approach - or is there even annother approach??

**Further Investigation**  
No I tried to follow the code [here](https://documentation.bloomreach.com/14/library/concepts/fluent-search/fluent-hstquerybuilder-bootstrapping.html)

```
Repository repo = HstServices.getComponentManager().getComponent(Repository.class.getName());
Credentials creds = HstServices.getComponentManager().getComponent(Credentials.class.getName() + ".default");
ContentBeansTool cbt = HstServices.getComponentManager().getComponent(ContentBeansTool.class.getName());

Session session = null;

try {
    session = repo.login(creds);
    HstQueryManager queryManager = cbt.createQueryManager(session);

    final Node scope = JcrUtils.getNodeIfExists("/content/documents/myproject", session);
    final HstQuery hstQuery = HstQueryBuilder.create(scope)
            .ofTypes("myproject:news")
            .build(queryManager);
    // ...
} finally {
    if (session != null) session.logout();
}

```

Unfortunately this code ends up in a `NullPointerException` when trying to connect to the repo ☹  
I am getting frustrated 🙍‍♂️

---

<div class="post-metadata">

**Author:** ![Thomas](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/thomas/32/753_2.png) [@Thomas](https://community.bloomreach.com/u/Thomas)\
**Post date:** [November 21, 2020, 3:55pm UTC](https://community.bloomreach.com/t/access-repository-outside-a-request/2215/2 "2020-11-21T15:55:08Z")

</div>

Is there really nobody, who can help ???

---

<div class="post-metadata">

**Author:** ![ThoLe](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/thole/32/98_2.png) [@ThoLe](https://community.bloomreach.com/u/ThoLe)\
**Post date:** [November 22, 2020, 10:39am UTC](https://community.bloomreach.com/t/access-repository-outside-a-request/2215/3 "2020-11-22T10:39:45Z")

</div>

Hey, if you are trying to get the JCR session in site application then you can easily get it by following way

```auto
HstRequestContext requestContext = RequestContextProvider.get();
Session session = requestContext.getSession()

```

---

<div class="post-metadata">

**Author:** ![Thomas](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/thomas/32/753_2.png) [@Thomas](https://community.bloomreach.com/u/Thomas)\
**Post date:** [November 22, 2020, 11:03am UTC](https://community.bloomreach.com/t/access-repository-outside-a-request/2215/4 "2020-11-22T11:03:33Z")

</div>

And this works **without a request**? As I remember I tried that before - and when I am not wrong RequestContextProvider was null !?

The use case is to query the repository from a ValueListProvider to dynamically populate a dropdown in a ComponentInfo-Interface !!!

---

<div class="post-metadata">

**Author:** ![ThoLe](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/thole/32/98_2.png) [@ThoLe](https://community.bloomreach.com/u/ThoLe)\
**Post date:** [November 22, 2020, 11:08am UTC](https://community.bloomreach.com/t/access-repository-outside-a-request/2215/5 "2020-11-22T11:08:48Z")

</div>

> [@Thomas](#):
>
> ValueListProvider

Then the code should be in the cms module instead of the site ?

---

<div class="post-metadata">

**Author:** ![Thomas](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/thomas/32/753_2.png) [@Thomas](https://community.bloomreach.com/u/Thomas)\
**Post date:** [November 22, 2020, 11:25am UTC](https://community.bloomreach.com/t/access-repository-outside-a-request/2215/6 "2020-11-22T11:25:23Z")

</div>

?? The documentation (see the provided [link](https://documentation.bloomreach.com/14/library/concepts/fluent-search/fluent-hstquerybuilder-bootstrapping.html)) says:

> In cases where you don’t have a HstRequestContext (for example for during some background process or for external application integration that does not involve an HTTP request), you can get hold of the HstQueryManager to build an HstQuery with it (through HstQueryBuilder#build(HstQueryManager) method:

I would prefer to keep all custom code in site-modul (like the ComponentInfo-Interfaces)!

---

<div class="post-metadata">

**Author:** ![ThoLe](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/thole/32/98_2.png) [@ThoLe](https://community.bloomreach.com/u/ThoLe)\
**Post date:** [November 22, 2020, 1:57pm UTC](https://community.bloomreach.com/t/access-repository-outside-a-request/2215/7 "2020-11-22T13:57:21Z")

</div>

If you are talking about this ValueListProvider [https://documentation.bloomreach.com/14/library/concepts/plugins/selections/configuration.html](https://documentation.bloomreach.com/14/library/concepts/plugins/selections/configuration.html) then it must be in the cms module because it will be called by the CMS configuration.

---

<div class="post-metadata">

**Author:** ![Thomas](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/thomas/32/753_2.png) [@Thomas](https://community.bloomreach.com/u/Thomas)\
**Post date:** [November 22, 2020, 2:58pm UTC](https://community.bloomreach.com/t/access-repository-outside-a-request/2215/8 "2020-11-22T14:58:21Z")

</div>

No, I am talking about `@DropDownList` - Annotation for Component Configuration Parameters, as described here: [Annotate Channel or Component Configuration Parameters with UI Directives - Bloomreach Experience Manager (PaaS/Self-Hosted) - The Fast and Flexible Headless CMS](https://documentation.bloomreach.com/12/library/concepts/template-composer/annotate-channel-or-component-configuration-parameters-with-ui-directives.html)

> The set of values can also be dynamically pulled from an implementation of org.hippoecm.hst.core.parameters.ValueListProvider:

```
@Parameter(name = "cssDisplay2", displayName = "CSS Display 2")
@DropDownList(valueListProvider = CssDisplayValueListProvider.class)
String getCssDisplay2();

```

---

<div class="post-metadata">

**Author:** ![ThoLe](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/thole/32/98_2.png) [@ThoLe](https://community.bloomreach.com/u/ThoLe)\
**Post date:** [November 23, 2020, 2:37am UTC](https://community.bloomreach.com/t/access-repository-outside-a-request/2215/9 "2020-11-23T02:37:37Z")

</div>

Class org.hippoecm.repository.LocalHippoRepository is under this library hippo-repository-engine.jar  
You need to check why your module does not have this library in the class path. Using RMI is an option but not a very good way in this case.

---

<div class="post-metadata">

**Author:** ![Thomas](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/thomas/32/753_2.png) [@Thomas](https://community.bloomreach.com/u/Thomas)\
**Post date:** [November 23, 2020, 5:28am UTC](https://community.bloomreach.com/t/access-repository-outside-a-request/2215/10 "2020-11-23T05:28:45Z")

</div>

> [@ThoLe](#):
>
> org.hippoecm.repository.LocalHippoRepository

For which solution? Getting the repository with:  
`Repository repo = HstServices.getComponentManager().getComponent(Repository.class.getName());`

Can you supply a full example?
