0

Im checking how RetroFit works and tried the following:

RestClient:

public class RestClient {

    private static TaskService REST_CLIENT;
    private static String ROOT =
            "URL";
    static {
        setupRestClient();
    }

    private RestClient() {}

    public static TaskService get() {
        return REST_CLIENT;
    }

    private static void setupRestClient() {
        OkHttpClient OkHttpClient=new OkHttpClient();

        RestAdapter.Builder builder = new RestAdapter.Builder()
                .setEndpoint(ROOT)
                .setClient(new OkClient(new OkHttpClient()))
        .setConverter(new SimpleXmlConverter());
        builder.setLogLevel(RestAdapter.LogLevel.FULL);
        RestAdapter restAdapter = builder.build();
        REST_CLIENT = restAdapter.create(TaskService.class);
    }
}

In Activity:

public void testMethod()
    {
        User user=new User("58","345435","4","","0");
        RestClient.get().getWeather(user,new Callback<String>() {

            @Override
            public void success(String s, Response response) {
                Log.d("testret", "success: " + s);
                Log.d("testret", "successu: " + response.getUrl());
                Log.d("testret", "successs: " + response.getStatus());
            }
            @Override
            public void failure(RetrofitError error)
            {
                Log.d("testret", "errore: " + error);
                Log.d("testret", "erroru: " + error.getUrl());
            }
        });
    }

User:

public class User {



    String FTID,UUID,TYPE,DateTimeStamp,SDFVersionNb;

    public User(String FTID,String UUID,String TYPE,String DateTimeStamp,String SDFVersionNb)
    {
        this.DateTimeStamp=DateTimeStamp;
        this.FTID=FTID;
        this.UUID=UUID;
        this.SDFVersionNb=SDFVersionNb;
        this.TYPE=TYPE;
    }
}

Interface:

public interface TaskService {

    @POST("/GetBulkQueryUpdates")
    void getWeather(@Body User user,
                    Callback<String> callback);
}

the above webservice method returns the follwing:

<ROWS>
<ROW>
<GroupBy>3</GroupBy>
<QUERY>
 Query Statement
</QUERY>
</ROW>
</ROWS>

So i am using the post method to retrieve the above data, but i keep on getting an internal server error 500 each time though when executing the webservice method from the web, data is being retrieved. so the problem is with the code above but i cant figure out what. i tried adding the .setConverter(new SimpleXmlConverter()); after looking at the following URL: Android Retrofit return status 500 internal server error but it was the same.

any help would be appreciated.

Community
  • 1
  • 1
Rashad.Z
  • 2,494
  • 2
  • 27
  • 58

1 Answers1

0

Try this..... Adding a .xml will fix the problem

public interface TaskService {

@POST("/GetBulkQueryUpdates.xml")
void getWeather(@Body User user,
                Callback<String> callback);
}

And ur User class has to be in this format

@Root(name = "breakfast_menu")
public class BreakFastMenu
{
@ElementList(inline = true)
List<Food> foodList;
}

@Root(name="food")
public class Food
{
@Element(name = "name")
String name;

@Element(name = "price")
String price;

@Element(name = "description")
String description;

@Element(name = "calories")
String calories;
}

EDIT 1:

@Root is a annotation and in ur case it should be @Root(name = "ROWS") which is the root element of ur XML

Gowtham Raj
  • 2,915
  • 1
  • 24
  • 38