Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Retrofit nao consegue fazer o login em uma pagina de login do Spring security

Link do webService: https://github.com/Irvayne/webServiceEstoque

na aplicação android a classe RetrofitInicializador

 private final Retrofit retrofit;

    public RetrofitInializador(){
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient.Builder client = new OkHttpClient.Builder();
        client.addInterceptor(interceptor);


        retrofit = new Retrofit.Builder().baseUrl("http://10.0.0.11:8080/webServiceEstoque/")
                .addConverterFactory(GsonConverterFactory.create()).client(client.build()).build();


    }

    public ProdutoService getProdutoService() {
        return retrofit.create(ProdutoService.class);
    }

    public LocalizacaoService getLocalizacaoService() {
        return retrofit.create(LocalizacaoService.class);
    }

    public LoteService getLoteService() {
        return retrofit.create(LoteService.class);
    }

    public LoginLogoutService getLoginLogoutService() {
        return retrofit.create(LoginLogoutService.class);
    }

A classe LoginLogoutService

 @FormUrlEncoded
    @POST("login")
    Call<String> login(@Field("username") String username, @Field("password") String password);

Chamo dessa forma na Activity de login


                String username = email;
                Call<String> call = new RetrofitInializador().getLoginLogoutService().login(username,password);

                call.enqueue(new Callback<String>() {
                    @Override
                    public void onResponse(Call<String> call, Response<String> response) {
                        String resposta = response.body();
                        Log.e("Login-TESTE",resposta);

                    }

                    @Override
                    public void onFailure(Call<String> call, Throwable t) {
                        Log.e("Login","deu erro");

                    }
                });

e recebo o seguinte erro

11-05 19:07:01.425 11963-12022/pitstop.com.br.pitstop D/OkHttp: --> POST http://10.0.0.11:8080/webServiceEstoque/login http/1.1
11-05 19:07:01.425 11963-12022/pitstop.com.br.pitstop D/OkHttp: Content-Type: application/x-www-form-urlencoded
11-05 19:07:01.427 11963-12013/pitstop.com.br.pitstop V/FA: Activity resumed, time: 16235425
11-05 19:07:01.427 11963-12022/pitstop.com.br.pitstop D/OkHttp: Content-Length: 29
11-05 19:07:01.428 11963-12022/pitstop.com.br.pitstop D/OkHttp: username=wilson&password=1234
11-05 19:07:01.429 11963-12022/pitstop.com.br.pitstop D/OkHttp: --> END POST (29-byte body)
11-05 19:07:01.543 11963-12022/pitstop.com.br.pitstop D/OkHttp: <-- 200  http://10.0.0.11:8080/webServiceEstoque/login (112ms)
11-05 19:07:01.543 11963-12022/pitstop.com.br.pitstop D/OkHttp: X-Content-Type-Options: nosniff
11-05 19:07:01.543 11963-12022/pitstop.com.br.pitstop D/OkHttp: X-XSS-Protection: 1; mode=block
11-05 19:07:01.543 11963-12022/pitstop.com.br.pitstop D/OkHttp: Cache-Control: no-cache, no-store, max-age=0, must-revalidate
11-05 19:07:01.543 11963-12022/pitstop.com.br.pitstop D/OkHttp: Pragma: no-cache
11-05 19:07:01.543 11963-12022/pitstop.com.br.pitstop D/OkHttp: Expires: 0
11-05 19:07:01.543 11963-12022/pitstop.com.br.pitstop D/OkHttp: X-Frame-Options: DENY
11-05 19:07:01.543 11963-12022/pitstop.com.br.pitstop D/OkHttp: Content-Type: text/html;charset=UTF-8
11-05 19:07:01.543 11963-12022/pitstop.com.br.pitstop D/OkHttp: Content-Length: 482
11-05 19:07:01.543 11963-12022/pitstop.com.br.pitstop D/OkHttp: Date: Sun, 05 Nov 2017 19:07:02 GMT
11-05 19:07:01.545 11963-12022/pitstop.com.br.pitstop D/OkHttp: <html><head><title>Login Page</title></head><body onload='document.f.username.focus();'>
11-05 19:07:01.545 11963-12022/pitstop.com.br.pitstop D/OkHttp: <h3>Login with Username and Password</h3><form name='f' action='/webServiceEstoque/login' method='POST'>
11-05 19:07:01.545 11963-12022/pitstop.com.br.pitstop D/OkHttp:  <table>
11-05 19:07:01.545 11963-12022/pitstop.com.br.pitstop D/OkHttp:     <tr><td>User:</td><td><input type='text' name='username' value=''></td></tr>
11-05 19:07:01.545 11963-12022/pitstop.com.br.pitstop D/OkHttp:     <tr><td>Password:</td><td><input type='password' name='password'/></td></tr>
11-05 19:07:01.545 11963-12022/pitstop.com.br.pitstop D/OkHttp:     <tr><td colspan='2'><input name="submit" type="submit" value="Login"/></td></tr>
11-05 19:07:01.546 11963-12022/pitstop.com.br.pitstop D/OkHttp:   </table>
11-05 19:07:01.546 11963-12022/pitstop.com.br.pitstop D/OkHttp: </form></body></html>
11-05 19:07:01.546 11963-12022/pitstop.com.br.pitstop D/OkHttp: <-- END HTTP (482-byte body)
11-05 19:07:01.775 11963-11963/pitstop.com.br.pitstop E/Login-TESTE: <html><head><title>Login

Por que está retornado a pagina web?

3 respostas

Quando eu coloco login e senha errada é retornado a pagina com a exceção que informa bad credential, mas quando eu coloco login certo ele simplesmente me retorna a pagina de login. fui debugar no webservice e chega uma hora que ele para e nao redireciona para a pagina que ele deveria redirecionar. Se eu fizer esse processo pela pagina web funciona normalmente mas se eu fizer uma requisição pelo android nao funciona. Fiz teste e vi que o login chega no servidor e passa pela metodo onAuthenticationSuccess.

ALGUEM PODE AJUDAR????

solução!

Oi Irvayne, tudo bem? Olha, vi que você duplicou o tópico e eu queria pedir para que, por favor, não faça isso, temos um time que está diariamente verificando as perguntas e respondendo o mais rápido possível.

Esse time considera prioridade as perguntas mais antigas, então ficar criando tópicos novos pode atrapalhar e ainda levar mais tempo para ser respondido, justamente por ser um tópico mais novo.

vou deixar o link do outro tópico aqui para que os alunos possam acompanhar, caso queiram: https://cursos.alura.com.br/forum/topico-retrofit-nao-consegue-fazer-login-no-formulario-de-login-do-spring-security-49184