Error in HTTP GET Request with gadgets.io.makeRequest

678 views Asked by At

Sorry but I spent a half a day practicing first with gadgets.io.makeRequest, and can not understand why the request response contains an error. The code is Javascript working as OpenSocial gadget:

requestURI = "https://jazz.server.com:9443/rm/views?projectURL=https%3A%2F%2Fjazz.server.com%3A9443%2Frm%2Fprocess%2Fproject-areas%2F_FvrWIG3nEeexYJvvGxVsZg&amp;oslc.query=true&oslc.prefix=rt=<https://jazz.server.com:9443/rm/types/>&oslc.select=rt:_W0SGoW3nEeexYJvvGxVsZg";
makeGETRequest(requestURI);

...

function makeGETRequest(url) {
    try {
        var params = {};
        params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
        params[gadgets.io.RequestParameters.HEADERS] = {
                  "Accept" : "application/rdf+xml",
                  "OSLC-Core-Version": "2.0"
                }
        gadgets.io.makeRequest(url, function(obj) {
            console.log("===== HTTP REQUEST START =====");
            console.log("Method   : GET");
            console.log("URL      : " + url);
            console.log("Response : " + obj.text);
            console.log("====== HTTP REQUEST END ======");
        }, params);
    }
    catch(err) {
        console.log("Can not perform HTTP request because of error: " + err.message);
    }
};

When I do the same request with REST Client in Firefox, everything works properly. But if I do that with the code above, then I get an error in the log (abbreviated):

===== HTTP REQUEST START =====
common.js:311 Method   : GET
common.js:312 URL      : https://jazz.server.com:9443/rm/views?projectURL=https%3A%2F%2Fjazz.server.…roject-areas%2F_FvrWIG3nEeexYJvvGxVsZg&amp;oslc.query=true&oslc.prefix=rt=<https://jazz.server.com:9443/rm/types/>&oslc.select=rt:_W0SGoW3nEeexYJvvGxVsZg
common.js:313 Response : {"errorMessage":"Illegal character in query at index 178: https:&#x2F;&#x2F;jazz.server.com:9443&#x2F;rm&#x2F;views?projectURL=https%3A%2F%2Fjazz.server.com%3A9443%2Frm%2Fprocess%2Fproject-areas%2F_FvrWIG3nEeexYJvvGxVsZg&amp;amp;oslc.query=true&amp;oslc.prefix=rt=&lt;https:&#x2F;&#x2F;jazz.server.com:9443&#x2F;rm&#x2F;types&#x2F;&gt;&amp;oslc.select=rt:_W0SGoW3nEeexYJvvGxVsZg","errorClass":"java.lang.IllegalArgumentException","errorTrace":["java.net.URI.create(URI.java:871)","org.apache.http.client.methods.HttpGet.<init>
...
common.js:314 ====== HTTP REQUEST END ======

I tried to replace greater and less symbols by their hex values but there's no result. And there's no ideas currently. May be somebody could make a fresh sight to the code and define the problem on the fly. Help me please, I'm at a dead end. Thank you very much in advance for any advice!

2

There are 2 answers

2
MrKickkiller On

The error in your Response indicates the Java system on the server side can't create a valid URI from your query. Therefor it throws back an error

My best guess would be the dot just before query=true in oslc.query=true. And therefor all following uses of oslcDOT .

From RFC 1738 specification:

Thus, only alphanumerics, the special characters "$-_.+!*'(),", and reserved characters used for their reserved purposes may be used unencoded within a URL.

0
Dmitry A. Smirnov On

I discovered that gadgets.io.makeRequest isn't very stable as I would like to expect. May be I do some wrong but sometimes this function completes without any feedback and without starting the response function in the parameters. I changed to next code:

function makeGETRequest(urlValue) {
    try {
        $.ajax({
            url: urlValue,
            type: 'GET',
            dataType: 'text',
            headers: {
                'Accept': 'application/rdf+xml',
                'OSLC-Core-Version': '2.0'
            },
            success: function (result) {
               var data = result;

            },
            error: function (error) {
                console.log("Can not perform HTTP request because of error: " + error.message);
            }
        });
    }
    catch(err) {
        console.log("Can not perform HTTP request because of error: " + err.message);
    }
};

And there's no problem!