Search in sources :

Example 71 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project android-app by eoecn.

the class TopDao method mapperJson.

public List<Object> mapperJson(boolean useCache) {
    List<Object> topCategorys = new ArrayList<Object>();
    tabs.clear();
    try {
        String resultNews = RequestCacheUtil.getRequestContent(mActivity, Urls.TOP_NEWS_URL + Utility.getScreenParams(mActivity), Constants.WebSourceType.Json, Constants.DBContentType.Content_list, useCache);
        NewsMoreResponse newsMoreResponse = mObjectMapper.readValue(resultNews, new TypeReference<NewsMoreResponse>() {
        });
        if (newsMoreResponse != null) {
            this.newsCategorys = newsMoreResponse.getResponse();
        }
        String resultBlogs = RequestCacheUtil.getRequestContent(mActivity, Urls.TOP_BLOG_URL + Utility.getScreenParams(mActivity), Constants.WebSourceType.Json, Constants.DBContentType.Content_list, useCache);
        BlogsMoreResponse blogsMoreResponse = mObjectMapper.readValue(resultBlogs, new TypeReference<BlogsMoreResponse>() {
        });
        if (blogsMoreResponse != null) {
            this.blogsCategorys = blogsMoreResponse.getResponse();
        }
        String resultWiki = RequestCacheUtil.getRequestContent(mActivity, Urls.TOP_WIKI_URL + Utility.getScreenParams(mActivity), Constants.WebSourceType.Json, Constants.DBContentType.Content_list, useCache);
        WikiMoreResponse wikiMoreResponse = mObjectMapper.readValue(resultWiki, new TypeReference<WikiMoreResponse>() {
        });
        if (wikiMoreResponse != null) {
            this.wikiCategorys = wikiMoreResponse.getResponse();
        }
        Collections.addAll(topCategorys, newsCategorys, blogsCategorys, wikiCategorys);
        return topCategorys;
    } catch (JsonParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JsonMappingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) BlogsMoreResponse(cn.eoe.app.entity.BlogsMoreResponse) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) IOException(java.io.IOException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JsonParseException(org.codehaus.jackson.JsonParseException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) WikiMoreResponse(cn.eoe.app.entity.WikiMoreResponse) NewsMoreResponse(cn.eoe.app.entity.NewsMoreResponse)

Example 72 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException 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 73 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException 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 74 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException 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 75 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException 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)

Aggregations

JsonMappingException (org.codehaus.jackson.map.JsonMappingException)88 IOException (java.io.IOException)79 JsonParseException (org.codehaus.jackson.JsonParseException)53 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)36 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)27 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)19 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 Response (javax.ws.rs.core.Response)13 Map (java.util.Map)11 List (java.util.List)10 GET (javax.ws.rs.GET)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 TypeReference (org.codehaus.jackson.type.TypeReference)10 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)7 ClientResponse (com.sun.jersey.api.client.ClientResponse)6 StringWriter (java.io.StringWriter)5 Enterprise (com.itrus.portal.db.Enterprise)4