How do I access my REST builder application

thumbnail
Steve Weiss, modified 3 Years ago. Regular Member Posts: 112 Join Date: 9/20/11 Recent Posts

I've built an application using REST builder using DeveloperStudio 3.9.7. It compiled and deployed to LR 7.4 (liferay-dxp-7.4.13.u36/) without any errors. It shows up in the gogo shell when I run "jaxrs:check" (see attached screen capture). My rest-openapi.yaml file is as follows:

 

info:
   description: DlService REST API
   license:
      name: Apache 2.0
      url: http://www.apache.org/licenses/LICENSE-2.0.html
   title: DlService
   version: v1.0
openapi: 3.0.1
components:
   schemas:
      Folder:
         description: Contains all of the data for a folder in the Liferay document library.
         properties:
            name:
               description: The folder name
               type: string
            folderId:
               description: The folder ID.
               type: string
            description:
               description: The folder description
               type: string
            documents:
               description: A list of documents contained in this folder.
               items:
                  $ref: '#/components/schemas/Document'
               type: array
            folders:
               description: A list of sub-folders of this folder.
               items:
                  $ref: '#/components/schemas/Folder'
               type: array
            creator:
               allOf:
               -  $ref: '#/components/schemas/Creator'
               description: The folder's creator.
               readOnly: true
         type: object
      Document:
         description: A document in the document library
         properties:
            title:
               description: The title of the document.
               type: string
            documentId:
               description: The document ID.
               type: string
            description:
               description: The document description
               type: string
            extension:
               description: The file extension on the document
               type: string
            downloadUrl:
               description: The URL for downloading the document
               type: string
            dateCreated:
               description: The date the document was created.
               format: date-time
               readOnly: true
               type: string
            dateModified:
               description: The date the document was last modified.
               format: date-time
               readOnly: true
               type: string
            creator:
               allOf:
               -  $ref: '#/components/schemas/Creator'
               description: The document's creator.
               readOnly: true
         type: object
      Creator:
         description: Represents the user account of the content's creator/author. Properties follow the [creator](https://schema.org/creator)
            specification.
         properties:
            additionalName:
               description: The author's additional name (e.g., middle name).
               readOnly: true
               type: string
            familyName:
               description: The author's surname.
               readOnly: true
               type: string
            givenName:
               description: The author's first name.
               readOnly: true
               type: string
            id:
               description: The author's ID.
               format: int64
               readOnly: true
               type: integer
            image:
               description: A relative URL to the author's profile image.
               format: uri
               readOnly: true
               type: string
            name:
               description: The author's full name.
               readOnly: true
               type: string
            profileURL:
               description: A relative URL to the author's user profile.
               format: uri
               readOnly: true
               type: string
         type: object
paths:
   /dl-service/folders/{folderId}:
      get:
         operationId: getFolder
         tags:
         - Folder
         description: Retrieves the Folder via its ID.
         parameters:
         -  name: folderId
            in: path
            required: true
            schema:
               type: string
         responses:
            200:
               description: ''
               content:
                  application/json:
                     schema:
                        $ref: '#/components/schemas/Folder'
                  application/xml:
                     schema:
                        $ref: '#/components/schemas/Folder'

 

But when I try http://localhost:8080/o/v1.0/dl-service/folders/43741 in my browser I get a 404 error.

 

So I'm trying to figure out what the correct URL is. Any help would be greatly appreciated.


 

thumbnail
Russell Bohl, modified 3 Years ago. Expert Posts: 308 Join Date: 2/13/13 Recent Posts

I'm not familiar with building REST APIs, but for example, this is how I'd call a URL to a forms endpoint:

curl -X 'GET' 'http://localhost:8080/o/headless-form/v1.0/sites/20121/[SiteId]'  -u '[me@liferay.com:myPass]'

Site Id, user name, and password will vary of course. It's not a great example because it's a deprecated API, but it gets the point across.

Your URL structure looks different, in that it's missing the baseURI after the /o/ (defined in a rest-config.yaml as I seein Liferay's src code and the documentation).

thumbnail
Steve Weiss, modified 3 Years ago. Regular Member Posts: 112 Join Date: 9/20/11 Recent Posts

Thanks Russell. I hadn't seen that documentation before, it looks a bit more thorough than the one I found: https://help.liferay.com/hc/en-us/articles/360028748872-Generating-APIs-with-REST-Builder

 

I'll look through it, thanks again.

thumbnail
Steve Weiss, modified 3 Years ago. Regular Member Posts: 112 Join Date: 9/20/11 Recent Posts

I do have the baseURI property, it's in a separate file, rest-config.yaml:

 

apiDir: "../dl-service-api/src/main/java"
apiPackagePath: "gov.nasa.hq.liferay.dlservice"
application:
    baseURI: "/dl-service"
    className: "DlServiceApplication"
    name: "DlService"
author: "sweiss"
clientDir: "../dl-service-client/src/main/java"
testDir: "../dl-service-test/src/testIntegration/java"

 

thumbnail
Russell Bohl, modified 3 Years ago. Expert Posts: 308 Join Date: 2/13/13 Recent Posts

So you'd use the baseURI value in your URL; in my example the baseURI was the headless-form part. But if your enpoint isn't showing up in the API explorer (probably also under a menu item named after the baseURI) there may be some other issue.

thumbnail
David H Nebinger, modified 3 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts

An easy way to find this kind of detail is to just use the API explorer at /o/api

It can show you how Liferay presents your RESTBuilder solution, plus you can even run some active tests...

thumbnail
Steve Weiss, modified 3 Years ago. Regular Member Posts: 112 Join Date: 9/20/11 Recent Posts

