Uploaded image for project: 'Campaign Publisher'
  1. Campaign Publisher
  2. MGNLCAMPU-117

Calling PublishCampaignCommand via rest results in null pointer

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Trivial
    • None
    • 2.0.4

    Description

      When trying to call the PublishCampaignCommand with the commands endpoint I ended up with a null pointer.

      2023-10-04 15:30:25 2023-10-04 12:30:25,618 ERROR o.magnolia.rest.service.command.v2.CommandEndpoint: Error executing command [activate] from catalog [campaign-publisher] with commandMap [{comment=Published via REST, repository=campaigns, path=/Xmas-sample, recursive=false}]
      2023-10-04 15:30:25 java.lang.NullPointerException: null
      2023-10-04 15:30:25     at info.magnolia.campaignpublisher.command.PublishCampaignCommand.getCommandForNode(PublishCampaignCommand.java:160) ~[magnolia-campaign-publisher-2.0.4.jar:?]
      2023-10-04 15:30:25     at info.magnolia.campaignpublisher.command.PublishCampaignCommand.execute(PublishCampaignCommand.java:105) ~[magnolia-campaign-publisher-2.0.4.jar:?]
      2023-10-04 15:30:25     at info.magnolia.commands.CommandsManager.executeCommand(CommandsManager.java:256) ~[magnolia-core-6.2.32.jar:?]
      

      Initially my attempt to make the call was modelled after the publish page example in our docs.

      curl http://localhost:8080/dx-core-webapp/.rest/commands/v2/campaign-publisher/activate \
        -H "Content-Type: application/json" \
        -X POST --user superuser:superuser \
        --data \
      '{
        "comment": "Published via REST",
        "repository": "campaigns",
        "path": "/Xmas-sample",
        "recursive": false
      }'  
      

      After some time debugging I discovered the issue was related to the mappings being null here.

      When trying to publish the path /Xmas-sample through the UI I found that mappings was set to an empty list anyway.

      Why not make sure mappings isn't null...

          private Command getCommandForNode(Node node) throws RepositoryException {
              String nodeType = node.getPrimaryNodeType().getName();
              if (mappings != null) for (PublishCampaignAction.CommandMappingDefinition definition : mappings) {
                  if (nodeType.equals(definition.getNodeType())) {
                      String catalog = definition.getCatalog();
                      String command = definition.getCommand();
                      return commandsManager.getCommand(catalog, command);
                  }
              }
              return commandsManager.getCommand(getCommandName());
          }
      

      In any case I was able to workaround the issue by setting it in the post data:

      curl http://localhost:8080/dx-core-webapp/.rest/commands/v2/campaign-publisher/activate \
        -H "Content-Type: application/json" \
        -X POST --user superuser:superuser \
        --data \
      '{
        "comment": "Published via REST",
        "repository": "campaigns",
        "path": "/Xmas-sample",
        "recursive": false,
        "commandMappings": []
      }'  
      

      Checklists

        Acceptance criteria

        Attachments

          Activity

            People

              Unassigned Unassigned
              rgange Richard Gange
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Checklists

                  Bug DoR
                  Task DoD