Yan Min Sheng created CXF-4772:
----------------------------------
Summary: 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
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