Exemplo n.º 1
0
  public Object fromMessage(Message msg) throws JMSException, MessageConversionException {
    log.debug("--OperationlogMsgConverter fromMessage--");
    if (!(msg instanceof MapMessage)) {
      throw new MessageConversionException("Message isn't a MapMessage");
    }

    if ((msg == null) || (msg.getBooleanProperty("NullMessage"))) {
      return null;
    }

    MapMessage mapMessage = (MapMessage) msg;
    OperationLog optLog = new OperationLog();
    @SuppressWarnings("unused")
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    optLog.setMainType(Integer.valueOf(mapMessage.getInt("mainType")));
    optLog.setMinorType(Integer.valueOf(mapMessage.getInt("minorType")));
    optLog.setCtrlUnitId(Integer.valueOf(mapMessage.getInt("ctrlUnitId")));
    optLog.setUserId(Integer.valueOf(mapMessage.getInt("userId")));

    optLog.setTriggerTime(Calendar.getInstance().getTime());

    optLog.setResourceId(Integer.valueOf(mapMessage.getInt("resourceId")));
    try {
      if (mapMessage.getString("logTxt") == null) {
        return null;
      }
      optLog.setLogTxt(new String(mapMessage.getString("logTxt").getBytes("ISO-8859-1"), "UTF-8"));
    } catch (UnsupportedEncodingException e) {
      log.error(e.getMessage());
    }

    return optLog;
  }
Exemplo n.º 2
0
  public Message toMessage(Object obj, Session session)
      throws JMSException, MessageConversionException {
    if (!(obj instanceof OperationLog)) {
      throw new MessageConversionException("Object isn't a WorkState");
    }

    OperationLog optLog = (OperationLog) obj;
    MapMessage msg = session.createMapMessage();
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    msg.setInt("mainType", optLog.getMainType().intValue());
    msg.setInt("minorType", optLog.getMinorType().intValue());
    msg.setInt("ctrlUnitId", optLog.getCtrlUnitId().intValue());
    msg.setInt("userId", optLog.getUserId().intValue());
    msg.setString("triggerTime", dateFormat.format(optLog.getTriggerTime()));
    msg.setInt("resourceId", optLog.getResourceId().intValue());
    msg.setString("logTxt", optLog.getLogTxt());

    return msg;
  }