cancel
Showing results for 
Search instead for 
Did you mean: 

How to call Java Backend web script from Aikau service?

theobroma
Confirmed Champ
Confirmed Champ

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});
            }
        });
    });
1 ACCEPTED ANSWER

afaust
Legendary Innovator
Legendary Innovator

It's always good to look at existing code of the library you are using. It could provide examples of how to call a backend web script.

View answer in original post

2 REPLIES 2

afaust
Legendary Innovator
Legendary Innovator

It's always good to look at existing code of the library you are using. It could provide examples of how to call a backend web script.

Thank you Axel once more. I've solved it.