SAP UI5 odata create fail - sapui5

i'm working with SapUi5 to build a webapp which connects to our Netweaver Gateway. This App consumes the data successfully, i only have problems to create objects with the service.
The response data i get is
500
Internal Server Error
content-type
application/xml
-
-
001560AA0E081DEB8CA398CC1690D406
Error while parsing an XML stream
-
52FB96CF506729E0E1000000C0A8EA2A
The Gateway error log says
Exception /IWCOR/CX_BAD_REQUEST occured.
When i insert data with the Gateway Client everything works fine.
EDIT
My Object is created like this
var testObject = {
smtp_adr: "ui5#test.de",
first_name: "SapUI5",
last_name: "test",
nr: 9999
};
and i upload it with
oModel.create("/MyService", testObject, null, false, null,function() {
alert("Create successful");
});

500 internal server error is related to payload. You are not passing the data properly to back-end. Please check the data that you are passing from front-end.

The problem is stated in your error message "bad request" ... oModel.create allows 3 parameters (Source)
sPath e.g. /MyService
oData e.g. testObject
mParameters?
You are passing 4 parameters, which leads to a "BAD_REQUEST" ...
Please see this, where its explained how to pass data: SAPUI5 oModel.create() - how to post data to the SAP backend?

Do you have access to the gateway box through SAP GUI can you check the error logs there?
The error your are getting around parsing XML stream most often happens when there is either an additional field in your create model or there is a type mismatch. can you try passing in
var testObject = {
smtp_adr: "ui5#test.de",
first_name: "SapUI5",
last_name: "test",
nr: "9999"
};
And see if that makes a difference most of the times I have seen this the type mismatch has been the issue.

Related

Mapping template for API gateway to firehose results in avoid invalid json

I am using API Gateway to receive data from a webhook and pushing it to Kinesis. Using mapping template, I create a JSON using data from the webhook payload.
The problem is, when I encode it to base64 and Kinesis decodes it, it ends up becoming an invalid json. The ":" get replaced by "=".
Here's my mapping template:
#set ($account = $util.parseJson($input.params().header.get("some-field")).account) //fetching a field from a header
{
"StreamName": "$input.params('stream-name')",
"Data": "$util.base64Encode(
{"Payload": "$input.json('$.payload')",
"Account": "$account",
"Event": "$input.json('$.event')"
})",
"PartitionKey": "$account"
}
What's happening is, the Data JSON object is getting corrupted when it gets decoded by Firehose for inline parsing (for dynamic partitioning). I get
{
Payload={"a":1,"b":2},
Account=abcdehdds,
Event="abc"
}
Notice the = instead of :, making this an invalid JSON.
What's strange is when the data is pushed from Firehose to s3 without any dynamic partitioning, it's a perfect JSON.
I'm at my wits end trying to solve this. Would appreciate any help.

Building a Restful CRUD API with Node.js with Mongodb

i get the error:
{
"message": "Note content can not be empty"
}
The MongoDB is running and if i start $ node server.js, i get the messages:
Server is listening on port 3000
Successfully connected to the database
if i delete the following lines in note.controller.js. The Response-Status are 200-OK :
//return res.status(400).send({
// message: "Note content can not be empty"
// });
but the 'titel' contains the default content: "title": "Untitled Note".
I guess, it's a problem with the Middleware/ Mongooseenter code here.
Does anyone have a solution?
So, this error occurred to me when I followed the same tutorial, and the reason being that I was not experienced in using the Postman application.
The issue occurs when you choose the body as raw in the POST method by keeping the format of body as Text
For it to work properly, since the date should be in JSON format to be written into MongoDB as per the server configuration, we need to choose the raw body format as Json, as shown in the image below.

Using sails.io pubsub works with shortcuts, but not with RESTful record creation

