Good morning, I created a web service with soap and tested it on the SoapUI tool. This tool works cool. In android to using Ksoap and when I command to list the data in Logcat this is bursting an exception:
SoapFault - faultcode: 'soapenv: Server' faultstring: '1' faultactor: 'null'
Could you help me?
The program is stopping at the command line:
SoapPrimitive resposta = (SoapPrimitive) envelope.getResponse();
that is in the UserDAO class
The UserDao classes, where I have declared the methods and class MainActivity
where I call the InserirUsuario
method
public class UserDAO {
private static final String URL = "http://192.168.0.12:5037/EngeplayWebService/services/UsuarioDAO?wsdl";
private static final String NAMESPACE = "http://engecard.engeplay.card.com/";
private static final String INSERIR = "InserirUsuario";
private static final String BUSCARTODOS= "buscarTodosUsuarios";
private static final String EXCLUIR= "ExcluirUsuario";
private static final String BUSCARUSUARIO= "buscarUsuarioPorId";
private static final String ATUALIZAR = "atualizarUsuario";
public boolean InserirUsuario(User usuario){
SoapObject inserirUsuario = new SoapObject(NAMESPACE, INSERIR);
SoapObject usr = new SoapObject(NAMESPACE, "User");
usr.addProperty("id", usuario.getId());
usr.addProperty("nome", usuario.getNome());
usr.addProperty("numeroCartao", usuario.getNumeroCartao());
inserirUsuario.addSoapObject(usr);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(inserirUsuario);
envelope.implicitTypes = true;
HttpTransportSE http = new HttpTransportSE(URL);
try {
http.call("urn:" + INSERIR, envelope);
SoapPrimitive resposta = (SoapPrimitive) envelope.getResponse();
return Boolean.parseBoolean(resposta.toString());
}catch(Exception e){
e.printStackTrace();
return false;
}
}
}
public class MainActivity extends Activity {
Button btnEfetuarLogin;
EditText edtTxtUsuario;
EditText edtTxtSenha;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(android.os.Build.VERSION.SDK_INT > 9){
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
UserDAO dao = new UserDAO();
User usr = new User(2,"TesteNovo","323223323244");
boolean resultado = dao.InserirUsuario(usr);
Log.d("Exemplo: ", resultado + "");
}
}
The exception I get is this:
SoapFault - faultcode: 'soapenv:Server' faultstring: '1' faultactor: 'null' detail: org.kxml2.kdom.Node@41d12308
at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:147)
at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)
at org.ksoap2.transport.Transport.parseResponse(Transport.java:118)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:275)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
at com.card.engeplay.engecardsystem.UserDAO.InserirUsuario(UserDAO.java:43)
at com.card.engeplay.engecardsystem.MainActivity.onCreate(MainActivity.java:44)
at android.app.Activity.performCreate(Activity.java:5447)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$800(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5584)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
My WSDL
<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns="http://engecard.engeplay.card.com" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ax21="http://engecard.engeplay.card.com/xsd" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://engecard.engeplay.card.com">
<wsdl:documentation>
Please Type your service description here
</wsdl:documentation>
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://engecard.engeplay.card.com/xsd">
<xs:complexType name="Usuario">
<xs:sequence>
<xs:element minOccurs="0" name="id" type="xs:int"/>
<xs:element minOccurs="0" name="nome" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="numeroCartao" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema xmlns:ax22="http://engecard.engeplay.card.com/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://engecard.engeplay.card.com">
<xs:import namespace="http://engecard.engeplay.card.com/xsd"/>
<xs:element name="buscarTodosUsuarios">
<xs:complexType>
<xs:sequence/>
</xs:complexType>
</xs:element>
<xs:element name="buscarTodosUsuariosResponse">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ax22:Usuario"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="buscarUsuarioPorId">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="id" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="buscarUsuarioPorIdResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="ax22:Usuario"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="atualizarUsuario">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="usuario" nillable="true" type="ax22:Usuario"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="atualizarUsuarioResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="InserirUsuario">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="usuario" nillable="true" type="ax22:Usuario"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="InserirUsuarioResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ExcluirUsuario">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="usuario" nillable="true" type="ax22:Usuario"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ExcluirUsuarioResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="buscarTodosUsuariosRequest">
<wsdl:part name="parameters" element="ns:buscarTodosUsuarios"/>
</wsdl:message>
<wsdl:message name="buscarTodosUsuariosResponse">
<wsdl:part name="parameters" element="ns:buscarTodosUsuariosResponse"/>
</wsdl:message>
<wsdl:message name="InserirUsuarioRequest">
<wsdl:part name="parameters" element="ns:InserirUsuario"/>
</wsdl:message>
<wsdl:message name="InserirUsuarioResponse">
<wsdl:part name="parameters" element="ns:InserirUsuarioResponse"/>
</wsdl:message>
<wsdl:message name="buscarUsuarioPorIdRequest">
<wsdl:part name="parameters" element="ns:buscarUsuarioPorId"/>
</wsdl:message>
<wsdl:message name="buscarUsuarioPorIdResponse">
<wsdl:part name="parameters" element="ns:buscarUsuarioPorIdResponse"/>
</wsdl:message>
<wsdl:message name="ExcluirUsuarioRequest">
<wsdl:part name="parameters" element="ns:ExcluirUsuario"/>
</wsdl:message>
<wsdl:message name="ExcluirUsuarioResponse">
<wsdl:part name="parameters" element="ns:ExcluirUsuarioResponse"/>
</wsdl:message>
<wsdl:message name="atualizarUsuarioRequest">
<wsdl:part name="parameters" element="ns:atualizarUsuario"/>
</wsdl:message>
<wsdl:message name="atualizarUsuarioResponse">
<wsdl:part name="parameters" element="ns:atualizarUsuarioResponse"/>
</wsdl:message>
<wsdl:portType name="UsuarioDAOPortType">
<wsdl:operation name="buscarTodosUsuarios">
<wsdl:input message="ns:buscarTodosUsuariosRequest" wsaw:Action="urn:buscarTodosUsuarios"/>
<wsdl:output message="ns:buscarTodosUsuariosResponse" wsaw:Action="urn:buscarTodosUsuariosResponse"/>
</wsdl:operation>
<wsdl:operation name="InserirUsuario">
<wsdl:input message="ns:InserirUsuarioRequest" wsaw:Action="urn:InserirUsuario"/>
<wsdl:output message="ns:InserirUsuarioResponse" wsaw:Action="urn:InserirUsuarioResponse"/>
</wsdl:operation>
<wsdl:operation name="buscarUsuarioPorId">
<wsdl:input message="ns:buscarUsuarioPorIdRequest" wsaw:Action="urn:buscarUsuarioPorId"/>
<wsdl:output message="ns:buscarUsuarioPorIdResponse" wsaw:Action="urn:buscarUsuarioPorIdResponse"/>
</wsdl:operation>
<wsdl:operation name="ExcluirUsuario">
<wsdl:input message="ns:ExcluirUsuarioRequest" wsaw:Action="urn:ExcluirUsuario"/>
<wsdl:output message="ns:ExcluirUsuarioResponse" wsaw:Action="urn:ExcluirUsuarioResponse"/>
</wsdl:operation>
<wsdl:operation name="atualizarUsuario">
<wsdl:input message="ns:atualizarUsuarioRequest" wsaw:Action="urn:atualizarUsuario"/>
<wsdl:output message="ns:atualizarUsuarioResponse" wsaw:Action="urn:atualizarUsuarioResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="UsuarioDAOSoap11Binding" type="ns:UsuarioDAOPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="buscarTodosUsuarios">
<soap:operation soapAction="urn:buscarTodosUsuarios" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="InserirUsuario">
<soap:operation soapAction="urn:InserirUsuario" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="buscarUsuarioPorId">
<soap:operation soapAction="urn:buscarUsuarioPorId" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="ExcluirUsuario">
<soap:operation soapAction="urn:ExcluirUsuario" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="atualizarUsuario">
<soap:operation soapAction="urn:atualizarUsuario" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="UsuarioDAOSoap12Binding" type="ns:UsuarioDAOPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="buscarTodosUsuarios">
<soap12:operation soapAction="urn:buscarTodosUsuarios" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="InserirUsuario">
<soap12:operation soapAction="urn:InserirUsuario" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="buscarUsuarioPorId">
<soap12:operation soapAction="urn:buscarUsuarioPorId" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="ExcluirUsuario">
<soap12:operation soapAction="urn:ExcluirUsuario" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="atualizarUsuario">
<soap12:operation soapAction="urn:atualizarUsuario" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="UsuarioDAOHttpBinding" type="ns:UsuarioDAOPortType">
<http:binding verb="POST"/>
<wsdl:operation name="buscarTodosUsuarios">
<http:operation location="buscarTodosUsuarios"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="InserirUsuario">
<http:operation location="InserirUsuario"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="buscarUsuarioPorId">
<http:operation location="buscarUsuarioPorId"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="ExcluirUsuario">
<http:operation location="ExcluirUsuario"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="atualizarUsuario">
<http:operation location="atualizarUsuario"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="UsuarioDAO">
<wsdl:port name="UsuarioDAOHttpSoap11Endpoint" binding="ns:UsuarioDAOSoap11Binding">
<soap:address location="http://192.168.0.121:8080/EngeplayWebService/services/UsuarioDAO.UsuarioDAOHttpSoap11Endpoint/"/>
</wsdl:port>
<wsdl:port name="UsuarioDAOHttpSoap12Endpoint" binding="ns:UsuarioDAOSoap12Binding">
<soap12:address location="http://192.168.0.121:8080/EngeplayWebService/services/UsuarioDAO.UsuarioDAOHttpSoap12Endpoint/"/>
</wsdl:port>
<wsdl:port name="UsuarioDAOHttpEndpoint" binding="ns:UsuarioDAOHttpBinding">
<http:address location="http://192.168.0.121:8080/EngeplayWebService/services/UsuarioDAO.UsuarioDAOHttpEndpoint/"/>
</wsdl:port>
</wsdl:service>
Ws log 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:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
public class UserDAO {
public boolean InserirUsuario(User usuario){
try {
Connection conn = ConectarMysql.Conecta();
String queryInserir = "INSERT INTO Usuarios VALUES (null, ?, ?)"; //campo null pq o campo id da tabela é auto increment
PreparedStatement ppStm = conn.prepareStatement(queryInserir);
ppStm.setString(1, usuario.getNome());
ppStm.setString(2, usuario.getNumeroCartao());
ppStm.executeUpdate();
conn.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
}
public class User {
private int id;
private String nome;
private String numeroCartao;
public User(){
}
public User(int id, String nome, String numeroCartao) {
this.id = id;
this.nome = nome;
this.numeroCartao = numeroCartao;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getNumeroCartao() {
return numeroCartao;
}
public void setNumeroCartao(String numeroCartao) {
this.numeroCartao = numeroCartao;
}
}
Android Project User Class
public class User {
private int id;
private String nome;
private String numeroCartao;
public User(){
}
public User(int id, String nome, String numeroCartao) {
this.id = id;
this.nome = nome;
this.numeroCartao = numeroCartao;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getNumeroCartao() {
return numeroCartao;
}
public void setNumeroCartao(String numeroCartao) {
this.numeroCartao = numeroCartao;
}
Web.xml
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "id=" WebApp_ID "version=" 2.5 "> EngeplayWebService index.html index.htm index.jsp default.html default.htm default.jsp /axis2-web/index.jsp Apache-Axis Servlet AxisServlet org.apache.axis2.transport.http.AxisServlet AxisServlet / servlet / AxisServlet AxisServlet .jws AxisServlet / services / Home Apache-Axis Admin Servlet Web Admin AxisAdminServlet org.apache.axis2.transport.http.AxisAdminServlet 100 AxisAdminServlet / axis2-admin / *