Ksoap: J2ME Client and Perl SOAP::Lite Server

"Fernando Villar" <[email protected]> Wed, 19 Nov 2003 14:42:11 +0100
Newsgroups gmane.comp.java.enhydra.ksoap
Message-ID <[email protected]>
I have deployed a simple "Hello World" SOAP server using Perl SOAP::Lite
module and
I am trying to use it from a J2ME Client but I always get the same error
message:
 
********************************************
java.io.IOException: malformed header field
        at com.sun.midp.io.j2me.http.Protocol.readHeaders(+63)
        at com.sun.midp.io.j2me.http.Protocol.sendRequestEndSession(+75)
        at com.sun.midp.io.j2me.http.Protocol.sendRequest(+139)
        at com.sun.midp.io.j2me.http.Protocol.openInputStream(+48)
        at org.ksoap2.transport.HttpTransport.call(+243)
        at org.ksoap2.samples.hola.HolaDemo.commandAction(+73)
        at
javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+152)
        at com.sun.kvem.midp.lcdui.EmulEventHandler$EventLoop.run(+459)
<v:Envelope xmlns:i="http://www.w3.org/1999/XMLSchema-instance"
xmlns:d="http://www.w3.org/1999/XMLSchema"
xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="
<http://schemas.xmlsoap.org/soap/envelope/>
http://schemas.xmlsoap.org/soap/envelope/"><v:Header /><v:Body><n0:hello
id="o0" c:root="1" xmlns:n0="http://213.97.86.246/Demo"
/></v:Body></v:Envelope>
null
java.lang.NullPointerException
        at org.ksoap2.serialization.SoapSerializationEnvelope.getResult(+9)
        at org.ksoap2.samples.hola.HolaDemo.commandAction(+126)
        at
javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+152)
        at com.sun.kvem.midp.lcdui.EmulEventHandler$EventLoop.run(+459)

********************************************
 
The MIDP code is:
 
##################################
package org.ksoap2.samples.hola;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;
 
import org.ksoap2.*;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.*;
 
public class HolaDemo extends MIDlet implements CommandListener {
 
    Form mainForm = new Form("HolaMundo");
    TextField symbolField = new TextField("Demo", "Test", 10,
TextField.ANY);
    StringItem resultItem = new StringItem("", "");
    Command getCommand = new Command("Get", Command.SCREEN, 1);
 
    public HolaDemo() {
        mainForm.append(symbolField);
        mainForm.append(resultItem);
        mainForm.addCommand(getCommand);
        mainForm.setCommandListener(this);
    }
 
    public void startApp() {
        Display.getDisplay(this).setCurrent(mainForm);
    }
 
    public void pauseApp() {
    }
 
    public void destroyApp(boolean unconditional) {
    }
 
    public void commandAction(Command c, Displayable d) {
        try {
            // build request string
            String symbol = symbolField.getString();
 
            SoapObject rpc =
                new SoapObject("http://213.97.86.246/Demo", "hello");
 
            SoapSerializationEnvelope envelope =
                new SoapSerializationEnvelope(SoapEnvelope.VER10);
 
            envelope.bodyOut = rpc;
 
            resultItem.setLabel(symbol);
 
            HttpTransport ht = new
HttpTransport("http://213.97.86.246/ws/demo_server.pl");
             ht.debug = true;
             
             try {
                ht.call("http://213.97.86.246/Demo#hello", envelope);
             }
             catch (Exception e) {
                e.printStackTrace();
                System.err.println (ht.requestDump);  
                System.err.println (ht.responseDump);  
             }
 
            resultItem.setText("" + envelope.getResult());
 
        }
        catch (Exception e) {
            e.printStackTrace();
            resultItem.setLabel("Error:");
            resultItem.setText(e.toString());
        }
    }
 
    /** for me4se */
 
    public static void main(String[] argv) {
        new HolaDemo().startApp();
    }
}
##################################
 
This is the response of the same SOAP service obtained from a Perl Soap
Client:
********************************************
Connection: close
Date: Tue, 18 Nov 2003 22:24:26 GMT
Server: Microsoft-IIS/5.0
Content-Length: 537
Content-Type: text/xml; charset=utf-8
Client-Date: Tue, 18 Nov 2003 22:24:08 GMT
Client-Junk: HTTP/1.1 200 OK
Client-Peer: 213.97.86.246:80
Client-Response-Num: 1
SOAPServer: SOAP::Lite/Perl/0.55
X-Powered-By: ASP.NET
 
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
SOAP-ENV:encodingStyle="'>http://schemas.xmlsoap.org/soap/encoding/"
<http://schemas.xmlsoap.org/soap/encoding/> >
<SOAP-ENV:Body>
<namesp1:helloResponse xmlns:namesp1="'>http://213.97.86.246/Demo"
<http://213.97.86.246/Demo> >
<s-gensym3 xsi:type="xsd:string">Hello World</s-gensym3>
</namesp1:helloResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
********************************************