Solved

Apache-Commons Httpclient MultipartPost (display part values)

Posted on 2004-08-11
8
343 Views
Last Modified: 2010-03-31
I am trying to use Apache-Commons Httpclient to send a MultipartPost request to a web server!  The server is not receiving the file I am sending!  I would like to know how to look at a trace of everything being sent by my MultipartPost!  That shows all the parts of the MultipartPost!  With each part's value exactly as the server sees the request coming to it!

The server is using Struts to receive the file!
0
Comment
Question by:Tgerdes
  • 4
  • 3
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 11779097
iterate thru each part and display its content.
0
 
LVL 1

Author Comment

by:Tgerdes
ID: 11786845
I did create a Part[] array and ran the ".getparts" method to copy the part attributes into an array!  The problem is that I do not know how to display its content.  What method do I use!  I can get all sorts of attributes about the part but not the content!
0
 
LVL 1

Author Comment

by:Tgerdes
ID: 11786899
I meant I do not know how to display an individual part's content.  The Part[] array contains attributes of the part... yet there is no method to display the content or value of each individual part!  
0
 
LVL 3

Expert Comment

by:kumvjuec
ID: 11787435
Better use HTTPLook. It can give you all u want without programming to do.
You will find that using HTTPClient, the request contains much lesser attributes and a different data when u send a multipart request.

http://www.shareup.com/HTTPLook-download-3133.html
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:kumvjuec
ID: 11787676
There is another way also, to see the content of your Part objects.
Download cocoon.jar from
http://cvs.sourceforge.net/viewcvs.py/krysalis/krysalis-wings/lib/core/Attic/cocoon.jar?rev=1.2

Then include it in your classpath and then this code will work :)
####
byte[] partContent = org.apache.cocoon.utils.IOUtil.objectToBytes(Part[0]);
System.out.println(partContent.toString());
####
0
 
LVL 1

Author Comment

by:Tgerdes
ID: 11796746
I tried adding the cocoon.jar to my classpath and I got the error below:

Attaching Java program to /pospay/JavaHttpClient/classes/cocoon.JAR.                        
java.io.NotSerializableException: org.apache.commons.httpclient.methods.multipart.StringPart
        at java/lang/Throwable.<init>(Throwable.java:195)                                  
        at java/io/IOException.<init>(IOException.java:40)                                  
        at java/io/ObjectStreamException.<init>(ObjectStreamException.java:24)              
        at java/io/NotSerializableException.<init>(NotSerializableException.java:26)        
        at java/io/ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)            
        at java/io/ObjectOutputStream.writeObject(ObjectOutputStream.java:278)              
        at org/apache/cocoon/util/IOUtils.objectToBytes(IOUtils.java:373)                  
        at TESTMEJ.main(TESTMEJ.java:162)                                                  
                                                                                           
0
 
LVL 3

Accepted Solution

by:
kumvjuec earned 300 total points
ID: 11796858
hi,

ok, Part doesn't implement serializable interface.
You can do this to see all the content your parts have. Try this

part[index].send(System.out);

All the data with header will print on console. Tell me if that helped or not..:)
0
 
LVL 1

Author Comment

by:Tgerdes
ID: 11853191
Thanks! this last solution allowed me to view the data being sent to the server in the exact same format that the server sees it!  This worked well for me!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

758 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

17 Experts available now in Live!

Get 1:1 Help Now