Return-Path: list-help: list-unsubscribe: List-Post: List-Id: Mailing-List: contact cactus-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list cactus-user@jakarta.apache.org Received: (qmail 67081 invoked by uid 99); 6 May 2005 10:35:16 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from gate.consol.de (HELO gate.consol.de) (194.246.122.10) by apache.org (qpsmtpd/0.28) with ESMTP; Fri, 06 May 2005 03:35:11 -0700 Received: from msgsrv.bb.consol.de (imap.consol.de [10.250.0.113]) by gate.consol.de (8.12.11/8.12.11) with ESMTP id j46AWTRP001798 for ; Fri, 6 May 2005 12:32:29 +0200 (CEST) (envelope-from Alvin.Antony@consol.de) Received: from charpak (charpak.int.consol.de [10.0.1.141]) by msgsrv.bb.consol.de (8.12.11/8.12.11) with ESMTP id j46AWR3g088500 for ; Fri, 6 May 2005 12:32:29 +0200 (CEST) (envelope-from alvin.antony@consol.de) From: "Alvin Antony" To: "'Cactus Users List'" Subject: AW: Problem with ObjectInputStream and WebRequest.setUserData & .getUserData() Date: Fri, 6 May 2005 12:32:27 +0200 Message-ID: <002d01c55226$e7626f70$8d01000a@int.consol.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 In-Reply-To: <200505060939.j469dhT8099889@gate.consol.de> X-Antivirus: Scanned by Vexira Antivirus 1.0.6 X-Virus-Checked: Checked 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 { =20 public TestObjectInputStreamServlet ( String name ) { super(name); } =20 /** * Prepare the request object. Add an ObjectInputStream into request object. *=20 * @param theRequest * @throws IOException * @throws ClassNotFoundException */ public void beginSendUserData(WebRequest theRequest) throws IOException, ClassNotFoundException { Map projectInfo =3D new HashMap(); String projectName =3D "Cactus"; String organisation =3D "Apache.org"; projectInfo.put("projectname", projectName); projectInfo.put("organisation", organisation); =20 ByteArrayOutputStream byteArrayOutputStream =3D new ByteArrayOutputStream(); =20 ObjectOutputStream objectOutputStream =3D new = ObjectOutputStream( byteArrayOutputStream); objectOutputStream.writeObject( projectInfo ); objectOutputStream.flush(); byteArrayOutputStream.close(); =20 ObjectInputStream objectInputStream =3D new ObjectInputStream( = new ByteArrayInputStream( byteArrayOutputStream.toByteArray() ) ) ; =20 theRequest.setUserData( objectInputStream ); theRequest.setContentType( "application/binary" ); } /** * Verify that we can send arbitrary binary data (ObjectStream) in the request body. *=20 * @exception Exception on test failure */ public void testSendUserData() throws Exception { InputStream in =3D request.getInputStream(); ObjectInputStream objectInputStream =3D new ObjectInputStream ( in ); =20 Map projectInfo =3D (Map) objectInputStream.readObject(); assertNotNull( projectInfo ); assertEquals( projectInfo.get( "projectname"), "Cactus" ); assertEquals( projectInfo.get( "organisation"), "Apache.org" ); } =20 } Thanks, Alvin -----Urspr=FCngliche Nachricht----- Von: Vincent Massol [mailto:vmassol@pivolis.com]=20 Gesendet: Freitag, 6. Mai 2005 11:39 An: 'Cactus Users List' Betreff: RE: Problem with ObjectInputStream and WebRequest.setUserData & .getUserData()=20 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 =3D new ByteArrayInputStream( "some data to send in the body".getBytes()); theRequest.setUserData(bais); theRequest.setContentType("text/xml"); } /** * Verify that we can send arbitrary data in the request body. *=20 * @exception Exception on test failure */ public void testSendUserData() throws Exception { String buffer; StringBuffer body =3D new StringBuffer(); BufferedReader reader =3D request.getReader(); while ((buffer =3D reader.readLine()) !=3D null) { body.append(buffer); } assertEquals("some data to send in the body",=20 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() >=20 > Dear Friends, >=20 > I am new to the mailing list and so to Cactus!! Please pardon me if it > is a silly Q. >=20 > 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. >=20 >=20 > public void beginService ( WebRequest webRequest ) throws > ClassNotFoundException, IOException > { > ProdFinderIntegratonTestRepository prodFinderIntegrationTestRep > =3D new ProdFinderIntegratonTestRepository (); > Map input; > try { > input =3D > prodFinderIntegrationTestRep.getRequestToCreateMainCategory(); > assertNotNull( input ); >=20 > ByteArrayOutputStream bos =3D new > ByteArrayOutputStream(); > ObjectOutputStream oos =3D new ObjectOutputStream( bos > ); > oos.writeObject( input ); > oos.flush(); > bos.close(); > ByteArrayInputStream byteArrayInputStream =3D = new > ByteArrayInputStream( bos.toByteArray() ); > objectInputStream =3D new ObjectInputStream( > byteArrayInputStream ); > webRequest.setContentType("application/binary"); > webRequest.setUserData( objectInputStream ) ; > } catch (ObjectNotFoundException e) { > e.printStackTrace(); > } catch (PFInternalError e) { > e.printStackTrace(); >=20 > } > } >=20 > /** > * > * Class under test for void service(HttpServletRequest, > HttpServletResponse) > */ > public void testService() throws ServletException, IOException { >=20 > InputStream is =3D request.getInputStream(); > ObjectInputStream oInput =3D new ObjectInputStream(is); > MessageReceiver messageReceiver =3D new MessageReceiver(); > messageReceiver.init( config ); > messageReceiver.service(request, response ); > assertNotNull( response); > } >=20 > [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.(ObjectInputStream.java:253) > [cactus] at > com.siemens.productfinder.communication.TestMessageReceiver.t > estService(Unknown Source)... >=20 >=20 > Any help would be great >=20 > Thanks in advance, >=20 >=20 > Alvin >=20 --------------------------------------------------------------------- To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: cactus-user-help@jakarta.apache.org