8

I am trying to build an Application with offline sync and followed the tutorial on Azure

Now the offline storage works well, but no items are added to on the server with the following exception:

       Error syncAsync com.microsoft.windowsazure.mobileservices.table.sync.push.MobileServicePushFailedException
 java.util.concurrent.ExecutionException: com.microsoft.windowsazure.mobileservices.table.sync.push.MobileServicePushFailedException
     at com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:299)
     at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:286)
     at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:116)
     at irisrecognition.example.com.irisrecognition.util.ItemManager$5.doInBackground(ItemManager.java:237)
     at irisrecognition.example.com.irisrecognition.util.ItemManager$5.doInBackground(ItemManager.java:232)
     at android.os.AsyncTask$2.call(AsyncTask.java:288)
     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
     at java.lang.Thread.run(Thread.java:818)
 Caused by: com.microsoft.windowsazure.mobileservices.table.sync.push.MobileServicePushFailedException
     at com.microsoft.windowsazure.mobileservices.table.sync.MobileServiceSyncContext.pushOperations(MobileServiceSyncContext.java:939)
     at com.microsoft.windowsazure.mobileservices.table.sync.MobileServiceSyncContext.consumePushSR(MobileServiceSyncContext.java:834)
     at com.microsoft.windowsazure.mobileservices.table.sync.MobileServiceSyncContext.access$1100(MobileServiceSyncContext.java:85)
     at com.microsoft.windowsazure.mobileservices.table.sync.MobileServiceSyncContext$PushSyncRequestConsumer.run(MobileServiceSyncContext.java:1127)

Here is the code for onCreate()

  try {
        mClient = new MobileServiceClient(
                Constants.ROOT_URL,
                "kfogvaexzeDLYyPbRmBiHxQEBUYpku30",
                this).withFilter(new ProgressFilter());

        initLocalStore().get();
        syncAsync();
        refreshItemsFromTable();

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

and some more...

private AsyncTask<Void, Void, Void> initLocalStore() throws MobileServiceLocalStoreException, ExecutionException, InterruptedException {

        AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... params) {
                try {
                    mPullQuery = mClient.getTable(IrisEntry.class).where().orderBy("__createdAt", QueryOrder.Descending);

                    MobileServiceSyncContext syncContext = mClient.getSyncContext();
                    SQLiteLocalStore localStore = new SQLiteLocalStore(mClient.getContext(), "OfflineStore", null, 1);
                    SimpleSyncHandler handler = new SimpleSyncHandler();

                    Map<String, ColumnDataType> tableDefinition = new HashMap<String, ColumnDataType>();
                    tableDefinition.put("id", ColumnDataType.String);
                    tableDefinition.put("text", ColumnDataType.String);
                    tableDefinition.put("device", ColumnDataType.String);
                    tableDefinition.put("segmentationAlgo", ColumnDataType.String);
                    tableDefinition.put("imageUri", ColumnDataType.String);
                    tableDefinition.put("containerName", ColumnDataType.String);
                    tableDefinition.put("resourceName", ColumnDataType.String);
                    tableDefinition.put("sasQueryString", ColumnDataType.String);
                    tableDefinition.put("userId", ColumnDataType.String);
                    tableDefinition.put("complete", ColumnDataType.Boolean);

                    localStore.defineTable(Constants.TABLE_IRIS, tableDefinition);
                    syncContext.initialize(localStore, handler).get();

                    mIrisTable = mClient.getSyncTable(IrisEntry.class);
                } catch (final Exception e) {
                    e.printStackTrace();
                }

                return null;
            }
        };

        return runAsyncTask(task);
    }


 public void syncAsync() {
        if (isNetworkAvailable()) {
            new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                    try {
                        mClient.getSyncContext().push().get();
                        mIrisTable.pull(mPullQuery).get();
                        Log.e(LOGTAG, "Success syncAsync");

                    } catch (Exception e) {
                        Log.e(LOGTAG, "Error syncAsync " + e.getMessage());
                        e.printStackTrace();

                    }
                    return null;
                }
            }.execute();
        } else {
            Log.e(LOGTAG, "You are not online, re-sync later!");
        }
    }

    private boolean isNetworkAvailable() {
        ConnectivityManager connectivityManager
                = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        return activeNetworkInfo != null && activeNetworkInfo.isConnected();
    }

Permissions for my table are set to allow with Application Key. Any ideas?

EDIT:

This appears in the log file on the server:

ERROR
{ [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
4ndro1d
  • 2,926
  • 7
  • 35
  • 65

2 Answers2

0

I am not sure if this is the answer but does "Constants.ROOT_URL" include the protocol header string like "http://myurl.com" ? The ENOTFOUND error means the address of the getaddrinfo call was not able to be resolved. Youmay want to try "myurl.com", without the protocol portion of the URI. Also the method requires a class type Uri for the argument. It looks like you might be getting the stack trace from the MalformedURIException handler. (The call is probably using https even if you specified something else).

bobwilmes
  • 64
  • 6
0

As far as I figured it out, the problem is that my tables are set to Anonmyous Access. I set them to Authenticated Only and sync was working fine again. Anyways I want some tables to be accessed without authentication (read by all users) and gonna check if I can fix that somehow

4ndro1d
  • 2,926
  • 7
  • 35
  • 65