Note that there are some explanatory texts on larger screens.

plurals
  1. POHttpTransportSE requestDump gives NullPointerException
    text
    copied!<p>I'm trying to access a <code>webservice</code> in Android via <code>Ksoap2</code> for Android. </p> <p>The <code>SoapObject</code> is created OK, the S.O.P of the <code>bodyOut</code> outputs the desired strings. But when I do a <code>requestDump</code> of the <code>HttpTransportSE</code> object I create to make the call, a <code>NullPointerException</code> happens. In other words, the transport object is null. How can this happen?</p> <p>Web Service is at <a href="http://srilanka.lk:9080/services/CropServiceProxy?wsdl" rel="nofollow">http://srilanka.lk:9080/services/CropServiceProxy?wsdl</a> </p> <p><strong>This service works very well with SoapUI.</strong> </p> <p><strong>SoapUI Request:</strong></p> <pre><code>&lt;soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:v1="http://schemas.icta.lk/xsd/crop/handler/v1/"&gt; &lt;soap:Header/&gt; &lt;soap:Body&gt; &lt;v1:getCropDataList&gt; &lt;v1:code&gt;ABK&lt;/v1:code&gt; &lt;/v1:getCropDataList&gt; &lt;/soap:Body&gt; &lt;/soap:Envelope&gt; </code></pre> <p><strong>SoapUI Response:</strong></p> <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"&gt; &lt;soapenv:Body&gt; &lt;ns1:getCropDataListResponse xmlns:ns1="http://schemas.icta.lk/xsd/crop/handler/v1/"&gt; &lt;ns1:cropInfo&gt; &lt;ns1:name&gt;Ambul Kesel&lt;/ns1:name&gt; &lt;ns1:price&gt;35.0&lt;/ns1:price&gt; &lt;ns1:location&gt;Dambulla&lt;/ns1:location&gt; &lt;/ns1:cropInfo&gt; &lt;ns1:cropInfo&gt; &lt;ns1:name&gt;Ambul Kesel&lt;/ns1:name&gt; &lt;ns1:price&gt;40.0&lt;/ns1:price&gt; &lt;ns1:location&gt;Dambulla&lt;/ns1:location&gt; &lt;/ns1:cropInfo&gt; &lt;/ns1:getCropDataListResponse&gt; &lt;/soapenv:Body&gt; &lt;/soapenv:Envelope&gt; </code></pre> <p><strong>Client Side Complex Type <code>KvmSerializable</code> implementation:</strong></p> <pre><code>public class CropInfo implements KvmSerializable { private String name; private float price; private String location; @Override public Object getProperty(int arg0) { switch (arg0){ case 0: return name; case 1: return price; case 2: return location; default: return null; } } @Override public int getPropertyCount() { return 3; } @Override public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) { switch (arg0){ case 0: arg2.type = PropertyInfo.STRING_CLASS; arg2.name = "Name"; break; case 1: arg2.type = Float.class; arg2.name = "Price"; break; case 2: arg2.type = PropertyInfo.STRING_CLASS; arg2.name = "Location"; break; default: break; } } @Override public void setProperty(int arg0, Object arg1) { switch(arg0){ case 0: name = arg1.toString(); break; case 1: price = Float.parseFloat(arg1.toString()); case 2: location = arg1.toString(); default: break; } } } </code></pre> <p><strong>Web Service Call:</strong></p> <pre><code>public void btnOnClick(View v){ String NAMESPACE = "http://schemas.icta.lk/xsd/crop/handler/v1/"; String URL = "http://220.247.225.202:9080/services/CropServiceProxy.CropServiceProxyHttpSoap12Endpoint"; String method_name = "getCropDataList"; String SOAP_ACTION = "http://schemas.icta.lk/xsd/crop/handler/v1/getCropDataList"; SoapObject soap_request = new SoapObject(NAMESPACE, method_name); soap_request.addProperty("code", "ABK" ); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); envelope.setOutputSoapObject(soap_request); envelope.addMapping(NAMESPACE, "cropInfo", CropInfo.class); //envelope.dotNet=true; Marshal floatMarshal = new MarshalFloat(); floatMarshal.register(envelope); System.out.println("body out : " + envelope.bodyOut.toString()); //AndroidHttpTransport http_transport = new AndroidHttpTransport(URL); HttpTransportSE http_transport = new HttpTransportSE(URL); try { //NullPointerException HERE System.out.println(http_transport.requestDump); http_transport.call(SOAP_ACTION, envelope); //because we should expect a vector, two kinds of prices are given Vector&lt;CropInfo&gt; result_array = (Vector&lt;CropInfo&gt;)envelope.getResponse(); if(result_array != null){ for (CropInfo current_crop: result_array){ System.out.println(current_crop.getName()); System.out.println(Float.toString(current_crop.getPrice())); } } } catch (Exception e) { e.printStackTrace(); answer.setText("error caught"); //System.out.println(http_transport.responseDump); } // String result_string[] = (String[])result; //answer.setText("returned"); } </code></pre> <p>Can anyone explain this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload