I have some troubles when I recieve the json data from my application in app engine, some cases I recieve the json empty and in the log viewer of my application appears the following
2014-07-03 16:46:21.193 /service/concentraciondeptos/ 400 43ms 0kb Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 module=default version=2
181.48.97.68 - - [03/Jul/2014:14:46:21 -0700] "GET /service/concentraciondeptos/ HTTP/1.1" 400 146 - "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36" "Instance ID" ms=44 cpu_ms=80 cpm_usd=0.000016 app_engine_release=1.9.6 trace_id=e2164f3bbeb2302c384164569b22b8dd
and here's my code
package com.servinfo.services.controller;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.servinfo.database.Manager;
import com.servinfo.services.AbstractController;
import com.servinfo.services.entity.ResponseObject;
import com.servinfo.services.entity.afe.ConcentracionDeptos;
@Controller
@RequestMapping("service/concentraciondeptos/*")
public class ConcentracionDeptosController {
// private static final Logger log = Logger.getLogger("AreaTController");
protected final static String RESPONSE_FORMAT = "application/json";
private final static String GET = "";
private static String STATE = "";
private static String MESSAGE = "";
@RequestMapping(value = GET, method = RequestMethod.GET, produces = RESPONSE_FORMAT)
public @ResponseBody
ResponseEntity<ResponseObject> getPoint() {
if (getData().isEmpty()) {
STATE = "ERROR";
MESSAGE = ResponseObject.MSG_EMPTY;
}
// log.warning("Servicio areat");
ResponseObject response = new ResponseObject(STATE, MESSAGE, getData());
if (response.getStatus().equals("OK")) {
return new ResponseEntity<ResponseObject>(response,
AbstractController.getHeader(), HttpStatus.OK);
}
return new ResponseEntity<ResponseObject>(response,
AbstractController.getHeader(), HttpStatus.BAD_REQUEST);
}
public List<ConcentracionDeptos> getData() {
STATE = "ERROR";
MESSAGE = ResponseObject.MSG_ERROR;
int intContador = 0;
List<ConcentracionDeptos> result = new ArrayList<ConcentracionDeptos>();
try {
String sql = "select depto.coddane "
+ ""
+ "from departamentos as depto, proyecto as p, aporte_depto as apdepto,"
+ "aporte_muni as apomuni, ciudades as ciu"
+ " "
+ "where apdepto.nit = p.nit and apdepto.id_proyecto = p.id "
+ "and apdepto.coddane_depto = depto.coddane and apomuni.nit = p.nit "
+ "and apomuni.id_proyecto = p.id and apomuni.coddane_ciudad = ciu.coddane";
Manager mng = new Manager();
ResultSet rs = mng.executeQuery(sql);
if (rs.first()) {
rs.beforeFirst();
STATE = "OK";
MESSAGE = ResponseObject.MSG_SUCCESS;
} else {
Thread.sleep(200);
rs = mng.executeQuery(sql);
if (rs.first()) {
rs.beforeFirst();
STATE = "OK";
MESSAGE = ResponseObject.MSG_SUCCESS;
} else {
STATE = "ERROR";
MESSAGE = ResponseObject.MSG_ERROR;
}
}
ConcentracionDeptos obEntity = new ConcentracionDeptos();
while (rs.next()) {
intContador++;
obEntity.setCoddane(rs.getString("coddane"));
}
obEntity.setCantidadP(Integer.toString(intContador));
result.add(obEntity);
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
when I execute the sql command in mysql I retrieve the correct information. and here's th connection code
import java.sql.*;
import com.google.appengine.api.utils.SystemProperty;
public class Manager {
public ResultSet executeQuery(String sql){
try{
String url = null;
if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
Class.forName("com.mysql.jdbc.GoogleDriver");
url = "jdbc:google:mysql://ID:App ID/DB?user=root";
} else {
Class.forName("com.mysql.jdbc.Driver");
url = "jdbc:mysql://IP:3306/afe_services?user=root&password=****";
}
Connection conn = DriverManager.getConnection(url);
ResultSet rs = conn.createStatement().executeQuery(sql);
return rs;
}catch(Exception e){
e.printStackTrace();
}
return null;
}
}
what I'm doing bad?
Thanks.