Search in sources :

Example 76 with JsonMappingException

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());
    }
}
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)

Example 77 with JsonMappingException

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;
}
Also used : Response(javax.ws.rs.core.Response) 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)

Example 78 with JsonMappingException

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());
    }
}
Also used : Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) 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)

Example 79 with JsonMappingException

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;
}
Also used : HashMap(java.util.HashMap) BundleValidationCheckResult(org.onebusaway.admin.model.BundleValidationCheckResult) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) Map(java.util.Map) HashMap(java.util.HashMap) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 80 with JsonMappingException

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;
}
Also used : TripInfo(org.onebusaway.gtfs_realtime.archiver.model.TripInfo) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) LinkAVLData(org.onebusaway.gtfs_realtime.archiver.model.LinkAVLData) StopUpdate(org.onebusaway.gtfs_realtime.archiver.model.StopUpdate) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) JsonParseException(org.codehaus.jackson.JsonParseException)

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