forwadring to Servlet from Remote object fails

Posted on 2011-04-26
Last Modified: 2012-05-11
hi guys
I am generating Pdf from flex. From my flex client i call 'RemoteCustomer'  a java remote object and call generatePdf()method. In this method i am trying to forward to a java Servlet called PDFServlet which is in the same package as RemoteCustomer but i get error shown below

public class RemoteCustomer{

public void generatePdf(Workflow workflow){
boolean pdfStatus = true;
String sessionKeyName = "PDF_BYTESTREAM";
ByteArrayOutputStream pdfByteStream = null;
HttpServletRequest request = flex.messaging.FlexContext.getHttpRequest();
HttpServletResponse response = flex.messaging.FlexContext.getHttpResponse();
pdfByteStream = PdfMaker.makePdf(workflow); -- this contains the byte stream which needs to be passed to servlet
request.getSession().setAttribute(sessionKeyName,p dfByteStream);
request.getRequestDispatcher("PDFServlet").forward(request, response); //PDFServlet exist in same package as this class

PDFServlet is my servlet class but unfortunately its not forwarding to the servlet.

It says

org.springframework.flex.servlet.MessageBrokerHand lerAdapter handle Received invalid request for endpoint path '/messagebroker/PDFServlet'.[4/26/11 12:58:10:850 EDT] 00000029 srt W addHeader WARNING: Cannot set header. Response already committed.
[4/26/11 12:58:10:865 EDT] 00000029 srt W setDateHeader WARNING: Cannot set header. Response already committed.
[4/26/11 12:58:10:865 EDT] 00000029 srt W setHeader WARNING: Cannot set header. Response already committed.
[4/26/11 12:58:10:928 EDT] 00000029 srt W setIntHeader WARNING: Cannot set header. Response already committed.
[4/26/11 12:58:10:944 EDT] 00000029 SystemOut O [BlazeDS]SRVE0209E: Writer already obtained
java.lang.IllegalStateException: SRVE0209E: Writer already obtained
at Outpu

Any help will be greatly appreciated
Question by:royjayd
    LVL 20

    Expert Comment

    Well I guess you are recieving this error because you are using the http-request and response objects to output your data. Unfortunately blazeds uses these objects to output an AMF serialized form of the data returned by a method call. So you are bypassing the AMF serialization and this is what BlazeDS and Flex are complaining about. In BlazeDS ByteArrays are extremely imperformant (byte[] would be great, but Byte[] really sucks (takes about 10 times the memory).

    I would suggest to call your Servlet directly from the Flex client using an UrlRequest or something like that.

    Author Comment

    yeah, makes sense

    when you said
    >>>byte[] would be great, but Byte[] really sucks

    whats the difference between byte[] and Byte[]

    LVL 20

    Accepted Solution

    Well one byte is one byte of size ... the Java Object Byte is a lot bigger. I encountered really major memory issues as Flex Uploade of about 10MB used more than 100MB of memory on the server. ... Guess this is because BlazeDS reads the AMF for a starting array and therefore creates An Object[] ... unfortunately each element of the array is one byte to BlazeDS creates one byte Object and not a byte primitive and adds that to the array.

    My solution was to do uploads and downloads of byte data parralell to AMF/BlazeDS using Spring MVC components.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Flex automation silktest 3 894
    check for non negative number 2 435
    how to edit swc file 3 521
    Adobe upload listbox 2 486
    First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
    DECT technology has become a popular standard for wireless voice communication. DECT devices are not likely to be affected by other electronic devices and signals because they operate in a separate frequency-band.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now