I asked a question a few days ago (sorry it got a bit
long-winded), and I'm curious if anyone had an answer.  

Basically, I POST'ed an xml payload using the XMLHttpRequest 
(in the send method) to one of our servlets.  I hit 
the breakpoint in the servlet while debugging and the 
request body is empty (content-length is 0 and the reader 
in the request returns nothing). It's deployed as a 
proxied server app (not SOLO).

Here's the code - 

        ...
        xmlHttpRequest = new XMLHttpRequest();

        xmlHttpRequest.onreadystatechange = processReqChange;
        xmlHttpRequest.open("POST", url, true);
        xmlHttpRequest.send(xmlMsg.serialize());

Any help would be appreciated...

Thanks,
Dave

-----Original Message-----
From: Dave Buchwald [mailto:[EMAIL PROTECTED] 
Sent: Sunday, February 19, 2006 3:05 PM
To: [email protected]
Subject: [Laszlo-user] XMLHttpRequest and XML content

I'm trying to integrate Laszlo with an existing servlet we
have at work (which already takes posted xml and processes
it).  I'm trying 2 ways, but not being very successful.
One is with the XMLHttpRequest, and the other is with a straight
call to the doRequest on the lzDataset with an lzParam.

here are some versions:
Tomcat 5.5
OpenLaszlo 3.1

Before I start, my questions are -
1) which is the better method, use XMLHttpRequest or use a
normal dataset and call the doRequest method?

2) does the XMLHttpRequest have a problem with sending content?
Or could it the fact that I'm calling a servlet outside the lps
context?  I have a webapp within my Tomcat installation into
which I put the lps directory (all the Laszlo components).  I'm
describing this only because I know the SOLO deployment can't
do XML posted content with XMLHttpRequest.

3) if there's no problem, should I be extracting the xml from the
HttpServletRequest differently?  i'm trying not to change the servlet
as it is today (it now gets xml from the request).

4) could you release some more examples using XMLHttpRequest with
actual content?  The one that's there only sets the request headers
and calls the send method with a null arg.

I create 2 datasets - one gets the xml from a file which works fine:
<dataset name="cellStatus" src="getXml.xml" />

I then call loadXMLDoc(cellStatus.serialize()) and embed the xml in
the body with this:

  function loadXMLDoc(xmlMsg) {

    var url = "http://someurl:8080/context/xmlCall.srv";;
    xmlHttpRequest = new XMLHttpRequest();
    xmlHttpRequest.onreadystatechange = processReqChange;
    xmlHttpRequest.open("POST", url, true);
    xmlHttpRequest.send(xmlMsg);

I set a breakpoint in Eclipse on the servlet in doPost(),
and the XMLHttpRequest in fact does the POST.  But the
content length is zero (and there's nothing in the request's
reader). Then when I try to get an InputSource and
parse the xml with a DOMParser, it throws an exeption.

    InputSource inputSource = new InputSource(request.getReader());
    DOMParser parser = (DOMParser)xmlParserPool.borrowObject();
    parser.parse(inputSource);
    xmlDocument = parser.getDocument();

The other method is to create another dataset and data pointer:

  <dataset name="sendData" request="false"
src="http://localhost:8080/somecontext/xmlCall.srv";>
  <datapointer xpath="sendData:/*" ondata="processData();">
      <method name="processData">
        Debug.write("Hey = " + this.getNodeName());
        Debug.write(sendData.serialize());
      </method>
  </datapointer

  <button>Load Data
    <method event="onclick">
      <![CDATA[
          var sd = canvas.datasets.sendData;
          var param = new LzParam();
          param.addValue("lzpostbody", cellStatus.serialize(), false);
          sd.setQueryString(param);
          sd.setQueryType("POST");
          sd.doRequest();

          ]]>
        </method>
    </button>

When I used the builtin param "lzpostbody", the above actually took the
xml I posted to the servlet and split it into 2 pieces -
one piece under the request param name, and the other as the param's
value
(very strange).  When I used a different param name, it worked fine.
This code is very similar to what's in ajax.lz.  Except it calls the
setQueryParam() method.

thanks in advance,
Dave

_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user
This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. If 
you have received this email in error please notify the sender immediately. 
Please note that any views or opinions presented in this email are solely those 
of the author and do not necessarily represent those of the company. Even 
though this company takes every precaution to ensure this email is virus-free, 
the recipient should check this email and any attachments for the presence of 
viruses. The company accepts no liability for any damage caused by any virus 
transmitted by this email.
Protedyne Corporation, 1000 Day Hill Rd, Windsor, CT 06095, USA,                
                                                  
www.protedyne.com


_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user

Reply via email to