Re: Accessing shockwave/flash video via HttpUnit?

<[email protected]>
Newsgroups gmane.comp.web.httpunit.devel
Message-ID <[email protected]>
Use HTTPUnit to capture the webpage that contains your embedded flash
video. Since the video file is nothing but a web resource sitting on
some server, download it to your local directory. Once you have this
file on your local drive you can do a benchmark comparison with your
existing file that you want to compare against which is also accessible
locally. 
I am attaching the code to download this video file. 

Assuming you have a webResponse object called "currentPage"

     private static final String SRC_MARKER   = "src=";
      String text;
            try
            {
                text = currentPage.getText();
            }
            catch (IOException e)
            {
                throw new GenericException("Unable to read response
page: " 
                + e.getMessage(), e);
            }
        
            String lower = text.toLowerCase();
            URL pageURL = currentPage.getURL();    
            StringBuffer notFoundImages = new StringBuffer();
        
            for(int i = 0; (i = lower.indexOf(SRC_MARKER, i + 1)) != -1;
)
            {
                int start = i + SRC_MARKER.length();
                char quoteChar = text.charAt(start);
                int end = text.indexOf(quoteChar, ++start);
                String src = text.substring(start, end);
         
                try
                {
                    URL imageURL = new URL(pageURL, src);
                    String urlString = imageURL.toString();
                    InputStream in;
                    
                    String targetFile =
TestConfig.getlogDir()+CACHE_DIR+
 
File.separator+HTTPUtilities.fixLocalFileSource(imageURL.getFile());
                    String targetFileDir =
targetFile.substring(0,targetFile.lastIndexOf('/'));
                    
                    in = new BufferedInputStream(imageURL.openStream());
                    imageFound =
downloadWebResources(imageURL,targetFile,targetFileDir,in);
                    
                }
                catch (MalformedURLException e)
                {
                }
            }
        }
    }
    
    /* 
     * Download a file from a URL to a local directory
     * 
     * @parm URL - The URL to read from
     * @return - true if more than zero bytes were read from the URL.
     */
    public static boolean downloadWebResources(URL resourceURL, String
targetFile, String targetFileDir,
                                                InputStream in) 
    throws GenericException, MalformedURLException, IOException,
SAXException
    {
        boolean resourceFound = false;
        OutputStream out = null;
        String urlString = null; 
		 
        try
        {
            HTTPUtilities.mkdir(targetFileDir);
            int totalBytes = 0;

            FileOutputStream fos = new FileOutputStream(targetFile);
            out = new BufferedOutputStream(fos);
	    byte[] buffer = new byte[4096];
    	    int bytesRead;
            
            while ((bytesRead = in.read(buffer)) != -1){
                	out.write(buffer, 0, bytesRead);
                	totalBytes += bytesRead;
            }
			
            if (totalBytes > 0) resourceFound = true;

            }
            catch (MalformedURLException mue)   
            {  
			//System.out.println("A MalformedURLException
happened.");   
			mue.printStackTrace();   
            }   
            catch (IOException e)
            {
                System.out.println("IOException encountered while
downloading "+
                             resourceURL +":\n" + e.getMessage());
            }
            catch (Exception e)   
            {   
                System.out.println("Exception happened : " + e);   
		e.printStackTrace();   
		}   
            finally
            {
                try
                {
                    if (in != null) in.close();
                    if (out != null) out.close();
                }
                catch (IOException e1)
                {
                    // Nothing to do.
                }                   
            }
            return resourceFound;
    }





-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of
Richard Stein
Sent: Wednesday, April 04, 2007 4:30 AM
To: [email protected]
Subject: [Httpunit-develop] Accessing shockwave/flash video via
HttpUnit?


I'm looking for a means to apply HttpUnit to capture a shockwave/flash
video that may be embedded in a web page. I recognize that HttpUnit can
identify an HTML object of the form:

<object width="425" height="350"><param name="movie"
value="http://www.website.com/v/IwD25nkGV1A"></param>
<param name="wmode" value="transparent"></param><embed
src="http://www.website.com/v/IwD25nkGV1A"
type="application/x-shockwave-flash" wmode="transparent" width="425"
height="350"></embed></object>

But how can I capture the video stream that arises from the URL and
compare against a known reference? The media stream resides within our
firewall. Thx.

--
Richard M. Stein
Healthe.com Test Engineering
Office: +65-64935015
Mobile: +65-93524723
FAX: +65-65331582

Disclaimer: This message is intended only for the use of the
addressee(s) named above and may contain privileged information. If you
are not the intended recipient of this message you are hereby notified
that you must not disseminate, copy or take any action based upon it.
Please delete and destroy the message from your computer. If you
received this message in error please notify the Healthe Group of
Companies immediately. Any views expressed in this message are those of
the individual sender, except where the sender specifically states them
to be the views of the Group.
 


------------------------------------------------------------------------
-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share
your opinions on IT & business topics through brief surveys-and earn
cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDE
V
_______________________________________________
Httpunit-develop mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.