I created Java files from SOAP WSDL and called the operation of WSDL from Adapter JS file. On returning the string I am getting below error.
"isSuccessful": false,
"warnings": [],
"errors": [
"Runtime: Procedure return value must be a Javascript Object, it is currently a String."
],
"info": []
This is my procedure:
function callSoap(CustId){
var callMethod = new com.idea.actions.SoapCallUtil();
var custBalance= callMethod.getBalance(CustId);
return custBalance;
}
How to convert this "custBalance" String in Javascript Object.Someone please help me how to resolve this.
The return value from an HTTP adapter should be a proper JSON.
Modify your current code from :
return custBalance;
to
return { myResponse : custBalance};
or
var resp = JSON.stringify(custBalance);
return {myResponse: resp};
Related
I have developed a call back REST service using the following link as reference https://docs.clickatell.com/channels/one-api/one-api-reference/#tag/One-API-Client-Callbacks/operation/sendPostOmniReplyCallback. I am using the sample payload as supplied by the Clickatell example using Postman and I can process and post the payload without problems. It also works when I deploy this as a public URL on the web. However, when pasting my URL in the Clickatell Customer Call Back I do not receive any call backs. I am obviously missing something or misinterpreting the sample code provided by Clickatell. Please note that for testing purposes I write the full payload to MySQL - works when using Postman, but not from Clickatell Call Back URL.
enter code here
{
[Route("client-callback/one-api-reply")]
[ApiController]
public class MessageController : ControllerBase
{
[HttpPost]
public async Task<dynamic> StartProcessiongAsync([FromBody] dynamic obj)
{
string myObj = JsonConvert.SerializeObject(obj);
var data = JsonConvert.DeserializeObject<Rootobject>(myObj);
var context = new DataContext();
var command = context.Database.GetDbConnection().CreateCommand();
context.Database.OpenConnection();
command = context.Database.GetDbConnection().CreateCommand();
{
command.CommandText =
"INSERT INTO testcallback(message) VALUES ('" + myObj + "');";
command.ExecuteNonQuery();
}
return Ok(obj);
}
}
}
Postman Payload Sample
{
"integrationId": "fa8090815f05d5ed015f0b5b56080cd2",
"integrationName": "My integration",
"event": {
"moText": [
{
"channel": "sms",
"messageId": "3a89680503414383af44dcd0e4e5f184",
"relatedMessageId": "d33eef0838a121f71069a4cc8d55c19e",
"relatedClientMessageId": "d33eef0838a121f71069a4cc8d55c19e",
"from": "2799900001",
"to": "2799900001",
"timestamp": 1506607698000,
"content": "Text Content of the reply message",
"charset": "UTF-8",
"sms": {
"network": "Network ID"
},
I am trying to make a post to the dev.azure.com{organization}/_apis/accesscontrolentries/{namespaceId}?api-version=5.1.
I need help on obtaining the descriptor that starts with S-1-9.
{ "token": "", "merge": true, "accessControlEntries": [ { "descriptor": "Microsoft.TeamFoundation.Identity;S-1-9-**********-**********-**********-**********-**********-*-**********-**********-**********-**********", "allow": 128, "deny": 0 } ] }
Thank you.
Obtaining the descriptor that starts with S-1-9.
There’s no directly rest api to get this descriptor which start with S-1-9. You need to use the follow api get the user descriptor(SID) firstly:
GET https://vssps.dev.azure.com/{org name}/_apis/graph/users?api-version=5.1-preview.1
I have one answer about how to obtain it from response body, please refer to this answer for more details.
Now the descriptor we get is based on base64. To achieve what you want, just decode this SID.
Here has a blog which written by our Azure Identity Team engineer: C# Decode script. Just located to the corresponding part to achieve this decode script:
public static string Base64Decode(string base64EncodedData)
{
var lengthMod4 = base64EncodedData.Length % 4;
if (lengthMod4 != 0)
{
//fix Invalid length for a Base-64 char array or string
base64EncodedData += new string('=', 4 - lengthMod4);
}
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}
public static string Base64Encode(string plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}
I customized RESTAdapter to connect to a RestHeart server (a RestFull web
gateway server for mongodb):
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
host:'http://127.0.0.1:8080',
namespace: 'boards'
});
I created a model to test :
import DS from 'ember-data';
export default DS.Model.extend({
identity: DS.attr()
});
Everything works fine, but when I use the save method on a record (developer):
I have a warning in the browser console :
The server returned an empty string for POST
http://.../boards/Developer, which cannot be parsed into a valid JSON.
Return either null or {}.
and the folowing error :
SyntaxError: Unexpected end of JSON input
at parse ()
at ajaxConvert (jquery.js:8787)
at done (jquery.js:9255)
at XMLHttpRequest. (jquery.js:9548)
I know why :
The RESTAdapter is waiting for a JSON response, and the restHeart server returns an empty response when adding => so jQuery causes an error when it tries to parse the null response.
With previous versions of ember-data, it was possible to set the dataType variable of jQuery ajax requests to '*' using the hook ajaxOptions this way:
export default DS.RESTAdapter.extend({
ajaxOptions(url, type, options) {
var hash = this._super(url, type, options);
hash.dataType = "*";
return hash;
},
host:'http://127.0.0.1:8080',
namespace: 'boards'
});
With ember-data 2.16, ajaxOptions is now private, and I do not know how to modify the dataType variable... so that the null response is not parsed as a JSON response
Versions :
ember-data 2.16
ember 2.18
Solution found
export default DS.RESTAdapter.extend({
ajaxOptions: function(url, type, options) {
// get the default RESTAdapter 'ajaxOptions'
var hash = this._super(url, type, options);
// override if it's a POST request
if (type == 'POST') {
hash.dataType = 'text';
}
return hash;
},
ajaxSuccess: function(jqXHR, data) {
if (typeof data === 'string') {
// return an empty object so the Serializer handles it correctly
return {};
} else {
return data;
}
},
host:'http://127.0.0.1:8080',
namespace: 'boards'
});
It works without any warning or error,strangely,
because I don't know if I respect the encapsulation of the RESTAdapter class ...
see Ember-data 2.6 & 2.7 release notes
I am doing a PUT request to RESTfull service which changes password of a user. For the time being I have just hardcoded values of new and old password in my AJAX test my service. However it is giving me a 400 error.
AJAX call
$.ajax({
type: "PUT",
url: "api/teachers/"+user,
data: {"old":"123","new":"qwe"},
contentType: "application/json",
success: function(data,status)
{
datax = data;
alert(data+status);
ko.applyBindings(new AddMarkSheetKo(data));
},
error: function(XMLHttpRequest, textStatus, errorThrown)
{
alert(XMLHttpRequest+textStatus+ errorThrown);
// error handler here
}
});
Restful function:
#PUT
#Path("/{name}")
#Consumes(MediaType.APPLICATION_JSON)
public Response changePwd(#PathParam ("name")String name,#QueryParam ("old") String old, #QueryParam("new") String nw){
System.out.println("entered function"+old+nw);
Teacher t = DataAccessUtil.getByName(Teacher.class, name);
if(t.getPassword().equals(old)){
t.setPassword(nw);
DataAccessUtil.update(t);
return Response.ok().build();
}
else{
return Response.status(Status.BAD_REQUEST).entity("Wrong password !!!").build();
}
//return reposnse;
}
This information might be useful that on the console it prints
entered functionnullnull
So it the restfull function is called however it is not receiving the query parameters.
Any help would be really appreciated!
First, you could replace the #QueryParam annotations with #FormParam ones to retrieve the 'new' and 'old' parameters of the PUT request. Then, you should remove the #Consumes("application/json") annotation and contentType:application/json from your server and browser side code, and finally replace the submitted data in JSON format into something like 'new=qwe&old=123'.
If you want to stay with a content in JSON format, you should probably map the incoming body with an entity (ie, a Java class annotated with JAXB annotations), so that the JAX-RS implementation you use could unmarshall the incoming JSON content into a Java object.
HTH.
Documentation seems to be lacking on both the plugin side as well as the HTTPBuilder side of things. I'm trying to submit some json through the put method, but it keeps telling me that put() doesn't like the map I am feeding it.
Does anyone have an example of a PUT using the Grails REST Client plugin? Here is what I've tried:
withHttp(uri: "http://foo/doo/roo") {
def bodyContent = [
pano: jsonText
]
def json = put(body: bodyContent)
if (json.stat == 'ok') {
wsr.success = true
}
}
Error:
No signature of method: com.wbr.pano.PanService.put() is applicable for argument types: (java.util.LinkedHashMap) values: [[body:
{
"class":"com.wbr.platform.Pano",
"errorMessage":"null",
"imageSize":0,
"id":26,
"completed":"2011-03-20 3:50:27.257",
"downloading":"2011-03-20 3:49:12.269",
"processing":"2011-03-20 3:49:42.911",
"uploading":"2011-03-20 3:50:12.107"
}
]]
HTTPBuilder doesn't have a put method. Try changing withHttp to withRest so that your statements are executed with the RESTClient. Also, I think by default the body is encoded as URL encoded, so you might need to specify requestContentType: groovyx.net.http.ContentType.JSON as another parameter to your put.
import static groovyx.net.http.ContentType.*
withRest(uri: "http://foo/doo/roo") {
def bodyContent = [
pano: jsonText
]
def json = put(body: bodyContent, requestContentType: JSON)
if (json.status == 200) {
wsr.success = true
}
}