Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sending a xml file/String to remote servlet.

Posted on 2004-04-14
7
Medium Priority
?
358 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Did you know there are services out there that can turn an Instagram feed into an RSS feed? I found some interesting exclusive Instagram content which I wanted to follow without signing up for yet another social media account. RSS to the rescue!
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

824 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