I'm having an issue where I'm getting events from the sails resourceful pubsub when I create a record with the shortcut routes, but not with the RESTful routes.
In my client code, I have a sails socket that I listen to for the model:
io.socket.on('users', function(event){console.log(event);})
If I use a shortcut route to create a record (http://localhost:1337/users/create?name=test), I get the callback in the console as expected:
>{verb: "created", data: {…}, id: 44}
However, if I use the socket to post from the client, the callback never fires.
io.socket.post('/users', { name: 'test' });
The record is created in the DB, and even more confusing is that the Sails server log says its publishing the message:
silly: Published message to sails_model_create_users : { verb: 'created',
data:
{ name: 'test',
createdAt: '2017-10-09T02:58:18.218Z',
updatedAt: '2017-10-09T02:58:18.218Z',
id: 44 },
id: 44 }
I'm the using generic blueprints, sails is v0.12.14. Any ideas what I'm doing wrong?
I figured out why I wasn't getting the events back on the pubsub. Sails excludes the socket that sent the req from the event. You can get the result from the post callback, but this breaks my nice dataflow. So I ended up using io.sails.connect() to create 2 sockets, one for the crud calls and one for the pubsib.

Getting error "Action Error: Missing result from request body"

I'm running one of the examples in my own project and running into the error.
Action Error: Missing result from request body
Github Sample Project: dialogflow-silly-name-maker-webhook-nodejs
Hookbin: Shows the webhook coming from the assistant.https://hookbin.com/bin/ZjPzJ1Yb
Might there be an error in the sample code or in my set-up?
I was getting this error. In my case it was because the request object I was passing to ActionsSdkApp() constructor had a body property which was a JSON string as opposed to data structure.
Adding this in before instantiating ActionsSdkApp fixed it for me...
request.body = JSON.parse(request.body);
Then I could carry on like this...
App = new ActionsSdkApp({'request': request, 'response': response});
That error message is printed by the Action on Google client library if the incoming request doesn't have the intent information, but your JSON looks good.
Make sure your action enables debug logging for the client library: process.env.DEBUG = 'actions-on-google:*';
Then study the complete log to understand your issue.

HATEOAS client with AngularJS

I was wondering if there were any features hidden in Angular or exposed by some 3rd-party libraries to easily create HATEOAS-compliant Restful clients.
On backend side, I am using Spring Data/REST to produce an HATEOAS JSON API.
Consuming it, though, is quite another story.
For instance, I've got those 3 entities:
Company {name, address}
Employee {firstName, lastName, employer[Company]}
Activity {rate, day, employee[Employee], client[Company]}
and requesting an activity (the most complex entity of the model) produces something like this:
{
links: [],
content: [{
rate: 456,
day: 1366754400000,
links: [{
rel: "self",
href: "http://localhost:8080/api/activities/1"
},
{
rel: "activities.activity.client",
href: "http://localhost:8080/api/activities/1/client"
},
{
rel: "activities.activity.employee",
href: "http://localhost:8080/api/activities/1/employee"
}]
}]
}
My API talks in terms of REST (resources identified by links).
An Activity has an Employee for instance. What I really want to use is : {rate: 456, day: 1366754400000, employee: {firstName:"xxx", lastName:"xxx" ...}}.
However, as you can see in the first output, my Activity only contains a link to the employee, not its data. Is there anything in Angular or in a 3rd-party library to resolve those links and embed the resulting data instead?
Any input on this?
Thanks in advance!
Checkout angular-hateoas. ITs an AngularJS module for using $resource with a HATEOAS-enabled REST API.
You could write a Response Transformation that would inspect your returned object, check for links, and resolve them before returning the response. See the section "Transforming Requests and Responses" in the $http service documentation.
Something like this:
transformResponse: function(rawData) {
var json = JSON.parse( rawData );
forEach( json.content.links, function(link) {
// resolve link...
});
return json;
}
Since the "resolve link" step is itself an $http call, sub-references would also be resolved. HOWEVER, since these are asynchronous, you would likely return a promise instead of the real value; I don't know if the transform function is allowed to do this.
As #charlietfl pointed out, however, please note that this will result in several HTTP calls to return a single entity. Even though I like the concept of HATEOAS, this will likely result in sluggishness if too many calls are made. I'd suggest that your server return the data, or some of it, directly, PLUS the link for details.
Based on your comment about wanting to work with data as against links on the client, I think Restangular would be a good fit.
I've been using angular-hal for one of my projects. It was a Spring HATEOAS backend. And I didn't run into any issues. It handles parametrized resources. I suspect it only supports HAL so since you're using Spring Data Rest you probably have to configure it to generate HAL compliant responses.
I think the confusion may be that you are asking for an Angular solution, when what you really want to do is have Spring Data send a more complete JSON response. I.e, you really just want the server to return the employee data as part of the response JSON, rather than having the client perform extra steps to look it up. I don't know what data store you are using in Spring Data, but the general solution would be to add public getEmployee() method to your Activity class and then annotate the method with #RelatedTo and #Fetch (this would be the setup for Neo4J -- may be different annotations for your flavor of Spring Data). This should cause Spring HATEOAS to include the Employee record within the response for /activity. Hope this helps.