strongloop-community / loopback-sdk-android

Android Client SDK for the LoopBack framework.
Other
67 stars 41 forks source link

loginUser problem #105

Closed paranoiasystem closed 8 years ago

paranoiasystem commented 8 years ago

I'm developing an application that uses the Android SDK of Loopback for make REST requests. I have an issue when i try to login a user, I receive that error

08-03 10:44:21.149 12375-12375/com.marcoferraioli.loopback E/Chatome: Login E org.apache.http.client.HttpResponseException: Not Found at com.loopj.android.http.AsyncHttpResponseHandler.sendResponseMessage(AsyncHttpResponseHandler.java:404) at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:161) at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:178) at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:109) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) at java.util.concurrent.FutureTask.run(FutureTask.java:237) 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)

I have create User class

package com.marcoferraioli.loopback;

public class User extends com.strongloop.android.loopback.User {
}

and UserRepository class

package com.marcoferraioli.loopback;

public class UserRepository extends com.strongloop.android.loopback.UserRepository<User> {

    public interface LoginCallback extends com.strongloop.android.loopback.UserRepository.LoginCallback<User> {
        }

    public UserRepository() {
        super("admin", null, User.class);
    }

}

this is MainActivity


package com.marcoferraioli.loopback;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.strongloop.android.loopback.AccessToken;
import com.strongloop.android.loopback.RestAdapter;
import com.strongloop.android.loopback.callbacks.ListCallback;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    private TextView textProva;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textProva = (TextView) findViewById(R.id.prova);

        RestAdapter adapter = new RestAdapter(getApplicationContext(), "http://********:3000/api");

        OperaRepository operaRepository = adapter.createRepository(OperaRepository.class);

        operaRepository.findAll(new ListCallback<Opera>(){ //This work
            @Override
            public void onSuccess(List<Opera> objects) {
                for (Opera opera : objects){
                    textProva.append("\n" + opera.toString());
                }
            }

            @Override
            public void onError(Throwable t) {
                Log.e("Error", "findAll", t);
            }
        });

        UserRepository userRepo = adapter.createRepository(UserRepository.class);

        userRepo.loginUser("super@admin.it" , "superadmin" , new UserRepository.LoginCallback() {
            @Override
            public void onSuccess(AccessToken token, User currentUser) {
                textProva.append("\n" + token.getUserId() + ":" + currentUser.getId());
            }

            @Override
            public void onError(Throwable t) {
                Log.e("Chatome", "Login E", t);
            }
        });

    }
}

How I fix this issue?

paranoiasystem commented 8 years ago

I have resolve this problem, I have wrong in the UserRepository class, this is the correct code:

package com.marcoferraioli.loopback;

public class UserRepository extends com.strongloop.android.loopback.UserRepository<User> {

    public interface LoginCallback extends com.strongloop.android.loopback.UserRepository.LoginCallback<User> {
        }

    public UserRepository() {
        super("user", null, User.class);
    }

}

In the constructor the first parameter is the name of model.