CXF #multipart annotation not working with cxf-rt-frontend-jaxrs 3.5.0 - jax-rs

I use cxf to define my rest apis. And it looks like this
#POST
#Path("/{configurationName}.diff")
#Consumes(MediaType.MULTIPART_FORM_DATA)
#Produces({MediaType.APPLICATION_JSON})
ConfigurationDiffDTO diff(#PathParam("configurationName") String configurationName,
#Multipart(value = "fromRev", required = false) Long fromRev, #Multipart(value = "toRev", required = false) Long toRev, #Multipart(value = "file", required = false) Attachment file);
Above declaration works fine till cxf 3.4.5. It does not read my fromRev and toRev values from 3.5.0 version.
My form data from chrome console
------WebKitFormBoundary64lWWqSfXrPL3mg5
Content-Disposition: form-data; name="fromRev"
3
------WebKitFormBoundary64lWWqSfXrPL3mg5
Content-Disposition: form-data; name="toRev"
4
------WebKitFormBoundary64lWWqSfXrPL3mg5--

Related

Parse multipart/form-data response in rust / reqwest

I'm relatively new to rust and using reqwest to fetch a PDF document from a REST API endpoint. The content-type of the response is multipart/form-data; boundary=bc1f6465-6738-4b46-9d9d-b9ae36afa8cb with two parts:
--bc1f6465-6738-4b46-9d9d-b9ae36afa8cb
Content-Disposition: form-data; name="metadata"
Content-Type: application/json
{"documentId":"QkNfRENfSUwwMDEsRTA1OEU3ODQtMDAwMC1DNzY5LTg1MjktMTRFRkI5RTBFNjRF"}
--bc1f6465-6738-4b46-9d9d-b9ae36afa8cb
Content-Disposition: form-data; name="document"; filename=document.pdf
Content-Type: application/pdf
%PDF-1.4
<binary content>
%%EOF
--bc1f6465-6738-4b46-9d9d-b9ae36afa8cb--
I want now to save the PDF document in the 2nd part as a valid PDF file on disk. But the multipart functionality within reqwest seems to create new multipart requests whereas I need to parse a multipart response.
My code to download the file:
use reqwest::{self, header::AUTHORIZATION};
fn main() {
let url = "https://example.com/rest/document/123";
let authorization_header = String::from("Bearer ") + access_token.as_str();
let res = client.get(url)
.header(AUTHORIZATION, &authorization_header)
.send()
.expect("Error calling API");
}
Any hint on how to process the multipart/form-data response is appreciated!

Multi-Part upload has no payload

I am trying to do a multi-part upload from my javascript application and it works fine in the chrome browser but fails without error when run in electron.
I can't find information, why it fails in electron, but maybe some of you have an idea? :)
var fileContent = new Uint8Array([64,65,66,67]);
var fileBlob = new Blob([fileContent], {type: 'application/octet-stream'});
var data = new FormData();
data.set('file', fileBlob, 'blob.bin');
fetch('http://my.end.point', {
method: 'POST',
body: data
});
When I run that code in Chrome, I can see the 4 bytes payload in the network tab and my end point receives the 4 bytes. If I do the same in electron, the payload in the network tab is empty and the end point receives the multi-part request with the payload missing. I also tried using XMLHttpRequest instead of fetch but that shows exactly the same behavior.
Request Payload from within electron:
------WebKitFormBoundaryNXzPiiAvBttdDATr
Content-Disposition: form-data; name="file"; filename="blob.bin"
Content-Type: application/octet-stream
------WebKitFormBoundaryNXzPiiAvBttdDATr--
Request payload from withon chrome browser:
------WebKitFormBoundarywTEtXn4z3NFt3sAb
Content-Disposition: form-data; name="file"; filename="blob.bin"
Content-Type: application/octet-stream
#ABC
------WebKitFormBoundarywTEtXn4z3NFt3sAb--
Does someone know, why it doesn't work from within electron?

Setting REQUEST header Http Client vb.net

Consider the following VB code:
Public Async Function someFunction(ByVal url As String, Optional ByVal methodPost As Boolean = False, Optional ByVal postContent As HttpContent = Nothing) As Threading.Tasks.Task(Of String)
Using client = New HttpClient
client.DefaultRequestHeaders.Authorization = makeAuthenticationHeader()
If methodPost Then
client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json"))
Dim Response = Await client.PostAsync(url, postContent)
Dim content As String = Await Response.Content.ReadAsStringAsync
Return content
Else
Return Await client.GetStringAsync(url)
End If
End Using
End Function
I want to set the request content type to application/json as well as the response content type to application/json.
If I add the following line of code:
client.DefaultRequestHeaders.Add("content-type", "application/json") then the system throws an exception Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects..
I've searched all over google for a way to set the requests header to JSON. Using fiddler (on the server) I can see that the request is sent as plain/text.
POST **URL REMOVED FOR SAFETY REASONS** HTTP/1.1
Authorization: Basic **HASHED AUTH DETAILS - REMOVED FOR SAFETY REASONS**
Accept: application/json
Content-Type: text/plain; charset=utf-8
Host: **HOST REMOVED FOR SAFETY REASONS**
Content-Length: 1532
Expect: 100-continue
Connection: Keep-Alive
Content-Type: text/plain; charset=utf-8 This is where I am having an issue. This needs to be set to a content type for JSON as the body of the request is JSON. How do I set this content-type to JSON in vb.net Code.
I found a solution, I don't know if it is the correct solution or if there is a better solution out there.
Basically you need to set the content-type header on the actual content that you are sending and not on the HTTP Client.
So basically adding content.Headers.ContentType = New MediaTypeWithQualityHeaderValue("application/json") to your code should set the REQUEST's content-type to JSON as well.
Public Async Function someDifferentFunction() As Threading.Tasks.Task(Of String)
Dim url As String = "http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Dim content As HttpContent = New StringContent(txtRequestBody.Text)
content.Headers.ContentType = New MediaTypeWithQualityHeaderValue("application/json")
Return Await someFunction(url, True, content)
End Function

How can I change the filename in a fine-uploader blob request

Using the basic fine-uploader and addFile to insert a blob based entry.Everything goes ok until the server reject the request due to "security issues".
If I convert the blob to a file and send it to the fine-uploader the server is quite happy. The only difference between the two requests is the filename in the request header.
The file-uploader setName() doesn't appear to change to "blob" name.
fails:
Content-Disposition: form-data; name="qqfile"; filename="blob"
Content-Type: image/jpeg
Any way to replace the 'filename="blob"' with a name that contains the correct extension - blob.jpg, blob.gif,etc?
var myblob = new Blob([outputBuffer], {type: "image/jpeg"});
myblob.name = ofile;
var myfile = new File([myblob], 'ImageTest.jpg', {
lastModified: new Date(0), // optional - default = now
type: "image/jpeg" // optional - default = ''
});
fineUploader.addFiles({blob:myblob, name:ofile});
console.log(fineUploader.getName(0));
fineUploader.setName(0,ofile);
console.log(fineUploader.getName(0));
fineUploader.addFiles(myfile);

Resteasy destroys filename encoding on multipart/form-data POST requests

I do a fileupload to the following annotated Restservice
#POST
#Path("/uploadFile")
#Consumes("multipart/form-data")
public Response uploadFile(MultipartFormDataInput input)
When special characters in the filename like "äÄöÖüÜß" are used, the filename gets corrupted during processing of Resteasy subsystem.
I verified this by creating a Logginginterceptor
#Provider
#ServerInterceptor
public class LoggingInterceptor implements PreProcessInterceptor
Inside this interceptor, the http fileupload (multipart/form-data) is still correct
Content-Disposition: form-data; name="file"; filename="TestäÄöÖüÜßFile2.pdf"
Content-Type: application/pdf
when Resteasy calls the uploadFile Method, the filename is corrupted
Content-Disposition: form-data; name="file"; filename="Test��������������File2.pdf"
Content-Type: application/pdf
Is there a possibility (maybe by some annotation) to preserve the filename encoding in the Entity?
Kind regards
Shane