jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alvin Antony" <Alvin.Ant...@consol.de>
Subject AW: Problem with ObjectInputStream and WebRequest.setUserData & .getUserData()
Date Fri, 06 May 2005 12:50:23 GMT
Vincent,

ooops, thanks a lot. It works!!! 

regards,

Alvin


-----Ursprüngliche Nachricht-----
Von: Vincent Massol [mailto:vmassol@pivolis.com] 
Gesendet: Freitag, 6. Mai 2005 14:21
An: 'Cactus Users List'
Betreff: RE: Problem with ObjectInputStream and WebRequest.setUserData &
.getUserData() 

Alvin,

I've just spent some time working on this... It appears your code is
wrong...

Replace:

ByteArrayInputStream byteArrayInputStream  = 
    new ByteArrayInputStream( bos.toByteArray() );
objectInputStream = new ObjectInputStream( byteArrayInputStream );
webRequest.setUserData( objectInputStream ) ;

with:

ByteArrayInputStream byteArrayInputStream  = 
    new ByteArrayInputStream( bos.toByteArray() );
webRequest.setUserData( byteArrayInputStream );

and it'll work... :-)

-Vincent

> -----Original Message-----
> From: Alvin Antony [mailto:Alvin.Antony@consol.de]
> Sent: vendredi 6 mai 2005 13:59
> To: 'Cactus Users List'
> Subject: AW: Problem with ObjectInputStream and WebRequest.setUserData
&
> .getUserData()
> 
> Vincent,
> 
> Yes, it works in production. Btw. The Applet client is using
> URL.openConnection(), which returns a URLConnecton and uses the
> URLConnection.getOutputStream() to write into. I don't know, if it
makes
> any difference?
> 
> Alvin
> 
> 
> alvin.antony@consol.de                     ConSol* Software GmbH
> Phone +49-89-45841-191                     Consulting & Solutions
> Fax   +49-89-45841-111                     Franziskanerstr. 38
> Mobile+49-160-97340713
> http://www.consol.de                       81669 München
> 
> *******************************************************************
> Besuchen Sie uns auf der Midvision/Midrange 2005 in Karlsruhe vom
> 8. bis 9. Juni 2005 im BPM-Vision-Pavillon, Halle 1, Stand E50/1
> *******************************************************************
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: Vincent Massol [mailto:vmassol@pivolis.com]
> Gesendet: Freitag, 6. Mai 2005 13:45
> An: 'Cactus Users List'
> Betreff: RE: Problem with ObjectInputStream and WebRequest.setUserData
&
> .getUserData()
> 
> Alvin,
> 
> Thanks, I'll try it. Just a question: is your code working (i.e. the
> object
> is properly deserialized on the server side) when you run it outside
> Cactus?
> 
> Thanks
> -Vincent
> 
> > -----Original Message-----
> > From: Alvin Antony [mailto:Alvin.Antony@consol.de]
> > Sent: vendredi 6 mai 2005 12:32
> > To: 'Cactus Users List'
> > Subject: AW: Problem with ObjectInputStream and
WebRequest.setUserData
> &
> > .getUserData()
> >
> > Hello Vincent,
> >
> > Well I also tried the same test of yours with request.getInputstream
> and
> > it just works!! So the problem is when I use an ObjectInputStream.
You
> > could find a sample testcase here which fail on test.
> >
> >
> > package org.apache.cactus.sample.servlet;
> >
> > import java.io.ByteArrayInputStream;
> > import java.io.ByteArrayOutputStream;
> > import java.io.IOException;
> > import java.io.InputStream;
> > import java.io.ObjectInputStream;
> > import java.io.ObjectOutputStream;
> > import java.util.HashMap;
> > import java.util.Map;
> >
> > import org.apache.cactus.ServletTestCase;
> > import org.apache.cactus.WebRequest;
> >
> >
> > /**
> >  * @author antony
> >  *
> >  * Test case for testing WebRequest.setUserData with an
> > ObjectInputStream
> >  */
> > public class TestObjectInputStreamServlet extends ServletTestCase {
> >
> >
> >     public TestObjectInputStreamServlet ( String name )
> >     {
> >         super(name);
> >     }
> >
> >     /**
> >      * Prepare the request object. Add an ObjectInputStream into
> request
> > object.
> >      *
> >      * @param theRequest
> >      * @throws IOException
> >      * @throws ClassNotFoundException
> >      */
> >     public void beginSendUserData(WebRequest theRequest) throws
> > IOException, ClassNotFoundException
> >     {
> >         Map projectInfo = new HashMap();
> >         String projectName = "Cactus";
> >         String organisation = "Apache.org";
> >         projectInfo.put("projectname", projectName);
> >         projectInfo.put("organisation", organisation);
> >
> >         ByteArrayOutputStream byteArrayOutputStream = new
> > ByteArrayOutputStream();
> >         ObjectOutputStream objectOutputStream = new
> ObjectOutputStream(
> > byteArrayOutputStream);
> >         objectOutputStream.writeObject( projectInfo );
> >         objectOutputStream.flush();
> >         byteArrayOutputStream.close();
> >
> >         ObjectInputStream objectInputStream = new ObjectInputStream(
> new
> > ByteArrayInputStream( byteArrayOutputStream.toByteArray() ) ) ;
> >
> >
> >         theRequest.setUserData( objectInputStream );
> >         theRequest.setContentType( "application/binary" );
> >     }
> >
> >     /**
> >      * Verify that we can send arbitrary binary data (ObjectStream)
in
> > the request body.
> >      *
> >      * @exception Exception on test failure
> >      */
> >     public void testSendUserData() throws Exception
> >     {
> >         InputStream in = request.getInputStream();
> >         ObjectInputStream  objectInputStream = new ObjectInputStream
(
> > in );
> >         Map projectInfo = (Map) objectInputStream.readObject();
> >         assertNotNull( projectInfo );
> >         assertEquals( projectInfo.get( "projectname"), "Cactus" );
> >         assertEquals( projectInfo.get( "organisation"), "Apache.org"
> );
> >
> >     }
> >
> > }
> >
> > Thanks,
> >
> > Alvin
> >
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Vincent Massol [mailto:vmassol@pivolis.com]
> > Gesendet: Freitag, 6. Mai 2005 11:39
> > An: 'Cactus Users List'
> > Betreff: RE: Problem with ObjectInputStream and
WebRequest.setUserData
> &
> > .getUserData()
> >
> > Hi Alvin,
> >
> > Personally I've never tried reading data with an ObjectInputStream
> > inside
> > Cactus. The test we have for the setuserData() feature is the
> following:
> >
> >     public void beginSendUserData(WebRequest theRequest)
> >     {
> >         ByteArrayInputStream bais = new ByteArrayInputStream(
> >             "<data>some data to send in the
body</data>".getBytes());
> >
> >         theRequest.setUserData(bais);
> >         theRequest.setContentType("text/xml");
> >     }
> >
> >     /**
> >      * Verify that we can send arbitrary data in the request body.
> >      *
> >      * @exception Exception on test failure
> >      */
> >     public void testSendUserData() throws Exception
> >     {
> >         String buffer;
> >         StringBuffer body = new StringBuffer();
> >
> >         BufferedReader reader = request.getReader();
> >
> >         while ((buffer = reader.readLine()) != null)
> >         {
> >             body.append(buffer);
> >         }
> >
> >         assertEquals("<data>some data to send in the body</data>",
> >             body.toString());
> >         assertEquals("text/xml", request.getContentType());
> >     }
> >
> > Hmm... Maybe the problem is with the "request.getInputStream();". In
> the
> > test above it's doing a "request.getReader()".
> >
> > It would be nice to have another test with an input stream to try to
> > reproduce your problem. If you could come up with a simple test as
> above
> > that would reproduce the problem, I could add it to the Cactus test
> > suite
> > and we could tackle the problem (if any) and fix it.
> >
> > Thanks
> > -Vincent
> >
> > > -----Original Message-----
> > > From: Alvin Antony [mailto:Alvin.Antony@consol.de]
> > > Sent: vendredi 6 mai 2005 11:05
> > > To: cactus-user@jakarta.apache.org
> > > Subject: Problem with ObjectInputStream and WebRequest.setUserData
&
> > > .getUserData()
> > >
> > > Dear Friends,
> > >
> > > I am new to the mailing list and so to Cactus!! Please pardon me
if
> it
> > > is a silly Q.
> > >
> > > I am writing a test suit for an Applet& Servlet client server
> > > Application.
> > > The Applet sends the information to the Servlet through an Object
> > > stream, but my test case for this throws an EOFException.
> > >
> > >
> > > public void beginService ( WebRequest webRequest ) throws
> > > ClassNotFoundException, IOException
> > >     {
> > >         ProdFinderIntegratonTestRepository
> > prodFinderIntegrationTestRep
> > > = new ProdFinderIntegratonTestRepository ();
> > >         Map input;
> > >         try {
> > >             input =
> > > prodFinderIntegrationTestRep.getRequestToCreateMainCategory();
> > >                     assertNotNull( input );
> > >
> > >                     ByteArrayOutputStream bos = new
> > > ByteArrayOutputStream();
> > >                     ObjectOutputStream oos = new
ObjectOutputStream(
> > bos
> > > );
> > >                     oos.writeObject( input );
> > >                     oos.flush();
> > >                     bos.close();
> > >                     ByteArrayInputStream byteArrayInputStream  =
> new
> > > ByteArrayInputStream( bos.toByteArray() );
> > >                     objectInputStream = new ObjectInputStream(
> > > byteArrayInputStream );
> > >
webRequest.setContentType("application/binary");
> > >                     webRequest.setUserData( objectInputStream ) ;
> > >         } catch (ObjectNotFoundException e) {
> > >             e.printStackTrace();
> > >         } catch (PFInternalError e) {
> > >             e.printStackTrace();
> > >
> > >         }
> > >     }
> > >
> > >     /**
> > >      *
> > >      * Class under test for void service(HttpServletRequest,
> > > HttpServletResponse)
> > >      */
> > >     public void testService() throws ServletException, IOException
{
> > >
> > >         InputStream is =  request.getInputStream();
> > >         ObjectInputStream oInput = new ObjectInputStream(is);
> > >         MessageReceiver messageReceiver = new MessageReceiver();
> > >         messageReceiver.init( config );
> > >         messageReceiver.service(request, response );
> > >         assertNotNull( response);
> > >     }
> > >
> > >    [cactus] Testcase:
> > > testService(com.siemens.productfinder.communication.TestMe
> > > ssageReceiver): Caused an ERROR
> > >    [cactus] null
> > >    [cactus] java.io.EOFException
> > >    [cactus]     at
> > > java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInp
> > > utStream.java:2165)
> > >    [cactus]     at
> > > java.io.ObjectInputStream$BlockDataInputStream.readShort(Obje
> > > ctInputStream.java:2631)
> > >    [cactus]     at
> > > java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.
> > > java:734)
> > >    [cactus]     at
> > > java.io.ObjectInputStream.<init>(ObjectInputStream.java:253)
> > >    [cactus]     at
> > > com.siemens.productfinder.communication.TestMessageReceiver.t
> > > estService(Unknown Source)...
> > >
> > >
> > > Any help would be great
> > >
> > > Thanks in advance,
> > >
> > >
> > > Alvin
> > >
> >
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> >
> >
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org


___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-user-help@jakarta.apache.org





Mime
View raw message