Announcement Announcement Module
Collapse
No announcement yet.
error while testing spring android basicauth Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • error while testing spring android basicauth

    hello,
    when I run the sample app (see above) I get following exception:
    Code:
    D/MainActivity(  307): http://localhost:8080/server/getmessage
    W/dalvikvm(  307): threadid=9: thread exiting with uncaught exception (group=0x40015560)
    E/AndroidRuntime(  307): FATAL EXCEPTION: AsyncTask #1
    E/AndroidRuntime(  307): java.lang.RuntimeException: An error occured while executing doInBackground()
    E/AndroidRuntime(  307):        at android.os.AsyncTask$3.done(AsyncTask.java:200)
    E/AndroidRuntime(  307):        at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
    E/AndroidRuntime(  307):        at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
    E/AndroidRuntime(  307):        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
    E/AndroidRuntime(  307):        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    E/AndroidRuntime(  307):        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
    E/AndroidRuntime(  307):        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
    E/AndroidRuntime(  307):        at java.lang.Thread.run(Thread.java:1019)
    E/AndroidRuntime(  307): Caused by: org.springframework.web.client.ResourceAccessException: I/O error: localhost/127.0.0.1:8080 - Connection refused; nested exception is java.net.ConnectException: localhost/127.0.0.1:8080 - Connection refused
    E/AndroidRuntime(  307):        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:490)
    E/AndroidRuntime(  307):        at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:438)
    E/AndroidRuntime(  307):        at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:414)
    E/AndroidRuntime(  307):        at org.springframework.android.basicauth.MainActivity$FetchSecuredResourceTask.doInBackground(MainActivity.java:108)
    E/AndroidRuntime(  307):        at org.springframework.android.basicauth.MainActivity$FetchSecuredResourceTask.doInBackground(MainActivity.java:73)
    E/AndroidRuntime(  307):        at android.os.AsyncTask$2.call(AsyncTask.java:185)
    E/AndroidRuntime(  307):        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
    E/AndroidRuntime(  307):        ... 4 more
    E/AndroidRuntime(  307): Caused by: java.net.ConnectException: localhost/127.0.0.1:8080 - Connection refused
    E/AndroidRuntime(  307):        at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:207)
    E/AndroidRuntime(  307):        at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:437)
    E/AndroidRuntime(  307):        at java.net.Socket.connect(Socket.java:983)
    E/AndroidRuntime(  307):        at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
    E/AndroidRuntime(  307):        at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
    This is weird because I put the right uri (http://localhost:8080/server) but AsyncTask method seems using this: localhost/127.0.0.1:8080

    Any suggestions
    Thanks

  • #2
    Problem Solved.
    The right uri ist http://10.0.2.2:8080/server. I did know that 10.0.2.2 is the localhost for the emulator!

    Comment


    • #3
      Yes, you are correct. Localhost on the emulator and device actual refers to the device itself. 10.0.2.2 is a proxy to the hosted environment when you are running the emulator. Glad you were able to resolve the issue!

      Comment

      Working...
      X