javaee / metro-jax-ws

https://javaee.github.io/metro-jax-ws/
Other
132 stars 68 forks source link

java.lang.IllegalStateException in BodyPartEntity getInputStream() using RESTful POST request #1191

Open KrithikaKR17 opened 7 years ago

KrithikaKR17 commented 7 years ago

Hello,

I am trying to download multiple attachments in REST mode using FormDataMultiPart (app1 to app2). I am facing an exception when I try to extract the input stream from BodyPartEntity on the REST based application side. At first glance, it looks like the input stream in the MIMEParser of BodyPartEntity seems to be already parsed. Surprisingly this is working fine in the other way around (app2 to app1). I am using mimepull version 1.9.3.

Kindly help me in resolving this issue.

Stacktrace is:

java.lang.IllegalStateException: No such MIME Part: Part=0:binary at org.jvnet.mimepull.DataHead.read(DataHead.java:145) at org.jvnet.mimepull.MIMEPart.read(MIMEPart.java:94) at org.glassfish.jersey.media.multipart.BodyPartEntity.getInputStream(BodyPartEntity.java:80)

The code to construct the inputStream and attach it to FormDataMultiPart:

for(int i = 0; i < attachments.length; i++) { InputStream inputStream = new FileInputStream(new File("sample.xml")); formDataMultiPart.field("files", inputStream, MediaType.TEXT_XML_TYPE); }

The code to get the inputStream is:

List bodyParts = attachments.getFields("files"); for(int i = 1; i < bodyParts.size(); i++) { BodyPartEntity bodyPartEntity = (BodyPartEntity) bodyParts.get(i).getEntity(); InputStream is = bodyPartEntity.getInputStream(); }