SOAP Request with WSSE-Header in Javascript - javascript

I have the following code to execute a SOAP request with an wsse header but it seems not to work. I get a error response but I am not able to get the fault/error out of the response.
Does the below code look correct or do I miss something?
var request = "<soapenv:Envelope" +
"xmlns:dlg='http://dlg123Lib'" +
"xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>" +
"<soapenv:Header>" +
"<wsse:Security" +
"xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'" +
"xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'>" +
"<wsse:UsernameToken wsu:Id='UsernameToken-BF09AFF37A2C36D4AB164000000000000000'>" +
"<wsse:Username>BLABLABLA</wsse:Username>" +
"<wsse:Password Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'>BLABLABLA</wsse:Password>" +
"</wsse:UsernameToken>" +
"</wsse:Security>" +
"</soapenv:Header>" +
"<soapenv:Body>" +
"<dlg:getData>" +
"<name>AB</name>" +
"</dlg:getData>" +
"</soapenv:Body>" +
"</soapenv:Envelope>"
jQuery.ajax({
url: 'https://endpoint_url/dlg/data',
type: "POST",
data: request,
dataType: "xml",
contentType: "text/xml; charset='utf-8'",
success: function (soapResponse) {
alert("Success");
},
error: function (soapResponse) {
alert("Error");
}
});
When I execute the exact same request like above in SoapUI without setting an Authorization the request is executed correctly.
So it must be something wrong with the jQuery implementation(?)
UPDATE 15.01.2022
I was told by the customer that the Payload of the request is empty. Anybody an idea why this could happen?

Related

Handling file download from ajax get request in JavaScript

I am using a python CGI server to handle a cgi-bin request that I am making from an ajax call.
I'm trying to download the information I'm receiving on the Python side from my browser, using a button that triggers the ajax call.
I have tried some different things I saw on StackOverflow, but nothing has helped.
function issueDownloadCmd(port) {
var statusURL = window.location.protocol + "//" + window.location.host + "/cgi-bin/sod_log.py" + "?" + "down" + port.toString();
$.ajaxSetup({ 'cache': true });
$.ajax({
type: 'GET',
url: statusURL,
error: function (xhr, desc, exception) {
$('#traceStatus').html("Fail: response=" + xhr.status + "\nbecause: " + desc + "\nexception: " + exception);
},
success: function (data) {
console.log("data was downloaded");
}
});
return false;
}

SOAP "POST" request (AJAX) in JavaScript (VUE) in Browser not giving right response

