New answers tagged

1

Checking the file suffix seems easy, but ultimately pointless. A file named foo.bar might be a valid jpeg file. A file named reallyIsA.jpg might be a nasty virus. Remember when some corporate firewalls forbid you from emailing .exe or .zip files and everybody just changed the extensions? IMO, your API should specify "a file in one of these image formats: ...


1

You should provide an API with documentation. In your documentation you should document what unusal inputs are handled well, what incorrect inputs you will detect and how you will respond to them - and what incorrect inputs you will not detect. And your implementation should follow that documentation. Your API can be written with the attitude "calling it ...


0

In this example and in most other real world examples the overhead of validation will be negligible compared to the work your API is supposed to do. For starters you may want to create a class MediaFile that encapsulates the input of your API. All validation can then be done in the constructor of the media file class. MediaFile could be abstract and you ...


0

Both controller layer and service layer expose certain interfaces. Interfaces define contracts on how the interface should be used. Contract usually means which arguments (and its types and values) are expected, which exceptions can be thrown, which side effects are created etc. Now, your validation is essentially enforcement of the contract of controller ...


0

Input should be checked in service layer. And "Can't find id" is logical error condition. So should be thrown from controller layer. This again depends on your layering / design. What a service layer is supposed to do and what is expected from controller layer.


5

To validate an XML file, you first need an XML Schema Definition (XSD) that describes the structure of a valid XML document. You can find the specification for XSD files at W3C. Going into how to build the XSD requires knowing how your XML should be structured. For detailed information about the actual Java implementation of this, check out What's the best ...


0

we can't have duplicate Category names either, that would just cause confusing and redundancy. Assuming that you have a business invariant that requires no duplicate category names, then the responsibility for enforcing that invariant belongs in some aggregate. Since enforcing the rule requires having access to all of the category names currently in ...



Top 50 recent answers are included