Download different content types with spring - spring

I need to expose a POST endpoint where the user uploads an excel file and based on some validations, I either send back the file with some information added to it along with json response OR just send status code as 200 OK(no data).
I am trying to do this in spring boot. I tried following link:
https://javadigest.wordpress.com/2012/02/13/downloading-multiple-files-using-multipart-response/
This works but needs adding boundary manually. Is there any other way to do it so that I can send both the data ?

You should use #Produces as it is written here: https://docs.oracle.com/cd/E19776-01/820-4867/ghrpv/index.html
You can define the MIME-Type of your payload.

Related

Exist DB XQuery: How to make an HTTP POST Request

Question: How do you make an HTTP POST request to an external service within Exist DB, ideally using just XQuery?
Motivation: I want to take a set of XML documents in Exist DB, and send each to an external server for processing, then I want to receive the result, and store them back in Exist DB.
I can accomplish this with an external script that interacts with the Exist DB REST interface, but I would like to it all within Exist DB and XQuery. Marklogic has a http request function that does POST requests under the xdmp namespace, which seems to accomplish this. Does something similar exist for Exist-DB?
Bonus points if the request body can be sent in JSON format.
eXist-db implements the EXPath HTTP Client specification, which defines a function, http:send-request, that can perform HTTP POST requests.
For sample code, including sending a request body containing JSON, see eXist-db send JSON via POST request using eXPath Http_module.

How Should I Make Spring Boot Rest API's Return Response in Client Requested Formate

I have Spring boot Rest APIS, but i want make those APIS Response as per the Client Requested Format.
For Instance :
Rest APIS Return Response By default In Json format. But Client Want to in XML formate or any other formate.
In the above situation how can i make my APIS dynamically Retunr the Response as per the Client requested format.
can any tell how can i do this.
Thanks in advance.
What you are talking about is Content Negotiation - Here's a Baeldung article that describes how you might use Jackson libraries to handle both XML and JSON data,
https://www.baeldung.com/spring-mvc-content-negotiation-json-xml
You need to devise a content negotiation strategy - very often, that is the use of the Accept header. Your API then has to respect this header and return the appropriate content, which might mean your API contracts having certain attributes to allow it to easily serialize to JSON/XML.
The article linked above links to a github repo that shows how this might be achieved - https://github.com/eugenp/tutorials/tree/master/spring-mvc-basics

Upload image to Lambda using gateway API

I'm trying to let user upload pictures to a lambda function for processing; using the gateway API interface.
I tried to specify a model for my POST method, but so far I keep getting the error
Invalid model specified: Validation Result: warnings : [], errors : [Invalid model schema specified]
... Not so helpful.
I understand that I cannot directly send raw data to lambda and must using some kind of formatting in-between.
What I understood is that I could make the gateway interface base64 encode the data for me.
I tried to do so by using the following model schema with the content type image/jpeg
{
"body" : $util.base64Encode($input.body)
}
How to send the image ?
There is no native support in API Gateway for binary data as you have seen. We are working on this but I don't have an ETA for you. Some customers have had success base64 encoding the data like you have in your question, only it should be in a mapping template in the Integration Request not the Method Request.
If you set the content type to image/jpeg, then the encoding will apply only when the Content-Type header on the incoming request is also image/jpeg, so make sure to set that.
You can also reject incoming requests to the method that don't send the right Content Type by setting the 'Request body passthrough' (passthroughBehavior in the API) to the recommended value ("when there are no templates defined" or 'WHEN_NO_TEMPLATES' in the API)
Docs for the passthrough behavior -> https://docs.aws.amazon.com/apigateway/api-reference/resource/integration/#passthroughBehavior
Since it seems like working with binary data and API Gateway is complicated, I think you should:
Upload the image using API Gateway as an S3 proxy
Set a trigger for your lambda function on PUT for the bucket where you've uploaded the image

How to ensure that fineuploader sends a streaming upload request instead of MPE request?

I do not see any options to remove parameters or disable sending parameters when uploading using fineuploader. I can only override existing parameters or add new ones. Is there a way to do an upload using PUT without sending any parameters? Since I have signed PUT URI, I don't need to send the parameters. I tried using paramsInBody = false but that adds the content type "octet-stream" to the request. Amazon S3 returns unauthorized because of the incorrect content type.
Note: I am not using fineuploaderS3 since I need to upload to different endpoints.
Edit: Additional information
If the upload is not multi-part, fine uploader is adding the following header
xhr.setRequestHeader("Content-Type", "application/octet-stream");
This causes an authentication error with amazon S3.
I would like not to send default parameters like qquuid, qqparentsize, qqfile and qqfilename in the body since only file data is expected in the body. Setting paramsInBody to false sends them in query string. This works because the URL parameters are ignored by S3 but I would prefer to have an option to not send them at all.
By default, Fine Uploader sends all files as part of a multipart encoded request. To instruct the library to simply send the file as the entire request body, you must set the request.forceMultipart option to false.
Note: It is not possible to prevent uploads sent from IE9 and older to be non-multipart encoded. The only way to upload a file in IE9 and older is via a multipart encoded request.

How to authenticate birt report engine requests

When designing report I was getting this error:
XML data source cannot be retrieved. XML data source file is invalid or the file doesn't exist.
It was asked.
Then I found out it was because the request was intercepted by my spring security plugin. Now I disabled the plugin for a moment and my report is working. But this is not solution!
So now I want to somehow configure the report engine to use its own username and password; To be used when sending the requests.
Is there any hook in the plugin for doing this or any other workaround?
Or
when render engine sends a request to the datasource url is possible to add params?
e.g http://app/report?param1="value"&param2="value". Putting such url on the report design data source field results in invalid url.
update:
I am not using database connection as datasource.
my data source is a service that return xml response.
I think that you need to have some basic user in your DB.
When you're using the code, use this user to make it, so this user will be used only for these cases.

Resources