Search in sources :

Example 26 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project databus by linkedin.

the class ClusterCheckpointPersistenceProvider method getCheckpoint.

/**
     * internal function that fetches contents from Helix property store
     * 
     * @param key
     * @return checkpoint or null
     */
private Checkpoint getCheckpoint(String key) {
    ZNRecord zn = _propertyStore.get(key, null, AccessOption.PERSISTENT);
    if (zn != null) {
        String v = zn.getSimpleField(KEY_CHECKPOINT);
        try {
            Checkpoint cp;
            cp = new Checkpoint(v);
            return cp;
        } catch (JsonParseException e) {
            LOG.error("Cannot deserialize value for key=" + key + " value=" + v + " exception=" + e);
        } catch (JsonMappingException e) {
            LOG.error("Cannot deserialize value for key=" + key + " value=" + v + " exception=" + e);
        } catch (IOException e) {
            LOG.error("Cannot deserialize value for key=" + key + " value=" + v + " exception=" + e);
        }
    } else {
        LOG.error("No record for key = " + key);
    }
    return null;
}
Also used : Checkpoint(com.linkedin.databus.core.Checkpoint) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) ZNRecord(org.apache.helix.ZNRecord)

Example 27 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project databus by linkedin.

the class PhysicalSourceConfigBuilder method build.

@Override
public PhysicalSourceStaticConfig[] build() throws InvalidConfigException {
    ObjectMapper mapper = new ObjectMapper();
    PhysicalSourceStaticConfig[] list = new PhysicalSourceStaticConfig[null == _fileNames ? 0 : _fileNames.length];
    if (_fileNames == null)
        return list;
    for (int i = 0; i < _fileNames.length; ++i) {
        File sourceJson = _fileNames[i];
        PhysicalSourceConfig pConfig = null;
        Exception e = null;
        try {
            pConfig = mapper.readValue(sourceJson, PhysicalSourceConfig.class);
        } catch (JsonParseException jpe) {
            e = jpe;
        } catch (JsonMappingException jme) {
            e = jme;
        } catch (IOException ioe) {
            e = ioe;
        }
        if (e != null || pConfig == null) {
            throw new InvalidConfigException(e);
        }
        pConfig.checkForNulls();
        LOG.info("Generated Physical source config: name= " + pConfig.getId());
        list[i] = pConfig.build();
    }
    /*
    for(PhysicalSourceStaticConfig pCfg : pConfigs) {
      for(LogicalSourceStaticConfig lSC : pCfg.getSources()) {
        config.setSourceName("" + lSC.getId(), lSC.getName());
      }
    }
    */
    return list;
}
Also used : PhysicalSourceStaticConfig(com.linkedin.databus2.relay.config.PhysicalSourceStaticConfig) PhysicalSourceConfig(com.linkedin.databus2.relay.config.PhysicalSourceConfig) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JsonParseException(org.codehaus.jackson.JsonParseException) IOException(java.io.IOException)

Example 28 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException 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 29 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException 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 30 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException 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)

Aggregations

JsonMappingException (org.codehaus.jackson.map.JsonMappingException)39 IOException (java.io.IOException)31 JsonParseException (org.codehaus.jackson.JsonParseException)30 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)14 TypeReference (org.codehaus.jackson.type.TypeReference)10 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 Map (java.util.Map)4 MeetingBO (org.mifos.application.meeting.business.MeetingBO)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 InputStream (java.io.InputStream)2 MessagingException (javax.mail.MessagingException)2 MimeBodyPart (javax.mail.internet.MimeBodyPart)2 MimeMultipart (javax.mail.internet.MimeMultipart)2