Announcement Announcement Module
No announcement yet.
soap attachment limited size issue Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • soap attachment limited size issue

    We are using Springs SaajSoapMessage Factory to attach a large incoming xml (1MB) and send it as a webservice call to another endpoint.

    It appears the attachment is getting attached correctly but on the receiving end when we iterate through the attachment the size of the attached file is around 8 KB only.

    Looks like the remaining xml is getting trucated.

    1.> Is there any size limit on the attachment which we can send over the wire?

    2.> Does anyone have any sample code for sending attachments using SoapMessage?

    Below are the code snippets

    WebServiceMessageCallback requestCallBack1 = null;
    try {
    requestCallBack1 = new WebServiceMessageCallback() {

    public void doWithMessage(WebServiceMessage message)
    throws IOException, TransformerException {
    SoapMessage soapMessgae = (SoapMessage) message;
    soapMessgae.addAttachment("1", new ByteArrayResource(xml.getBytes()), "application/octet-stream");

    } catch(Exception e){


    LogResponse logResponse = (LogResponse) this.webServiceTemplate
    logRequest, requestCallBack1);

  • #2
    The only difference I can find quickly between your code and mine is that you are using a SoapMessage instead of a SaajSoapMessage.

    I haven't tried this with a large (> 1 MB) file yet:
    new WebServiceMessageCallback() {
    	public void doWithMessage(WebServiceMessage message) 
    		throws IOException, TransformerException {
    		SaajSoapMessage saajMessage = (SaajSoapMessage) message;
    		//file is of type
    		saajMessage.addAttachment(file.getName(), file); 
    This is just the Callback - I doubt the rest is relevant to you since I'm using MarshallSendAndReceive.
    Last edited by evandongen; Jun 16th, 2010, 02:44 AM. Reason: Clarify the type of file


    • #3
      soap attachment limited size issue

      Hi Evandongen,

      Thanks for you suggestion!

      But Still I'm gettting truncated xml. Can you please check below code

      Here I'm receiving the attachment.....

      SoapMessage message = (SoapMessage)messageContext.getRequest();
      Iterator<Attachment> iterator= message.getAttachments();

      Attachment attachment = (Attachment);
      InputStream inputStream = attachment.getInputStream();
      //buffer = new StringBuilder();
      byte[] data = new byte[1024];
      try {
      while ((count, 0, 1024)) != -1) {
      buffer.append(new String(data, 0, count));
      } finally{
      }//End Of While


      • #4
        My code looks like what you have, with the same difference as we had on the client side

        I'm using SaajSoapMessage:
        protected List<Attachment> getAttachments() {
        	SaajSoapMessage saajSoapMessage = (SaajSoapMessage) messageContext.getRequest();
        	Iterator<Attachment> iterator = saajSoapMessage.getAttachments();
        	ArrayList<Attachment> attachments = new ArrayList<Attachment>();
        	while (iterator.hasNext()) {
        	return attachments;
        I haven't implemented the actual retrieval and saving of an attachment yet. When debugging it looked all fine in my watch window though.

        If this doesn't help I don't know what else it could be .. Good luck, hth