streaming soap with attachments

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pmakoi
    New Member
    • Jun 2007
    • 7

    #1

    streaming soap with attachments

    dear all
    this might be a piece of cake for some of you out there but it is causing me a lot of stress given the fact that there is not enogh documentation out there regarding this topic

    I am writing a web service that uses soap with attachments to send a large streaming data,
    The concept works quite well but when I started to test it I got this problem.
    When my client program calls a method that should return a real time data the streaming starts after 10 seconds
    How can I avoid the fact that the message calls waits that long before the data starts streaming in?
    To be more specific
    I have a method that returns a streaming data in 10 seconds [getSteamingData (long seconds)]
    I would like to test if I already get some data steaming in after one second of it starts.
    To do so I started a thread that checks the OutputSteam size every 1 second and then compare the result with the previous size say a second ago, there should be an increase in size each second!!!
    But when I start the thread… the streaming does not start right away instead, it starts after 10 seconds causing the thread to return null size
    In real life with real large streaming data that 10 seconds could be 10 hours or God forbidden 10 years
    Is there a way around or is that not possible in SwA?
    Anybody have any idea
    thanks in advance
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by pmakoi
    dear all
    this might be a piece of cake for some of you out there but it is causing me a lot of stress given the fact that there is not enogh documentation out there regarding this topic

    I am writing a web service that uses soap with attachments to send a large streaming data,
    The concept works quite well but when I started to test it I got this problem.
    When my client program calls a method that should return a real time data the streaming starts after 10 seconds
    How can I avoid the fact that the message calls waits that long before the data starts streaming in?
    To be more specific
    I have a method that returns a streaming data in 10 seconds [getSteamingData (long seconds)]
    I would like to test if I already get some data steaming in after one second of it starts.
    To do so I started a thread that checks the OutputSteam size every 1 second and then compare the result with the previous size say a second ago, there should be an increase in size each second!!!
    But when I start the thread… the streaming does not start right away instead, it starts after 10 seconds causing the thread to return null size
    In real life with real large streaming data that 10 seconds could be 10 hours or God forbidden 10 years
    Is there a way around or is that not possible in SwA?
    Anybody have any idea
    thanks in advance
    Unfortunately once things over a network cable lots of things come into into play. It could be just your network playing tricks e.t.c. I don't know if posting your method for sending the data will help.

    Comment

    • pmakoi
      New Member
      • Jun 2007
      • 7

      #3
      thxs for the quick reply
      here is the code

      [CODE=java] public javax.activatio n.DataHandler[] returnStreaming ByteArray(final int timeout) {
      DataHandler ret = new DataHandler(new DataSource() {
      private long start = System.currentT imeMillis();
      private long end = start + timeout;

      public String getContentType( ) {
      return "text/plain";
      }

      public InputStream getInputStream( ) throws IOException {
      return new InputStream() {
      public int read() throws IOException {
      try {
      Thread.sleep(10 );
      } catch (InterruptedExc eption e) {
      //ignore this exception
      }
      if (System.current TimeMillis() > end) {
      return -1;
      } else {
      return (int)(Math.rand om() * 256);
      }
      }
      };
      }

      public String getName() {
      return "";
      }

      public OutputStream getOutputStream () throws IOException {
      return null;
      }

      });
      return new DataHandler[]{ret};
      }[/CODE]
      Last edited by r035198x; Jun 28 '07, 02:25 PM. Reason: added the missing code tags

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by pmakoi
        thxs for the quick reply
        here is the code

        [CODE=java] public javax.activatio n.DataHandler[] returnStreaming ByteArray(final int timeout) {
        DataHandler ret = new DataHandler(new DataSource() {
        private long start = System.currentT imeMillis();
        private long end = start + timeout;

        public String getContentType( ) {
        return "text/plain";
        }

        public InputStream getInputStream( ) throws IOException {
        return new InputStream() {
        public int read() throws IOException {
        try {
        Thread.sleep(10 );
        } catch (InterruptedExc eption e) {
        //ignore this exception
        }
        if (System.current TimeMillis() > end) {
        return -1;
        } else {
        return (int)(Math.rand om() * 256);
        }
        }
        };
        }

        public String getName() {
        return "";
        }

        public OutputStream getOutputStream () throws IOException {
        return null;
        }

        });
        return new DataHandler[]{ret};
        }[/CODE]
        What value are you passing for the timeout?

        Comment

        • pmakoi
          New Member
          • Jun 2007
          • 7

          #5
          the value that i gave it is 10000

          here is a part of a unit test class that i used to test it

          [CODE=java] package com.markit.soap attachments.cli ent;

          import javax.activatio n.DataHandler;
          import java.io.InputSt ream;
          import java.io.ByteArr ayOutputStream;
          import java.util.Array s;

          public class AttachmentsServ ice_ServiceWern erTestCase extends junit.framework .TestCase {

          ……………………………………
          …………………………………



          //this is the thread that runs the test
          private class StreamListener extends Thread {

          private int time;
          private ByteArrayOutput Stream outputStream;

          public StreamListener( int time) {
          this.time = time;
          }

          public void run() {
          try {
          //Write
          DataHandler[] ret = binding.returnS treamingByteArr ay(time);

          assertNotNull(" Expected non-null value to be returned",ret);
          assertEquals("E xpected length of DataHandler array to be 1", 1, ret.length);

          //Read
          DataHandler handler = ret[0];

          InputStream is = handler.getInpu tStream();
          int value;
          outputStream = new ByteArrayOutput Stream();
          try {
          while ((value = is.read()) != -1) {
          outputStream.wr ite(value);
          }
          } finally {
          outputStream.cl ose();
          }
          } catch (Exception e) {
          fail("Unexpecte d exception: " + e);
          }
          }

          public int getNrBytesRead( ) {
          return outputStream == null ? 0 : outputStream.si ze();
          }

          public byte[] getBytes() {
          return outputStream == null ? new byte[0] : outputStream.to ByteArray();
          }
          }

          public void testAttachments ServiceReturnSt reamingByteArra y() throws Exception {
          // Test operation
          long start = System.currentT imeMillis();

          StreamListener listener = new StreamListener( 10000);
          listener.start( );
          int nrOfBytesRead = 0;
          int previousNrOfByt esRead = 0;

          while (System.current TimeMillis() < start + 10000) {
          Thread.sleep(10 00);
          nrOfBytesRead = listener.getNrB ytesRead();
          assertTrue("Exp ected number of bytes read to have incremented", nrOfBytesRead > previousNrOfByt esRead);
          previousNrOfByt esRead = nrOfBytesRead;
          }
          listener.join() ;

          byte[] returnedBytes = listener.getByt es();

          assertTrue("Exp ected streaming to have lasted more than 10 seconds", System.currentT imeMillis() - start > 10000);

          assertTrue("Exp ected byte array to be filled", returnedBytes.l ength > 0);

          }


          }[/CODE]

          Comment

          • pmakoi
            New Member
            • Jun 2007
            • 7

            #6
            first i would like to thank every viewer for their attention and r035198x in particular

            I have been goggling around trying to figure out what might have been going wrong during the transmission? And I came up with some questions that might provide a hint as to where the problems might be coming from?
            1- in old postings about SwA it is stated that the attachments are sent in a one-go fashion, is that still the case now or can some new implementations support streaming the attachments through the network?
            If there are no data streaming soap with attachments implementations out there, would my problem be, that the streaming that I am trying to simulate in the above code is just using the activations framework streaming capabilities and the 10000 ms overhead is just a result of the work done by the processor to allocate resources for the large amount of data that is being received in one-go?

            Comment

            Working...