Search in sources :

Example 51 with JsonParseException

use of org.codehaus.jackson.JsonParseException in project carina by qaprosoft.

the class MobileFactory method getDeviceInfo.

/**
 * Returns device information from Grid Hub using STF service.
 *
 * @param seleniumHost - Selenium Grid host
 * @param sessionId - Selenium session id
 * @return remote device information
 */
private RemoteDevice getDeviceInfo(String seleniumHost, String sessionId) {
    RemoteDevice device = null;
    try {
        HttpClient client = HttpClientBuilder.create().build();
        HttpGet request = new HttpGet(seleniumHost.split("wd")[0] + "grid/admin/DeviceInfo?session=" + sessionId);
        HttpResponse response = client.execute(request);
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        device = mapper.readValue(response.getEntity().getContent(), RemoteDevice.class);
    } catch (JsonParseException e) {
    // do nothing as it is direct call to the Appium without selenium
    } catch (Exception e) {
        LOGGER.error("Unable to get device info: " + e.getMessage());
    }
    return device;
}
Also used : HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) RemoteDevice(com.qaprosoft.carina.commons.models.RemoteDevice) JsonParseException(org.codehaus.jackson.JsonParseException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) MalformedURLException(java.net.MalformedURLException) JsonParseException(org.codehaus.jackson.JsonParseException)

Example 52 with JsonParseException

use of org.codehaus.jackson.JsonParseException in project ovirt-engine by oVirt.

the class AttestationService method attestHosts.

public List<AttestationValue> attestHosts(List<String> hosts) {
    String pollURI = Config.getValue(ConfigValues.PollUri);
    List<AttestationValue> values = new ArrayList<>();
    PostMethod postMethod = new PostMethod("/" + pollURI);
    try {
        postMethod.setRequestEntity(new StringRequestEntity(writeListJson(hosts)));
        postMethod.addRequestHeader("Accept", CONTENT_TYPE);
        postMethod.addRequestHeader("Content-type", CONTENT_TYPE);
        HttpClient httpClient = getClient();
        int statusCode = httpClient.executeMethod(postMethod);
        String strResponse = postMethod.getResponseBodyAsString();
        log.debug("return attested result: {}", strResponse);
        if (statusCode == 200) {
            values = parsePostedResp(strResponse);
        } else {
            log.error("attestation error: {}", strResponse);
        }
    } catch (JsonParseException e) {
        log.error("Failed to parse result: {}", e.getMessage());
        log.debug("Exception", e);
    } catch (IOException e) {
        log.error("Failed to attest hosts, make sure hosts are up and reachable: {}", e.getMessage());
        log.debug("Exception", e);
    } finally {
        postMethod.releaseConnection();
    }
    return values;
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException)

Example 53 with JsonParseException

use of org.codehaus.jackson.JsonParseException in project coprhd-controller by CoprHD.

the class ServiceCodeExceptionMapperTest method jsonParseException.

@Test
public void jsonParseException() {
    final JsonParseException exception = new JsonParseException("Failed to parse the JSON content", null);
    assertException("Failed to parse the JSON content", 1013, "Bad request body", 400, exception);
}
Also used : JsonParseException(org.codehaus.jackson.JsonParseException) Test(org.junit.Test)

Example 54 with JsonParseException

use of org.codehaus.jackson.JsonParseException 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 55 with JsonParseException

use of org.codehaus.jackson.JsonParseException 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

JsonParseException (org.codehaus.jackson.JsonParseException)68 IOException (java.io.IOException)59 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)56 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)30 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)9 TypeReference (org.codehaus.jackson.type.TypeReference)9 List (java.util.List)7 Map (java.util.Map)7 ClientResponse (com.sun.jersey.api.client.ClientResponse)5 CertificationChargingList (com.itrus.portal.entity.CertificationChargingList)3 CertificationChargingWrap (com.itrus.portal.entity.CertificationChargingWrap)3 ChargingPriceList (com.itrus.portal.entity.ChargingPriceList)3 ServiceNameList (com.itrus.portal.entity.ServiceNameList)3 JsonParser (org.codehaus.jackson.JsonParser)3 JSONArray (org.json.JSONArray)3 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)3