2

I have a project made with Eclipse, Maven and Retrofit 1.3. I wanted to migrate to Android Studio and I had to import in gradle Retrofit 2.0.

After I made all the changes necessary to make it work, I am getting something unexpected.

I have my retrofit builder set like this:

Retrofit.Builder builder = new Retrofit.Builder()
                .baseUrl("http://localhost:8080/openbravo/org.openbravo.service.json.jsonrest")
                .client(httpClient)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create(gson));

So my service methods were changed to use <Call<List<T>> instead of just List<T>

When I execute a GET Method to login I get this response error:

Response{protocol=http/1.1, code=404, message=Not Found, url=http://localhost:8080/ADUser?_where=username%3D%27Openbravo%27}

But the url is supposed to be:

http://localhost:8080/openbravo/org.openbravo.service.json.jsonrest/ADUser?_where=username%3D%27Openbravo%27

Can anyone tell me why? I have no idea what is going on... This worked perfect on 1.3

Carlos Andres
  • 89
  • 2
  • 14

2 Answers2

2

You need to add a trailing / at the end of your base url. Otherwise retrofit ignores it. See https://github.com/square/retrofit/issues/1049.

Retrofit.Builder builder = new Retrofit.Builder()
                .baseUrl("http://localhost:8080/openbravo/org.openbravo.service.json.jsonrest/")
                .client(httpClient)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create(gson));
iagreen
  • 31,470
  • 8
  • 76
  • 90
0

You can,

Make your base url to http://localhost:8080

and in your controller class,

public interface RestController {

    @GET("/openbravo/org.openbravo.service.json.jsonrest/ADUser")
    Whatever getData(@Path("_where") String whatever);

}
diyoda_
  • 5,274
  • 8
  • 57
  • 89
  • It's what I was trying to avoid but its the only solution I see right now... thanks – Carlos Andres Oct 16 '15 at 14:09
  • @CarlosAndres: In Retrofit2 you need to add the trailing `/` in the end of your base url. Moreover, if you have the `/` in the beginning of the relative url, the url will be prepended with server root url instead of any api version or relative url. You can see this answer from Jake: http://stackoverflow.com/questions/32352159/retrofit-2-removes-characters-after-hostname-from-base-url – ninjahoahong Mar 29 '16 at 13:28