org.msgpack.MessageTypeException Java Examples

The following examples show how to use org.msgpack.MessageTypeException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessagePackRequestMarshaller.java    From ob1k with Apache License 2.0 6 votes vote down vote up
private void registerBean(final Set<Class> processed, final Class cls) {
  if (cls == Request.class || cls == HttpRequest.class || cls == HttpResponse.class)
    return;

  processed.add(cls);
  final Field[] declaredFields = cls.getDeclaredFields();
  for (final Field field: declaredFields) {
    if (Modifier.isStatic(field.getModifiers()))
      continue;

    final Type fieldType = field.getGenericType();
    registerTypes(processed, fieldType);
  }

  try {
    registerWithoutJavaLogs(cls);
  } catch (final MessageTypeException | TemplateBuildException e) {
    logger.warn("class " + cls.getName() + " is not MsgPack compatible. class must have empty constructor, all fields must be concrete and have getters and setters");
    logger.debug("failed registering type", e);
    throw new IllegalArgumentException("'" + cls.getName() + "' is not MsgPack compatible");
  }
}
 
Example #2
Source File: ObjectTemplate.java    From jvm-serializer with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Packer pk, Object v, boolean required) throws IOException {
    if (v == null) {
        if (required) {
            throw new MessageTypeException("Attempted to write null");
        }
        pk.writeNil();
        return;
    }
    pk.write(v);
}
 
Example #3
Source File: ObjectTemplate.java    From jvm-serializer with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Packer pk, Object v, boolean required) throws IOException {
    if (v == null) {
        if (required) {
            throw new MessageTypeException("Attempted to write null");
        }
        pk.writeNil();
        return;
    }
    pk.write(v);
}
 
Example #4
Source File: MessagePackRequestMarshaller.java    From ob1k with Apache License 2.0 4 votes vote down vote up
@Override
public void registerTypes(final Type... types) throws MessageTypeException {
  registerTypes(new HashSet<>(), types);
}
 
Example #5
Source File: MessagePackRequestMarshaller.java    From ob1k with Apache License 2.0 4 votes vote down vote up
public void registerTypes(final Set<Class> processed, final Type... types) throws MessageTypeException {
  for(final Type type: types) {
    if (type == null)
      continue;

    if (type instanceof Class) {
      final Class cls = (Class) type;
      if (processed.contains(cls))
        continue;

      if (!Modifier.isAbstract(cls.getModifiers()) || cls.isEnum()) {
        boolean found;
        try {
          found = (msgPack.lookup(cls) != null);
        } catch (final MessageTypeException e) {
          found = false;
        }
        if (!found) {
          registerBean(processed, cls);
        }
      } else if(cls.isArray()) {
        registerTypes(processed, cls.getComponentType());
      }

    } else if (type instanceof ParameterizedType) {
      final ParameterizedType paramType = (ParameterizedType) type;
      final Type[] actualTypes = paramType.getActualTypeArguments();
      registerTypes(processed, actualTypes);
      registerTypes(processed, paramType.getOwnerType());
      registerTypes(processed, paramType.getRawType());

    } else if (type instanceof GenericArrayType) {
      final GenericArrayType genType = (GenericArrayType) type;
      registerTypes(processed, genType.getGenericComponentType());

    } else if (type instanceof TypeVariable) {
      final TypeVariable varType = (TypeVariable) type;
      registerTypes(processed, varType.getBounds());

    }
  }
}
 
Example #6
Source File: ServerErrorTest.java    From msgpack-rpc-java with Apache License 2.0 4 votes vote down vote up
public String throwException(String errorMessage) throws Exception{
    throw new MessageTypeException(errorMessage);
}
 
Example #7
Source File: DecoratorTest.java    From msgpack-rpc-java with Apache License 2.0 4 votes vote down vote up
public String throwError(String errorMessage) throws Exception{
    throw new MessageTypeException(errorMessage);
}