Invoking the following adapter return Ecma Error: TypeError: Cannot read property \"Body\" from undefined.
I have read similar threads and had
-Dorg.xml.sax.driver = com.sun.org.apache.xerces.internal.parsers.SAXParser
to eclipse.ini
but didn't solve the issue.
function getStateDetails(idstate) {
var request='<?xml version="1.0" encoding="utf-8"?>'+
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
+'<soap:Body>'
+ '<test_demo><in0>{idstate}</in0></test_demo>'
+'</soap:Body>'
+'</soap:Envelope>';
var input = {
method : 'post',
returnedContentType : 'xml',
path : '/axis2/services/ws_demo/test_demo.wsdl',
body : {
content: request.toString(),
contentType: 'text/xml; charset=utf-8'
}
};
var result = WL.Server.invokeHttp(input);
return result.Envelope.Body;
}
finally it works fine with the help of soapui and adding headers in the request.
function getStateDetails(idstate) {
var request='<?xml version="1.0" encoding="UTF-8"?>'
+'<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">'
+'<Body><test_demo xmlns="http://www.ibm.com/informix/i4gl-soa/2010-11/ws_commandes">'
+'<in0>'+idstate+'</in0></test_demo>'
+'</Body></Envelope>';
WL.Logger.debug("SOAP Request " + request);
var input = {
method : 'post',
returnedContentType : 'xml',
headers: {SOAPAction: 'test_demo'},
path : '/axis2/services/ws_commandes',
body : {
content: request.toString(),
contentType: 'text/xml; charset=utf-8'
}
};
var result = WL.Server.invokeHttp(input);
return result.Envelope.Body.test_demo_response;
}
Looks like you're making a request to the WSDL, not service itself.
Related
with the following code I'm trying to create new conversation post for Capability. But it says
Cannot parse input stream due to I/O error as JSON document: Parse error: expected '{' but saw '' [ chars read = >>><<< ]
function createPost(objId, post) {
objId = "313878829904";
post = "<p>MindMap:Hello from GAS.</p>"
var url = "https://rally1.rallydev.com/slm/webservice/v2.0/conversationpost/create";
var payload = {
"ConversationPost": {
"Artifact": "/portfolioitem/capability/" + objId,
"Text": post
}
}
var method = "POST";
var options = optionsPost_(method, payload);
var response = UrlFetchApp.fetch(url, optionsPost_(method, options));
var content = JSON.parse(response.getContentText());
content.CreateResult.Errors.forEach(error => Logger.log(error));
}
function optionsPost_(method, payload) {
var rallyApiKey = "";
if (rallyApiKey != "") {
PropertiesService.getScriptProperties().setProperty("RallyApiKey", rallyApiKey);
} else {
rallyApiKey = PropertiesService.getScriptProperties().getProperty("RallyApiKey");
}
if (rallyApiKey == null) return null;
return {
headers: { "ZSESSIONID": rallyApiKey },
payload: payload,
method: method
};
}
I can't spot any problem.
Could you please help?
Thank you!
Petr
I thought that from your error message, the payload might be required to be sent as JSON data. If my guessing is correct, how about the following modification?
Modified script:
From:
return {
headers: { "ZSESSIONID": rallyApiKey },
payload: payload,
method: method
};
To:
return {
headers: { "ZSESSIONID": rallyApiKey },
payload: JSON.stringify(payload),
method: method,
contentType: "application/json"
};
Note:
In this modification, it supposes that the values of payload and rallyApiKey are valid values for using the API. Please be careful this.
When above modification was not the dierct solution of your issue, can you provide the official document of API you want to use? By this, I would like to confirm it.
Reference:
fetch(url, params) of Class UrlFetchApp
Thanks for the fast response.
With the following
var payload = {"ConversationPost":{"Artifact": "/portfolioitem/capability/"+objId,"Text": post}};
var method = "POST";
var options = optionsPost_(method, payload);
and
var options={
headers: { "ZSESSIONID": rallyApiKey },
payload: payload,
method: method,
contentType:"application/json"
};
It gives me
Cannot parse input stream due to I/O error as JSON document: Parse error: expected '{' but saw 'h' [ chars read = >>>h<<< ]
If I change it to
var options={
headers: { "ZSESSIONID": rallyApiKey },
payload: JSON.stringify(payload),
method: method,
contentType:"application/json"
};
It gives me
Cannot parse input stream due to I/O error as JSON document: Parse error: expected '}' but saw ',' [ chars read = >>>{"headers":{"ZSESSIONID":"_ycHaCSd2QZSf8kbkQ0R1yhjohUvSzUYas0caApHt2A"},<<< ]
Only documentation I use is this:
https://rally1.rallydev.com/slm/doc/webservice/objectModel.sp#ConversationPost
I can't find any difference but this actually started working.
I believe the problem was caused by combination of mistakes. I removed one problem but perhaps add another one.
Here is a code which works.
function createPost(objId, post) {
objId = '313878829908';
post = "<p>MindMap:Hello from GAS.</p>"
var url = "https://rally1.rallydev.com/slm/webservice/v2.0/conversationpost/create";
var payload = {'ConversationPost':{'Artifact': '/portfolioitem/capability/'+objId,'Text': post}};
var method = 'POST';
//var options = optionsPost_(method, payload);
var response = UrlFetchApp.fetch(url, optionsPost_(method, payload));
var content = JSON.parse(response.getContentText());
content.CreateResult.Errors.forEach(error => Logger.log(error));
}
function optionsPost_(method, payload) {
var rallyApiKey = "";
if (rallyApiKey != "") {
PropertiesService.getScriptProperties().setProperty("RallyApiKey", rallyApiKey);
} else {
rallyApiKey = PropertiesService.getScriptProperties().getProperty("RallyApiKey");
}
if (rallyApiKey == null) return null;
var options={
'headers': {'ZSESSIONID': rallyApiKey },
'payload': JSON.stringify(payload),
'method': method,
'contentType':'application/json'
};
return options;
}
Thanks Tanaike for your help. I really appreciate it.
I am using worklight adapter to implementing on restful web service. but i can not get any successful response.
This is my adapter:
function getTest(username,password) {
var path = "http://test.mybluemix.net";
var request = 'username='+username+'&'+'password='+password;
var input = {
method : 'get',
returnedContentType : 'plain',
path : path,
headers: {
"Host":"http://test.mybluemix.net"
},
body : {
contentType: 'text/xml; charset=UTF-8',
content: request.toString()
}
};
return WL.Server.invokeHttp(input);
}
this i got response for when i call the adapter..
response header is connection close and X-Backside-Transport is failed
normally i have to hit above the url its working fine http://test.mybluemix.net/?username=sssss&password=dffa
response : {"ID":"5","USERNAME":"sassad","PASSWORD":"adsa","ROLE":"abc","PHONENUMBER":"12345678"}
Several things look wrong to me.
The path variable should not point to the hostname. It's supposed to be the part afterwards:
In the adapter XML file you define the protocol, host and port values.
Then you provide the path, for example: http://myhost:8080/THE-PATH. In this case I don't think you need it since according to your working URL example there is no actual path - there are only the parameters, the request.
I'm not sure you need the host header. Try w/out it first...
Try this. Hopefully that'll work.
function getTest(username,password) {
var request = 'username='+username+'&'+'password='+password;
var input = {
method : 'get',
returnedContentType : 'plain',
path : path,
//headers: {
// "Host":"http://test.mybluemix.net"
// },
body : {
contentType: 'text/xml; charset=UTF-8',
content: request.toString()
}
};
return WL.Server.invokeHttp(input);
}
I want to submit json file form sencha touch to my tomcat server using http post multipart but i don't know how to do ?
can any one give me some idea or example.
Thanks
you can do this using jQuery.
var request = new FormData();
$.each(context.prototype.fileData, function(i, obj) { request.append(i, obj.value.files[0]); });
request.append('action', 'upload');
request.append('id', response.obj.id);
$.ajax({
type : 'POST',
url : context.controller,
data : request,
processData : false,
contentType : false,
success : function(r) {
console.log(r);
//if (errors != null) { } else context.close();
},
error : function(r) { alert('jQuery Error'); }
});
I am new to MVC and I am trying to create an application with Knockout.js to send data back to the server dynamically. I am following an example i found at:
http://www.mytecbits.com/microsoft/dot-net/knockout-js-and-bootstrap-with-asp-net-mvc-part-2
It works perfectly off the site, but i am trying to send data to multiple models instead just one as in the example
The Knockout code used in the example to send the data back to the server is
var urlPath = window.location.pathname;
var CreateArticleVM = {
Title: ko.observable(),
Excerpts: ko.observable(),
Content: ko.observable(),
Test: ko.observable(),
btnCreateArticle: function() {
$.ajax({
url: urlPath + '/Create',
type: 'post',
dataType: 'json',
data: ko.toJSON(this),
contentType: 'application/json',
success: function(result) {
window.location.href = urlPath + '/';
},
error: function(err) {
if (err.responseText == "success") {
window.location.href = urlPath + '/';
}
else {
alert(err.responseText);
}
},
complete: function() {}
});
}
};
ko.applyBindings(CreateArticleVM);
How do i modify the above code to be able to accept a FormCollection? Or what is the best solution to my problem?
Thanks
Say your service is expecting more than one argument like following.
[HttpPost]
public String Create(ModelA modela, ModelB modelb)
{
//Server code.
}
In order pass the data for Create method from client side you need to form your postdata as follows.
$.ajax({
url: urlPath + '/Create',
type: 'post',
dataType: 'json',
data: {modela: { "modela data in the expected form" }, modelb : { "modelb data.." } },
contentType: 'application/json',
success: function(result) {
window.location.href = urlPath + '/';
},
.
.
.
.
});
I have been trying to do a post request using a proxy. I have tried the direct proxy, rest and ajax proxy, and haven't been able to find a working example for a POST request.
Is it possible? Because all the examples that I have seen seen to be using only GET.
Any working examples, or pointers in this direction?
Also, I couldn't figure what is the correct way to generate URLs for a proxy at run-time, for example, calling a function to return the URL.
It appears that this might not be possible:
http://www.sencha.com/forum/showthread.php?205557-Using-Ext.data.proxy.Ajax-via-a-POST-with-jsonData
If you look at the source code for Ext.data.proxy.Rest you'll see a config object for actionMethods. They're not documented, but you should be able to pass that as a config on your proxy to override it.
For example:
proxy: {
type: 'ajax',
url: 'path/to/foo',
actionMethods: {
create : 'POST',
read : 'POST',
update : 'PUT',
destroy: 'DELETE'
},
reader: {
type: 'json',
rootProperty: 'root',
totalProperty : 'totalCount'
}
}
Easiest example of POST request could be like this:
var obj = new Object();
obj.userId = username;
obj.password = password;
var data = Ext.JSON.encode(obj);
Ext.Ajax.request({
url : 'http://myservice/auth/login?_type=json', // url : this.getUrl(),
method : "POST",
headers: {
'Content-Type': 'application/json'
},
params : data,
useDefaultXhrHeader : false,
withCredentials: true,
success : function(response) {
Ext.Msg.alert("Success", "Welcome "+respObj.user.name);
},
failure : function(response) {
var respObj = Ext.JSON.decode(response.responseText);
Ext.Msg.alert("Error", respObj.status.statusMessage);
}
});
Please note here you can customize url as per your convenience.