use of org.codehaus.jackson.map.JsonMappingException in project onebusaway-application-modules by camsys.
the class KeysResource method listKeyDetails.
@Path("/list/{apiKey}")
@GET
@Produces("application/json")
public Response listKeyDetails(@PathParam("apiKey") String apiKey) throws JsonGenerationException, JsonMappingException, IOException {
log.info("Starting listKeyDetails");
try {
validateSecurity();
UserIndexKey key = new UserIndexKey(UserIndexTypes.API_KEY, apiKey);
UserIndex userIndex = _userService.getUserIndexForId(key);
if (userIndex == null)
throw new Exception("API key " + apiKey + " not found (userIndex null).");
User user = userIndex.getUser();
UserBean bean = _userService.getUserAsBean(user);
Map<String, String> result = new HashMap<String, String>();
result.put("keyValue", apiKey);
result.put("contactName", bean.getContactName());
result.put("contactCompany", bean.getContactCompany());
result.put("contactEmail", bean.getContactEmail());
result.put("contactDetails", bean.getContactDetails());
result.put("minApiRequestInterval", bean.getMinApiRequestInterval().toString());
Response response = constructResponse(result);
log.info("Returning response from listKeyDetails");
return response;
} catch (Exception e) {
log.error(e.getMessage());
throw new WebApplicationException(e, Response.serverError().build());
}
}
use of org.codehaus.jackson.map.JsonMappingException in project onebusaway-application-modules by camsys.
the class KeysResource method deleteKey.
@Path("/delete/{keyValue}")
@GET
@Produces("application/json")
public Response deleteKey(@PathParam("keyValue") String keyValue) throws JsonGenerationException, JsonMappingException, IOException {
log.info("Starting deleteKey with parameter " + keyValue);
String message = "API Key deleted: " + keyValue;
try {
validateSecurity();
delete(keyValue);
} catch (Exception e) {
log.error(e.getMessage());
message = "Failed to delete key: " + e.getMessage();
}
Response response = constructResponse(message);
log.info("Returning deleteKey result.");
return response;
}
use of org.codehaus.jackson.map.JsonMappingException in project onebusaway-application-modules by camsys.
the class KeysResource method listKeys.
@Path("/list")
@GET
@Produces("application/json")
public Response listKeys() throws JsonGenerationException, JsonMappingException, IOException {
log.info("Starting listKeys");
try {
validateSecurity();
List<String> apiKeys = _userService.getUserIndexKeyValuesForKeyType(UserIndexTypes.API_KEY);
Response response = constructResponse(apiKeys);
log.info("Returning response from listKeys");
return response;
} catch (Exception e) {
log.error(e.getMessage());
throw new WebApplicationException(e, Response.serverError().build());
}
}
use of org.codehaus.jackson.map.JsonMappingException in project onebusaway-application-modules by camsys.
the class StopForRouteResultChecker method checkResults.
@Override
public BundleValidationCheckResult checkResults(BundleValidateQuery query) {
ObjectMapper mapper = new ObjectMapper();
BundleValidationCheckResult checkResult = new BundleValidationCheckResult();
String result = query.getQueryResult();
mapper.configure(SerializationConfig.Feature.AUTO_DETECT_FIELDS, true);
Map<String, Object> parsedResult = new HashMap<String, Object>();
boolean parseFailed = false;
try {
parsedResult = mapper.readValue(result, HashMap.class);
} catch (JsonParseException e) {
_log.error("JsonParseException trying to parse query results.");
checkResult.setTestResult("JsonParseException trying to parse query results.");
parseFailed = true;
} catch (JsonMappingException e) {
_log.error("JsonMappingException trying to parse query results.");
checkResult.setTestResult("JsonMappingException trying to parse query results.");
parseFailed = true;
} catch (IOException e) {
_log.error("IOException trying to parse query results.");
checkResult.setTestResult("IOException trying to parse query results.");
parseFailed = true;
}
if (parseFailed) {
checkResult.setTestStatus(FAIL);
return checkResult;
}
// JSON successfully parsed, so continue processing
int httpCode = (Integer) parsedResult.get("code");
Map<String, Object> data = (Map<String, Object>) parsedResult.get("data");
Map<String, Object> entry = (Map<String, Object>) data.get("entry");
ArrayList<Object> routeIds = (ArrayList<Object>) entry.get("routeIds");
if (httpCode != 200 || routeIds == null || routeIds.size() == 0) {
// Call failed or didn't find any route entries
checkResult.setTestStatus(FAIL);
checkResult.setTestResult(query.getErrorMessage() + "Did not find any routes for stop #" + query.getStopId());
} else {
// Succeeded at finding stop info, but does it include this route?
if (routeIds.contains(query.getRouteId())) {
checkResult.setTestResult(query.getErrorMessage() + "Found stop #" + query.getStopId() + " on Route #" + query.getRouteId());
if (query.getSpecificTest().toLowerCase().equals("stop for route")) {
checkResult.setTestStatus(PASS);
} else {
checkResult.setTestStatus(FAIL);
}
} else {
// Didn't find that route for that stop
checkResult.setTestResult(query.getErrorMessage() + "Did not find stop #" + query.getStopId() + " on Route #" + query.getRouteId());
if (query.getSpecificTest().toLowerCase().equals("stop date at time")) {
checkResult.setTestStatus(FAIL);
} else {
checkResult.setTestStatus(PASS);
}
}
}
return checkResult;
}
use of org.codehaus.jackson.map.JsonMappingException in project onebusaway-application-modules by camsys.
the class LinkAvlRealtimeArchiverTask method deserializeAvlJson.
private LinkAVLData deserializeAvlJson(String avlJson) {
LinkAVLData avlData = new LinkAVLData();
ObjectMapper mapper = new ObjectMapper().enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
mapper.configure(SerializationConfig.Feature.AUTO_DETECT_FIELDS, true);
try {
avlData = mapper.readValue(avlJson, LinkAVLData.class);
} catch (JsonParseException e) {
_log.error("JsonParseException trying to parse feed data.");
} catch (JsonMappingException e) {
_log.error("JsonMappingException: " + e.getMessage());
} catch (IOException e) {
_log.error("IOException trying to parse feed data.");
} catch (Exception e) {
_log.error("Exception trying to parse feed data: " + e.getMessage());
}
avlData.setAvlSource(_avlFeedId);
if (avlData.getTrips() == null)
return avlData;
for (TripInfo tripInfo : avlData.getTrips()) {
tripInfo.setLinkAVLData(avlData);
for (StopUpdate stopUpdate : tripInfo.getStopUpdates()) {
stopUpdate.setTripInfo(tripInfo);
}
}
return avlData;
}
Aggregations