Solved

Sending a xml file/String to remote servlet.

Posted on 2004-04-14
7
321 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

IT, Stop Being Called Into Every Meeting

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

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

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

20 Experts available now in Live!

Get 1:1 Help Now