Martin Perrie
Martin Perrie

Reputation: 410

xe:viewJsonService and sessionAsSigner

Is it possible to use the ExtLib REST service xe:viewJsonService (and xe:documentJsonService) with the equivalent of sessionAsSigner?

I can do this if I use xe:customRestService and write code for doGet and doPost, but just wondering if there is a way to do the same with the built-in services.

Upvotes: 1

Views: 215

Answers (1)

Cameron Gregor
Cameron Gregor

Reputation: 1460

From what I can tell from the Source Code, unfortunately no you can't :(

Those services extend the abstract class 'RestDominoService'. and they use it's loadDatabase method to get the handle to the database. It does this using it's 'defaultSession' member field.

protected void loadDatabase(DominoParameters parameters) throws NotesException {
    String dbName = parameters.getDatabaseName();
    if(StringUtil.isEmpty(dbName)) {
        if(defaultDatabase==null) {
            throw new IllegalStateException("No default database assigned to the service"); // $NLX-RestDominoService.Nodefaultdatabaseassignedtotheser-1$
        }
        this.database = defaultDatabase;
        this.shouldRecycleDatabase = false;
        return;
    }
    if(defaultSession==null) {
        throw new IllegalStateException("No default session assigned to the service"); // $NLX-RestDominoService.Nodefaultsessionassignedtotheserv-1$
    }
    this.database = DominoUtils.openDatabaseByName(defaultSession,dbName);
    this.shouldRecycleDatabase = true;
}

This 'defaultSession' is set when the RestEngine is created, and uses DominoUtils.getCurrentSession(). This is the equivalent of the 'session' variable in xpages and unfortunetly not the sessionAsSigner. There does not seem to be any point where it could be changed between the RestEngine creation, and the renderService method which generates the response.

    private class Engine extends RestViewJsonService {
        Engine(HttpServletRequest httpRequest, HttpServletResponse httpResponse, Parameters params) {
            super(httpRequest,httpResponse,params);
            setDefaultSession(DominoUtils.getCurrentSession());
            setDefaultDatabase(DominoUtils.getCurrentDatabase());
        }

If you really need to do it certainly could be modified to allow it to be controlled by a property, but this would mean you would build your own version of extension library.

A 'sessionAsSigner' property could be added to com.ibm.xsp.extlib.component.rest.DominoService, and also the definition of the property it in the appropriate xsp-config file.

This property can then be accessed when creating the rest engine

    private class Engine extends RestViewJsonService {
        Engine(HttpServletRequest httpRequest, HttpServletResponse httpResponse, Parameters params) {
            super(httpRequest,httpResponse,params);

            if (isSessionAsSigner()) {
                setDefaultSession(ExtLibUtil.getCurrentSessionAsSigner());
            } else {
                setDefaultSession(DominoUtils.getCurrentSession());
            }

            setDefaultDatabase(DominoUtils.getCurrentDatabase());
        }

I haven't tested it but my brain says it will work, but it is 11pm on a friday.

It might just be easier to stick with your customRestService for now if you are not in the habit of cooking up your own version of the Extension Library.

Upvotes: 3

Related Questions