[ https://issues.apache.org/jira/browse/CXF-4772?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13560392#comment-13560392 ]
Yan Min Sheng commented on CXF-4772: ------------------------------------ Hi, Freeman, I get your point. Delegate attachment can only be read once. It will return empty for the second time. But this case is special, as the second time read is done by CXF code in the AttachmentOutInterceptor. As my sample code demonstrates, client side send a single image, and server side first write the image into a file and then return the image object to the client at the sametime. However, when CXF serialize the image object into response stream, it will read empty content as the image attachment is a "Delegate" stream. Do you think the test code as following should be modified to "hold" the stream of the img object? public ImageDepot sendImage(ImageDepot imgin){ ImageDepot imgout = new ImageDepot(); List<DataHandler> imglist = imgin.getImage(); // traverse each of the image for (DataHandler img : imglist) { if (img != null) { File f = new File("image_"+imglist.indexof(img)); if (f.exists()) { f.delete(); } FileOutputStream fos = new FileOutputStream(f); img.writeTo(fos); imgout.getImage().add(img); fos.close(); } } return imgout; } > AssessmentDataStore do not cache the last attachment binary stream, so the > DataHandler.writeTo() will fail if it is called for the second time > ---------------------------------------------------------------------------------------------------------------------------------------------- > > Key: CXF-4772 > URL: https://issues.apache.org/jira/browse/CXF-4772 > Project: CXF > Issue Type: Bug > Components: Core > Affects Versions: 2.6.2 > Reporter: Yan Min Sheng > Priority: Critical > Labels: patch > Attachments: CXF4772.patch > > > When trying test MTOM through JAX-WS, we found that the AssessmentDataStore > can only be written once. It will fail for the second time. After > investigation, it seems that the binary stream is not cached by the > AssessmentDataStore, so each time a DelegatingStream will be created to > handle the writeTo request. While the DelegatingStream is closed, it can not > handle the writeTo request again. > The suggestion is to cache the newly created attachement after it is created > in AttachmentDeserializer > The interface is: > /** > * This class was generated by the JAXWS SI. > * JAX-WS RI 2.0_01-b15-fcs > * Generated source version: 2.0 > * > */ > @WebService(name = "MTOMInterface", targetNamespace = > "http://shengym.com/wssvt/acme/InsBusiness/") > public interface MTOMInterface { > /** > * > * @param input > * @param params > * @return > * returns com.ibm.wssvt.acme.insbusiness.ImageDepot > * @throws InsFaultException > */ > @WebMethod(action = "http://shengym.com/wssvt/acme/sendImage") > @WebResult(name = "output", targetNamespace = "") > @RequestWrapper(localName = "sendImage", targetNamespace = > "http://shengym.com/wssvt/acme/InsBusiness/", className = > "com.shengym.wssvt.acme.insbusiness.SendImage") > @ResponseWrapper(localName = "sendImageResponse", targetNamespace = > "http://shengym.com/wssvt/acme/InsBusiness/", className = > "com.shengym.wssvt.acme.insbusiness.SendImageResponse") > public ImageDepot sendImage( > @WebParam(name = "input", targetNamespace = "") > ImageDepot input, > @WebParam(name = "params", targetNamespace = "") > ParamsType params) > throws InsFaultException > ; > } > ImageDepot.java > @XmlAccessorType(XmlAccessType.FIELD) > @XmlType(name = "ImageDepot", propOrder = { > "image" > }) > public class ImageDepot { > @XmlElement(required = true) > @XmlMimeType("multipart/*") > protected List<DataHandler> image; > /** > * Gets the value of the image property. > * > * <p> > * This accessor method returns a reference to the live list, > * not a snapshot. Therefore any modification you make to the > * returned list will be present inside the JAXB object. > * This is why there is not a <CODE>set</CODE> method for the image > property. > * > * <p> > * For example, to add a new item, do as follows: > * <pre> > * getImage().add(newItem); > * </pre> > * > * > * <p> > * Objects of the following type(s) are allowed in the list > * {@link DataHandler } > * > * > */ > public List<DataHandler> getImage() { > if (image == null) { > image = new ArrayList<DataHandler>(); > } > return this.image; > } > } > The client code will look like: > void setOutputImage(ImageDepot imgin, ImageDepot imgout) throws > Exception { > List<DataHandler> imglist = imgin.getImage(); > try { > DataHandler img = null; > // traverse each of the image > for (DataHandler img : imglist) { > if (img != null) { > File f = new File(msgID + > "_server_image"+ imglist.indexOf(img)); > if (f.exists()) { > f.delete(); > } > FileOutputStream fos = new > FileOutputStream(f); > img.writeTo(fos); > imgout.getImage().add(img); > fos.close(); > } > } > } catch (Exception e) { > System.out.println("Exception caught in MTOMService > sendImage ..."); > e.printStackTrace(System.out); > throw e; > } > } -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira