Ejemplo n.º 1
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.jboss.netty.handler.codec.oneone.OneToOneDecoder#decode(org.jboss
   * .netty.channel.ChannelHandlerContext, org.jboss.netty.channel.Channel,
   * java.lang.Object)
   */
  @Override
  protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    Message message = (Message) msg;
    long commandId = ((Long) message.getHeader().getCommandId()).longValue();

    if (packetType.getCommandId() != commandId) return msg;

    ReportRequestMessage requestMessage = new ReportRequestMessage();

    requestMessage.setHeader(message.getHeader());
    requestMessage.setBodyBuffer(message.getBodyBuffer());

    ChannelBuffer bodyBuffer = ChannelBuffers.copiedBuffer(message.getBodyBuffer());

    requestMessage.setSequenceNumber(
        DefaultSequenceNumberUtil.bytes2SequenceN(
            bodyBuffer.readBytes(ReportRequest.SUBMITSEQUENCENUMBER.getLength()).array()));
    requestMessage.setReporttype(bodyBuffer.readUnsignedByte());
    requestMessage.setUsernumber(
        bodyBuffer
            .readBytes(ReportRequest.USERNUMBER.getLength())
            .toString(GlobalVars.defaultTransportCharset));
    requestMessage.setState(bodyBuffer.readUnsignedByte());
    requestMessage.setErrorcode(bodyBuffer.readUnsignedByte());
    requestMessage.setReserve(
        bodyBuffer
            .readBytes(ReportRequest.RESERVE.getLength())
            .toString(GlobalVars.defaultTransportCharset));

    return requestMessage;
  }
Ejemplo n.º 2
0
  /* (non-Javadoc)
   * @see org.jboss.netty.handler.codec.oneone.OneToOneDecoder#decode(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.Channel, java.lang.Object)
   */
  @Override
  protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    Message message = (Message) msg;
    long commandId = ((Long) message.getHeader().getCommandId()).longValue();

    if (packetType.getCommandId() != commandId) return msg;

    UnbindRequestMessage requestMessage = new UnbindRequestMessage();

    requestMessage.setHeader(message.getHeader());
    requestMessage.setBodyBuffer(message.getBodyBuffer());

    return requestMessage;
  }
  /* (non-Javadoc)
   * @see org.jboss.netty.handler.codec.oneone.OneToOneEncoder#encode(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.Channel, java.lang.Object)
   */
  @Override
  protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    if (!(msg instanceof Message)) return msg;

    Message message = (Message) msg;

    long commandId = ((Long) message.getHeader().getCommandId()).longValue();
    if (commandId != packetType.getCommandId()) return msg;

    CmppDeliverResponseMessage responseMessage = (CmppDeliverResponseMessage) msg;

    ChannelBuffer bodyBuffer = ChannelBuffers.dynamicBuffer();
    bodyBuffer.writeBytes(DefaultMsgIdUtil.msgId2Bytes(responseMessage.getMsgId()));
    bodyBuffer.writeInt((int) responseMessage.getResult());

    message.setBodyBuffer(bodyBuffer.copy().array());

    ChannelBuffer messageBuffer = ChannelBuffers.dynamicBuffer();
    messageBuffer.writeBytes(message.getHeader().getHeadBuffer());
    messageBuffer.writeBytes(message.getBodyBuffer());
    return messageBuffer;
  }
  /* (non-Javadoc)
   * @see org.jboss.netty.handler.codec.oneone.OneToOneDecoder#decode(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.Channel, java.lang.Object)
   */
  @Override
  protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    Message message = (Message) msg;
    long commandId = ((Long) message.getHeader().getCommandId()).longValue();
    if (packetType.getCommandId() != commandId) return msg;

    CmppDeliverRequestMessage requestMessage = new CmppDeliverRequestMessage();
    requestMessage.setBodyBuffer(message.getBodyBuffer());
    requestMessage.setHeader(message.getHeader());

    ChannelBuffer bodyBuffer = ChannelBuffers.copiedBuffer(message.getBodyBuffer());

    requestMessage.setMsgId(
        DefaultMsgIdUtil.bytes2MsgId(
            bodyBuffer.readBytes(CmppDeliverRequest.MSGID.getLength()).array()));
    requestMessage.setDestId(
        bodyBuffer
            .readBytes(CmppDeliverRequest.DESTID.getLength())
            .toString(GlobalVars.defaultTransportCharset)
            .trim());
    requestMessage.setServiceid(
        bodyBuffer
            .readBytes(CmppDeliverRequest.SERVICEID.getLength())
            .toString(GlobalVars.defaultTransportCharset)
            .trim());
    requestMessage.setTppid(bodyBuffer.readUnsignedByte());
    requestMessage.setTpudhi(bodyBuffer.readUnsignedByte());
    requestMessage.setMsgfmt(bodyBuffer.readUnsignedByte());
    requestMessage.setSrcterminalId(
        bodyBuffer
            .readBytes(CmppDeliverRequest.SRCTERMINALID.getLength())
            .toString(GlobalVars.defaultTransportCharset)
            .trim());
    requestMessage.setSrcterminalType(bodyBuffer.readUnsignedByte());
    requestMessage.setRegisteredDelivery(bodyBuffer.readUnsignedByte());
    requestMessage.setMsgLength(bodyBuffer.readUnsignedByte());

    if (requestMessage.getRegisteredDelivery() == 0) {
      requestMessage.setMsgContent(
          bodyBuffer
              .readBytes(requestMessage.getMsgLength())
              .toString(GlobalVars.defaultTransportCharset)
              .trim());
    } else {
      requestMessage
          .getReportRequestMessage()
          .setMsgId(
              DefaultMsgIdUtil.bytes2MsgId(
                  bodyBuffer.readBytes(CmppReportRequest.MSGID.getLength()).array()));
      requestMessage
          .getReportRequestMessage()
          .setStat(
              bodyBuffer
                  .readBytes(CmppReportRequest.STAT.getLength())
                  .toString(GlobalVars.defaultTransportCharset)
                  .trim());
      requestMessage
          .getReportRequestMessage()
          .setSubmitTime(
              bodyBuffer
                  .readBytes(CmppReportRequest.SUBMITTIME.getLength())
                  .toString(GlobalVars.defaultTransportCharset)
                  .trim());
      requestMessage
          .getReportRequestMessage()
          .setDoneTime(
              bodyBuffer
                  .readBytes(CmppReportRequest.DONETIME.getLength())
                  .toString(GlobalVars.defaultTransportCharset)
                  .trim());
      requestMessage
          .getReportRequestMessage()
          .setDestterminalId(
              bodyBuffer
                  .readBytes(CmppReportRequest.DESTTERMINALID.getLength())
                  .toString(GlobalVars.defaultTransportCharset)
                  .trim());
      requestMessage.getReportRequestMessage().setSmscSequence(bodyBuffer.readUnsignedInt());
    }

    requestMessage.setLinkid(
        bodyBuffer
            .readBytes(CmppDeliverRequest.LINKID.getLength())
            .toString(GlobalVars.defaultTransportCharset));

    return requestMessage;
  }