You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kimmy Lin <ki...@cs.umb.edu> on 2004/09/01 00:15:59 UTC

Re: How do I read only the XML data in doPost(req,res)?

Do you have control over how the request is composed?
If so, you can put the XML data in a parameter say "xmldoc"
and the equivalent GET request will look like the following

http://URL?xmldoc=<yourXML>...</yourXML>

("<" and ">" not escaped)

Then in your program do

request.getParameter("xmldoc");

to get the xml data.

kimmy

----- Original Message ----- 
From: "tom ly" <bo...@yahoo.com>
To: <to...@jakarta.apache.org>
Sent: Tuesday, August 31, 2004 3:16 PM
Subject: How do I read only the XML data in doPost(req,res)?


> I'm receiving a HTTP POST request containg XML data and want to process
the data in the doPost method of my servlet.  When I do
request.getContentLength(), it gives the length of the entire request
including the HTTP header etc, but I only want the XML portion of it.  I
can't find any Java methods which will return only the data part of the
request.  How can I do this?
>
> Thanks,
> Tom
>
>
>
>
> ---------------------------------
> Do you Yahoo!?
> Win 1 of 4,000 free domain names from Yahoo! Enter now.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: How do I read only the XML data in doPost(req,res)?

Posted by Kimmy Lin <ki...@cs.umb.edu>.
What I really meant was to write a parameter "xmldoc=<yourXML>...</yourXML>"
into the outputstream of the HttpURLConnection like the following to make it
a Post.

OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(params);

Not sure whether there is any limit this way though.

But Request#getInputStream() does provide the request body w/o the header.

kimmy

----- Original Message ----- 
From: "QM" <qm...@brandxdev.net>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Tuesday, August 31, 2004 6:27 PM
Subject: Re: How do I read only the XML data in doPost(req,res)?


> On Tue, Aug 31, 2004 at 06:15:59PM -0400, Kimmy Lin wrote:
> : http://URL?xmldoc=<yourXML>...</yourXML>
> : request.getParameter("xmldoc");
>
> The OP may run into some limits with that, unless those are very small
> XML docs. =)
>
> Doesn't Request#getInputStream() provide the body? -or does it get the
> whole request, headers and all?
>
> -QM
>
> -- 
>
> software  -- http://www.brandxdev.net
> tech news -- http://www.RoarNetworX.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: How do I read only the XML data in doPost(req,res)?

Posted by John Gentilin <jo...@gentilin.org>.
Try this, override service and not doGet / doPost

where the code is
 public void service( ServletRequest request, ServletResponse response ) 
throws javax.servlet.ServletException, java.io.IOException
{
      Document doc;
      // Create an InputStream to read in the XML data to be parsed
      ServletInputStream is = request.getInputStream();
      doc = m_DocBuilder.parse(is);
}

Where m_DocBuilder created in init()
        m_DocFactory = DocumentBuilderFactory.newInstance();
        m_DocBuilder = m_DocFactory.newDocumentBuilder();

declared as
  private static DocumentBuilderFactory m_DocFactory = null;
  private static DocumentBuilder m_DocBuilder = null;


HTH
John G


QM wrote:

>On Tue, Aug 31, 2004 at 06:15:59PM -0400, Kimmy Lin wrote:
>: http://URL?xmldoc=<yourXML>...</yourXML>
>: request.getParameter("xmldoc");
>
>The OP may run into some limits with that, unless those are very small
>XML docs. =)
>
>Doesn't Request#getInputStream() provide the body? -or does it get the
>whole request, headers and all?
>
>-QM
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: How do I read only the XML data in doPost(req,res)?

Posted by QM <qm...@brandxdev.net>.
On Tue, Aug 31, 2004 at 06:15:59PM -0400, Kimmy Lin wrote:
: http://URL?xmldoc=<yourXML>...</yourXML>
: request.getParameter("xmldoc");

The OP may run into some limits with that, unless those are very small
XML docs. =)

Doesn't Request#getInputStream() provide the body? -or does it get the
whole request, headers and all?

-QM

-- 

software  -- http://www.brandxdev.net
tech news -- http://www.RoarNetworX.com


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org