REST service returning wrong content-type if file created has its header set to some value in iOS objective C - httpresponse

In iOS I am using AFNetworking for calling the web-services. Here I am getting the error: "unacceptable content type: application/excel". After a lot of struggle I came to know that it is the server team problem. I have a question regarding this:
Before returning the response of service call to the app, notification is being sent and at the same time the notification information(text, time, etc) is logged in notification.xls file on the server where the header is set for the file like below,
function calledWhenServiceCalled(){
someJsonArray; //generate some json array
saveNotification();
return someJsonArray;
}
function saveNotification(){
//some functionality
header('Content-Type: application/excel');
//save the file to .csv
}
If I comment out the 'header('Content-Type: application/excel');' line above then the service call does not return any error and returns proper json response. But if the line is retained then I get unacceptable content type error(application/excel) from the server.
Please let me know why is the content type set for the file header is being sent as unaaceptable content-header for service response? There is no connection between the file created and service response right?? I am not getting what the problem is.. Please help... Let me know If I have not made myself clear...

Related

How can we pass nested requested body which contains file in postman

I have two model files in java spring boot where in one i have declared the variables for database and another one to include file in Request body itself.
I have a controller which takes the request body this. How can i send the following request in postman. Is there better way of doing including a file and my other model class rather than just passing it as request param.
public String saveReferenceData(#RequestBody TestClass testClass){
// custom logic written
return "done";
You should use multipart request for handling files and text data. Multipart request is similar to any other payload but defined boundaries for server to handle and parse.
To Upload multipart file In postman:
Switch to body tab
select form-data
add keys
Alternative solution
Dothttp is similar tool with great control over these.
For Multipart upload
POST https://req.dothttp.dev
// selects as multipart
multipart(
'name'< 'john',
'photo'< 'C:\Users\john\documents\photo.jpg',
// and many more
)

Unable to access POST parameter values - IIB Esql

So I'm quite new to IIB and Extended SQL but what I want to do should be straight forward. I have a REST application which has a resource that is attached to a subflow. What I want to do is to get the input value passed to the service and use it to call a remote web service using the HTTP request node as shown below
SET OutputLocalEnvironment.Destination.HTTP.RequestLine.Method = 'POST';
SET OutputLocalEnvironment.Destination.HTTP.RequestURL = 'http://localhost:8002/MyService';
SET OutputLocalEnvironment.Destination.HTTP.QueryString.RemoteParam= InputLocalEnvironment.REST.Input.Parameters.myValue;
What is happening is, when I call the REST method and pass the value as a GET, I'm able to access the value. However, when I pass the parameter value using POST, I'm unable to access the value. My current flow is as follows:
Input > Compute > HTTPRequest > Compute > Output
I have searched on Google and applied all recommendations (e.g. setting compute node to LocalEnvironment) but nothing seems to work.
Well, we need more information in order to solve your problem but I guess you have problem in your HTTP request node
Go to HTTP request then in properties go to HTTP setting and change HTTP method to the method that you are using ( get or post )
and if you want to see if you are fetching data from right property just lunch debugger and put breakepoint in before and after of your nodes, then you can see what data you are receiving in each level and you can call the proper property.
ps. don't forget to deploy your project again in order to see new
changes
I hope that works for you
After further research, I found that IIB does not automatically parse content submitted as application/x-www-form-urlencoded. I inserted a trace node and realised that the parameters are instead submitted as a BLOB. All I had to do was read the blob, cast it to a string then use a Split function or a message model to get the individual parameters. Thanks for the pointers

How to use custom error settings for JWT middleware

I have followed the cook books guide to the letter, found here https://echo.labstack.com/cookbook/jwt
But when using the JWT middleware I am having some issues with adding custom error messages. Login works fine, even to the point of not giving details (username & password) that returns a 404.
But when the JWT is missing it returns a 400, I want it to also return a 404.
So in my research I found this, https://forum.labstack.com/t/custom-error-message-in-jwt-middleware/325/3 which lists the following middleware.ErrJWTMissing & middleware.ErrJWTInvalid But is very unclear on how to set these?
I have tried setting them as vars on the router file, like so
var (
ErrJWTInvalid = echo.NewHTTPError(http.StatusTeapot, "test 104")
ErrJWTMissing = echo.NewHTTPError(http.StatusTeapot, "test 103")
)
But the error that sill comes back to me is a 400 and not a 418 (as this is just a test). So what am I doing wrong?
You can change the HTTP code and message this way.
func init() {
middleware.ErrJWTMissing.Code = 401
middleware.ErrJWTMissing.Message = "Unauthorized"
}
First, a point on your statement that you want to return a 400 and also a 404 error - you cannot do this. You're sending one response from the server so it gets exactly one response code. You could send a 207, but we're not really talking about multiple resources here, so don't do that. In my opinion, a 400 error is indeed the correct response for a missing JWT as that constitutes a bad request. A 404 "Not Found" means that the requested resource (the thing on the server side) could not be found. It does not mean that something in the request could not be found.
As for setting your custom error message, you're likely to be out of luck without altering the source code for Echo. That specific response is coming from within the middleware handlers of the package itself (you can see it here). This is mostly abstracted away from you, so without looking at the inner workings of the package, there would be no way to tell where this was coming from, and frankly there's not a lot that you can easily do about it. ErrJWTMissing is indeed the variable that the package uses internally for this error message, but Echo does not appear to provide an exported setter method for you to change this value, so you're stuck with what it is.
If you truly wanted to set a custom error method for this case I think your options would be to:
Write your own middleware to intercept the request before it was handled by Echo's middleware, where you could handle the request however you wanted.
Edit the Echo source to work how you wanted it to work -- specifically, all you would have to do is edit ErrJWTMissing.
Basically, Echo is trying to do you favors by handling all of this middleware processing for you, and it's a lot of work or hackery to un-do that work while still using Echo.

Parse cloud code send flag to save object

I've been trying to send a flag to save request. This save request is sent from different platforms so we seperated them with a flag. The problem is that it gives
Result: TypeError: Cannot read property '0' of undefined
when you send the request to table without the parameter. I did not want to add this parameter as a column in the table but it seems it automatically creates it when you successfully save the object. Is there a way to save the object without creating the flag column and seperate the save requests with and without the flag? Thank you in advance.
Parse.Cloud.beforeSave("MessageTest", function(request, response) {
if(!request.object.get("fromMessages")) {
..
..
}
else response.succcess();
});
If you try to save an object directly from your app, you cannot remove the field from your request in beforeSave trigger. A better approach is to save your object via a Cloud function instead. Send in your object alongside of your platform flag to a cloud function, then construct a MessageTest object from the parameters (obviously ignoring your platform flag) and then save it from there.

wireload / Ratatosk : How to make POST requests?

In my Cappuccino frontend I'm using Ratatosk to make queries to a RESTful JSON-based API.
When I create a new resource with
[myNewResource ensureCreated];
my backend returns the status code 201 and a Location header with the URI of the newly created resource. The response body is empty. As far as I know, that's the way a REST API should react to successful POST requests.
But upon receiving the response, Ratatosk calls
- (void)connection:(CPURLConnection)aConnection didReceiveData:(CPString)data
(in WLRemoteLink.j) and tries to decode the response body. This throws an error because the response body is empty. As a consequence, the request is repeated infinitely.
How should I go about this? Am I supposed to return the whole resource in the response body?
EDIT:
Returning the ID in the response solved the problem, like
{"id":1}
Ratatosk expects the status code 204 (no content) if the response is to be empty. Otherwise it expects the full representation of the resource which was just created (which it uses to populate server side dynamic properties locally like created_at).

Resources