{"id":16683,"date":"2013-08-26T19:00:40","date_gmt":"2013-08-26T16:00:40","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=16683"},"modified":"2013-08-26T13:57:01","modified_gmt":"2013-08-26T10:57:01","slug":"how-to-implement-input-validation-for-rest-resources","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html","title":{"rendered":"How To Implement Input Validation For REST resources"},"content":{"rendered":"<h2>How To Implement Input Validation For REST\u00a0resources<\/h2>\n<p>The SaaS platform I\u2019m working on has a RESTful interface that accepts XML payloads.<a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/rest-validation.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/rest-validation-150x150.png\" alt=\"rest-validation\" width=\"150\" height=\"150\" class=\"alignright size-thumbnail wp-image-16761\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/rest-validation-150x150.png 150w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/rest-validation-100x100.png 100w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/rest-validation-42x42.png 42w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/a><\/p>\n<h4>Implementing REST Resources<\/h4>\n<p>For a Java shop like us, it makes sense to use <a href=\"http:\/\/jaxb.java.net\/\" target=\"_blank\" rel=\"nofollow\">JAX-B<\/a> to generate <a href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/javabeans\/\" target=\"_blank\" rel=\"nofollow\">JavaBean<\/a> classes from an XML Schema. Working with XML (and JSON) payloads using JAX-B is very easy in a <a href=\"http:\/\/jax-rs-spec.java.net\/\" target=\"_blank\" rel=\"nofollow\">JAX-RS<\/a> environment like <a href=\"https:\/\/jersey.java.net\/documentation\/latest\/user-guide.html\" target=\"_blank\" rel=\"nofollow\">Jersey<\/a>:<\/p>\n<pre class=\" brush:java\">@Path(\"orders\")\r\npublic class OrdersResource {\r\n  @POST\r\n  @Consumes({ \"application\/xml\", \"application\/json\" })\r\n  public void place(Order order) {\r\n    \/\/ Jersey marshalls the XML payload into the Order \r\n    \/\/ JavaBean, allowing us to write type-safe code \r\n    \/\/ using Order's getters and setters.\r\n    int quantity = order.getQuantity();\r\n    \/\/ ...\r\n  }\r\n}<\/pre>\n<p>(Note that you shouldn\u2019t use these generic media types, but that\u2019s a discussion for another day.)<\/p>\n<p>The remainder of this post assumes JAX-B, but its main point is valid for other technologies as well. Whatever you do, please don\u2019t use <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/beans\/XMLDecoder.html\" target=\"_blank\" rel=\"nofollow\"><code>XMLDecoder<\/code><\/a>, since that is open to a <a title=\"Using XMLDecoder to execute server-side Java Code on an Restlet application (i.e. Remote Command Execution)\" href=\"http:\/\/blog.diniscruz.com\/2013\/08\/using-xmldecoder-to-execute-server-side.html\" target=\"_blank\" rel=\"nofollow\">host of vulnerabilities<\/a>.<\/p>\n<h4>Securing REST Resources<\/h4>\n<p>Let\u2019s suppose the order\u2019s <code>quantity<\/code> is used for billing, and we want to prevent people from <a href=\"http:\/\/blog.whitehatsec.com\/root-of-the-issue\/\" target=\"_blank\" rel=\"nofollow\">stealing our money by entering a negative amount<\/a>.<\/p>\n<p>We can do that with <a href=\"https:\/\/www.owasp.org\/index.php\/Category:Input_Validation\" target=\"_blank\" rel=\"nofollow\">input validation<\/a>, one of the most important tools in the <a href=\"http:\/\/securesoftwaredev.com\/security\/appsec\/\" target=\"_blank\">AppSec<\/a> toolkit. Let\u2019s look at some ways to implement it.<\/p>\n<h4>Input Validation With XML Schema<\/h4>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/xml-schema.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/xml-schema.png\" alt=\"xml-schema\" width=\"160\" height=\"76\" class=\"alignleft size-full wp-image-16762\" \/><\/a>We could rely on <a title=\"Deriving simple types from built-in types\" href=\"http:\/\/www.w3.org\/TR\/xmlschema-0\/#ref7\" target=\"_blank\" rel=\"nofollow\">XML Schema for validation<\/a>, but XML Schema can only validate so much.<\/p>\n<p>Validating individual properties will probably work fine, but things get hairy when we want to validate relations between properties. For maximum flexibility, we\u2019d like to use Java to express constraints.<\/p>\n<p>More importantly, <strong>schema validation is generally not a good idea in a REST service<\/strong>.<\/p>\n<p>A major goal of REST is to <a href=\"http:\/\/www.ics.uci.edu\/~fielding\/pubs\/dissertation\/rest_arch_style.htm#sec_5_1_2\" target=\"_blank\" rel=\"nofollow\">decouple client and server<\/a> so that they can evolve separately.<\/p>\n<p>If we validate against a schema, then a new client that sends a new property would break against an old server that doesn\u2019t understand the new property. It\u2019s usually better to silently ignore properties you don\u2019t understand.<\/p>\n<p>JAX-B does this right, and also the other way around: properties that are not sent by an old client end up as <code>null<\/code>. Consequently, the new server must be careful to handle <code>null<\/code> values properly.<\/p>\n<h4>Input Validation With Bean Validation<\/h4>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/bean-validation.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/bean-validation.png\" alt=\"bean-validation\" width=\"160\" height=\"134\" class=\"alignright size-full wp-image-16763\" \/><\/a>If we can\u2019t use schema validation, then what about using JSR 303 <a href=\"http:\/\/beanvalidation.org\/\" target=\"_blank\" rel=\"nofollow\">Bean Validation<\/a>?<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Jersey supports Bean Validation by adding the <a href=\"http:\/\/search.maven.org\/#browse|-776590769\" target=\"_blank\" rel=\"nofollow\"><code>jersey-bean-validation<\/code><\/a> jar to your classpath.<\/p>\n<p>There is an <a href=\"https:\/\/www.java.net\/\/forum\/topic\/glassfish\/metro-and-jaxb\/jaxb-plugin-generate-bean-validation-annotations-jsr-303\" target=\"_blank\" rel=\"nofollow\">unofficial Maven plugin to add Bean Validation annotations<\/a> to the JAX-B generated classes, but I\u2019d rather use something better supported and that works with <a href=\"http:\/\/www.gradle.org\/\" target=\"_blank\" rel=\"nofollow\">Gradle<\/a>.<\/p>\n<p>So let\u2019s turn things around. We\u2019ll handcraft our JavaBean and <a href=\"http:\/\/jaxb.java.net\/guide\/Invoking_schemagen_programatically.html\" target=\"_blank\" rel=\"nofollow\">generate the XML Schema from the bean<\/a> for documentation:<\/p>\n<pre class=\" brush:java\">@XmlRootElement(name = \"order\")\r\npublic class Order {\r\n  @XmlElement\r\n  @Min(1)\r\n  public int quantity;\r\n}<\/pre>\n<pre class=\" brush:java\">@Path(\"orders\")\r\npublic class OrdersResource {\r\n  @POST\r\n  @Consumes({ \"application\/xml\", \"application\/json\" })\r\n  public void place(@Valid Order order) {\r\n    \/\/ Jersey recognizes the @Valid annotation and\r\n    \/\/ returns 400 when the JavaBean is not valid\r\n  }\r\n}<\/pre>\n<p>Any attempt to <code>POST<\/code> an order with a non-positive quantity will now give a <code>400 Bad Request<\/code> status.<\/p>\n<p>Now suppose we want to allow clients to change their pending orders. We\u2019d use <code>PATCH<\/code> or <code>PUT<\/code> to update individual order properties, like quantity:<\/p>\n<pre class=\" brush:java\">@Path(\"orders\")\r\npublic class OrdersResource {\r\n  @Path(\"{id}\")\r\n  @PUT\r\n  @Consumes(\"application\/x-www-form-urlencoded\")\r\n  public Order update(@PathParam(\"id\") String id, \r\n      @Min(1) @FormParam(\"quantity\") int quantity) {\r\n    \/\/ ...\r\n  }\r\n}<\/pre>\n<p>We need to add the <code>@Min<\/code> annotation here too, which is duplication. To make this <a href=\"http:\/\/c2.com\/cgi\/wiki?DontRepeatYourself\" target=\"_blank\" rel=\"nofollow\">DRY<\/a>, we can turn <code>quantity<\/code> into a class that is responsible for validation:<\/p>\n<pre class=\" brush:java\">@Path(\"orders\")\r\npublic class OrdersResource {\r\n  @Path(\"{id}\")\r\n  @PUT\r\n  @Consumes(\"application\/x-www-form-urlencoded\")\r\n  public Order update(@PathParam(\"id\") String id, \r\n      @FormParam(\"quantity\")\r\n      Quantity quantity) {\r\n    \/\/ ...\r\n  }\r\n}<\/pre>\n<pre class=\" brush:java\">@XmlRootElement(name = \"order\")\r\npublic class Order {\r\n  @XmlElement\r\n  public Quantity quantity;\r\n}<\/pre>\n<pre class=\" brush:java\">public class Quantity {\r\n  private int value;\r\n\r\n  public Quantity() { }\r\n\r\n  public Quantity(String value) {\r\n    try {\r\n      setValue(Integer.parseInt(value));\r\n    } catch (ValidationException e) {\r\n      throw new IllegalArgumentException(e);\r\n    }\r\n  }\r\n\r\n  public int getValue() {\r\n    return value;\r\n  }\r\n\r\n  @XmlValue\r\n  public void setValue(int value) \r\n      throws ValidationException {\r\n    if (value &lt; 1) {\r\n      throw new ValidationException(\r\n          \"Quantity value must be positive, but is: \" \r\n          + value);\r\n    }\r\n    this.value = value;\r\n  }\r\n}<\/pre>\n<p>We need a public no-arg constructor for JAX-B to be able to unmarshall the payload into a JavaBean and another <a href=\"https:\/\/jersey.java.net\/documentation\/latest\/user-guide.html#d0e1432\" target=\"_blank\" rel=\"nofollow\">constructor that takes a <code>String<\/code><\/a> for the <code>@FormParam<\/code> to work.<\/p>\n<p><code>setValue()<\/code> throws <code>javax.xml.bind.ValidationException<\/code> so that JAX-B will stop unmarshalling. However, Jersey returns a <code>500 Internal Server Error<\/code> when it sees an exception.<\/p>\n<p>We can fix that by mapping validation exceptions onto <code>400<\/code> status codes using an <a href=\"https:\/\/jersey.java.net\/documentation\/latest\/user-guide.html#d0e3490\" target=\"_blank\" rel=\"nofollow\">exception mapper<\/a>. While we\u2019re at it, let\u2019s do the same for <code>IllegalArgumentException<\/code>:<\/p>\n<pre class=\" brush:java\">@Provider\r\npublic class DefaultExceptionMapper \r\n    implements ExceptionMapper&lt;Throwable&gt; {\r\n\r\n  @Override\r\n  public Response toResponse(Throwable exception) {\r\n    Throwable badRequestException \r\n        = getBadRequestException(exception);\r\n    if (badRequestException != null) {\r\n      return Response.status(Status.BAD_REQUEST)\r\n          .entity(badRequestException.getMessage())\r\n          .build();\r\n    }\r\n    if (exception instanceof WebApplicationException) {\r\n      return ((WebApplicationException)exception)\r\n          .getResponse();\r\n    }\r\n    return Response.serverError()\r\n        .entity(exception.getMessage())\r\n        .build();\r\n  }\r\n\r\n  private Throwable getBadRequestException(\r\n      Throwable exception) {\r\n    if (exception instanceof ValidationException) {\r\n      return exception;\r\n    }\r\n    Throwable cause = exception.getCause();\r\n    if (cause != null &amp;&amp; cause != exception) {\r\n      Throwable result = getBadRequestException(cause);\r\n      if (result != null) {\r\n        return result;\r\n      }\r\n    }\r\n    if (exception instanceof IllegalArgumentException) {\r\n      return exception;\r\n    }\r\n    if (exception instanceof BadRequestException) {\r\n      return exception;\r\n    }\r\n    return null;\r\n  }\r\n\r\n}<\/pre>\n<h4>Input Validation By Domain Objects<\/h4>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/51WLtI-uLcL._BO2204203200_PIsitb-sticker-arrow-clickTopRight35-76_AA278_PIkin4BottomRight-5122_AA300_SH20_OU01_.jpg\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/51WLtI-uLcL._BO2204203200_PIsitb-sticker-arrow-clickTopRight35-76_AA278_PIkin4BottomRight-5122_AA300_SH20_OU01_-150x150.jpg\" alt=\"http:\/\/www.amazon.com\/Domain-Driven-Design-Tackling-Complexity-ebook\/dp\/B00794TAUG\/ref=tmm_kin_title_0?ie=UTF8&amp;qid=1376856556&amp;sr=1-1\" width=\"150\" height=\"150\" class=\"alignleft size-thumbnail wp-image-16766\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/51WLtI-uLcL._BO2204203200_PIsitb-sticker-arrow-clickTopRight35-76_AA278_PIkin4BottomRight-5122_AA300_SH20_OU01_-150x150.jpg 150w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/51WLtI-uLcL._BO2204203200_PIsitb-sticker-arrow-clickTopRight35-76_AA278_PIkin4BottomRight-5122_AA300_SH20_OU01_-200x200.jpg 200w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/51WLtI-uLcL._BO2204203200_PIsitb-sticker-arrow-clickTopRight35-76_AA278_PIkin4BottomRight-5122_AA300_SH20_OU01_-100x100.jpg 100w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/51WLtI-uLcL._BO2204203200_PIsitb-sticker-arrow-clickTopRight35-76_AA278_PIkin4BottomRight-5122_AA300_SH20_OU01_-42x42.jpg 42w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/51WLtI-uLcL._BO2204203200_PIsitb-sticker-arrow-clickTopRight35-76_AA278_PIkin4BottomRight-5122_AA300_SH20_OU01_.jpg 300w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/a>Even though the approach outlined above will work quite well for many applications, it is fundamentally flawed.<\/p>\n<p>At first sight, proponents of <a href=\"http:\/\/dddcommunity.org\/learning-ddd\/what_is_ddd\/\" target=\"_blank\" rel=\"nofollow\">Domain-Driven Design<\/a> (DDD) might like the idea of creating the <code>Quantity<\/code> class.<\/p>\n<p>But the <code>Order<\/code> and <code>Quantity<\/code> classes do not model domain concepts; they model REST representations. This distinction may be subtle, but it is important.<\/p>\n<p><strong>DDD deals with domain concepts, while REST deals with <em>representations<\/em> of those concepts.<\/strong> Domain concepts are discovered, but <strong>representations are designed<\/strong> and are subject to all kinds of trade-offs.<\/p>\n<p>For instance, a collection REST resource may use paging to prevent sending too much data over the wire. Another REST resource may combine several domain concepts to make the client-server protocol less chatty.<\/p>\n<p>A REST resource may even have no corresponding domain concept at all. For example, a <code>POST<\/code> may return <a href=\"http:\/\/tools.ietf.org\/html\/rfc2616#section-10.2.3\" target=\"_blank\" rel=\"nofollow\"><code>202 Accepted<\/code><\/a> and point to a REST resource that represents the progress of an asynchronous transaction.<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/ubiquitous-language.png\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/ubiquitous-language-300x200.png\" alt=\"ubiquitous-language\" width=\"300\" height=\"200\" class=\"alignright size-medium wp-image-16764\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/ubiquitous-language-300x200.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/ubiquitous-language.png 486w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/a>Domain objects need to capture the <a href=\"http:\/\/www.jamesshore.com\/Agile-Book\/ubiquitous_language.html\" target=\"_blank\" rel=\"nofollow\">ubiquitous language<\/a> as closely as possible, and must be free from trade-offs to make the functionality work.<\/p>\n<p>When designing REST resources, on the other hand, one needs to make trade-offs to meet non-functional requirements like performance, scalability, and evolvability.<\/p>\n<p>That\u2019s why I don\u2019t think an approach like <a href=\"http:\/\/restfulobjects.org\/\" target=\"_blank\" rel=\"nofollow\">RESTful Objects<\/a> will work. (For similar reasons, I don\u2019t believe in <a href=\"http:\/\/en.wikipedia.org\/wiki\/Naked_objects\" target=\"_blank\" rel=\"nofollow\">Naked Objects<\/a> for the UI.)<\/p>\n<p>Adding validation to the JavaBeans that are our resource representations means that those beans now have two reasons to change, which is a clear violation of the <a href=\"http:\/\/www.objectmentor.com\/resources\/articles\/srp.pdf\" target=\"_blank\" rel=\"nofollow\">Single Responsibility Principle<\/a>.<\/p>\n<p>We get a much <a href=\"http:\/\/blog.8thlight.com\/uncle-bob\/2012\/08\/13\/the-clean-architecture.html\" target=\"_blank\" rel=\"nofollow\">cleaner architecture<\/a> when we use JAX-B JavaBeans only for our REST representations and create separate domain objects that handle validation.<\/p>\n<p>Putting validation in domain objects is what <a title=\"Introducing Domain Driven Security\" href=\"http:\/\/dearjunior.blogspot.nl\/2009\/09\/introducing-domain-driven-security.html\" target=\"_blank\" rel=\"nofollow\">Dan Bergh Johnsson<\/a> refers to as <a href=\"http:\/\/vimeo.com\/28768994\" target=\"_blank\" rel=\"nofollow\">Domain-Driven Security<\/a>.<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/cave-art.jpg\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/cave-art.jpg\" alt=\"cave-art\" width=\"160\" height=\"117\" class=\"alignleft size-full wp-image-16765\" \/><\/a>In this approach, primitive types are replaced with value objects. (Some people even <a title=\"Should String Be An Abstract Class?\" href=\"http:\/\/appsandsecurity.blogspot.nl\/2013\/05\/should-string-be-abstract-class.html\" target=\"_blank\" rel=\"nofollow\">argue against using any <code>String<\/code>s<\/a> at all.)<\/p>\n<p>At first it may seem overkill to create a whole new class to hold a single integer, but I urge you to give it a try. You may find that getting rid of <a href=\"http:\/\/c2.com\/cgi\/wiki?PrimitiveObsession\" target=\"_blank\" rel=\"nofollow\">primitive obsession<\/a> provides value even beyond validation.<br \/>\n&nbsp;<\/p>\n<h4>What do you think?<\/h4>\n<p>How do you handle input validation in your RESTful services? What do you think of Domain-Driven Security? Please leave a comment.<br \/>\n&nbsp;<\/p>\n<div style=\"border: 1px solid #D8D8D8; background: #FAFAFA; width: 100%; padding-left: 5px;\"><b><i>Reference: <\/i><\/b><a href=\"http:\/\/securesoftwaredev.com\/2013\/08\/19\/how-to-implement-input-validation-for-rest-resources\/\">How To Implement Input Validation For REST resources<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Remon Sinnema at the <a href=\"http:\/\/securesoftwaredev.com\/\">Secure Software Development<\/a> blog.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>How To Implement Input Validation For REST\u00a0resources The SaaS platform I\u2019m working on has a RESTful interface that accepts XML payloads. Implementing REST Resources For a Java shop like us, it makes sense to use JAX-B to generate JavaBean classes from an XML Schema. Working with XML (and JSON) payloads using JAX-B is very easy &hellip;<\/p>\n","protected":false},"author":280,"featured_media":112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[54],"class_list":["post-16683","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-restful-web-services"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How To Implement Input Validation For REST resources<\/title>\n<meta name=\"description\" content=\"How To Implement Input Validation For REST\u00a0resources The SaaS platform I\u2019m working on has a RESTful interface that accepts XML payloads. Implementing REST\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Implement Input Validation For REST resources\" \/>\n<meta property=\"og:description\" content=\"How To Implement Input Validation For REST\u00a0resources The SaaS platform I\u2019m working on has a RESTful interface that accepts XML payloads. Implementing REST\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2013-08-26T16:00:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Remon Sinnema\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Remon Sinnema\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/how-to-implement-input-validation-for-rest-resources.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/how-to-implement-input-validation-for-rest-resources.html\"},\"author\":{\"name\":\"Remon Sinnema\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/2be19454dea628d08c8d74390e39aa1f\"},\"headline\":\"How To Implement Input Validation For REST resources\",\"datePublished\":\"2013-08-26T16:00:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/how-to-implement-input-validation-for-rest-resources.html\"},\"wordCount\":948,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/how-to-implement-input-validation-for-rest-resources.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"keywords\":[\"RESTful Web Services\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/how-to-implement-input-validation-for-rest-resources.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/how-to-implement-input-validation-for-rest-resources.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/how-to-implement-input-validation-for-rest-resources.html\",\"name\":\"How To Implement Input Validation For REST resources\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/how-to-implement-input-validation-for-rest-resources.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/how-to-implement-input-validation-for-rest-resources.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"datePublished\":\"2013-08-26T16:00:40+00:00\",\"description\":\"How To Implement Input Validation For REST\u00a0resources The SaaS platform I\u2019m working on has a RESTful interface that accepts XML payloads. Implementing REST\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/how-to-implement-input-validation-for-rest-resources.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/how-to-implement-input-validation-for-rest-resources.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/how-to-implement-input-validation-for-rest-resources.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"java-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/how-to-implement-input-validation-for-rest-resources.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"How To Implement Input Validation For REST resources\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/2be19454dea628d08c8d74390e39aa1f\",\"name\":\"Remon Sinnema\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c1c904b7cd0db78ca7fc1f5f60f05a86efe698d67f440bfbba705956d18c02d3?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c1c904b7cd0db78ca7fc1f5f60f05a86efe698d67f440bfbba705956d18c02d3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c1c904b7cd0db78ca7fc1f5f60f05a86efe698d67f440bfbba705956d18c02d3?s=96&d=mm&r=g\",\"caption\":\"Remon Sinnema\"},\"sameAs\":[\"http:\\\/\\\/securesoftwaredev.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Remon-Sinnema\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Implement Input Validation For REST resources","description":"How To Implement Input Validation For REST\u00a0resources The SaaS platform I\u2019m working on has a RESTful interface that accepts XML payloads. Implementing REST","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html","og_locale":"en_US","og_type":"article","og_title":"How To Implement Input Validation For REST resources","og_description":"How To Implement Input Validation For REST\u00a0resources The SaaS platform I\u2019m working on has a RESTful interface that accepts XML payloads. Implementing REST","og_url":"https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-08-26T16:00:40+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Remon Sinnema","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Remon Sinnema","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html"},"author":{"name":"Remon Sinnema","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/2be19454dea628d08c8d74390e39aa1f"},"headline":"How To Implement Input Validation For REST resources","datePublished":"2013-08-26T16:00:40+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html"},"wordCount":948,"commentCount":5,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","keywords":["RESTful Web Services"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html","url":"https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html","name":"How To Implement Input Validation For REST resources","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","datePublished":"2013-08-26T16:00:40+00:00","description":"How To Implement Input Validation For REST\u00a0resources The SaaS platform I\u2019m working on has a RESTful interface that accepts XML payloads. Implementing REST","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","width":150,"height":150,"caption":"java-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/how-to-implement-input-validation-for-rest-resources.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"How To Implement Input Validation For REST resources"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/2be19454dea628d08c8d74390e39aa1f","name":"Remon Sinnema","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c1c904b7cd0db78ca7fc1f5f60f05a86efe698d67f440bfbba705956d18c02d3?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c1c904b7cd0db78ca7fc1f5f60f05a86efe698d67f440bfbba705956d18c02d3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c1c904b7cd0db78ca7fc1f5f60f05a86efe698d67f440bfbba705956d18c02d3?s=96&d=mm&r=g","caption":"Remon Sinnema"},"sameAs":["http:\/\/securesoftwaredev.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Remon-Sinnema"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/16683","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/280"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=16683"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/16683\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/112"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=16683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=16683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=16683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}