Oracle Blog

EARTHLY Powers

@FormParam

I have been unifying the injection mechanism in Jersey, making it more modular and improving the performance of injection (now it is possible to plug-in your own injectable behavior for injecting on to fields, constructors and resource methods, including overriding or augmenting existing behavior... more later in another entry perhaps...).

As a serendipitous consequence of those changes it was so easy to implement the support for form parameters i could not resist (in fact the implementation is pluggable so i could have provided the functionality as a separate jar if so desired). In less than 2 hours it was in the main trunk :-)

So by popular request (many have requested this on the users list) I introduce @FormParam.

Form parameters will only work with resource methods where each parameter is annotated and at least one parameter is annotated with @FormParam. The same rules apply as for the other parameters, such as @QueryParam (with the exception that the encoded form is not currently supported).

When using @FormParam for "multipart/form-data" it does not obey the same rules as when using it for MediaType.APPLICATION_FORM_URLENCODED, or the same rules for @QueryParam. Under those rules information is read from characters.

When using with "multipart/form-data" information is read from bytes using the content type of the body part and a matching MessageBodyReader for the annotated Java type.

Thus you can use JAXB beans or another other supported Java type that can be used directly for an entity.

There is no message body reader registered for a Java int type. What would be the media type for the serialization of an integer?

>There is no message body reader registered for a Java int type. What would be the media type for the serialization of an integer?
Good point. application/octet-stream? Then it would be hard to differentiate between basic types.. Anyway I can live with some type checking on my web app :)

BTW, congratulations for your great work. You've made making applications that deal with forms ridiculously easy.

I'm a bit late considering the publish date of this article, but I just added a file upload to my rest service (using @FormParam("foo")File file) and I am wondering if it is possible to obtain the original file name inside my service method?