Not able to load the response - javascript

var soapre1 = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:glob=\"http://sap.com/xi/SAPGlobal20/Global\">";
var soapre2 = "<soapenv:Header/><soapenv:Body><glob:EmployeeLeaveRequestByParticipantQuery><EmployeeLeaveRequestSelectionByParticipant><EmployeeLeaveRequestParticipantRoleCode listVersionID=\"?\">2</EmployeeLeaveRequestParticipantRoleCode>";
var soapre3 = "<!--Zero or more repetitions:--> <EmployeeLeaveRequestParticipantWorkAgreementIDInterval><IntervalBoundaryTypeCode>1</IntervalBoundaryTypeCode> <!--Optional:--> <LowerBoundaryWorkAgreementID schemeID=\"?\" schemeAgencyID=\"?\">1009</LowerBoundaryWorkAgreementID></EmployeeLeaveRequestParticipantWorkAgreementIDInterval>";
var soapre4 = " <!--Zero or more repetitions:--> </EmployeeLeaveRequestSelectionByParticipant></glob:EmployeeLeaveRequestByParticipantQuery> </soapenv:Body></soapenv:Envelope>";
var soapRequest = soapre1+soapre2+soapre3+soapre4;
var authstr = 'Basic ' +Titanium.Utils.base64encode('S0009231839'+':'+ 'm8390967743!');
var soapxhr = Ti.Network.createHTTPClient();
soapxhr.setRequestHeader('SOAPAction',soapRequest);
soapxhr.open("POST","http://erp.esworkplace.sap.com/sap/bc/srt/pm/sap/ecc_empleavereqparctqr/800/default_profile/2/binding_t_http_a_http_ecc_empleavereqparctqr_default_profile");
soapxhr.setRequestHeader('Authorization', authstr);
soapxhr.setRequestHeader('Content-Type','text/xml','charset=utf-8');
soapxhr.send();
soapxhr.onload = function(e)
{
Ti.API.info('abcd');
//get the xml data and let it roll!
var doc = this.responseXML;
Ti.API.info(doc);
}
soapxhr.onerror = function (e){
alert('Error');
Ti.API.info(e);
}
Unable to load the response Its directly getting error
[INFO] {
source = "[object TiNetworkClient]";
type = error;
}
Any one advice how to fix the issue!
# Thanks in advance

In all browser its saying error! but i found some wsdl and soap request so in order to open the response i need to pass the method name to the http request ! then it working

Related

Load external JSON data via API into PDF file form field

I have a button inside a PDF file which when clicked should call an API and write the data into a form field. Inside the Acrobat Reader Debugger I get the 'undefined' error. What am I missing?
FYI I have changed the API key...
var API = "https://api.openweathermap.org/data/2.5/weather?q=Berlin&units=metric&lang=de&appid=860b8e982b1aecb176f5aee385c73be0"
var getData = app.trustedFunction(function (cURL) {
app.beginPriv();
var params = {
cVerb: "GET",
cURL: cURL,
oHandler: {
response: function (msg, uri, e) {
var stream = msg;
var string = "";
string = SOAP.stringFromStream(stream);
var data = eval("(" + string + ")");
}
}
};
Net.HTTP.request(params);
app.endPriv();
});
getData(API);
getField('1').value = data.main.temp;

Java net url refused connection

I'm working with ARIS tool and I want to make calls(GET, POST...) in ARIS to ARIS API repository!
I have authentication that works when I try it directly in the repository, but I got an error when I debug the code I have in ARIS.
The error: Error running script: Connection refused: connect.
I have the following code:
var obj = new java.net.URL(url);
var con = obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", java.net.USER_AGENT);
var tenant = "";
var name = "";
var password = "";
var key = "";
var authString = tenant + ":" + name + ":" + password + ":" + key;
var encoder = new java.lang.String(Base64.encode(authString));
con.setRequestProperty("Authorization", "Basic" + encoder);
var responseCode = con.getResponseCode();
var iN = new java.io.BufferedReader(new java.io.InputStreamReader(con.getInputStream()));
var inputLine = new java.lang.String();
var response = new java.lang.StringBuffer();
while((inputLine = iN.readLine()) != null){
response.append(inputLine);
}
iN.close();
return new java.lang.String(response);
Is the problem that I use Basic authentication, but I have tenant and key also or it's something else?
Also, name, password, key and tenant I'm leaving empty for security purposes, but in the original code the values are inserted. Also the url parameter contains the url link that is called directly in the repository.
Can someone please help me?
Thanks!

TFS Extension - How to read TaskAttachment content