I have been trying to POST a SOAP request via $ajax (see below) to a remote web service. I am using unsecure Chrome and testing from localhost, the response is not what I am getting on SOAPUI.
I have tested the same service with the same parameters in SOAPUI and it works perfectly. In the browser I am getting a 200 code but getting an error code that is built in the web service. what am i doing wrong? does it have to do with the browser? AJAX?
data () {
return {
str: '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">' +
'<soapenv:Header>' +
'<tem:ROClientIDHeader>' +
'<tem:ID>{E5D6D2B8-3624-4959-872A-E536B213DCA0}</tem:ID>' +
'</tem:ROClientIDHeader>' +
'</soapenv:Header>' +
'<soapenv:Body>' +
'<tem:LeerlingService___FindLeerling>' +
'<tem:Credentials>' +
'<tem:Username>TONATHIU</tem:Username>' +
'<tem:Password>tonathiu</tem:Password>' +
'</tem:Credentials>' +
'<tem:INSZNummer>8788041754941</tem:INSZNummer>' +
'<tem:Naam>Redroban</tem:Naam>' +
'<tem:Voornaam>Tonathiu</tem:Voornaam>' +
'<tem:GeboorteDatum>1988-04-17T00:00:00.000Z</tem:GeboorteDatum>' +
'<tem:EnkelZoekenOpINSZ>false</tem:EnkelZoekenOpINSZ>' +
'</tem:LeerlingService___FindLeerling>' +
'</soapenv:Body>' +
'</soapenv:Envelope>'
}
},
methods: {
soapRequest () {
$.ajax({
type: 'POST',
url: 'my web service',
data: this.str,
success: function (result) {
console.log(result)
},
contentType: 'application/xml',
dataType: 'text/xml;'
})
},
Problem solved!
<tem:GeboorteDatum>
This should have been <tem:Geboortedatum>. Always check what the back-end is looking for. The strangest part was that SoapUI was correcting that for me, and was not noticed.

Ajax character encoding changed after send to server

I have an ajax like this:
$.ajax('../EditUser?userId=' + editingId + '&full_name=' + name + '&position=' + position + '&office=' + office
+ '&office_address=' + office_address + '&age=' + age + '&user_login_name=' + user_login_name + '&email=' + email
+ '&user_type=' + usertype + '&password=' + password + '&meetingIds=' + selectedmeetingid, {
type: 'POST',
success: function (data) {
if (data.indexOf('error://') < 0) {
$('#tbl_meetings').html(data);
} else {
$('#errorMessage').html(data);
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert("error " + errorThrown);
alert("error " + textStatus);
alert("error " + jqXHR.status);
}
}
);
and my server received data with wrong encoding,example: "Hà Thị Minh Thắng" became "H? Th? Minh Th?ng" after received on server side.I tried adding
contentType: "application/x-www-form-urlencoded;charset=ISO-8859-15",
and
beforeSend: function(jqXHR) {
jqXHR.overrideMimeType('text/html;charset=iso-8859-1');
}
to my ajax but it didn't works. So, anyone know how to fix this?
Try specifying content type to the ajax request & you have to add header to the server side to receive the charset.
$.ajax({
data: parameters,
type: "POST",
url: your-url,
timeout: 20000,
contentType: "application/x-www-form-urlencoded;charset=ISO-8859-1",
dataType: 'json',
success: callback
});
// Server Side... (This is an example in php which I have used in my app)
header('Content-Type: text/html; charset=ISO-8859-1');
Hope this helps you!

jQuery 1.8 ajax call returns null although post response has value

I'm having problems with the return value of a jQuery ajax call. I can debug the whole thing server side and I know everything is working correctly and the return value is properly being calculated. I can look under the NET tab in FireBug and see that the response is:
{"d":false}
But when I test the value in the Success function of the ajax call, msg is NULL. Why?
Here's the ajax call:
function GetStateCertifiable(areaID) {
$.ajax({
url: "../WebServices/AoP.asmx/GetStateCertifiable",
data: '{"AreaID":"' + areaID + '"}',
dataType: 'json',
success: function (msg) {
alert(msg); // for debugging
if (msg)
$("#isCertified").slideDown("fast");
else
$("#isCertified").slideUp("fast");
},
error: function (msg) {
alert("An error occured. \nStatus: " + result.status
+ "\nStatus Text: " + result.statusText
+ "\nError Result: " + result);
},
complete: function () {
}
});
};
Other, similarly structured client-side calls work fine. This is a same-domain request.
try changing the name of the variable to something other than msg. I think that might be a message box or something similar. Try
function GetStateCertifiable(areaID) {
$.ajax({
url: "../WebServices/AoP.asmx/GetStateCertifiable",
data: '{"AreaID":"' + areaID + '"}',
dataType: 'json',
success: function (result) {
alert(result); // for debugging
if (result)
$("#isCertified").slideDown("fast");
else
$("#isCertified").slideUp("fast");
},
error: function (result) {
alert("An error occured. \nStatus: " + result.status
+ "\nStatus Text: " + result.statusText
+ "\nError Result: " + result);
},
complete: function () {
}
});
};
It turns out the problem was that my web service (../WebServices/AoP.asmx/GetStateCertifiable) returned a bool and from the post response, I know that was properly sent back to the client. Ajax, however, didn't like that. Once I changed the web service to return the strings "true" or "false", everything worked.
Does jQuery ajax only work for strings or is there something I should have done to prepare the msg object to receive a bool?

Jquery ajax call throws empty JS exception?

This function works on one page but not another. I've added all sorts of logging to try to find the error, but cannot. The output of this code on the broken page is:
[13:59:56.427] "here"
[13:59:56.428] "beforesend: /admin/test.html?server=eferbelly&port=24466&username=akilandy&password=vkjvkc9776A"
[13:59:56.428] "fileName=undefined"
[13:59:56.428] "lineNumber=undefined"
[13:59:56.428] "columnNumber=undefined"
[13:59:56.428] "here6"
That tells me it's getting into the exception handler, completely skipping my ajax() call, but it's not telling me the exception.
function test(server, port, username, password, spanId) {
spanId = "#" + spanId;
$(spanId).html("<img src='/images/ajax-small.gif'/>");
console.log("here");
try {
$.ajax({
dataType: "json",
type: "GET",
url: "/admin/test.html?server=" + server + "&port=" + port + "&username=" + username + "&password=" + password,
success: function(json){
console.log("here2");
if (json.httpStatus == "200") {
// Change the image to show success
$(spanId).html("<img src='/images/accept.png' title='success'/>");
}
else {
console.log("here7");
// Change the image to show failure
$(spanId).html("<span style='color:#b22222;'>" + json.httpStatus +"</span> <img style='vertical-align: middle;' src='/images/cancel.png' title='placeholder'/>");
}
console.log("here8");
$(spanId).tooltip({ content: json.msg});
},
// Display the URL
beforeSend: function(b,c,d) {console.log("beforesend: " + c.url);},
error: function(b,c,d) {console.log("here5");}
});
}
catch(e) {
console.log(e);
for (var i in e)
console.log(i + "=" + i[e]);
}
console.log("here6");
}
What could I do further to debug this?
UPDATE: Output of code on a working page
Here's the output of the exact same code but on the page where it is working:
[15:01:20.158] "here"
[15:01:20.159] "beforesend: /admin/test.html?server=eferbelly&port=24466&username=akilandy&password=vkjvkc9776A"
[15:01:20.159] "here6"
[15:01:21.661] GET https://localhost/images/accept.png [HTTP/1.1 200 OK 2ms]
[15:01:21.599] "here2"
[15:01:21.600] "here8"
So it obviously gets through the ajax call with flying colors. No errors, nothing. How can I find the problem on the page where it doesn't work?

Categories

Resources