raaja81
asked on
Receive xml which is sent using HTTP Post (from one of our vendor) in a JSP /JAVA Servlet and Send respond back an XML Back using http post
Hi ,
I am trying to receive a XML file which is sent using HTTP Post .I have to recieve it in a JSP file or a java servlet ...use the data in the xml file and send back a responce in xml format using http post ...i am totally new to web ...Your help is much appreciated ..
Thanks ,
Raaja.
I am trying to receive a XML file which is sent using HTTP Post .I have to recieve it in a JSP file or a java servlet ...use the data in the xml file and send back a responce in xml format using http post ...i am totally new to web ...Your help is much appreciated ..
Thanks ,
Raaja.
ASKER
No its not sent using request parameter .its the xml file which is sent accross
ASKER
thanks for your reply Kuldeepchaturvedi
okay then you can just do a request.getinputStream();
and then read the XML off this stream...
once you are done processing it, you can write it back to response.getOutputStream() ;
and then read the XML off this stream...
once you are done processing it, you can write it back to response.getOutputStream()
ASKER
Thanks Kuldeepchaturvedi,
thanks for your quick responce...can you provide me a sample code for request.getinputStream();
and response.getOutputStream() ;...thanks in advance
thanks for your quick responce...can you provide me a sample code for request.getinputStream();
and response.getOutputStream()
int contentLength = request.getContentLength()
byte[] buffer = new byte[contentLength];
java.io.InputStream inputStream = request.getInputStream();
inputStream.read(buffer);
String content = new String(buffer);
Now this string content should have the XML that was sent in...
after processing it you can do
OutputStream os = response.getOutputStream()
and then write your response using.
os.write()
ASKER
thank you
1) request.getInputStream(); worked fine
2)where as response.getOutputStream() ; didnt work
this is wat i have done please go through the code for server sided and client sided
This is what i am getting for my below :
java.io.IOException: Server returned HTTP response code: 500 for URL:XXXXXXXXXXXXXXXXXXXX
1) request.getInputStream(); worked fine
2)where as response.getOutputStream()
this is wat i have done please go through the code for server sided and client sided
This is what i am getting for my below :
java.io.IOException: Server returned HTTP response code: 500 for URL:XXXXXXXXXXXXXXXXXXXX
-------------Server side(servlet)-----------
response.setContentType("text/xml");
OutputStream os = response.getOutputStream();
OutputStreamWriter wout = new OutputStreamWriter(os, "UTF-8");
String xml_string = <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?> <Request> <Envelope> <EnvelopeID>_1</EnvelopeID> <NAME>VICTOR</NAME> </Envelope> </Request>";
wout.write(xml_string);
--------------------------
----------------Client Side--------------
Result_From_Server = new BufferedReader(new InputStreamReader(UrlConnection.getInputStream()));
StringBuffer Result_String_Buffer = new StringBuffer();
String inputLine = null;
while ((inputLine = Result_From_Server.readLine()) != null)
Result_String_Buffer.append(inputLine);
Result_From_Server.close();
String result_string = new String(Result_String_Buffer);
out.println(result_string);
-----------------------
do a wout.close() after writing.
also that xml string does not look correct, ( the opening " is missing I guess);
That should fix it.
also that xml string does not look correct, ( the opening " is missing I guess);
That should fix it.
ASKER
Thanks It works fine ...thanks you very much bro
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
this variable can be recieved in a string and then you can manupulate it to do what ever you want.