AnsweredAssumed Answered

How to call Java Backend web script from Aikau service?

Question asked by theobroma on Dec 19, 2017
Latest reply on Dec 20, 2017 by theobroma

Is it possible to call Java Backend web script from Aikau service using Xhr. I tried it but got status code 500. When I call web script from the (Surf) document library it works. Below is my code:

 

define(["dojo/_base/declare",
        "alfresco/services/BaseService",
        "alfresco/core/CoreXhr",
        "service/constants/Default",
        "alfresco/core/PathUtils",
        "alfresco/enums/urlTypes",
        "dojo/_base/lang",
        "dojo/_base/array"],
    function(declare, BaseService, CoreXhr, AlfConstants, PathUtils, urlTypes, lang, array) {

        return declare([BaseService, CoreXhr, PathUtils], {

            constructor: function alfresco_services_BaseService__constructor(args) {
                this.alfSubscribe("ADD_ITEMS_TO_LIST", lang.hitch(this, this.onAction));
            },

            onAction: function facetedsearch_DocumentService_onAction(payload) {
                var config = {nodesToArchive: []};

                if (payload.nodes)
                {
                    array.forEach(payload.nodes, function(node) {
                        config.nodesToArchive.push({"nodeRef": node.nodeRef});
                    });
                }
                var url ="http://localhost:8080/alfresco/s/com/test/export/documents";
                var headers = {
                    "Content-Type": "application/json"
                };

                this.serviceXhr({
                    url: url,
                    headers: headers,
                    method: "POST",
                    data: {
                        "nodes": config.nodesToArchive
                    },
                    callbackScope: this,
                    successCallback: this.onSuccess,
                    failureCallback: this.onFailure
                });

            },
            onSuccess:
            function facetedsearch_DocumentService_onSuccess(response, originalRequestConfig) {
                var msg = "Items are added successfully.";
                this.alfLog("log", msg, response, originalRequestConfig);
                Alfresco.util.PopupManager.displayMessage({ title: "Info", text: msg});
            },
            onFailure:
            function facetedsearch_DocumentService_onFailure(response, originalRequestConfig) {
                var msg = "Something went wrong.";
                this.alfLog("log", msg, response, originalRequestConfig);
                Alfresco.util.PopupManager.displayMessage({ title: "Info", text: msg});
            }
        });
    });

Outcomes