} catch (RuntimeException e) {
throw new EntityEncodingException("Unable to populate bean for ref ("+ref+") from request: " + e.getMessage(), ref+"", e);
}
} else {
// no request params, bad request
throw new EntityException("No request params for html input request (there must be at least one) for reference: " + ref,
ref.toString(), HttpServletResponse.SC_BAD_REQUEST);
}
}
} else {
// all other formats
if (input == null) {
// no request params, bad request
throw new EntityException("No input for input translation (input cannot be null) for reference: " + ref,
ref.toString(), HttpServletResponse.SC_BAD_REQUEST);
} else {
String data = StringUtils.makeStringFromInputStream(input);
Map<String, Object> decoded = null;
try {
decoded = decodeData(data, format);
} catch (IllegalArgumentException iae) {
throw new EntityEncodingException("No encoder available for the given format ("+format+"), ref=" + ref + ":" + iae.getMessage(), ref.toString(), iae);
} catch (UnsupportedOperationException uoe) {
throw new EntityEncodingException("Failure during internal input encoding of entity: " + ref + " to format ("+format+"):" + uoe.getMessage(), ref.toString(), uoe);
}
entity = current;
// handle the special case where the JSON was created by xstream or something else that puts the data inside an object with a "root"
if (decoded.size() == 1 && decoded.containsKey(ref.getPrefix())) {
Object o = decoded.get(ref.getPrefix());
if (o instanceof Map) {
decoded = (Map<String, Object>) o;
}
}
try {
ReflectUtils.getInstance().populate(entity, decoded);
} catch (RuntimeException e) {
throw new EntityEncodingException("Unable to populate bean for ref ("+ref+") from data: " + decoded + ":" + e.getMessage(), ref+"", e);
}
}
}
}
} else {
throw new IllegalArgumentException("This entity ("+ref+") does not allow input translation");
}
if (entity == null) {
throw new EntityException("Unable to encode entity from input for reference: " + ref, ref.toString(), HttpServletResponse.SC_BAD_REQUEST);
}
return entity;
}