use of org.codehaus.jackson.JsonGenerationException in project onebusaway-application-modules by camsys.
the class AgencyMetadataResource method listAgencyMetadata.
@Path("/list")
@GET
@Produces("application/json")
public Response listAgencyMetadata() throws JsonGenerationException, JsonMappingException, IOException {
try {
List<AgencyMetadata> agencyMetadata = _agencyMetadataService.getAllAgencyMetadata();
Response response = constructResponse(agencyMetadata);
return response;
} catch (Exception e) {
log.error(e.getMessage());
throw new WebApplicationException(e, Response.serverError().build());
}
}
use of org.codehaus.jackson.JsonGenerationException in project onebusaway-application-modules by camsys.
the class AgencyMetadataResource method constructResponse.
// Private methods
private Response constructResponse(Object result) {
final StringWriter sw = new StringWriter();
final MappingJsonFactory jsonFactory = new MappingJsonFactory();
Response response = null;
try {
final org.codehaus.jackson.JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
mapper.writeValue(jsonGenerator, result);
response = Response.ok(sw.toString()).build();
} catch (JsonGenerationException e) {
log.error("Error generating response JSON");
response = Response.serverError().build();
e.printStackTrace();
} catch (JsonMappingException e) {
log.error("Error mapping response to JSON");
response = Response.serverError().build();
e.printStackTrace();
} catch (IOException e) {
log.error("I/O error while creating response JSON");
response = Response.serverError().build();
e.printStackTrace();
}
return response;
}
use of org.codehaus.jackson.JsonGenerationException in project onebusaway-application-modules by camsys.
the class AgencyMetadataResource method createAgencyMetadata.
@Path("/create")
@GET
@Produces("application/json")
public Response createAgencyMetadata(@QueryParam("gtfs_id") String gtfs_id, @QueryParam("name") String name, @QueryParam("short_name") String short_name, @QueryParam("legacy_id") String legacy_id, @QueryParam("gtfs_feed_url") String gtfs_feed_url, @QueryParam("gtfs_rt_feed_url") String gtfs_rt_feed_url, @QueryParam("bounding_box") String bounding_box, @QueryParam("ntd_id") String ntd_id, @QueryParam("agency_message") String agency_message) throws JsonGenerationException, JsonMappingException, IOException {
log.info("Starting createAgencyMetadata with gtfs_id: " + gtfs_id + ", name: " + name + ", short_name: " + short_name + ", legacy_id: " + legacy_id + ", gtfs_feed_url: " + gtfs_feed_url + ", gtfs_rt_feed_url: " + gtfs_rt_feed_url + ", bounding_box: " + bounding_box + ", ntd_id: " + ntd_id + ", agency_message: " + agency_message);
String message = "Agency Metadata record created for: " + name;
try {
_agencyMetadataService.createAgencyMetadata(gtfs_id, name, short_name, legacy_id, gtfs_feed_url, gtfs_rt_feed_url, bounding_box, ntd_id, agency_message);
} catch (Exception e) {
log.error(e.getMessage());
throw new WebApplicationException(e, Response.serverError().build());
}
Response response = constructResponse(message);
return response;
}
use of org.codehaus.jackson.JsonGenerationException in project onebusaway-application-modules by camsys.
the class KeysResource method constructResponse.
private Response constructResponse(Object result) {
final StringWriter sw = new StringWriter();
final MappingJsonFactory jsonFactory = new MappingJsonFactory();
Response response = null;
try {
final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(sw);
mapper.writeValue(jsonGenerator, result);
response = Response.ok(sw.toString()).build();
} catch (JsonGenerationException e) {
log.error("Error generating response JSON");
response = Response.serverError().build();
e.printStackTrace();
} catch (JsonMappingException e) {
log.error("Error mapping response to JSON");
response = Response.serverError().build();
e.printStackTrace();
} catch (IOException e) {
log.error("I/O error while creating response JSON");
response = Response.serverError().build();
e.printStackTrace();
}
return response;
}
use of org.codehaus.jackson.JsonGenerationException 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());
}
}
Aggregations