Search in sources :

Example 46 with JsonParseException

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

the class KHRequests method postRequestAsync.

public VNXeCommandJob postRequestAsync(ParamBase param) {
    setAsyncMode();
    ClientResponse response = postRequest(param);
    VNXeCommandJob job;
    String resString = response.getEntity(String.class);
    ObjectMapper mapper = new ObjectMapper();
    try {
        job = mapper.readValue(resString, VNXeCommandJob.class);
    } catch (JsonParseException e) {
        _logger.error(String.format("unexpected data returned: %s from: %s", resString, _url), e);
        throw VNXeException.exceptions.unexpectedDataError("unexpected data returned:" + resString, e);
    } catch (JsonMappingException e) {
        _logger.error(String.format("unexpected data returned: %s from: %s", resString, _url), e);
        throw VNXeException.exceptions.unexpectedDataError("unexpected data returned:" + resString, e);
    } catch (IOException e) {
        _logger.error(String.format("unexpected data returned: %s from: %s", resString, _url), e);
        throw VNXeException.exceptions.unexpectedDataError("unexpected data returned:" + resString, e);
    }
    if (job != null) {
        _logger.info("submitted the job: " + job.getId());
    } else {
        _logger.warn("No job returned.");
    }
    return job;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 47 with JsonParseException

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

the class KHRequests method deleteRequestAsync.

/*
     * Send DELETE request to KittyHawk server in async mode
     * 
     * @param resource webResource
     * 
     * @param param parameters for delete
     * 
     * @return VNXeCommandJob
     * 
     * @throws VNXeException
     */
public VNXeCommandJob deleteRequestAsync(Object param) throws VNXeException {
    _logger.debug("delete data: " + _url);
    setAsyncMode();
    ClientResponse response = deleteRequest(param);
    VNXeCommandJob job;
    String resString = response.getEntity(String.class);
    ObjectMapper mapper = new ObjectMapper();
    try {
        job = mapper.readValue(resString, VNXeCommandJob.class);
    } catch (JsonParseException e) {
        _logger.error(String.format("unexpected data returned: %s from: %s ", resString, _url), e);
        throw VNXeException.exceptions.unexpectedDataError(String.format("unexpected data returned: %s", resString), e);
    } catch (JsonMappingException e) {
        _logger.error(String.format("unexpected data returned: %s from: %s ", resString, _url), e);
        throw VNXeException.exceptions.unexpectedDataError(String.format("unexpected data returned: %s", resString), e);
    } catch (IOException e) {
        _logger.error(String.format("unexpected data returned: %s from: %s ", resString, _url), e);
        throw VNXeException.exceptions.unexpectedDataError(String.format("unexpected data returned: %s", resString), e);
    }
    if (job != null) {
        _logger.info("submitted the deleting file system job: {} ", job.getId());
    }
    return job;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 48 with JsonParseException

use of org.codehaus.jackson.JsonParseException in project portal by ixinportal.

the class MobileAppserviceChargingController method createOrUpdate.

// 新建和修改处理
@RequestMapping(value = "/createOrUpdate", method = RequestMethod.POST, produces = "text/html")
@ResponseBody
public synchronized Map<String, Object> createOrUpdate(@RequestParam("appserviceChargingStr") String appserviceChargingStr) {
    Map<String, Object> retMap = new HashMap<String, Object>();
    retMap.put("flag", false);
    DefaultTransactionDefinition dtd = new DefaultTransactionDefinition();
    // 事物的传播行为,使用同一个事物
    dtd.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status = transactionManager.getTransaction(dtd);
    try {
        AppserviceChargingWrap acw = jsonTool.readValue(appserviceChargingStr, AppserviceChargingWrap.class);
        List<AppserviceChargingList> appserviceChargingLists = acw.getAppserviceChargingLists();
        for (int i = 0; i < appserviceChargingLists.size(); i++) {
            // 取出单个的服务名称主表对象和服务名封装list
            MobileAppserviceCharging appCharging = appserviceChargingLists.get(i).getAppserviceCharging();
            // if (null == appCharging.getChargingType()) {
            // cc.setChargingType(ComNames.CHARGING_TYPE_SMRZ_1);
            // }
            List<AppserviceNameList> appserviceNameLists = appserviceChargingLists.get(i).getAppserviceNameLists();
            Map<String, Object> mapAC = new HashMap<String, Object>();
            mapAC = appserviceChargingService.saveOrUpdateAppserviceCharging(appCharging);
            boolean retCodeAC = false;
            retCodeAC = (boolean) mapAC.get("flag");
            // 新增或修改MobileAppserviceCharging成功
            if (retCodeAC) {
                appCharging = (MobileAppserviceCharging) mapAC.get("appserviceCharging");
                MobileAppserviceCharging oldAC = (MobileAppserviceCharging) mapAC.get("oldAppserviceCharging");
                // 将MobileAppserviceCharging的id值赋值给serviceNameList中新增的服务
                appserviceNameLists = appserviceNameService.insertIdIntoAppserviceName(appCharging, appserviceNameLists);
                // 2.新增或修改ServiceName
                for (int j = 0; j < appserviceNameLists.size(); j++) {
                    MobileAppserviceName appserviceName = appserviceNameLists.get(j).getAppserviceName();
                    ChargingPriceList chargingPriceList = appserviceNameLists.get(j).getChargingPriceList();
                    boolean retCodeSN = false;
                    Map<String, Object> mapAppserviceName = new HashMap<String, Object>();
                    mapAppserviceName = appserviceNameService.saveOrUpdateServiceName(appserviceName, appCharging, oldAC);
                    retCodeSN = (boolean) mapAppserviceName.get("flag");
                    // 新增或修改ServiceName成功
                    if (retCodeSN) {
                        appserviceName = (MobileAppserviceName) mapAppserviceName.get("appserviceName");
                        MobileAppserviceName oldAppserviceName = (MobileAppserviceName) mapAppserviceName.get("oldAppserviceName");
                        List<MobileAppserviceName> oldAppserviceNames = (List<MobileAppserviceName>) mapAppserviceName.get("appserviceNames");
                        // 将serviceNameId,CertificationCharging的id值赋值给chargingPriceList中计费以及价格区间
                        chargingPriceList = chargingPriceService.insertIdIntoChargingPrice(appserviceName, chargingPriceList);
                        List<MobileChargingPrice> chargingPrices = chargingPriceList.getChargingPriceLists();
                        // 3.charprice新增或修改
                        for (int k = 0; k < chargingPrices.size(); k++) {
                            Map<String, Object> mapChargingPrice = new HashMap<String, Object>();
                            mapChargingPrice = chargingPriceService.saveOrUpdateChargingPrice(appCharging, appserviceName, chargingPrices.get(k), oldAC, oldAppserviceName, oldAppserviceNames);
                            boolean retCodeChargingPrice = false;
                            retCodeChargingPrice = (boolean) mapChargingPrice.get("flag");
                            // 新增或修改ChargingPrice失败
                            if (!retCodeChargingPrice) {
                                transactionManager.rollback(status);
                                retMap = mapChargingPrice;
                                return retMap;
                            }
                        }
                    } else {
                        // TODO 新增或修改ServiceName错误,返回异常信息
                        transactionManager.rollback(status);
                        retMap = mapAppserviceName;
                        return retMap;
                    }
                }
            } else {
                // TODO 新增或修改CertificationCharging错误,返回异常信息
                transactionManager.rollback(status);
                retMap = mapAC;
                return retMap;
            }
        }
        LogUtil.adminlog(sqlSession, "新增计费规则", "新增了计费规则");
        transactionManager.commit(status);
        retMap.put("flag", true);
        // 修改应用对应的服务:将应用和服务关联起来
        // Set<Long> set = appserviceChargingService.getAllAppId();
        // if (null != set && set.size() >0) {
        // for (Long long1 : set) {
        // Set<Long> AppserviceIDs = appserviceChargingService.getAppserviceIDsByAppId(long1);
        // applicationInfoService.addServiceByAppInfo(long1,AppserviceIDs);
        // }
        // }
        // 通知其他机器,加载缓存
        CertificationChargingHandler cch = new CertificationChargingHandler();
        QueueThread.buildCertificationTask(cch);
        // cacheCustomer.initChargeRule();
        return retMap;
    } catch (JsonParseException e) {
        transactionManager.rollback(status);
        e.printStackTrace();
        retMap.put("retMsg", e.getMessage());
        return retMap;
    } catch (JsonMappingException e) {
        transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        e.printStackTrace();
        return retMap;
    } catch (IOException e) {
        transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        e.printStackTrace();
        return retMap;
    } catch (Exception e) {
        transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        e.printStackTrace();
        return retMap;
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) AppserviceNameList(com.itrus.portal.mobile.entity.AppserviceNameList) MobileChargingPrice(com.itrus.portal.db.MobileChargingPrice) ChargingPriceList(com.itrus.portal.mobile.entity.ChargingPriceList) TransactionStatus(org.springframework.transaction.TransactionStatus) JsonParseException(org.codehaus.jackson.JsonParseException) MobileAppserviceName(com.itrus.portal.db.MobileAppserviceName) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) List(java.util.List) CertificationChargingList(com.itrus.portal.entity.CertificationChargingList) AppserviceNameList(com.itrus.portal.mobile.entity.AppserviceNameList) ArrayList(java.util.ArrayList) ChargingPriceList(com.itrus.portal.mobile.entity.ChargingPriceList) AppserviceChargingList(com.itrus.portal.mobile.entity.AppserviceChargingList) ServiceNameList(com.itrus.portal.entity.ServiceNameList) MobileAppserviceCharging(com.itrus.portal.db.MobileAppserviceCharging) IOException(java.io.IOException) AppserviceChargingWrap(com.itrus.portal.mobile.entity.AppserviceChargingWrap) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) CertificationChargingHandler(com.itrus.portal.service.CertificationChargingHandler) AppserviceChargingList(com.itrus.portal.mobile.entity.AppserviceChargingList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 49 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 50 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)

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