404 when trying to access url post with springboot

0

Good evening, I have the code below with the implementation of a service rest / test123, and when calling this method from the angular-js code, already authenticated with the basic spring-boot authentication I have access to this service. When I try to access it from the retrofit2 of my android or the chrome postman extension, the two give 404 error. Someone tells me what I'm doing wrong. Just to make it clear that I'm pointing to the correct ip of the pc which is 192.168 .... and not to localhost at the time of the calls. Thank you.

@RestController
public class TesteController {
@RequestMapping(value = "/teste123", method = RequestMethod.POST)
public Programa gravaLote2(@RequestBody Programa programa) {
    System.out.println(programa);
    return new Programa();
} 
}

Below is the example of angled-js code that works.

$http.post("/teste123", {id: 'asd', txtPrograma: 'adsadasd'})
        .then(function (response) {
            console.log(response);
        }, function (response) {
            console.log(response);
        })

Here is the interface I used on android.

public interface ExecucaoService {

@POST("teste123")
public Call<Programa> gravaLote(@Body Programa programa);}

And to add the credentials in the retrofit header I did as follows.

        private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
private static Retrofit.Builder builder =
        new Retrofit.Builder()
                .baseUrl(baseUrlWS)
                .addConverterFactory(GsonConverterFactory.create());
        String credentials = username + ":" + password;
        final String basic = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);

        httpClient.addInterceptor(new Interceptor() {
            @Override
            public okhttp3.Response intercept(Interceptor.Chain chain) throws IOException {
                Request original = chain.request();

                Request.Builder requestBuilder = original.newBuilder()
                        .header("Authorization", basic)
                        .header("Accept", "application/json")
                        .method(original.method(), original.body());
                Request request = requestBuilder.build();
                return chain.proceed(request);
            }
        });
      OkHttpClient client = httpClient.build();
    Retrofit retrofit = builder.client(client).build();
    // retrofit.create(serviceClass); aqui pego a instancia do serviço criada.

here is the image showing the success of the angular on the left and the problem on the right.

I still have hope that it is not a retrofit or a postman problem, but a configuration I did not do in sptring-boot.

    
asked by anonymous 25.09.2016 / 01:14

1 answer

0

According to the spring-boot documentation, for you to create a basic web application, you only need the spring-boot parent and the spring-boot-starter-web dependency. The most common error that occurred to me at the beginning of my spring-boot apprenticeship was in relation to the wrong header that was sent in the request, but that caused me a 400 or 405. I do not have much experience with android but as far as I could Note that this code snippet (@POST ("execution / gravelLote")) indicates that you are sending a post to the executing / gravelLote address and that it may be causing the 404 error because its address is / test123. I hope I have helped!

    
26.09.2016 / 16:44