Hi,
I have 2 web application ClientA and ServerB. On ClientA application My requirement is I need to read an XML from a file system and then send it to
ServerB. This XML needs to be sent to ServerB over HTTP or HTTPs. HTTP is enough right now. When ServerB receives the XML, it will
do some basic validation, say for example one of the validation is if it is well formed. If everything is fine it will send response back to
ClientA
Ajoo Dar wrote:How can it be done? Any thought on this.... I want to use Java/Servlets... or if we can use webservices or JMS. I want to do it using Java technology
Is this a homework assignment?
Yes it can be done. I'd do it on the server side with a servlet.
Its unclear what your requirement is on the client, one could present a form with a big textfield, have the user cut and paste into the field, and then do a POST of the form to the servlet. Or write a client-side application in java, etc.
Ajoo Dar
Greenhorn
Joined: Dec 14, 2009
Posts: 5
posted
0
Thanks for your response, Yes it is homework example
Here is what I need to do on client side, my file is stored into my local drive....I need to read the XML and then send it to ServerB. After doing some validation on ServerB an XML message is sent back to Client.. It will be an Synchronous. Right now validation on server side will be to check if the xml file is well formed..
Ok, Here is what I have done so far..
How will I process from here to send the Document doc to another server
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("Inside CSMServlet");
try{
File file = new File("c:\\Java_J2ee\\MyXMLFile.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
System.out.println("******Document is***** "+doc);
doc.getDocumentElement().normalize();
System.out.println("Root Element is "+ doc.getDocumentElement().getNodeName());
Element msgElmnt = (Element) fstNode;
NodeList msgElmntLst = msgElmnt.getElementsByTagName("message");
Element msgElmnt2 = (Element) msgElmntLst.item(0);
NodeListmsg = msgElmnt2.getChildNodes();
System.out.println("Message from the element is "+ msg.item(0).getNodeValue());
}
}
*/
} catch(Exception e){
e.printStackTrace();
}
}
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35224
7
posted
0
You don't need to create a Document object; just read the bytes that make up the XML file (using FileInputStream) and send them in the POST body. Make sure to set the content encoding accordingly.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Sending XML over HTTP to Another Application