I ran a API request thorough postman and it ran successfully and this is its HTTP
POST //dummyendpoint/ HTTP/1.1
Host: dummyhost.com
Authorization: token="dummy_token"
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="config_enroll_settings"; filename="/C:/Users/SaurabhKumar/Desktop/config_enroll_settings.xml"
Content-Type: text/xml
(data)
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="usagePolicy"; filename="/C:/Users/SaurabhKumar/Desktop/usagePolicy.xml"
Content-Type: text/xml
(data)
----WebKitFormBoundary7MA4YWxkTrZu0gW
But then I am trying to achieve the same through JAXRS implementation I am getting 500 response code and when I checked the server side logs it said couldnt determine MIME boundary
This is my JAXRS interface I have explicitly added boundary but still it dosent works
@Consumes("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW")
@POST
@Path("/dummy_endpoint/{billingId}/")
public Object configureDeviceEnrollSettings(
@PathParam("billingId") String billingId,
@Multipart("multipartBody") MultipartBody multipartBody,
@HeaderParam("Authorization") String authorizationHeaderValue);
This is how I am calling this interface
Attachment configSettingsFile = new Attachment("config_enroll_settings", "multipart/form-data", new File("/C:/Users/SaurabhKumar/Desktop/config_enroll_settings.xml"));
Attachment usagePolicyFile = new Attachment("usagePolicy", "multipart/form-data", new File("/C:/Users/SaurabhKumar/Desktop/usagePolicy.xml"))
/*
I have tried this way also This way it resulted in exception
No serializer found for class java.io.FileDescriptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain:
org.apache.cxf.jaxrs.ext.multipart.MultipartBody["childAttachments"]
->java.util.AbstractList$SubList[0]
->org.apache.cxf.jaxrs.ext.multipart.Attachment["dataHandler"]
->javax.activation.DataHandler["dataSource"]
->org.apache.cxf.jaxrs.ext.multipart.InputStreamDataSource["inputStream"]
->java.io.FileInputStream["fd"])
File file1 = new File("/C:/Users/SaurabhKumar/Desktop/config_enroll_settings.xml");
ContentDisposition cd1 = new ContentDisposition("form-data; name=\"config_enroll_settings\"; filename=\"/C:/Users/SaurabhKumar/Desktop/config_enroll_settings.xml\"");
Attachment configSettingsFile = new Attachment("config_enroll_settings", new FileInputStream(file1), cd1);
File file2 =new File("/C:/Users/SaurabhKumar/Desktop/usagePolicy.xml");
ContentDisposition cd2 = new ContentDisposition("form-data; name=\"config_enroll_settings\"; filename=\"/C:/Users/SaurabhKumar/Desktop/usagePolicy.xml\"");
Attachment usagePolicyFile = new Attachment("usagePolicy", new FileInputStream(file2), cd2);
*/
List<Attachment> list=new LinkedList<>();
list.add(configSettingsFile);
list.add(usagePolicyFile);
MultipartBody body = new MultipartBody(list);
Object object = accountResource.configureDeviceEnrollSettings(billingId, body, "token=" + "\"" + authToken + "\"");
here is the stackTrace
com.webservices.utilities.httpclient.http.rest.ApiException: status 500 reading AccountResourceClient#configureDeviceEnrollSettings(String,MultipartBody,String)
at com.webservices.utilities.httpclient.http.rest.ApiErrorDecoder.decode(ApiErrorDecoder.java:42)
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:149)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:78)
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)
at com.sun.proxy.$Proxy16.configureDeviceEnrollSettings(Unknown Source)
at com.webservices.settings.ImportSettingsRoutine.importConfig(ImportSettingsRoutine.java:103)
at com.webservices.abstractclasses.AbstractRoutine.executeRoutine(AbstractRoutine.java:14)
at com.webservices.clients.ImportClient.executeRoutineQueue(ImportClient.java:47)
at com.webservices.Main.main(Main.java:69)
here is the raw request from the jaxrs client
POST https:/dummyendpoint/ HTTP/1.1
Accept: application/xml
Authorization: token="dummy_token"
Content-Length: 1861
Content-Type: multipart/form-data
User-Agent: ApiClient-1.0
X-FL-APPNAME: ApiClient
X-FL-REQ-ID: dumm_id
{
"type" : {
"type" : "multipart",
"subtype" : "related",
"parameters" : { },
"wildcardType" : false,
"wildcardSubtype" : false
},
"rootAttachment" : {
"headers" : {
"Content-ID" : [ "config_enroll_settings" ],
"Content-Type" : [ "text/xml" ]
},
"object" : "C:\\Users\\SaurabhKumar\\Desktop\\config_enroll_settings.xml",
"contentType" : {
"type" : "text",
"subtype" : "xml",
"parameters" : { },
"wildcardType" : false,
"wildcardSubtype" : false
},
"contentId" : "config_enroll_settings"
},
"allAttachments" : [ {
"headers" : {
"Content-ID" : [ "config_enroll_settings" ],
"Content-Type" : [ "text/xml" ]
},
"object" : "C:\\Users\\SaurabhKumar\\Desktop\\config_enroll_settings.xml",
"contentType" : {
"type" : "text",
"subtype" : "xml",
"parameters" : { },
"wildcardType" : false,
"wildcardSubtype" : false
},
"contentId" : "config_enroll_settings"
}, {
"headers" : {
"Content-ID" : [ "usagePolicy" ],
"Content-Type" : [ "text/xml" ]
},
"object" : "C:\\Users\\SaurabhKumar\\Desktop\\usagePolicy.xml",
"contentType" : {
"type" : "text",
"subtype" : "xml",
"parameters" : { },
"wildcardType" : false,
"wildcardSubtype" : false
},
"contentId" : "usagePolicy"
} ],
"childAttachments" : [ {
"headers" : {
"Content-ID" : [ "usagePolicy" ],
"Content-Type" : [ "text/xml" ]
},
"object" : "C:\\Users\\SaurabhKumar\\Desktop\\usagePolicy.xml",
"contentType" : {
"type" : "text",
"subtype" : "xml",
"parameters" : { },
"wildcardType" : false,
"wildcardSubtype" : false
},
"contentId" : "usagePolicy"
} ]
}