Category Archives: android-ksoap2

KSoap2 with htaccess and https

I'm using KSoap2 and I got an issue while trying to connect to a WSDL located on a server using HTTPS and protected by a htaccess.

Here is the error I got :

SoapFault - faultcode: 'WSDL' faultstring: 'SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://login:[email protected]://domain.com/url/to/wsdl/?wsdl=1' : failed to load external entity "http://login:[email protected]://domain.com/url/to/wsdl/?wsdl=1"

As you can see, the URL is weird.

Here is my code :

private Object send(SoapObject request)
{
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = false;
    envelope.xsd = SoapSerializationEnvelope.XSD;
    envelope.enc = SoapSerializationEnvelope.ENC;
    envelope.setOutputSoapObject(request);

    URI url = null;
    try {
        url = new URI(sUrl); //sUrl is "https://domain.com/url/to/wsdl/"
    } catch (URISyntaxException e) {
        e.printStackTrace();
        return null;
    }


    HttpsTransportSE ht = new HttpsTransportSE(url.getHost(), 443, url.getPath(), 30000);

    List<HeaderProperty> headerProperties = new ArrayList<>();
    HeaderProperty prop;
    auth = "Basic " + Base64.encodeToString((sHtaccessLogin+":"+sHtaccessPassword).getBytes(), Base64.NO_WRAP);
    try {
        prop = new HeaderProperty("Authorization", auth);
        headerProperties.add(prop);

        ht.call(ACTION, envelope, headerProperties);

    } catch (IOException | XmlPullParserException e) {
        e.printStackTrace();
    }
    ...

The code is working fine when there is no htaccess.

Any idea ?

Web service for android not working properly

I'm trying to invoke a web service through my android app, i just write in a text box a name, press a button and the web service should return to me "hello + name". But it isn't working, i went through a lot of errors but this is the latest one, and i can't find a way out.

This is the web service written in java (Eclipse),

public class CallerClass {
public String Calling(String name){
    System.out.print("Hello");
    return "Hello" + name;
}

Its a java class inside a dynamic web project to which i added a web service (and works on the server according to the tutorials)

On the other hand this is the android app part:

 b.setOnClickListener(new OnClickListener() {
	           public void onClick(View v) {
	               //Check if Name text control is not empty
	               if (et.getText().length() != 0 && et.getText().toString() != "") {
	                   //Get the text control value
	                   editText = et.getText().toString();
	                   //Create instance for AsyncCallWS
	                   AsyncCallWS task = new AsyncCallWS();
	                   //Call execute 
	                   task.execute();
	               //If text control is empty
	               } else {
	                   tv.setText("Please enter name");
	               }

Now this is the internal asyncTask class:

private class AsyncCallWS extends AsyncTask<String, Void, Void> {
	    @Override
	    protected Void doInBackground(String... params) {
	                    //Invoke webservice
	        displayText = WebService.invokeHelloWorldWS(editText,"Calling");
	        return null;
	    }

	    @Override
	    protected void onPostExecute(Void result) {
	    
	        //Set response
	        tv.setText(displayText);
	                    //Make ProgressBar invisible
	        pg.setVisibility(View.INVISIBLE);
	     }

	    @Override
	    protected void onPreExecute() {
	                    //Make ProgressBar invisible
	        pg.setVisibility(View.VISIBLE);
	    }

	    @Override
	    protected void onProgressUpdate(Void... values) {
	    }

	}

Finally this is the class calling the web service from the app:

public class WebService {

	//Namespace of the Webservice - It is http://tempuri.org for .NET webservice
    private static String NAMESPACE = "http://ws.apache.org/axis2";
    //Webservice URL - It is asmx file location hosted in the server in case of .Net
        //Change the IP address to your machine IP address    
    private static String URL = "http://10.0.2.2:8080/AndroidWeb/services/CallerClass?wsdl"	;
    //SOAP Action URI again http://tempuri.org
    private static String SOAP_ACTION = "http://ws.apache.org/axis2/Calling";
 
    public static String invokeHelloWorldWS(String name, String webMethName) {
        String resTxt = null;
        // Create request
        SoapObject request = new SoapObject(NAMESPACE, webMethName);
        // Property which holds input parameters
        PropertyInfo sayHelloPI = new PropertyInfo();
        // Set Name
        sayHelloPI.setName("Name");
        // Set Value
        sayHelloPI.setValue(name);
        // Set dataType
        sayHelloPI.setType(String.class);
        // Add the property to request object
        request.addProperty(sayHelloPI);
        // Create envelope
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        //Set envelope as dotNet
        envelope.dotNet = true;
        // Set output SOAP object
        envelope.setOutputSoapObject(request);
        // Create HTTP call object
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
 
        try {
            // Invoke web service
            androidHttpTransport.call(SOAP_ACTION, envelope);
            // Get the response
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            // Assign it to resTxt variable static variable    
           resTxt = response.toString();
 
        } catch (SoapFault fault) {
            Log.v("TAG", "soapfault = "+fault.getMessage());

        }
        catch (Exception e) {
            //Print error
            e.printStackTrace();
            //Assign error message to resTxt
            resTxt = e.toString();
        } 
        //Return resTxt to calling object
        return resTxt;
    }

Error I am getting this error

[ERROR] 1
java.lang.ArrayIndexOutOfBoundsException: 1
at org.apache.axis2.databinding.utils.BeanUtil.deserialize(BeanUtil.java: 630)
at org.apache.axis2.rpc.receivers.RPCUtil.processRequest(RPCUtil.java: 153)
at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java: 206)
at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java: 117)
at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java: 40)
at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java: 114)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java: 181)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java: 172)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java: 146)
at javax.servlet.http.HttpServlet.service(HttpServlet.java: 644)
at javax.servlet.http.HttpServlet.service(HttpServlet.java: 725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java: 52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java: 206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java: 219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java: 106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java: 503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java: 136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java: 79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java: 610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java: 88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java: 526)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java: 1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java: 655)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java: 222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java: 1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java: 1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java: 1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java: 617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java: 61)
at java.lang.Thread.run(Thread.java: 745)

Please help i've been at this for 2 days, it's a simple web service, i tried modifying it to print a message on my console but still the same error. Where is the problem? Configuration for the web service? or what...