• Question around Rest services

    By Michael Bourak 1 decade ago

    I try to use a custom servlet to provide customised JSON output from a Domino db but can not pass parameters (in a REST Way) to my service.

    I use this method to register a new factory :  factory.addFactory("Products", ...)

    This works but only the/xsp/services/Products url is caught by my service.

    If I try/xsp/services/Products/aDocumentIDorAnything, I got a "command not handled" exception.

    Is this normal ? How can I grab parameters from URL then ?


    Thanks

    • That's a limitation in the current build ...

      By Dave Delay 1 decade ago

      When dispatching requests, the DefaultServiceFactory.createEngine() method does an exact match on the path.  So if you specify "Products" as the path when you call addFactory(), your service will only see requests for/Products.  It will not see requests for/Products/xxx.

       

      I can think of two workarounds:

       

      1) The simplest workaround is to specify the product ID with a URL parameter --/Products?id=xxx.  Then you can parse the product ID when your service gets the request.  Of course, this is not very RESTful.  Ideally, the individual product should have it's own address.  URL parameters shouldn't be necessary.

       

      2) The second workaround is to implement your own ServiceFactory.  You can steal most of the code from DefaultServiceFactory, but your version of createEngine() would know that only the first path element is important when dispatching requests.  I haven't tried creating a different implementation of ServiceFactory, but it should work.

       

      Let us know if either of the above works for you.  Meanwhile, I will discuss this with some other folks on the team and see if we can fix this in a future build.

       

      Thanks.

       

      -- Dave

      • Second workaround

        By Michael Bourak 1 decade ago

        The second workaround works for me but, of course, I hope the extlib can work like that out of the box

         

        Thanks for the info and keep on providing such great stuff !

        • This will be fixed in the next extension library release </>

          By Dave Delay 1 decade ago