Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sending a xml file/String to remote servlet.

Posted on 2004-04-14
7
Medium Priority
?
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 750 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
The online market is growing at an unprecedented rate and retail eCommerce sales are expected to reach $4 trillion by 2020. Yet, the profit is not just there for the taking because you have to set yourself apart from the competition.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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