Search in sources :

Example 26 with JsonParseException

use of org.codehaus.jackson.JsonParseException in project databus by linkedin.

the class DbusEventSerializable method getErrorEventFromDbusEvent.

public static DbusErrorEvent getErrorEventFromDbusEvent(DbusEventInternalReadable event) {
    if (!event.isErrorEvent()) {
        throw new RuntimeException("Event is expected to be an error event: " + event);
    }
    ByteBuffer valueBuffer = event.value();
    byte[] valueBytes = new byte[valueBuffer.limit()];
    valueBuffer.get(valueBytes);
    try {
        DbusErrorEvent errorEvent = DbusErrorEvent.createDbusErrorEvent(new String(valueBytes));
        return errorEvent;
    } catch (JsonParseException e) {
        throw new RuntimeException(e);
    } catch (JsonMappingException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) ByteBuffer(java.nio.ByteBuffer)

Example 27 with JsonParseException

use of org.codehaus.jackson.JsonParseException in project openhab1-addons by openhab.

the class FritzahaQueryscriptUpdateNumberCallback method execute.

/**
     * {@inheritDoc}
     */
@Override
public void execute(int status, String response) {
    super.execute(status, response);
    if (validRequest) {
        logger.debug("Received State response " + response + " for item " + itemName);
        String valueType;
        if (type == MeterType.VOLTAGE) {
            valueType = "MM_Value_Volt";
        } else if (type == MeterType.CURRENT) {
            valueType = "MM_Value_Amp";
        } else if (type == MeterType.POWER) {
            valueType = "MM_Value_Power";
        } else if (type == MeterType.ENERGY) {
            valueType = "";
        } else {
            return;
        }
        ObjectMapper jsonReader = new ObjectMapper();
        Map<String, String> deviceData;
        try {
            deviceData = jsonReader.readValue(response, Map.class);
        } catch (JsonParseException e) {
            logger.error("Error parsing JSON:\n" + response);
            return;
        } catch (JsonMappingException e) {
            logger.error("Error mapping JSON:\n" + response);
            return;
        } catch (IOException e) {
            logger.error("An I/O error occured while decoding JSON:\n" + response);
            return;
        }
        if (type == MeterType.ENERGY) {
            String ValIdent = "EnStats_watt_value_";
            long valCount = Long.parseLong(deviceData.get("EnStats_count"));
            BigDecimal meterValue = new BigDecimal(0);
            BigDecimal meterValueScaled;
            long tmplong;
            BigDecimal tmpBD;
            for (int tmpcnt = 1; tmpcnt <= valCount; tmpcnt++) {
                tmplong = Long.parseLong(deviceData.get(ValIdent + tmpcnt));
                meterValue = meterValue.add(new BigDecimal(tmplong));
            }
            if (Long.parseLong(deviceData.get("EnStats_timer_type")) == 10) {
                // 10 Minute values are given in mWh, so scale to Wh
                meterValueScaled = meterValue.scaleByPowerOfTen(-6);
            } else {
                // Other values are given in Wh, so scale to kWh
                meterValueScaled = meterValue.scaleByPowerOfTen(-3);
            }
            webIface.postUpdate(itemName, new DecimalType(meterValueScaled));
        } else if (deviceData.containsKey(valueType)) {
            BigDecimal meterValue = new BigDecimal(deviceData.get(valueType));
            BigDecimal meterValueScaled;
            switch(type) {
                case VOLTAGE:
                    meterValueScaled = meterValue.scaleByPowerOfTen(-3);
                    break;
                case CURRENT:
                    meterValueScaled = meterValue.scaleByPowerOfTen(-4);
                    break;
                case POWER:
                    meterValueScaled = meterValue.scaleByPowerOfTen(-2);
                    break;
                default:
                    meterValueScaled = meterValue;
            }
            webIface.postUpdate(itemName, new DecimalType(meterValueScaled));
        } else {
            logger.error("Response did not contain " + valueType);
        }
    }
}
Also used : JsonMappingException(org.codehaus.jackson.map.JsonMappingException) DecimalType(org.openhab.core.library.types.DecimalType) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) BigDecimal(java.math.BigDecimal)

Example 28 with JsonParseException

use of org.codehaus.jackson.JsonParseException in project openhab1-addons by openhab.

the class FritzahaQueryscriptUpdateSwitchCallback method execute.

/**
     * {@inheritDoc}
     */
@Override
public void execute(int status, String response) {
    super.execute(status, response);
    if (validRequest) {
        logger.debug("Received State response " + response + " for item " + itemName);
        ObjectMapper jsonReader = new ObjectMapper();
        Map<String, String> deviceData;
        try {
            deviceData = jsonReader.readValue(response, Map.class);
        } catch (JsonParseException e) {
            logger.error("Error parsing JSON:\n" + response);
            return;
        } catch (JsonMappingException e) {
            logger.error("Error mapping JSON:\n" + response);
            return;
        } catch (IOException e) {
            logger.error("An I/O error occured while decoding JSON:\n" + response);
            return;
        }
        if (deviceData.containsKey("DeviceSwitchState")) {
            webIface.postUpdate(itemName, "1".equals(deviceData.get("DeviceSwitchState")) ? OnOffType.ON : OnOffType.OFF);
        }
    }
}
Also used : JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 29 with JsonParseException

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

