1
Fala galera!
I have a virtual store (Magento) in which I am trying to make a request SOAP with ksoap2 on Android. However, when executing the code, it generates an Exception, but the message of this Exception returns @null
. Below is the code I used:
package com.devx3.mageorderconsult.WS;
import android.app.ProgressDialog;
import android.util.Log;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.net.HttpRetryException;
import java.net.URL;
import java.util.Objects;
import de.timroes.axmlrpc.XMLRPCClient;
import de.timroes.axmlrpc.XMLRPCException;
/**
* Created by erick on 10/18/15.
*/
public class WSMagento {
ProgressDialog dialog;
public static final String NAMESPACE = "urn:Magento";
public String url;
public String user;
public String token;
public WSMagento( String url, String user, String token ) {
this.url = url;
this.user = user;
this.token = token;
}
public void callMagentoStore() {
try {
SoapSerializationEnvelope env = new SoapSerializationEnvelope(SoapEnvelope.VER11);
env.dotNet = false;
env.xsd = SoapSerializationEnvelope.XSD;
env.enc = SoapSerializationEnvelope.ENC;
SoapObject request = new SoapObject(NAMESPACE, "login");
request.addProperty("username", user);
request.addProperty("apiKey", token);
env.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(url);
androidHttpTransport.call("", env);
Object result = env.getResponse();
Log.d("DEVX3", result.toString());
} catch (Exception e) {
Log.e("DEVX3", "Exception: "+e.getMessage());
}
}
}
EDITION 20/10/2015
Well, guys, I gave up using Ksoap for several criticisms I saw about lib. I started using Xmlrpcclient Android. But, I’m still having problems, but now it is with internet connection permission.
Follow below my files:
Wsmagento.java.:
package com.devx3.mageorderconsult.WS;
import android.os.AsyncTask;
import android.util.Log;
import org.xmlrpc.android.XMLRPCException;
import java.net.URI;
/**
* Created by erick on 10/18/15.
*/
public class WSMagento {
public static final String NAMESPACE = "urn:Magento";
public AsyncTask<String, String, String> sessionId;
public String url;
public String user;
public String apiKey;
public WSMagento( String url, String user, String apiKey ) {
this.url = url;
this.user = user;
this.apiKey = apiKey;
}
public void callMagentoStore(){
sessionId = new ClientXMLRPCTask().execute(url, user, apiKey);
Log.d("DEVX3", "SessionID: "+sessionId);
}
public String toString() {
return "URL: "+url+" - USER: "+user+" - APIKEY: "+apiKey;
}
}
Clientxmlrpctask.java:
package com.devx3.mageorderconsult.WS;
import android.os.AsyncTask;
import android.util.Log;
import org.xmlrpc.android.XMLRPCClient;
import org.xmlrpc.android.XMLRPCException;
import java.net.URI;
/**
* Created by erick on 10/20/15.
*/
public class ClientXMLRPCTask extends AsyncTask <String, String, String> {
@Override
public String doInBackground(String... params){
URI url = URI.create(params[0]);
String user = params[1];
String apiKey = params[2];
XMLRPCClient client = new XMLRPCClient(url);
String session = null;
try {
session = (String) client.call("login", user, apiKey);
} catch (XMLRPCException e) {
Log.e("DEVX3", "Error ClientXMLRPCTask", e);
} finally {
return session;
}
}
}
Androidmanifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.devx3.mageorderconsult" >
<uses-permission android:name="ANDROID.PERMISSION.INTERNET" />
<uses-permission android:name="ANDROID.PERMISSION.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".OrdersListActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Exception generated:
SessionID: com.devx3.mageorderconsult.WS.ClientXMLRPCTask@424c1b88
Error ClientXMLRPCTask
org.xmlrpc.android.XMLRPCException: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
at org.xmlrpc.android.XMLRPCClient.callEx(XMLRPCClient.java:237)
at org.xmlrpc.android.XMLRPCClient.call(XMLRPCClient.java:297)
at com.devx3.mageorderconsult.WS.ClientXMLRPCTask.doInBackground(ClientXMLRPCTask.java:24)
at com.devx3.mageorderconsult.WS.ClientXMLRPCTask.doInBackground(ClientXMLRPCTask.java:14)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at org.xmlrpc.android.XMLRPCClient.callEx(XMLRPCClient.java:178)
... 10 more
Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
at libcore.io.Posix.getaddrinfo(Native Method)
at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
... 20 more
Caused by: libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied)
... 23 more
Could someone help me?
Thank you.
Take a look if this helps you http://answall.com/questions/56062/erro-ao-tentaryconsumer-webservice-server-n%C3%A3o-recognized the hair value%C3%A7garlic/56069#
– Murilo Fechio
So man, I gave up ksoap... I saw some reviews about the lib I ended up leaving quiet... I started trying to use xmlrpcandroid, but I’m still having problems :(
– user462
I am voting to close this question as out of scope because it is an old question that is unanswered and which was abandoned by the author who explained in a comment that has no more interest in it.
– Victor Stafusa
Hi Victor, okay, I tried to edit to help but in this case I will vote to close too
– Anthony Accioly