0

The android app I built requires http connection to a server to access data. I wrote automated test (based on Espresso) and tested it on my device and it works. The same test fails when tested on one of google cloud test lab devices. I looked at the log and it shows that it actually failed right when it tries to make the server connection.

Are there any special configurations I have to do first on google cloud devices before I test server connection on them.

Thanks, K00k00

Thanks Paisanco

THIS IS MY FIRST STACKOVERFLOW POSTING EVER. IF THINGS ARE MESSY, PLEASE FORGIVE ME!!!

Here is the code which is supposed to connect to a Servlet (ServletName) sitting on a server (www.servlet-location.com) and passing two params (firstName and lastName). The servlet creates account returns the details of the account in xml.

    URL url = null;
    HttpURLConnection conn = null;
    InputStream is = null;
    String xml = null;
    String line = "";
    StringBuilder builder = new StringBuilder();
    BufferedReader reader = null;

    try
    {
        url = new URL("http://www.servlet-location.com:8080/ServletName?firstName=Joe&lastName=Marvin");
        conn = (HttpURLConnection)url.openConnection();
        conn.setConnectTimeout(10000);
        conn.setReadTimeout(10000);
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        conn.setRequestProperty("charset", "utf-8");
        conn.setUseCaches(false);
        conn.connect();
        is = conn.getInputStream();
        reader = new BufferedReader(new InputStreamReader(is));

        while ((line = reader.readLine()) != null)
            builder.append(line.trim());

        if(is != null)
            is.close();

        if(conn != null)
            conn.disconnect();
    }
    catch(MalformedURLException e)
    {
        e.printStackTrace();

        try
        {
            if(is != null)
                is.close();

            if(conn != null)
                conn.disconnect();
        }
        catch(IOException ioe)
        {
            ioe.printStackTrace();
            return null;
        }

        return null;
    }
    catch(SocketTimeoutException e)
    {
        e.printStackTrace();

        try
        {
            if(is != null)
                is.close();

            if(conn != null)
                conn.disconnect();
        }
        catch(IOException ioe)
        {
            ioe.printStackTrace();
            return null;
        }

        return null;
    }
    catch(IOException e)
    {
        e.printStackTrace();

        try
        {
            if(is != null)
                is.close();

            if(conn != null)
                conn.disconnect();
        }
        catch(IOException ioe)
        {
            ioe.printStackTrace();
            return null;
        }

        return null;
    }

    return xml;
}

And here is the error I got from the Log (google cloud test lab Log file)...

06-18 12:34:35.537: W/System.err(22125): java.net.SocketTimeoutException: failed to connect to www.servlet-location.com/xxx.xxx.xxx.xxx (port 8080) after 10000ms
06-18 12:34:35.538: W/System.err(22125):    at libcore.io.IoBridge.connectErrno(IoBridge.java:169)
06-18 12:34:35.538: W/System.err(22125):    at libcore.io.IoBridge.connect(IoBridge.java:122)
06-18 12:34:35.538: W/System.err(22125):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
06-18 12:34:35.539: W/System.err(22125):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
06-18 12:34:35.539: W/System.err(22125):    at java.net.Socket.connect(Socket.java:882)
06-18 12:34:35.539: W/System.err(22125):    at com.android.okhttp.internal.Platform.connectSocket(Platform.java:174)
06-18 12:34:35.539: W/System.err(22125):    at com.android.okhttp.Connection.connect(Connection.java:152)
06-18 12:34:35.539: W/System.err(22125):    at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:276)
06-18 12:34:35.539: W/System.err(22125):    at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:211)
06-18 12:34:35.539: W/System.err(22125):    at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:382)
06-18 12:34:35.540: W/System.err(22125):    at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:106)
06-18 12:34:35.540: W/System.err(22125):    at com.yeha.mobilebirr.transport.DataTransportManager.request(DataTransportManager.java:135)
06-18 12:34:35.540: W/System.err(22125):    at 

Thanks again!!!

K00k00

sumitya
  • 2,631
  • 1
  • 19
  • 32
K00k00
  • 1
  • 2
  • Have you tried testing the URL connection separately with something like cURL? If that works and the problem is your code, we'd need to see a minimal example that duplicates the problem, to tell what's wrong. – paisanco Jun 18 '16 at 19:13

1 Answers1

0

I believe the problem is the fact that you are using port 8080. Test Lab only supports outbound HTTP (80) and HTTPS (443) connections.