I ran into some strange problem. Only my application does not work when I switch to a 3G service (with a proxy), but it works fine in WIFI and 3G (without a proxy).
The default proxy and port provided by my Starhub (network provider):
Proxy: 10.12.1.2 Port: 80
For data, I send a soap request to my web server.
Here is my 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) {
}
And here is my 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; } }
An exception:
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)
Additional information: all other applications work on a 3G network (with / without a proxy server), and in my application only a SOAP request does not work.
I tried all possible cases, but no luck. Please provide me some materials.
Thanks in advance.