Search in sources :

Example 26 with JsonGenerationException

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());
    }
}
Also used : Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) AgencyMetadata(org.onebusaway.agency_metadata.model.AgencyMetadata) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 27 with JsonGenerationException

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;
}
Also used : Response(javax.ws.rs.core.Response) MappingJsonFactory(org.codehaus.jackson.map.MappingJsonFactory) StringWriter(java.io.StringWriter) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException)

Example 28 with JsonGenerationException

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;
}
Also used : Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 29 with JsonGenerationException

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;
}
Also used : Response(javax.ws.rs.core.Response) MappingJsonFactory(org.codehaus.jackson.map.MappingJsonFactory) StringWriter(java.io.StringWriter) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JsonGenerator(org.codehaus.jackson.JsonGenerator) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException)

Example 30 with JsonGenerationException

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());
    }
}
Also used : Response(javax.ws.rs.core.Response) UserIndex(org.onebusaway.users.model.UserIndex) UserIndexKey(org.onebusaway.users.model.UserIndexKey) User(org.onebusaway.users.model.User) UserBean(org.onebusaway.users.client.model.UserBean) WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

JsonGenerationException (org.codehaus.jackson.JsonGenerationException)34 IOException (java.io.IOException)30 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)27 Response (javax.ws.rs.core.Response)13 GET (javax.ws.rs.GET)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 ArrayList (java.util.ArrayList)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 JsonGenerator (org.codehaus.jackson.JsonGenerator)7 StringWriter (java.io.StringWriter)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Enterprise (com.itrus.portal.db.Enterprise)4 UserCert (com.itrus.portal.db.UserCert)4 UserInfo (com.itrus.portal.db.UserInfo)4 HttpSession (javax.servlet.http.HttpSession)4 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 Bill (com.itrus.portal.db.Bill)3