My application doesn't seem to show up there. It does show up in the gogo shell though.

thumbnail
David H Nebinger, modified 3 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts

Use scr:list <bundle id> to list all of the OSGi component services in the bundle and ensure that all of the components are active.

If there are some that are not, use scr:info <service id> to see what problems they may have....

thumbnail
Steve Weiss, modified 3 Years ago. Regular Member Posts: 112 Join Date: 9/20/11 Recent Posts

Here is the output from the impl bundle, all seem to be active:

 

gov.nasa.hq.liferay.dlservice.internal.resource.v1_0.FolderResourceImpl in bundle 1,671 (gov.nasa.hq.liferay.dlservice.impl:1.0.0) enabled, 1 instance.
    Id: 10732, State:ACTIVE
gov.nasa.hq.liferay.dlservice.internal.resource.v1_0.OpenAPIResourceImpl in bundle 1,671 (gov.nasa.hq.liferay.dlservice.impl:1.0.0) enabled, 1 instance.
    Id: 10733, State:ACTIVE
gov.nasa.hq.liferay.dlservice.internal.graphql.servlet.v1_0.ServletDataImpl in bundle 1,671 (gov.nasa.hq.liferay.dlservice.impl:1.0.0) enabled, 1 instance.
    Id: 10730, State:ACTIVE
gov.nasa.hq.liferay.dlservice.internal.jaxrs.application.DlServiceApplication in bundle 1,671 (gov.nasa.hq.liferay.dlservice.impl:1.0.0) enabled, 1 instance.
    Id: 10731, State:ACTIVE
gov.nasa.hq.liferay.dlservice.internal.resource.v1_0.factory.FolderResourceFactoryImpl in bundle 1,671 (gov.nasa.hq.liferay.dlservice.impl:1.0.0) enabled, 1 instance.
    Id: 10734, State:ACTIVE
thumbnail
Steve Weiss, modified 3 Years ago. Regular Member Posts: 112 Join Date: 9/20/11 Recent Posts

If I run: scr:info DlService I get an error:

 

Error: Multiple components matching "DlService": [com.liferay.document.library.internal.upgrade.registry.DLServiceUpgradeStepRegistrator, gov.nasa.hq.liferay.dlservice.internal.resource.v1_0.FolderResourceImpl, gov.nasa.hq.liferay.dlservice.internal.resource.v1_0.OpenAPIResourceImpl, gov.nasa.hq.liferay.dlservice.internal.graphql.servlet.v1_0.ServletDataImpl, com.liferay.document.library.internal.verify.DLServiceVerifyProcess, gov.nasa.hq.liferay.dlservice.internal.jaxrs.application.DlServiceApplication, com.liferay.dynamic.data.lists.internal.upgrade.registry.DDLServiceUpgradeStepRegistrator, gov.nasa.hq.liferay.dlservice.internal.resource.v1_0.factory.FolderResourceFactoryImpl]

 

Could the problem be a name conflict?

thumbnail
Russell Bohl, modified 3 Years ago. Expert Posts: 308 Join Date: 2/13/13 Recent Posts

It's probably worth a shot to test a quick refactor.

thumbnail
Steve Weiss, modified 3 Years ago. Regular Member Posts: 112 Join Date: 9/20/11 Recent Posts

scr:info gov.nasa.hq.liferay.dlservice.internal.jaxrs.application.DlServiceApplication

 

Output

Component Description: gov.nasa.hq.liferay.dlservice.internal.jaxrs.application.DlServiceApplication
====================================================================================================
Class:         gov.nasa.hq.liferay.dlservice.internal.jaxrs.application.DlServiceApplication
Bundle:        1671 (gov.nasa.hq.liferay.dlservice.impl:1.0.0)
Enabled:       true
Immediate:     false
Services:      [javax.ws.rs.core.Application]
Scope:         singleton
Config PID(s): [gov.nasa.hq.liferay.dlservice.internal.jaxrs.application.DlServiceApplication], Policy: optional
Base Props:    (4 entries)
  liferay.jackson<String> = false
  osgi.jaxrs.application.base<String> = /dl-service
  osgi.jaxrs.extension.select<String> = (osgi.jaxrs.name=Liferay.Vulcan)
  osgi.jaxrs.name<String> = DlService

Component Configuration Id: 10731
---------------------------------
State:        ACTIVE
Service:      (total 4)
  20377 [javax.ws.rs.core.Application]
    Used by bundle 1489 (org.apache.aries.jax.rs.whiteboard:2.0.0)20378 [org.osgi.service.http.context.ServletContextHelper]
    Used by bundle 536 (com.liferay.portal.security.auth.verifier:6.0.14)
    Used by bundle 1489 (org.apache.aries.jax.rs.whiteboard:2.0.0)20381 [javax.servlet.Servlet]
    Used by bundle 77 (org.eclipse.equinox.http.servlet:1.2.2.v20211119-2358-LIFERAY-CACHED)20388 [com.liferay.oauth2.provider.scope.spi.scope.finder.ScopeFinder]
    Used by bundle 756 (com.liferay.oauth2.provider.scope.impl:4.0.17)
Config Props: (6 entries)
  component.id<Long> = 10731
  component.name<String> = gov.nasa.hq.liferay.dlservice.internal.jaxrs.application.DlServiceApplication
  liferay.jackson<String> = false
  osgi.jaxrs.application.base<String> = /dl-service
  osgi.jaxrs.extension.select<String> = (osgi.jaxrs.name=Liferay.Vulcan)
  osgi.jaxrs.name<String> = DlService
References:   (total 0)