My AngularJS front-end is connected to the backend using Restangular and a Java Servlet, which returns JSON data that is parsed to create a chart with Charts.js
Angular Factory
app.factory('graphService', function($http, Restangular) {
var exports = {};
exports.getRestangular = function() {
return Restangular.setBaseUrl("/apm/graph");
};
exports.getGraphDataDC = function(dcName) {
return exports.getRestangular().all("graphData/DC/" + dcName).getList();
};
}
Angular UI RestangularCall
graphService.getGraphDataDC(item.name).then(function (data) {
$scope.summary = data;
$scope.JSONtoArrays(data);
console.log(data);
$scope.createChart();
}, function(data) {
//Error
});
Java Servlet
try
{
dcData = persistance.getSummaryDelaysDC80Perc(from, to, pathInfo[pathInfo.length-1]);
} catch(RuntimeException e) {
LOGGER.error("Could not load data form database, reason: {}", e);
throw new ServletException(e);
}
json = ThreadsafeUtils.getGsonInstance(pretty).toJson(dcData);
LOGGER.debug(dcData.size() + " summary entries were read");
out.write(json);
break;
}
Persistence Facade This function is called by the Servlet
public List<SummaryDelaysDataCenter80Perc> getSummaryDelaysDC80Perc(Date from, Date to, String dcName) throws RuntimeException {
List<SummaryDelaysDataCenter80Perc> result = new ArrayList<>();
Calendar c = Calendar.getInstance(Locale.GERMANY);
java.sql.Date minDate;
java.sql.Date maxDate;
String call;
if (from != null)
minDate = new java.sql.Date(from.getTime());
else
minDate = Utils.getDBMinDate();
if (to != null) {
maxDate = new java.sql.Date(to.getTime());
} else {
maxDate = Utils.getDBMaxDate();
}
call = "CALL " + summaryDelaysDCProcedureName + "(?, ?, ?, ?)";
try {
java.sql.Connection connection = em.unwrap(java.sql.Connection.class);
java.sql.CallableStatement cst = connection.prepareCall(call);
cst.setDate(1, minDate, c);
cst.setDate(2, maxDate, c);
cst.setString(3, dcName);
cst.execute();
ResultSet rs = cst.getResultSet();
while (rs.next()) {
SummaryDelaysDataCenter80Perc sdeldc80 = new SummaryDelaysDataCenter80Perc();
DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY);
String strDate = dateFormat.format(rs.getTimestamp(1));
sdeldc80.setName(rs.getString(2));
sdeldc80.setDate(strDate);
sdeldc80.setPerc80serverdelay(Double.toString(rs.getDouble(3)));
sdeldc80.setPerc80networkdelay(Double.toString(rs.getDouble(4)));
sdeldc80.setPerc80clientdelay(Double.toString(rs.getDouble(5)));
sdeldc80.setPerc80roundtrips(Long.toString(rs.getLong(6)));
result.add(sdeldc80);
}
} catch (java.sql.SQLException e) {
throw new RuntimeException("StoredProcedureCall was not successful", e);
}
return result;
}
The converted JSON data looks like:
[{"Name" : "WER", "Count" : 90, "Date": "2016-05-25" },
{"Name" : "TWK", "Count" : 17, "Date": "2016-05-26" },
{"Name" : "XPR", "Count" : 26, "Date": "2016-05-27" }]
Although the Java Servlet code runs without errors, there is an issue when assigning values to $scope.summary
, resulting in an error related to JSON parsing.
The JSON string's length is 1367 characters, but the error message points to position 1367, causing confusion.
How can I investigate and resolve this JSON parsing error?