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;
  }
Ejemplo n.º 3
0
  /* (non-Javadoc)
   * @see org.jboss.netty.channel.SimpleChannelUpstreamHandler#messageReceived(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.MessageEvent)
   */
  @Override
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    Message message = (Message) e.getMessage();
    long commandId = ((Long) message.getHeader().getCommandId()).longValue();
    if (commandId != packetType.getCommandId()) {
      super.messageReceived(ctx, e);
      return;
    }

    ReportRequestMessage requestMessage = (ReportRequestMessage) message;
    ReportResponseMessage responseMessage = new ReportResponseMessage();

    responseMessage.setRequest(requestMessage);

    ctx.getChannel().write(responseMessage);

    ((Session) ctx.getChannel().getAttachment())
        .receive(requestMessage.setResponse(responseMessage));
  }
Ejemplo n.º 4
0
  /*
   * (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;

    DeliverRequestMessage requestMessage = (DeliverRequestMessage) message;

    ChannelBuffer bodyBuffer = ChannelBuffers.dynamicBuffer();

    bodyBuffer.writeBytes(
        Bytes.ensureCapacity(
            requestMessage.getUsernumber().getBytes(GlobalVars.defaultTransportCharset),
            DeliverRequest.USERNUMBER.getLength(),
            0));
    bodyBuffer.writeBytes(
        Bytes.ensureCapacity(
            requestMessage.getSpnumber().getBytes(GlobalVars.defaultTransportCharset),
            DeliverRequest.SPNUMBER.getLength(),
            0));
    bodyBuffer.writeByte(requestMessage.getTppid());
    bodyBuffer.writeByte(requestMessage.getTpudhi());
    bodyBuffer.writeByte(requestMessage.getMessagecoding());
    bodyBuffer.writeInt((int) requestMessage.getMessagelength());
    bodyBuffer.writeBytes(requestMessage.getMsgContentBytes());
    bodyBuffer.writeBytes(
        Bytes.ensureCapacity(
            requestMessage.getReserve().getBytes(GlobalVars.defaultTransportCharset),
            DeliverRequest.RESERVE.getLength(),
            0));

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

    ChannelBuffer msgBuffer = ChannelBuffers.dynamicBuffer();

    msgBuffer.writeBytes(requestMessage.getHeader().getHeadBuffer());
    msgBuffer.writeBytes(requestMessage.getBodyBuffer());

    return msgBuffer;
  }
  /* (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;
  }