【发布时间】:2016-08-30 04:09:33
【问题描述】:
我在这些代码行中找不到语义错误的位置:
PuntoGpsRecorridoDTO puntoGpsRecorridoDto = new PuntoGpsRecorridoDTO();
puntoGpsRecorridoDto.setDescripcion(puntoGpsRecorrido.getDescripcion());
puntoGpsRecorridoDto.setIdRecorrido(37);
puntoGpsRecorridoDto.setDemoraSeg(2);
puntoGpsRecorridoDto.setPrecisionMts(10);
puntoGpsRecorridoDto.setEstado(puntoGpsRecorrido.getEstado());
puntoGpsRecorridoDto.setFechaHora(puntoGpsRecorrido.getFechaHora());
puntoGpsRecorridoDto.setIdDispositivo("943953977-OFICINA");
puntoGpsRecorridoDto.setLatitud(puntoGpsRecorrido.getLatitud());
puntoGpsRecorridoDto.setLongitud(puntoGpsRecorrido.getLongitud());
puntoGpsRecorridoDto.setPrecisionMts(puntoGpsRecorrido.getPrecisionMts());
Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonDateDeserializer()).create();
Retrofit retrofit = new Retrofit.Builder().baseUrl(Util.URL_WS).addConverterFactory(GsonConverterFactory.create(gson)).build();
LocationService locationService = retrofit.create(LocationService.class);
Call<EstadoDTO> callEstadoDto = locationService.enviarPuntoGpsRecorrido(puntoGpsRecorridoDto);
Response<EstadoDTO> exec = callEstadoDto.execute();
estadoDto = exec.body(); // <<<------ body() return NULL
改造客户端的LocationService接口:
public interface LocationService
{
@POST("recorrido/sending")
Call<EstadoDTO> enviarPuntoGpsRecorrido(@Body PuntoGpsRecorridoDTO puntoGpsRecorridoDto);
}
连接到服务? ---> 是的,
它以另一种方式工作? --> 是的,通过 SoapUI 测试,
服务器? ---> Apache tomcat + Mysql + Hibernate
PuntoGpsRecorridoDTO 类:
public class PuntoGpsRecorridoDTO
{
private Integer idRecorrido;
private String idDispositivo;
private Double latitud;
private Double longitud;
private Boolean estado;
private String descripcion;
private Integer precisionMts;
private Integer demoraSeg;
private Date fechaHora;
public PuntoGpsRecorridoDTO()
{
}
}
PuntoGpsRecorrido 类:
@DatabaseTable(tableName = "PuntoGpsRecorrido")
public class PuntoGpsRecorrido
{
@DatabaseField(generatedId = true)
private Integer idRecorrido;
@DatabaseField(foreign = true, canBeNull = false)
private Dispositivo dispositivo;
@DatabaseField
private Double latitud;
@DatabaseField
private Double longitud;
@DatabaseField
private Boolean estado;
@DatabaseField
private String descripcion;
@DatabaseField
private Integer precisionMts;
@DatabaseField
private Integer demoraSeg;
@DatabaseField
private Date fechaHora;
public PuntoGpsRecorrido()
{}
}
EstadoDTO 类:
public class EstadoDTO
{
public static final String EXITO="001";
public static final String ERROR="000";
private String code;
private String msg;
private String extra;
public EstadoDTO()
{}
}
错误:
用 SoapUI 测试,很顺利:
我做错了什么?如果您需要更多信息,请告诉我 信息需求。提前致谢。
【问题讨论】:
-
响应中的 httpstatus 代码是什么?我想知道它不在 200~300 范围内
-
感谢 Long Ranger,httpstatus 代码是:500 内部服务器错误。
-
body()函数只有在http状态码在200~300范围内才会返回结果。在这里查看我的答案stackoverflow.com/questions/39097680/…
-
我明白了,但是如果一切顺利,服务器会返回 500?不管怎样,你知道我在哪里可以看到 Apache Tomcat 中该错误的详细信息吗?
-
您应该检查 apache 主位置中的日志文件夹。如果有任何错误并且您有用于登录 Web 应用程序的代码,则日志文件应该在其中。 errorBody 是否包含您需要的所有信息?
标签: android tomcat android-studio retrofit retrofit2