我的 ksoap2 网络服务和网络服务客户端与 HttpTransportSE 配合得很好。现在我想将 SSL 与受信任的证书一起使用。为了在 Tomcat SSL 上使用 Web 服务,我在 Axis2.xml 中添加了 Https Transport Reciver,我认为 Web 服务可以正常工作。这是我的 SSL 网络服务:
<https://myURL.de:8443/WebProject_KomplexeObjekte_SSL/services/HelloWorldWS?wsdl>?
下一步是在我的客户端中将 httptransportSE(URL) 更改为 httpstransportSE(HOST, PORT, FILE, TIMEOUT)。 这是我的客户:
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.transport.HttpsServiceConnectionSE;
import org.ksoap2.transport.HttpsTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class WSClientKomplexeObjekteActivity extends Activity {
private static final String SOAP_ACTION = "http://ws.chathura.com/getCategoryObject";
private static final String METHOD_NAME = "getCategoryObject";
private static final String NAMESPACE = "http://ws.chathura.com";
private static final String NAMESPACE2 = "http://ws.chathura.com/xsd";
private static final String HOST = "myURL.de";
private static final int PORT = 8443;
private static final String FILE = "/WebProject_KomplexeObjekte_SSL/services/HelloWorldWS?wsdl";
private static final int TIMEOUT = 1000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView)findViewById(R.id.textview1);
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Category C = new Category();
C.setCategoryId(1);
C.setDescription("Client Beschreibung");
C.setName("Client Name");
Request.addProperty("obj", C);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(Request);
envelope.addMapping(NAMESPACE2, C.getClass().getSimpleName(), C.getClass());
HttpsTransportSE androidHttpsTransport = new HttpsTransportSE(HOST, PORT, FILE, TIMEOUT);
Category ans = null;
try {
androidHttpsTransport.call(SOAP_ACTION, envelope);
ans = (Category)envelope.getResponse();
tv.setText("CategoryId: " + ans.getCategoryId() + "\nName: " + ans.getName() + "\nDescription: " + ans.getDescription());
}
catch(Exception e) {
e.printStackTrace();
}
}
}
现在我在 Logcat 中得到这个异常:
W/System.err(619): javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
由于这个异常,我尝试包含一个 keystore ,其中包含我的 tomcat 上用于 ssl 的证书。你可以在评论中看到这段代码。 那是没有成功的。我得到以下异常:
E/AndroidRuntime(654): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.bachelor.marcel/de.bachelor.marcel.WSClientKomplexeObjekteActivity}: java.lang.NullPointerException
最佳答案
好的...我自己解决了问题。客户端代码不是问题。它工作得很好。唯一的问题是在服务器端。 Android 不信任我的服务器,因为我忘记包含根证书。所以如果你有同样的问题,你可以用 http://www.sslshopper.com/ssl-checker.html# 检查你的 ssl 服务器。
关于android - 带有受信任证书的 KSaop2 HttpsTransportSE 的 SSLHandshakeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11155321/