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