Solved

Sending a xml file/String to remote servlet.

Posted on 2004-04-14
7
328 Views
Last Modified: 2010-04-01
Hi All
I am running a query and getting the resultset and using that i am formulating a string in xml format.My query here is i need to send that string/xmlfile to a remote servlet.
help me out how to send that to remote servlet(I need to send in post method only)
0
Comment
Question by:krishnamukuntha
  • 4
  • 3
7 Comments
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10823001
http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_20665134.html

Only thing that you might want to change in the code is the method that I am setting to GET... you will have to convert it to POST
0
 
LVL 2

Author Comment

by:krishnamukuntha
ID: 10823177
I want to send it from my servlet to remote
i hope your code is doing on other way...
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10823185
nopes its sending to the remote URL and reading the response back
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 2

Author Comment

by:krishnamukuntha
ID: 10823224
let me rephrase my query:
On Click of a button i am hittin the DB and creating report in xml format by looping the Resultset.
Now i ned to send the created xml file to repmote servlet.
I also need to know how the remort server can get my file in its doPost Method
0
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 250 total points
ID: 10823509
BufferedReader in=null;
                        
//                  String clientUrl = POINTProperties.getProperty("CFWURL");
                  String clientUrl = CFWURL;
                  clientUrl +="&setSystemProperties=AS400ConnectUserIdTREE("+usr+"),AS400ConnectUserPasswordTREE("+pwd+")";
//                  clientUrl +="&setOverrideProperties=AS400ConnectUserId("+usr+"),AS400ConnectUserPassword("+pwd+")";
                  URL cfwUrl = new URL(clientUrl);
                  
                  java.net.HttpURLConnection con = null;
                  //Open a connection to the specified url
                  try
                  {  
                        con =(java.net.HttpURLConnection) cfwUrl.openConnection();
                        con.setRequestProperty("Content-Type","text/xml");
                        con.setDoOutput(true);
                        con.setDoInput(true);
                        con.setRequestMethod("POST");
                        //Post the XML transaction to the system.
                        con.getOutputStream().write(xml.getBytes());//this code will post your XML to
whatever url you have in cfwURL...
                        in = new BufferedReader(new InputStreamReader(con.getInputStream()));
                  }
                  //Catch any errors that may happen is this process.
                  catch(ProtocolException pe)
                  {
                        System.out.println("Received a Protocol Exception in doRequest"+pe);
                        return null;
                  }
                  
                  catch (FileNotFoundException exception)
                  {
                        System.out.println("Exception in PM-doRequest"+exception);
                        InputStream err = con.getErrorStream();
                        in = new BufferedReader(new InputStreamReader(err));
                  }
                  catch(IOException ioe)
                  {
                        System.out.println("Received an Exception in PM-doRequest"+ioe);
                        ioe.printStackTrace();
                        return null;
                  
                  }
            //Try reading the response from the system. catch any errors that may happen in the process.      
                  try
                  {
                  StringBuffer response = new StringBuffer();
                  String line;
      
                  while ((line = in.readLine()) != null)
                        response.append(line);
                  in.close();
                  return response.toString();
                  }
                  catch(IOException ioex)
                  {
                  System.out.println("ioex in PM-doRequest"+ioex);
                  ioex.printStackTrace();
                  return null;
                  }
                  catch(Exception e1)
                  {
                        System.out.println("Error in PM-doRequest"+e1);
                        e1.printStackTrace();
                        return null;
                  }
            }
            catch(Exception e2)
            {
                  return null;
            }
      }


in the remote servlet all you have to do in doPost is
request.getInputStream(); //this stream will have the XML that you have posted
0
 
LVL 2

Author Comment

by:krishnamukuntha
ID: 10823856
thanks kuldeep
whole nation will proud of you :)
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10823869
:-) glad to be of help
thanks for the 'A' grade...
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

One of the biggest threats in the cyber realm pertains to advanced persistent threats (APTs). This paper is a compare and contrast of Russian and Chinese APT's.
An article on effective troubleshooting
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

13 Experts available now in Live!

Get 1:1 Help Now