1
votes

I would like to build own REST service on domino. I’ve tried sample from ExtLib github source - ‘DAS - Domino REST service’ - com.ibm.domino.services.sample.

http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Create_your_own_Domino_REST_service_using_DAS

I’ve not found how to inject my own context to a Resource. My context has connections to several NotesDatabases, probably will have other objects, which I do not want to initialize every time HTTP request is processed.

In fact I use Spring AppContext to store my context object and other beans I need.

So the question is if there is any possibility how to inject some objects (preferably Spring AppContext) to a Resource object.

I look for something like this:

SampleService.java

package com.ibm.domino.services.sample.resources;
...
public class SampleService extends RestService {

>> private ApplicationContext ctx = new ClassPathXmlApplicationContext(...);


public Set<Class<?>> getClasses() {
    Set<Class<?>> classes = new HashSet<Class<?>>();
    SAMPLE_SERVICE_LOGGER.getLogger().fine("Adding sample service resources."); // $NON-NLS-1$
    classes.add(RootResource.class);
    classes.add(ContactsListResource.class);

    return classes;
}
...

RootResource.java

package com.ibm.domino.services.sample.resources;
...
@Path("sample") // $NON-NLS-1$
public class RootResource {

>> @Inject / @Autowired
>> private ApplicationContext ctx;

/**
 * Gets links.
 * 
 * @param uriInfo
 * @return
 */
@GET
public Response getLinks(@Context UriInfo uriInfo) {
...

I’m a beginner in REST. Probably I’m moving in a wrong direction.

I would appreciate any ideas...

1
I don't think that this JavaEE feature is implemented in Domino.muenzpraeger

1 Answers

0
votes

REST APIs are usually stateless. In DAS each request gets a new instance of lotus.domino.Session. Even if two requests are authenticated by the same user, they will get different Session objects.

Of course there are ways to inject state into your implementation. For example, if you are trying to store per-user state between requests, you could create a static map of objects where the key is a unique user ID. However, you would be responsible for managing the cache. For instance, you would want to occasionally remove entries for inactive users. DAS doesn't help with that.

Also, you wouldn't want to keep any Notes back-end objects around between requests. Instances of Database, View, Document, etc. are all tied to a Session. Usually the Session is recycled at the end of the request so the other back-end objects go with it.