예제 #1
0
  @Override
  protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    // System.out.println("decode:" + in.readableBytes());
    if (in.readableBytes() > 4) {
      in.markReaderIndex();
      int needBytes = in.readInt();
      // System.out.println("needBytes:" + needBytes);
      if (in.readableBytes() >= needBytes) {
        byte[] content = new byte[in.readableBytes()];
        in.readBytes(content);
        // byte[] data= ZLipHelper.decompress(content);
        // System.out.println("data:" + new String(data));

        Amf3Input amf3Input = new Amf3Input(SerializationContext.getSerializationContext());
        //				amf3Input = new Amf3Input(SerializationContext.getSerializationContext());
        InputStream bais = new ByteArrayInputStream(content);
        amf3Input.setInputStream(bais);
        try {
          Object decoded = amf3Input.readObject();
          if (decoded != null) {
            out.add(decoded);
            // System.out.println("decoded:" + decoded);
          }
        } catch (Exception e) {
        }
        //				amf3Input.close();
      } else {
        in.resetReaderIndex();
      }
    }
  }
예제 #2
0
  /**
   * Validates the assignment of a property of an instance of a class to a value against the
   * deserialization validator. If the assignment is not valid, SerializationException is thrown.
   *
   * @param obj The class instance whose property is being assigned to a value.
   * @param propName The name of the property that is being assigned.
   * @param value The value that the property is being assigned to.
   * @throws SerializationException if the value assignment is not valid.
   */
  public static void validateAssignment(Object obj, String propName, Object value) {
    SerializationContext context = SerializationContext.getSerializationContext();
    DeserializationValidator validator = context.getDeserializationValidator();
    if (validator == null) return;

    boolean valid = true;
    try {
      valid = validator.validateAssignment(obj, propName, value);
    } catch (Exception e) {
      // Assignment validation of the object with type '{0}' for the property '{1}' failed.
      SerializationException se = new SerializationException();
      se.setMessage("10312");
      // se.setMessage(10312, new Object[]{obj == null? NULL : obj.getClass().getName(), propName});
      se.setRootCause(e);
      throw se;
    }
    if (!valid) {
      SerializationException se = new SerializationException();
      se.setMessage("10312");
      // se.setMessage(10312, new Object[]{obj == null? NULL : obj.getClass().getName(), propName});
      throw se;
    }
  }
예제 #3
0
  /**
   * Validates the creation of the class instance against the deserialization validator, if one
   * exists. If the class creation is not valid, SerializationException is thrown.
   *
   * @param cls The class to validate.
   * @throws SerializationException if the class creation is not valid.
   */
  public static void validateCreation(Class<?> cls) {
    SerializationContext context = SerializationContext.getSerializationContext();
    DeserializationValidator validator = context.getDeserializationValidator();
    if (validator == null) return;

    boolean valid = true;
    try {
      valid = validator.validateCreation(cls);
    } catch (Exception e) {
      // Creation validation for class '{0}' failed.
      SerializationException se = new SerializationException();
      se.setMessage("10311");
      // se.setMessage(10311, new Object[]{cls == null? NULL : cls.getName()});
      se.setRootCause(e);
      throw se;
    }
    if (!valid) {
      // Creation validation for class '{0}' failed.
      SerializationException se = new SerializationException();
      se.setMessage("10311");
      // se.setMessage(10311, new Object[]{cls == null? NULL : cls.getName()});
      throw se;
    }
  }
예제 #4
0
  protected static SerializationContext getSerializationContext() {
    SerializationContext context = SerializationContext.getSerializationContext();

    // set serialization context properties
    context.enableSmallMessages = true;
    context.instantiateTypes = true;
    context.supportRemoteClass = true;
    context.legacyCollection = false;
    context.legacyMap = false;
    context.legacyXMLDocument = false;
    context.legacyXMLNamespaces = false;
    context.legacyThrowable = false;
    context.legacyBigNumbers = false;
    context.restoreReferences = false;
    context.logPropertyErrors = false;
    context.ignorePropertyErrors = true;

    return context;
  }