I'm having trouble with reading the content of a "TaskAttachment" that I uploaded from one extension to another.
I'm using this code to get the "TaskAttachment", I'm getting it with the right name and URL, (Which I get have access to without nay authentication, e.g. from another clean browser)
var taskClient = DT_Client.getClient();
taskClient.getPlanAttachments(vsoContext.project.id, "build", build.orchestrationPlan.planId, "MyExtType").then((taskAttachments) => {
$.each(taskAttachments, (index, taskAttachment) => {
if (taskAttachment._links && taskAttachment._links.self && taskAttachment._links.self.href) {
var link = taskAttachment._links.self.href;
var attachmentName = taskAttachment.name;
var fileContent = readText(link);
...
And this javascript function to read the content
...
var readText = function readTextFile(file)
{
alert("file = " + file);
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function ()
{
alert("rawFile.readyState = " + rawFile.readyState);
alert("rawFile.status = " + rawFile.status);
alert("rawFile.responseText = " + rawFile.responseText);
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
var allText = rawFile.responseText;
alert(allText);
return allText;
}
}
}
rawFile.send(null);
return "Failed to get data..";
}
The problem is that I'm getting 401 error message :
"IIS 7.5 Detailed Error - 401.2 - Unauthorized"
How can I read this file content? Is there a better way to transfer data from a "Build Step Extension" to a "UI Extension" that present the data in the build summary page (new tab)?
According to "IIS 7.5 Detailed Error - 401.2 - Unauthorized" It's most likely due to directory permissions set in the file system.
Make sure Anonymous access is enabled on IIS -> Authentication.
Right click on it, then click on Edit, and choose a domain\username and password.
I just managed to read the attachment data using the "getAttachmentContent" method:
I'm not sure why MS doesn't put any reference to this function in the tutorial, after long digging in the documentation \ Q&A I found it.
taskClient.getPlanAttachments(vsoContext.project.id, "build", build.orchestrationPlan.planId, "My_Attachment_Type").then((taskAttachments) => {
$.each(taskAttachments, (index, taskAttachment) => {
if (taskAttachment._links && taskAttachment._links.self && taskAttachment._links.self.href) {
var recId = taskAttachment.recordId;
var timelineId = taskAttachment.timelineId;
taskClient.getAttachmentContent(vsoContext.project.id, "build", build.orchestrationPlan.planId,timelineId,recId,"My_Attachment_Type",taskAttachment.name).then((attachementContent)=> {
function arrayBufferToString(buffer){
var arr = new Uint8Array(buffer);
var str = String.fromCharCode.apply(String, arr);
return str;
}
var data = arrayBufferToString(attachementContent);

I am unable to print response for xmlHttpRequest

I am unable to print response for below :
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<head>
<script>
jQuery.noConflict();
jQuery(document).ready(function() {
alert("Hello world, part 2!");
callOtherDomain();
});
function callOtherDomain() {
var invocation = new XMLHttpRequest();
var uName = "";
var pWord = "";
var project = '';
var domain = '';
var url = 'https://url';
invocation.open('GET', url, true, uName, pWord, project, domain);
invocation.onreadystatechange = function () {
if (4 != invocation.readyState) {
return;
}
if (200 != invocation.status) {
return;
}
console.log(this.responseText);
console.log(invocation.responseText);
console.log(invocation);
};
invocation.send();
}
I get value for console.log(invocation); as - [object XMLHttpRequest] and this.responseText prints - undefined.
When using the same credentials with chrome extension for REST API I can see the response.
I have tried printing - var xmlResponse = invocation.responseXML; - gives 'null'
var xmlResponse1 = invocation.responseText; also prints whitespace/blank
console.log(invocation.status); - print 200 (which means the call is made successfully)
I am also getting console.log(invocation.readyState); - as 4.
Here is the details shown on that network tab snag.gy/kdcwc.jpg, does is mean the response is received
var headers = invocation.getAllResponseHeaders();
alert(headers);
All the headers are also printing blank/whitespace.
anyone can help please ?

parse HttpClientRequest response

i have another novice (and probably stupid) question. i am using HttpClientRequest and making a post call. also i have the response.
var url = <my url>
var request = new HttpClientRequest(url);
request.header["Content-Type"] = "application/x-www-form-urlencoded";
request.method = "POST";
try
{
request.execute();
var rawResponse = request.response.body.toString();
}
the response from server is in the following format:
{"token":"abc","expires_in":9292,"refresh":"deeDfTTgendj"}
i just need to extract "expires_in" and "refresh" fields from the response
Since that is valid JSON, you can parse it:
var rawResponse = request.response.body.toString(),
objectLiteral = JSON.parse(rawResponse);
var expires_in = objectLiteral['expires_in'],
refresh = objectLiteral['refresh'];
var rawResponse = '{"token":"abc","expires_in":9292,"refresh":"deeDfTTgendj"}';
objectLiteral = JSON.parse(rawResponse);
var expires_in = objectLiteral['expires_in'],
refresh = objectLiteral['refresh'];
console.log(expires_in, refresh);
Note: check out browser support for JSON.parse()

Categories