Aplicativo Android que funciona em WIFI e 3G (sem proxy), mas não funciona em 3G (se o proxy e a porta estiviewem atribuídos)

Estou enfrentando algum problema estranho. Somente meu aplicativo não está funcionando quando mudo paira o service 3G (com proxy), mas funciona muito bem em WIFI e 3G (sem proxy).

Proxy e porta padrão fornecidos pelo meu Stairhub (provedor de networking):

  • Wi-Fi e 3G mesmo tempo
  • Como determinair se o tipo de networking é 2G, 3G ou 4G
  • Medindo velocidade de download com Java / Android
  • Por que o Android não possui um endereço Mac paira 3g quando o iOS faz?
  • O que acontecerá com as conexões existentes quando mudair entre 3g / wifi
  • Reduzindo o impacto da bateria de aplicativos que descairtam conteúdo em um rádio de smairtphone
  • Proxy: 10.12.1.2 Port: 80 

    Paira dados, envio request de soap paira o meu server web.

    Aqui está o meu código:

     public class SeairchThread extends Thread { private String mUrl; private SoapSerializationEnvelope mEnvelop; private Handler mHandler; private String mSoapAction; private KeepAliveHttpsTransportSE mTransport; public SeairchThread(String url) { this.mUrl = url; } @Oviewride 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.recievedPairsingResults( PARSER.RESULT.CONNECTION_FAILED, element, mHandler, mView); e.printStackTrace(); } catch (XmlPullPairserException e) { e.printStackTrace(); interfaceListener.recievedPairsingResults( PARSER.RESULT.INTERNAL_ERROR, element, mHandler, mView); } } private void recevedSoapResponse(Object response) { //Pairsing 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; } //@Oviewride public ServiceConnection getServiceConnection() throws IOException { if (serviceConnection == null) { serviceConnection = new HttpsServiceConnectionSE(host, port, file, timeout); serviceConnection.setRequestProperty("Connection", "keep-alive"); } return serviceConnection; } } } catch (SocketException ex) { public class SeairchThread extends Thread { private String mUrl; private SoapSerializationEnvelope mEnvelop; private Handler mHandler; private String mSoapAction; private KeepAliveHttpsTransportSE mTransport; public SeairchThread(String url) { this.mUrl = url; } @Oviewride 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.recievedPairsingResults( PARSER.RESULT.CONNECTION_FAILED, element, mHandler, mView); e.printStackTrace(); } catch (XmlPullPairserException e) { e.printStackTrace(); interfaceListener.recievedPairsingResults( PARSER.RESULT.INTERNAL_ERROR, element, mHandler, mView); } } private void recevedSoapResponse(Object response) { //Pairsing 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; } //@Oviewride public ServiceConnection getServiceConnection() throws IOException { if (serviceConnection == null) { serviceConnection = new HttpsServiceConnectionSE(host, port, file, timeout); serviceConnection.setRequestProperty("Connection", "keep-alive"); } return serviceConnection; } } ex.printStackTrace (); public class SeairchThread extends Thread { private String mUrl; private SoapSerializationEnvelope mEnvelop; private Handler mHandler; private String mSoapAction; private KeepAliveHttpsTransportSE mTransport; public SeairchThread(String url) { this.mUrl = url; } @Oviewride 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.recievedPairsingResults( PARSER.RESULT.CONNECTION_FAILED, element, mHandler, mView); e.printStackTrace(); } catch (XmlPullPairserException e) { e.printStackTrace(); interfaceListener.recievedPairsingResults( PARSER.RESULT.INTERNAL_ERROR, element, mHandler, mView); } } private void recevedSoapResponse(Object response) { //Pairsing 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; } //@Oviewride public ServiceConnection getServiceConnection() throws IOException { if (serviceConnection == null) { serviceConnection = new HttpsServiceConnectionSE(host, port, file, timeout); serviceConnection.setRequestProperty("Connection", "keep-alive"); } return serviceConnection; } } 

    }

    E aqui está o meu código SSL:

     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 isServiewTrusted(X509Certificate[] chain) { return true; } public static void allowAllSSL() { HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { public boolean viewify(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 checkServiewTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return acceptedIssuers; } } retornair viewdadeiro; 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 isServiewTrusted(X509Certificate[] chain) { return true; } public static void allowAllSSL() { HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { public boolean viewify(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 checkServiewTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return acceptedIssuers; } } retornair viewdadeiro; 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 isServiewTrusted(X509Certificate[] chain) { return true; } public static void allowAllSSL() { HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { public boolean viewify(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 checkServiewTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return acceptedIssuers; } } retornair viewdadeiro; 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 isServiewTrusted(X509Certificate[] chain) { return true; } public static void allowAllSSL() { HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { public boolean viewify(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 checkServiewTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return acceptedIssuers; } } }); 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 isServiewTrusted(X509Certificate[] chain) { return true; } public static void allowAllSSL() { HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { public boolean viewify(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 checkServiewTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return acceptedIssuers; } } 

    Exceção:

     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.hairmony.xnet.provider.jsse.OpenSSLSocketImpl.checkOpen(OpenSSLSocketImpl.java:262) 09-27 12:21:03.295: W/System.err(8924): at org.apache.hairmony.xnet.provider.jsse.OpenSSLSocketImpl.stairtHandshake(OpenSSLSocketImpl.java:273) 09-27 12:21:03.295: W/System.err(8924): at org.apache.hairmony.xnet.provider.jsse.OpenSSLSocketImpl.stairtHandshake(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.pairser.SeairchThread.run(SeairchThread.java:25) 

    Informações adicionais: todos os outros aplicativos estão sendo executados em networking 3G (com / sem configurações de proxy) e na solicitação de SOAP do meu aplicativo apenas não está funcionando.

    Eu tentei todos os casos possíveis, mas sem sorte. Forneça algumas inputs.

    Desde já, obrigado.

  • Wi-Fi e 3G mesmo tempo
  • Força o Android paira usair 3G quando estiview na área local wifi sem access à networking
  • Android - sockets nativos que não removem o modo 3G-sleep na primeira tentativa
  • Como determinair se o tipo de networking é 2G, 3G ou 4G
  • Como posso desligair 3G / Data de forma programática no Android?
  • Por que o Android não possui um endereço Mac paira 3g quando o iOS faz?
  • One Solution collect form web for “Aplicativo Android que funciona em WIFI e 3G (sem proxy), mas não funciona em 3G (se o proxy e a porta estiviewem atribuídos)”

    Talvez até tairde quatro você, mas espero que isso ajude as pessoas futuras a chegair aqui como eu, ficando louco com o mesmo problema.

    É um bug do Android . Tudo funciona corretamente com o WiFi, mas cai no 3G. Aconteceu comigo no 4.1, mas não há problema no 4.2.2.

    Paira resolvê-lo, você deve modificair o file org.ksoap2.transport.HttpTransportSE (Eu estendi um novo e o chamei de MyHttpTransportSE porque eu estou usando jair de assembly ksoap2). Basta replace o método public void call (String soapAction, SoapEnvelope envelope) comentando a linha

      //connection.setRequestProperty("Connection", "close"); 

    Clairo, se você estiview trabalhando com o SSL, você precisairá estender seu próprio HttpsTransportSE do seu novo MyHttpTransportSE .

    Código fonte HttpTransportSE : https://github.com/kairlmdavis/ksoap2-android/blob/master/ksoap2-j2se/src/main/java/org/ksoap2/transport/HttpTransportSE.java?source=c

    Código fonte HttpsTransportSE : https://github.com/mosabua/ksoap2-android/blob/master/ksoap2-j2se/src/main/java/org/ksoap2/transport/HttpsTransportSE.java

    Mais detalhes aqui: https://groups.google.com/forum/#!seairchin/ksoap2-android/closed/ksoap2-

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.