Inside the doGet of your myXMLHandler class :
- Use the getInputStream() method of the request (HttpServletRequest) to =
get the InputStreamReader object associated
- Read the InputStreamReader data in a BufferedReader object
- Use readLine() method to extract an parse your data
Sample :
public class myXMLHandler extends HttpServlet {
public void doGet(HttpServletRequest req,...)
throws bla bla...
{
...
/* br should contain your xml document */
BuffereReader br = new BufferedReader(new InputStreamReader
(req.getInputStream()));
String s = br.readLine()
br.close
}
}
Note : To avoid coding the sending part of the document, you can configure
your Web server so that all "text/xml" content-type being automatically
handled by your servlet.
For that you must properly set your Web server Mime-Type Filters.
Edmond Cisse
IT Architect.
HealthCenter Internet Services Inc.
----- Original Message -----
From: "Paranj, Bali" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 24, 2001 3:25 PM
Subject: Exchanging XML data between servlets
> Hi all,
>
> I'm working on an app where I need to exchange XML data between
> Java Servlets. All of the examples/books/etc that I come across
> focus almost exclusively on either JSP-to-Servlet (via a GET or
> POST of form data) or outputing data from a Servlet to a JSP.
> In my case, I need to be able to compose an XML document (from
> withing either a JSP or a servlet), open a connection to my
> servlet, push the data over & then listen for a response.
> Basically, the code looks like this:
> StringBuffer doc = new StringBuffer();
> doc.append("<?xml version='1.0'?>");
> doc.append("<mydoc>");
> doc.append("<data>HelloWorld</data>");
> doc.append("</mydoc>");
>
> try {
> String sUrl = new String("http://
> [myDomain]/servlets/myXMLHandler");
> URL purl = new URL(sUrl);
> URLConnection urlc = purl.openConnection();
> urlc.setDoOutput(true);
> urlc.setDoInput(true);
> urlc.setRequestProperty("Content-type","text/xml");
>
> PrintWriter pw = new PrintWriter(new OutputStreamWriter
> (urlc.getOutputStream()),true);
>
> pw.write(doc + "\r\n");
> pw.flush();
> pw.close();
>
> } catch (Exception e)
> {
> // log the error....
> }
>
> My question is: for the servlet that receives this document,
> how, exactly does it extract the XML document from the stream of
> incoming data? doGet() and doPost() would only seem to apply if
> the data is being sent from a JSP with either a GET or POST. In
> this case, wouldn't I just extend/override the service() method?
> In that case, I'm obviously not using the getParameterX()
> methods, since there are no parameters... is the XML document
> embedded into the HTTP header?
>
> Any assistance would be greatly appreciated!
>
> Bala Paranj
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html