the class DumpCompiledPlanTest method dump.

private void dump(Plan p) {
    p.setExecutionConfig(new ExecutionConfig());
    try {
        OptimizedPlan op = compileNoStats(p);
        PlanJSONDumpGenerator dumper = new PlanJSONDumpGenerator();
        String json = dumper.getOptimizerPlanAsJSON(op);
        JsonParser parser = new JsonFactory().createJsonParser(json);
        while (parser.nextToken() != null) ;
    } catch (JsonParseException e) {
        e.printStackTrace();
        Assert.fail("JSON Generator produced malformatted output: " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("An error occurred in the test: " + e.getMessage());
    }
}
Also used : PlanJSONDumpGenerator(org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator) JsonFactory(org.codehaus.jackson.JsonFactory) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) JsonParseException(org.codehaus.jackson.JsonParseException) JsonParseException(org.codehaus.jackson.JsonParseException) OptimizedPlan(org.apache.flink.optimizer.plan.OptimizedPlan) JsonParser(org.codehaus.jackson.JsonParser)

Example 30 with JsonParseException

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

the class DemoPortalDataController method saveNewHostInfo.

public ModelAndView saveNewHostInfo(HttpServletRequest req, HttpServletResponse res) {
    log.info("WLMDataController.saveNewHostInfo >>");
    ModelAndView responseView = new ModelAndView(new JSONView());
    String hostObject = null;
    boolean newhost = false;
    try {
        hostObject = req.getParameter("hostObject");
        newhost = Boolean.parseBoolean(req.getParameter("newhost"));
    } catch (Exception e1) {
        responseView.addObject("result", false);
        responseView.addObject("message", e1.getMessage());
    }
    System.out.println(hostObject);
    ObjectMapper mapper = new ObjectMapper();
    HostDetailsEntityVO dataVO = new HostDetailsEntityVO();
    try {
        dataVO = mapper.readValue(hostObject, HostDetailsEntityVO.class);
    } catch (JsonParseException e) {
        log.error("Error While Parsing request parameters Data. " + e.getMessage());
        responseView.addObject("result", false);
        responseView.addObject("message", "Error While Parsing request parameters Data.");
        return responseView;
    } catch (JsonMappingException e) {
        log.error("Error While Mapping request parameters to Mle Data Object. " + e.getMessage());
        responseView.addObject("result", false);
        responseView.addObject("message", "Error While Mapping request parameters to Mle Data Object.");
        return responseView;
    } catch (IOException e) {
        log.error("IO Exception " + e.getMessage());
        responseView.addObject("result", false);
        responseView.addObject("message", "Error While Mapping request parameters to Mle Data Object.");
        return responseView;
    }
    dataVO.setUpdatedOn(new Date(System.currentTimeMillis()));
    try {
        if (newhost) {
            System.err.println("dataForNew : " + dataVO);
            responseView.addObject("result", demoPortalServices.saveNewHostData(dataVO, getAttestationService(req, AttestationService.class)));
        } else {
            System.err.println("dataForOLD : " + dataVO);
            responseView.addObject("result", demoPortalServices.updateHostData(dataVO, getAttestationService(req, AttestationService.class)));
        }
    } catch (DemoPortalException e) {
        log.error(e.getMessage());
        responseView.addObject("result", false);
        responseView.addObject("message", e.getMessage());
        return responseView;
    }
    log.info("WLMDataController.saveNewHostInfo <<<");
    return responseView;
}
Also used : JSONView(com.intel.mountwilson.util.JSONView) HostDetailsEntityVO(com.intel.mountwilson.datamodel.HostDetailsEntityVO) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) ModelAndView(org.springframework.web.servlet.ModelAndView) IOException(java.io.IOException) DemoPortalException(com.intel.mountwilson.common.DemoPortalException) JsonParseException(org.codehaus.jackson.JsonParseException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) DemoPortalException(com.intel.mountwilson.common.DemoPortalException) JsonParseException(org.codehaus.jackson.JsonParseException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Date(java.util.Date)

Aggregations

JsonParseException (org.codehaus.jackson.JsonParseException)35 IOException (java.io.IOException)30 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)30 TypeReference (org.codehaus.jackson.type.TypeReference)9 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)4 HashMap (java.util.HashMap)3 BlogsMoreResponse (cn.eoe.app.entity.BlogsMoreResponse)2 NewsMoreResponse (cn.eoe.app.entity.NewsMoreResponse)2 WikiMoreResponse (cn.eoe.app.entity.WikiMoreResponse)2 ByteString (com.linkedin.data.ByteString)2 PhysicalSourceConfig (com.linkedin.databus2.relay.config.PhysicalSourceConfig)2 File (java.io.File)2 InputStream (java.io.InputStream)2 Date (java.util.Date)2 MessagingException (javax.mail.MessagingException)2 MimeBodyPart (javax.mail.internet.MimeBodyPart)2 MimeMultipart (javax.mail.internet.MimeMultipart)2 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)2