Results 1 to 4 of 4

Thread: soap attachment limited size issue

  1. #1

    Default 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

    this.webServiceTemplate.setDefaultUri("http://localhost:8888/xml-logger-web/services/");
    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){

    e.printStackTrace();
    System.out.println(e.getMessage());
    }

    LogResponse logResponse = (LogResponse) this.webServiceTemplate
    .marshalSendAndReceive(
    //"http://qu-lss-01:7777/xml-logger-web/services/",
    "http://localhost:8888/xml-logger-web/services/",
    logRequest, requestCallBack1);

  2. #2
    Join Date
    Mar 2010
    Location
    Rotterdam
    Posts
    21

    Default

    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:
    Code:
    new WebServiceMessageCallback() {
    	
    	public void doWithMessage(WebServiceMessage message) 
    		throws IOException, TransformerException {
    		
    		SaajSoapMessage saajMessage = (SaajSoapMessage) message;
    	
    		//file is of type java.io.File
    		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 at 02:44 AM. Reason: Clarify the type of file

  3. #3

    Default 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();

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

  4. #4
    Join Date
    Mar 2010
    Location
    Rotterdam
    Posts
    21

    Default

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

    I'm using SaajSoapMessage:
    Code:
    protected List<Attachment> getAttachments() {
    	SaajSoapMessage saajSoapMessage = (SaajSoapMessage) messageContext.getRequest();
    	Iterator<Attachment> iterator = saajSoapMessage.getAttachments();
    	
    	ArrayList<Attachment> attachments = new ArrayList<Attachment>();
    	while (iterator.hasNext()) {
    		attachments.add(iterator.next());
    	}
    	
    	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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •