Topic
  • 10 replies
  • Latest Post - ‏2012-09-03T04:31:07Z by IdanAdar
EUMC_Priyotosh_Ghosh
13 Posts

Pinned topic Service Connection Error

‏2012-07-16T07:17:10Z |
I am trying to run simple busy indicator program in worklight.
it is running successfully in mobile browser simulator for both android and iphone but when I am
trying to run it with android emulator it is not running and force closing.
The following are the main errors I am getting . I am not understanding why I am getting this error.
If anyone know please send me the solution as early as possible.
***********************************************************

07-16 12:34:45.042: E/SQLiteLog(689): (14) cannot open file at line 30174 of 00bb9c9ce4
07-16 12:34:53.692: E/Web Console(689): XMLHttpRequest cannot load http://10.201.16.29:8080/apps/services/reach. Origin null is not allowed by Access-Control-Allow-Origin. at null:1

07-16 12:34:59.992: E/BusyDemoApp(689): Client init failed. Connection to the service is not available.

07-16 12:35:02.172: E/Web Console(689): XMLHttpRequest cannot load http://127.0.0.1:46727/6e88ba9f-ce22-4fc1-9109-37623812deab. Origin null is not allowed by Access-Control-Allow-Origin. at null:1
I have also attached the Tomcat error file also.

Any help will be highly appreciated.

Thanks and regards
Priyotosh
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Service Connection Error

    ‏2012-07-16T13:45:13Z  
    When you run the emulator it is using the localhost as its server. By default Eclipse will not allow you to make cross-domain requests. You have an .ajax() function which is trying to post to another domain http://anything outside my app. This should work fine when you deploy (as shown by it working in Android/iOS devices. But you won't be able to test it in the localhost.

    Ralph Pina
  • EUMC_Priyotosh_Ghosh
    13 Posts

    Re: Service Connection Error

    ‏2012-07-17T04:47:40Z  
    When you run the emulator it is using the localhost as its server. By default Eclipse will not allow you to make cross-domain requests. You have an .ajax() function which is trying to post to another domain http://anything outside my app. This should work fine when you deploy (as shown by it working in Android/iOS devices. But you won't be able to test it in the localhost.

    Ralph Pina
    Hi Pina,

    Then what will be solution if I want to run it through my Android Emulator.
    I am stuck with this for the last three days.

    Please help me if you know this.

    Thank You

    Priyotosh
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Service Connection Error

    ‏2012-07-17T05:43:46Z  
    Hi Pina,

    Then what will be solution if I want to run it through my Android Emulator.
    I am stuck with this for the last three days.

    Please help me if you know this.

    Thank You

    Priyotosh
    Priyotosh, to make sure I know your environment:

    You developed your project in Worklight Developer edition, not the paid versions.

    You run the Worklight server in Eclipse and in the Console you click on the Android and iPhone clients. They run well.

    You then deploy the application to a Tomcat server remotely. You then load your app in the ADT emulator in Eclipse. This throws those errors in the server.

    These things can be going on:

    1) You cannot deploy an app to another server without the Worklight Server which is only included in the paid versions. I have never done this, so I don't know if it would throw this error.

    2) You did not change the URL in the apps > appName > application-descriptor.xml file, so your emulator is trying to hit the wrong server.

    3) You trying to call something like .ajax( URL : http://someother.url/somefilepath ... ) and you have no access to that file or service so you can't allow it to accept cross domain requests. For example, without explicitly allowing it, I cannot make an ajax call from http://ralphpina.net/myContactForm.html to http://johnsmith.com/sendMail.php, PHP won't let that happen, but if I have access to sendMail, I can code it to allow that call.

    Also, you may want to look and post your LogCat output to see what the emulator is saying.

    Ralph Pina
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Service Connection Error

    ‏2012-07-19T18:39:34Z  
    Priyotosh, to make sure I know your environment:

    You developed your project in Worklight Developer edition, not the paid versions.

    You run the Worklight server in Eclipse and in the Console you click on the Android and iPhone clients. They run well.

    You then deploy the application to a Tomcat server remotely. You then load your app in the ADT emulator in Eclipse. This throws those errors in the server.

    These things can be going on:

    1) You cannot deploy an app to another server without the Worklight Server which is only included in the paid versions. I have never done this, so I don't know if it would throw this error.

    2) You did not change the URL in the apps > appName > application-descriptor.xml file, so your emulator is trying to hit the wrong server.

    3) You trying to call something like .ajax( URL : http://someother.url/somefilepath ... ) and you have no access to that file or service so you can't allow it to accept cross domain requests. For example, without explicitly allowing it, I cannot make an ajax call from http://ralphpina.net/myContactForm.html to http://johnsmith.com/sendMail.php, PHP won't let that happen, but if I have access to sendMail, I can code it to allow that call.

    Also, you may want to look and post your LogCat output to see what the emulator is saying.

    Ralph Pina
    Hi,
    I am having exactly same issues. I am hitting RSS reader engadget.com. Works fine from iOS simulator. But fails in Android simulator.
    Here is the error messages logged in LogCat.

    0719/140735:ERROR:entry_impl.cc(904)] Failed to save user data
    07-19 14:07:36.476: E/Web Console(629): XMLHttpRequest cannot load http://127.0.0.1:40403/8f364b03-9cc6-48a0-9b33-34f4b4409504. Origin null is not allowed by Access-Control-Allow-Origin. at null:1
    07-19 14:07:36.586: E/Web Console(629): XMLHttpRequest cannot load http://192.168.1.5:8080/apps/services/reach. Origin null is not allowed by Access-Control-Allow-Origin. at null:1
    07-19 14:07:49.856: E/EngadgetReader(629): Client init failed. Connection to the service is not available.

    Any thoughts?

    Thanks,
    Purush
  • AntonAleksandrov
    AntonAleksandrov
    55 Posts

    Re: Service Connection Error

    ‏2012-07-23T07:12:12Z  
    Hi,
    I am having exactly same issues. I am hitting RSS reader engadget.com. Works fine from iOS simulator. But fails in Android simulator.
    Here is the error messages logged in LogCat.

    0719/140735:ERROR:entry_impl.cc(904)] Failed to save user data
    07-19 14:07:36.476: E/Web Console(629): XMLHttpRequest cannot load http://127.0.0.1:40403/8f364b03-9cc6-48a0-9b33-34f4b4409504. Origin null is not allowed by Access-Control-Allow-Origin. at null:1
    07-19 14:07:36.586: E/Web Console(629): XMLHttpRequest cannot load http://192.168.1.5:8080/apps/services/reach. Origin null is not allowed by Access-Control-Allow-Origin. at null:1
    07-19 14:07:49.856: E/EngadgetReader(629): Client init failed. Connection to the service is not available.

    Any thoughts?

    Thanks,
    Purush
    First of all - you shouldn't specify localhost(==127.0.0.1) as your Worklight server URL. localhost is LOCAL host. It means that when application is running on Android device it will try to connect to itself and clearly fail. You need to specify an IP address of a machine running Worklight server and make sure that this IP is accessible from handset (e.g. try to open Worklight console from handset's browser)

    Another thing is this behaviour looks like a bug that occasionally occurs on Android 4.1 emulator. Try to use 4.0 emulator, it should fix the issue.
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Service Connection Error

    ‏2012-07-24T18:02:36Z  
    First of all - you shouldn't specify localhost(==127.0.0.1) as your Worklight server URL. localhost is LOCAL host. It means that when application is running on Android device it will try to connect to itself and clearly fail. You need to specify an IP address of a machine running Worklight server and make sure that this IP is accessible from handset (e.g. try to open Worklight console from handset's browser)

    Another thing is this behaviour looks like a bug that occasionally occurs on Android 4.1 emulator. Try to use 4.0 emulator, it should fix the issue.
    I have tried with IP address didn't work. So played with local host. So don't worry about localhost now.

    http://192.168.1.2:8080/console works fine from Android Simulator.

    192.168.1.2 is my workstation IP. I am using Mac OS X 10.7.4

    Here is the issue: Looks like problem with worklight.gadgete.api for Android 4.1.

    Android simulator trying to hit http://192.168.1.2:8080/apps/services/api/EngadgetReader/android/ & failing with following error.
    java.util.NoSuchElementException Caused by: com.worklight.gadgets.GadgetRuntimeException: java.util.NoSuchElementException at com.worklight.gadgets.api.GadgetAPIRequestCoder.decodeGadgetRequestInfo(GadgetAPIRequestCoder.java:212)

    Could IBM folks look into this API issue?

    Thanks
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Service Connection Error

    ‏2012-07-24T18:09:54Z  
    First of all - you shouldn't specify localhost(==127.0.0.1) as your Worklight server URL. localhost is LOCAL host. It means that when application is running on Android device it will try to connect to itself and clearly fail. You need to specify an IP address of a machine running Worklight server and make sure that this IP is accessible from handset (e.g. try to open Worklight console from handset's browser)

    Another thing is this behaviour looks like a bug that occasionally occurs on Android 4.1 emulator. Try to use 4.0 emulator, it should fix the issue.
    Note that i am using HTTP Adapter to make http call to an external RSS reader. This flow works fine with iOS simulator.

    I am also seeing following error in the LogCat.

    E/Web Console(616): XMLHttpRequest cannot load http://192.168.1.2:50198/73c6020f-7727-4e5e-a80f-d2d8451f2c0c. Origin null is not allowed by Access-Control-Allow-Origin. at null:1

    Thanks
    Purush
  • SreeMann
    SreeMann
    1 Post

    Re: Service Connection Error

    ‏2012-08-31T14:55:23Z  
    Even when I try to invoke a static page using JQMobile I am getting this error. There is not adapter or server connection. All the transactions happen locally.
    Everything works perfectly fine on ios simulator and ios device, But I get this error on adroid emulator

    08-31 10:43:30.492: E/Web Console(700): XMLHttpRequest cannot load file:///data/data/com.ControlsDemo/files/www/default/Camera.html. Origin null is not allowed by Access-Control-Allow-Origin. at null:1

    Camera.html is just a static page. I am calling this page using $.mobile.changePage(Camera.html). Both the invoking page and this page are in the same folder.
  • qcduong
    qcduong
    30 Posts

    Re: Service Connection Error

    ‏2012-09-02T10:47:42Z  
    • SreeMann
    • ‏2012-08-31T14:55:23Z
    Even when I try to invoke a static page using JQMobile I am getting this error. There is not adapter or server connection. All the transactions happen locally.
    Everything works perfectly fine on ios simulator and ios device, But I get this error on adroid emulator

    08-31 10:43:30.492: E/Web Console(700): XMLHttpRequest cannot load file:///data/data/com.ControlsDemo/files/www/default/Camera.html. Origin null is not allowed by Access-Control-Allow-Origin. at null:1

    Camera.html is just a static page. I am calling this page using $.mobile.changePage(Camera.html). Both the invoking page and this page are in the same folder.
    Just curious if you have attempted to use 4.0 emulator or a real device per the suggestion from Anton to see what the result is?
  • IdanAdar
    IdanAdar
    741 Posts

    Re: Service Connection Error

    ‏2012-09-03T04:31:07Z  
    Hi,

    Could it be that you are actually running Android 4.1.1 Jelly Bean? We have identified a change that was on Google's part that MAY break things on the Worklight end.
    It is currently being investigated.

    If that is indeed the case, you have a couple of options:
    1. Try a previous version, say 4.1

    2. You can try this workaround:

    Add this line to the main class that extends WLDroidGap:
    this.appView.getSettings().setAllowUniversalAccessFromFileURLs (true);

    public class test extends WLDroidGap {
        @Override
        public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           this.appView.getSettings().setAllowUniversalAccessFromFileURLs (true);

           //DeviceAuthManager.getInstance().setProvisioningDelegate(<Use default ProvisioningDelegateImpl class or replace with your IProvisioningDelegate implementation>);
           super.loadUrl(getWebMainFilePath());
        }        
    }

    Explenation:
    http://developer.android.com/reference/android/webkit/WebSettings.html#setAllowFileAccessFromFileURLs(boolean (http://developer.android.com/reference/android/webkit/WebSettings.html#setAllowFileAccessFromFileURLs%28boolean))

    public abstract void setAllowUniversalAccessFromFileURLs (boolean flag)

    Since: API Level 16
    Sets whether JavaScript running in the context of a file scheme URL should be allowed to access content from any origin. This includes access to content from other file scheme URLs. See setAllowFileAccessFromFileURLs(boolean). To enable the most restrictive, and therefore secure policy, this setting should be disabled.

    The default value is true for API level ICE_CREAM_SANDWICH_MR1 and below, and false for API level JELLY_BEAN and above.

    Parameters
    flag    whether JavaScript running in the context of a file scheme URL should be allowed to access content from any origin

    Idan Adar
    QA Engineer
    IBM Worklight Mobile Platform