How to call Java Backend web script from Aikau service?

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member II

How to call Java Backend web script from Aikau service?

Jump to solution

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 Solution

Accepted Solutions
Highlighted
Master

Re: How to call Java Backend web script from Aikau service?

Jump to solution

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 solution in original post

2 Replies
Highlighted
Master

Re: How to call Java Backend web script from Aikau service?

Jump to solution

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 solution in original post

Highlighted
Active Member II

Re: How to call Java Backend web script from Aikau service?

Jump to solution

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