forwadring to Servlet from Remote object fails

Posted on 2011-04-26
Medium Priority
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 com.ibm.ws.webcontainer.srt.SRTServletResponse addHeader WARNING: Cannot set header. Response already committed.
[4/26/11 12:58:10:865 EDT] 00000029 srt W com.ibm.ws.webcontainer.srt.SRTServletResponse setDateHeader WARNING: Cannot set header. Response already committed.
[4/26/11 12:58:10:865 EDT] 00000029 srt W com.ibm.ws.webcontainer.srt.SRTServletResponse setHeader WARNING: Cannot set header. Response already committed.
[4/26/11 12:58:10:928 EDT] 00000029 srt W com.ibm.ws.webcontainer.srt.SRTServletResponse 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 com.ibm.ws.webcontainer.srt.SRTServletResponse.get Outpu

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

Expert Comment

ID: 35468982
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

ID: 35470286
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

ChristoferDutz earned 2000 total points
ID: 35474473
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

[Video] Oticon Case Study

Open office environments can create the dynamics for innovation, but they also bring some challenges. With over 1,000 employees in an open office, Oticon needed a solution that would preserve the environment while mitigating disruptive background noises.

Watch how they did it.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Applications for our next round of the Experts Exchange Scholarship Contest are starting to roll in. It made us wonder what our past winners are up to these days. Here's a look at what four winners experienced with the contest and what they're doing…
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

864 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