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

Reply via email to