0

I have a WS REST, that I need to consume by POST, which method "calculo" expects a XML as below in the key "xmlEntrada".

<xml>
  <valor1/>
  <valor2/>
  <operacao/>
</xml>

I did the corresponding class to serialize, as expected by retrofit and SimpleXmlConverter

@Root(name="xml")
public class CalcRequest {
    public CalcRequest(){
        campo1 = campo2 = 0;
        operacao = "";
    }

    @Element(name="valor1", required = false)
    private float campo1;

    @Element(name="valor2", required = false)
    private float campo2;

    @Element(name="operador", required = false)
    private String operacao;
}

And I'm calling retrofit and all the stuff like this:

Retrofit retrofit = new Retrofit.Builder()
        .baseUrl("http://server_name/wsRest/Project1.dll/")
        .addConverterFactory(SimpleXmlConverterFactory.create())
        .client(new OkHttpClient())
        .build();

APIService API = retrofit.create(APIService.class);

Call<CalcResponse> call = API.EfetuaCalculo(calculo);
call.enqueue(new Callback<CalcResponse>() {
    @Override
    public void onResponse(Call<CalcResponse> call, Response<CalcResponse> response) {
        AlertMessage(response.body().retorno());
    }

    @Override
    public void onFailure(Call<CalcResponse> call, Throwable t) {
        AlertMessage("Error. MSG: " + t.toString());
    }
});

My method response serialization is fine, because I can read the error returned as XML, and it shows me that the request xml is arriving empty at the WS. I'm stucked on that by days, can anyone guess what's wrong?

Oh, here it's my APIService code:

public interface APIService {
    @POST("calculo")
    Call<CalcResponse> EfetuaCalculo(@Body CalcRequest xmlEntrada);
}
Jean Vitor
  • 893
  • 1
  • 18
  • 24
  • Did you see log? if not, I recommend you to try .http://stackoverflow.com/a/33256827/5183999 – nshmura Aug 13 '16 at 00:19
  • when I add the interceptor, the retrofit method "enqueue" gives me FATAL EXCEPTION, like this: FATAL EXCEPTION: OkHttp Dispatcher Process: com.example.romulogatto.calculadora, PID: 3555 java.lang.NoSuchMethodError: No virtual method log(Ljava/lang/String;)V in class Lokhttp3/internal/Platform; or its super classes (declaration of 'okhttp3.internal.Platform' appears in /data/data/com.example.romulogatto.calculadora/files/instant-run/dex/ – Rômulo Gatto Aug 16 '16 at 21:11

0 Answers0