Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can we pass XML file as an HttpServletRequest?  RSS feed

 
Vipul Bhara
Greenhorn
Posts: 22
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to pass an xml file as a servlet request but not as a parameter. In such a way that i can convert it to String directly.
some thing like this.
String x = new String(request.getInputStream().read())
( 'x' should contain the entire XML file)
but how can I pass XML file to HttpServletRequest directly?

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is the request being generated?
 
Vipul Bhara
Greenhorn
Posts: 22
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Request will be coming from some different application. I don't know how is it sending me that request. I want to test my application, That is why I want to know how I can generate that request. I have only detail of the request , i.e. request entirely contains the xml file , but to test it some how I'll need to pass such kind of request.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so what have you tried? What problems are you having?
 
Vipul Bhara
Greenhorn
Posts: 22
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to call the doPost Directly or from UI in such a way that request is itself an XMLFile. I am looking for creating my own request. but unable to find any way to do that. I am not sure whether we can manipulate or create our own HttpServletRequest Programmatically?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make up your mind: are you creating the request or is another application? You need to get your facts straight or you'll just confuse everyone.

Try again. In clear language, what are you trying to do?

(And no, you should never create your own container objects.)
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vipul Bhar wrote:I don't know how is it sending me that request. I want to test my application, That is why I want to know how I can generate that request.


You are getting ahead of yourself. You want to test that your application behaves correctly when it receives such a request? Then you had better know how the request is sent. There's no point in choosing a sending mechanism at random and testing that, when you don't know if it is the right mechanism to test.

So you should talk to the people in charge of the code which will send the request. Ask them if they are doing a file upload, or if their POST request is formatted in some other way. Ask them exactly how. As I said, get the specs before you write the test.
 
Ashish Arp
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vipul, I second Paul here. You need to talk to the other party that would send in the request and get the facts right(about the type of the request).

Regarding your testing, may be you can try asking them whether they can provide any mock servlet that you can use. This mock servlet when invoked will send the intended request to your app(I am saying mock because the data can just be any test data but in the format that they would be sending in reality to your app). This test will be better instead of trying to generate the request object itself.
 
Vipul Bhara
Greenhorn
Posts: 22
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gt the solution. We can use HttpClient class provided in one of the apache API....
 
Ashish Arp
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vipul, Can you elaborate the solution if you don't mind ?
 
Vipul Bhara
Greenhorn
Posts: 22
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PostMethod p=new PostMethod(url);
HttpClient c=new HttpClient();
p.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(file),file.getContentlength()));
c.executeMethod(p);

Refer the tutorial for apache httpclient
http://hc.apache.org/httpclient-3.x/tutorial.html
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!