everyone!
I'm trying to send a request to a Rest Service to upload a PDF file, but I'm getting a HTTP Status of 400.
The service allows sending several files, but only one is required. The WADL Definition is:
<resource path="/uploadFiles">
<method name="POST" id="uploadDocuments">
<request>
<representation mediaType="multipart/mixed">
<param name="attachment1" style="query" type="xs:anyType"/>
<param name="attachment2" style="query" type="xs:anyType"/>
<param name="attachment3" style="query" type="xs:anyType"/>
</representation>
</request>
<response>
<representation mediaType="application/json"/>
</response>
</method>
In my case, I just want to send one file in "attatchment1". I'm using jersey-multipart and I have this method to create the multipart object:
private MultiPart createMultiPart (String fileName){
File file = new File(fileName);
final FileDataBodyPart bodyPart = new FileDataBodyPart(fileName, file);
final FormDataContentDisposition dispo = FormDataContentDisposition
.name("attachment1")
.fileName(fileName)
.size(file.length())
.build();
bodyPart.contentDisposition(dispo);
final MultiPart multBody = new MultiPart().bodyPart(fd);
return multBody;
}
This is the client I have to send the request:
com.sun.jersey.api.client.Client client = new DefaultClientConfig();
com.sun.jersey.api.client.WebResource resource = client.resource(URI);
com.sun.jersey.api.client.WebResource.Builder resourceBuilder = resource.getRequestBuilder();
resourceBuilder = resourceBuilder.accept("application/json");
resourceBuilder = resourceBuilder.type("multipart/mixed");
com.sun.jersey.api.client.ClientResponse response;
response = resourceBuilder.method("POST", com.sun.jersey.api.client.ClientResponse.class, createMultiPart(fileName));
I think the trouble is I have any mistake creating the multiPart object. Does anyone know hoy to solve it?
Thanks in advance!