Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / March 2008



Tip: Looking for answers? Try searching our database.

Writing out Binary Data via CFScript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ssemrau - 26 Mar 2008 21:11 GMT
Hopefully someone will be able to provide some insight or possible resolution
to this:

On a site I'm now managing there is a piece of code that is being used to
write out binary data (images) to the client that are located on the HDD.  This
code (after doing some searching) is verbatim from Christian Cantrell's blog
posting from about 5 years ago
(http://weblogs.macromedia.com/cantrell/archives/2003/06/using_coldfusio.html).

As far as I can tell the end user is not experiencing any problems - but the
exception.log (as well as the application.log) is filling up with the following
error:

java.lang.IllegalStateException
    at jrun.servlet.JRunResponse.getOutputStream(JRunResponse.java:179)

(Hopefully the actual code in question is posted at the bottom of this message)

Of course if the end users are not getting an error this is fine, but it
doesn't reflect well on us when the client decides to look at the log files and
sees and endless stream of error messages related to this code.

I have tried using the reponse.reset(); in a couple of different locations
within that 'script' but this in turn generates teh following error:

java.lang.IllegalStateException: Response has already been committed
    at jrun.servlet.jrpp.ProxyEndpoint.resetBuffer(ProxyEndpoint.java:991)

I've searched and read every possible link I could google and nothing else
seems to provide any insight on a solution.

The client is currently running CFMX 7.0.2 (no hot fixes) standard edition ...
which seems to be utilizing JRun Updater 5.

Thanks in advance for any possible insight or fix.

<cffile action="readbinary" file="#ipath#" variable="pic"/>
   
    <cfscript>
        context = getPageContext();
        context.setFlushOutput(false);
        response = context.getResponse().getResponse();
        out = response.getOutputStream();
        response.setContentType("image/jpeg");
        response.setContentLength(arrayLen(pic));
        out.write(pic);
        out.flush();
        out.close();
    </cfscript>
-==cfSearching==- - 27 Mar 2008 04:11 GMT
I am not very familiar with servlets, but did you come across this TechNote
that describes a similar error?

http://kb.adobe.com/selfservice/viewContent.do?externalId=28c3e2c2&sliceId=2

> out.close();

I may be 100% wrong here, but I seem to recall reading that you should not
close the output stream of a servlet.
GArlington - 27 Mar 2008 13:32 GMT
> Hopefully someone will be able to provide some insight or possible resolution
> to this:
[quoted text clipped - 45 lines]
>                 out.close();
>         </cfscript>

Is the above script part of the function that you are calling a number
of times for the same page?
Try to add <cftry>...<cfcatch> block around your code and dump any
exceptions you catch to see any additional info and what is the actual
state...
ssemrau - 27 Mar 2008 15:07 GMT
Thank you for your reply - yes I did come across that TechNote - unfortunately to refers to a previous 'Updater' version [4]
-==cfSearching==- - 27 Mar 2008 16:34 GMT
Yes. The mention of 7.0.2 using updater 5 did not sound defintive. I was not
sure which version it used myself. So I thought I would mention the TechNote
just in case.

However, I realized the code must have been written for MX6.  MX7 introduced
the "variable" attribute of the cfcontent tag.  That attribute can contain
binary.  So you should be able to use cfcontent instead.
ssemrau - 27 Mar 2008 16:49 GMT
Yes - I'm not sure if I can even apply the JRun Updaters at this point and I
agree - I'm going to recommend changing from the <cfscript to using the
<cfcontent.  It's cleaner and saves about 12 lines of code :)
-==cfSearching==- - 27 Mar 2008 16:56 GMT
Yes, a new updater would definitively be a last resort ;-) Cfcontent should do the trick.

Best of luck
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.