Ich habe einige seltsame Problem, nur meine Anwendung funktioniert nicht, wenn ich auf 3G-Dienst (Mit Proxy) aber es funktioniert super in WIFI und 3G (ohne Proxy).Android-Anwendung funktioniert auf WIFI und 3G (Ohne Proxy), aber nicht auf 3G (Wenn Proxy und Port zugewiesen sind)
Standard-Proxy und Port gegeben durch meine Starhub (Netzbetreiber):
Proxy: 10.12.1.2
Port: 80
Für Daten, schicke ich Seife Anfrage an meinem Webserver.
Hier ist mein Code:
public class SearchThread extends Thread {
private String mUrl;
private SoapSerializationEnvelope mEnvelop;
private Handler mHandler;
private String mSoapAction;
private KeepAliveHttpsTransportSE mTransport;
public SearchThread(String url) {
this.mUrl = url;
}
@Override
public void run() {
mEnvelop = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER11);
mEnvelop.setOutputSoapObject(interfaceListener.getSoapObject(element));
mSoapAction = interfaceListener.getSoapAction(element);
try {
TrustManagerManipulator.allowAllSSL();
mTransport = new KeepAliveHttpsTransportSE(URLS.URL_MAIN, 443, mUrl, 60000);
mTransport.call(mSoapAction, mEnvelop);
if (this.isInterrupted()) {
Log.v(TAG,"Interrupted");
return;
}
recevedSoapResponse(mEnvelop.getResponse());
} catch (SocketException ex) {
Log.e("Error : ", "Error on soapPrimitiveData() " + ex.getMessage());
ex.printStackTrace();
} catch (IOException e) {
interfaceListener.recievedParsingResults(
PARSER.RESULT.CONNECTION_FAILED, element, mHandler, mView);
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
interfaceListener.recievedParsingResults(
PARSER.RESULT.INTERNAL_ERROR, element, mHandler, mView);
}
}
private void recevedSoapResponse(Object response) {
//Parsing XML here.
}
public class KeepAliveHttpsTransportSE extends HttpsTransportSE
{
private final String host;
private final int port;
private final String file;
private final int timeout;
private ServiceConnection serviceConnection;
public KeepAliveHttpsTransportSE (String host, int port, String file, int timeout) {
super(host, port, file, timeout);
this.host = host;
this.port = port;
this.file = file;
this.timeout = timeout;
}
//@Override
public ServiceConnection getServiceConnection() throws IOException
{
if (serviceConnection == null) {
serviceConnection = new HttpsServiceConnectionSE(host, port, file, timeout);
serviceConnection.setRequestProperty("Connection", "keep-alive");
}
return serviceConnection;
}
}
}
Und hier ist mein SSL-Code:
public class TrustManagerManipulator implements X509TrustManager {
private static TrustManager[] trustManagers;
private static final X509Certificate[] acceptedIssuers = new X509Certificate[] {};
public boolean isClientTrusted(X509Certificate[] chain) {
return true;
}
public boolean isServerTrusted(X509Certificate[] chain) {
return true;
}
public static void allowAllSSL() {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
SSLContext context = null;
if (trustManagers == null) {
trustManagers = new TrustManager[] { new TrustManagerManipulator() };
}
try {
context = SSLContext.getInstance("TLS");
context.init(null, trustManagers, new SecureRandom());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
HttpsURLConnection.setDefaultSSLSocketFactory(context
.getSocketFactory());
}
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return acceptedIssuers;
}
}
Ausnahme:
09-27 12:21:03.295: W/System.err(8924): java.net.SocketException: Socket is closed
09-27 12:21:03.295: W/System.err(8924): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.checkOpen(OpenSSLSocketImpl.java:262)
09-27 12:21:03.295: W/System.err(8924): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:273)
09-27 12:21:03.295: W/System.err(8924): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:257)
09-27 12:21:03.295: W/System.err(8924): at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:210)
09-27 12:21:03.295: W/System.err(8924): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:477)
09-27 12:21:03.295: W/System.err(8924): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:441)
09-27 12:21:03.295: W/System.err(8924): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
09-27 12:21:03.295: W/System.err(8924): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
09-27 12:21:03.295: W/System.err(8924): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
09-27 12:21:03.300: W/System.err(8924): at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:188)
09-27 12:21:03.300: W/System.err(8924): at libcore.net.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:280)
09-27 12:21:03.300: W/System.err(8924): at org.ksoap2.transport.HttpsServiceConnectionSE.openOutputStream(HttpsServiceConnectionSE.java:98)
09-27 12:21:03.300: W/System.err(8924): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:157)
09-27 12:21:03.300: W/System.err(8924): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:96)
09-27 12:21:03.300: W/System.err(8924): at com.mobile.utils.parser.SearchThread.run(SearchThread.java:25)
Zusätzliche Information: Alle anderen Anwendungen laufen auf 3 G-Netzwerk (mit/ohne Proxy-Einstellungen) und In meiner Anwendung funktioniert nur die SOAP-Anfrage nicht.
Ich habe alle möglichen Fälle versucht, aber kein Glück. Bitte geben Sie mir einige Eingaben.
Vielen Dank im Voraus.
Das ist mein Problem gelöst. Es sollte IMO akzeptiert werden. –