Search in sources :

Example 41 with JsonParseException

use of org.codehaus.jackson.JsonParseException in project openmrs-module-coreapps by openmrs.

the class VisitTypeHelper method getOrderedVisitTypes.

/**
 * Returns a list of ordered visit types.
 *
 * @param visitTypes All the visit types
 * @param propertyValue The visit types to order in JSON-like format
 * @param visitService
 * @return visitTypesOrdered The visit types ordered and merged with the input visit type list
 */
public List<VisitType> getOrderedVisitTypes(List<VisitType> visitTypes, String propertyValue, VisitService visitService) {
    Map<Integer, String> order = null;
    List<VisitType> visitTypesOrdered = new ArrayList<VisitType>();
    if (propertyValue != null) {
        try {
            order = new ObjectMapper().readValue(propertyValue, HashMap.class);
        } catch (JsonParseException e) {
            VisitTypeHelper.LOG.error("Unable to parse global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
        } catch (JsonMappingException e) {
            VisitTypeHelper.LOG.error("Unable to map global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
        } catch (APIException e) {
            VisitTypeHelper.LOG.error("Unable to load global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
        } catch (IOException e) {
            VisitTypeHelper.LOG.error("Unable to read global property \"" + CoreAppsConstants.VISIT_TYPES_ORDER_PROPERTY + "\"");
        }
    }
    if (order != null) {
        for (int i = 1; i <= order.size(); i++) {
            String typeUuid = order.get(Integer.toString(i));
            VisitType type = visitService.getVisitTypeByUuid(typeUuid);
            if (visitTypes.contains(type)) {
                visitTypesOrdered.add(visitService.getVisitTypeByUuid(typeUuid));
            }
        }
        for (VisitType type : visitTypes) {
            if (!order.containsValue(type.getUuid())) {
                visitTypesOrdered.add(type);
            }
        }
    }
    if (!(visitTypes.size() == visitTypesOrdered.size())) {
        VisitTypeHelper.LOG.warn("Visit Types order property is not used.");
        return visitTypes;
    }
    return visitTypesOrdered;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) APIException(org.openmrs.api.APIException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) VisitType(org.openmrs.VisitType) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 42 with JsonParseException

use of org.codehaus.jackson.JsonParseException in project OpenOLAT by OpenOLAT.

the class EdubaseManagerImpl method fetchBookDetails.

@Override
public BookDetails fetchBookDetails(String bookId) {
    BookDetails infoReponse = new BookDetailsImpl();
    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(TIMEOUT_5000_MILLIS).setConnectTimeout(TIMEOUT_5000_MILLIS).setConnectionRequestTimeout(TIMEOUT_5000_MILLIS).build();
    String url = String.format(edubaseModule.getInfoverUrl(), bookId);
    HttpGet request = new HttpGet(url);
    request.setConfig(requestConfig);
    try (CloseableHttpClient httpClient = HttpClients.createDefault();
        CloseableHttpResponse httpResponse = httpClient.execute(request)) {
        String json = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
        ObjectMapper objectMapper = new ObjectMapper();
        infoReponse = objectMapper.readValue(json, BookDetailsImpl.class);
    } catch (SocketTimeoutException socketTimeoutException) {
        log.warn("Socket Timeout while requesting informations of the Edubase book with the id " + bookId);
    } catch (JsonParseException | EOFException noesNotExitsException) {
        log.debug("Error while requesting informations for the Edubase book with the id " + bookId + ": Book does not exist.");
    } catch (Exception e) {
        log.error("", e);
    }
    return infoReponse;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) JsonParseException(org.codehaus.jackson.JsonParseException) SocketTimeoutException(java.net.SocketTimeoutException) EOFException(java.io.EOFException) JsonParseException(org.codehaus.jackson.JsonParseException) BookDetails(org.olat.modules.edubase.BookDetails) BookDetailsImpl(org.olat.modules.edubase.model.BookDetailsImpl) SocketTimeoutException(java.net.SocketTimeoutException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) EOFException(java.io.EOFException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 43 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 44 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 45 with JsonParseException

use of org.codehaus.jackson.JsonParseException in project stanbol by apache.

the class AnalyzedTextParser method parseAnnotation.

private void parseAnnotation(Span span, String key, ObjectNode jValue) throws IOException {
    JsonNode jClass = jValue.path("class");
    if (!jClass.isTextual()) {
        log.warn("unable to parse Annotation {} because 'class' field " + "is not set or not a stringis no JSON object (ignored, json: {}", key, jValue);
        return;
    }
    Class<?> clazz;
    try {
        clazz = AnalyzedTextParser.class.getClassLoader().loadClass(jClass.getTextValue());
    } catch (ClassNotFoundException e) {
        log.warn("Unable to parse Annotation " + key + " because the 'class' " + jClass.getTextValue() + " of the " + "the value can not be resolved (ignored, json: " + jValue + ")", e);
        return;
    }
    ValueTypeParser<?> parser = this.valueTypeParserRegistry.getParser(clazz);
    Object value;
    if (parser != null) {
        value = parser.parse(jValue, span.getContext());
    } else {
        JsonNode valueNode = jValue.path("value");
        if (valueNode.isMissingNode()) {
            log.warn("unable to parse value for annotation {} because the " + "field 'value' is not present (ignored, json: {}", key, jValue);
            return;
        } else {
            try {
                value = mapper.treeToValue(valueNode, clazz);
            } catch (JsonParseException e) {
                log.warn("unable to parse value for annotation " + key + "because the value can" + "not be converted to the class " + clazz.getName() + "(ignored, json: " + jValue + ")", e);
                return;
            } catch (JsonMappingException e) {
                log.warn("unable to parse value for annotation " + key + "because the value can" + "not be converted to the class " + clazz.getName() + "(ignored, json: " + jValue + ")", e);
                return;
            }
        }
    }
    JsonNode jProb = jValue.path("prob");
    if (!jProb.isDouble()) {
        span.addValue(key, Value.value(value));
    } else {
        span.addValue(key, Value.value(value, jProb.getDoubleValue()));
    }
}
Also used : JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JsonNode(org.codehaus.jackson.JsonNode) JsonParseException(org.codehaus.jackson.JsonParseException)

Aggregations

JsonParseException (org.codehaus.jackson.JsonParseException)65 IOException (java.io.IOException)56 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)54 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)30 ArrayList (java.util.ArrayList)17 TypeReference (org.codehaus.jackson.type.TypeReference)10 HashMap (java.util.HashMap)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 TransactionStatus (org.springframework.transaction.TransactionStatus)3 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)3 BlogsMoreResponse (cn.eoe.app.entity.BlogsMoreResponse)2 NewsMoreResponse (cn.eoe.app.entity.NewsMoreResponse)2 WikiMoreResponse (cn.eoe.app.entity.WikiMoreResponse)2 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)2