[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wink-user
Subject:    Re: POSTing from a Form
From:       Bryant Luk <bryant.luk () gmail ! com>
Date:       2009-12-10 23:45:28
Message-ID: d5d04a30912101545m26ece3cdi28978937d758530e () mail ! gmail ! com
[Download RAW message or body]

Hello,

I'm assuming that your request entity type BookEdition is a JAXB
annotated type (and you're using some JSON to JAXB provider like the
ones provided via Jettison/Jackson/json.org).

Unfortunately, there is no standard entity provider for turning
application/x-www-form-urlencoded typed content into a JAXB Java type.
 I believe the spec states that the JAXB entity provider only needs to
support text/xml, application/xml, and application/*+xml.

A String, byte[], etc., and specifically
javax.ws.rs.core.MultivaluedMap could be used for consuming
application/x-www-form-urlencoded content.

You may have to add a method specifically for URL encoded form data
(while removing the MediaType.APPLICATION_FORM_URLENCODED from your
previous method):

       @POST
       @Consumes({MediaType.APPLICATION_FORM_URLENCODED})
       @Produces(MediaType.APPLICATION_JSON)
       public BookEdition addNewEdition(MultivaluedMap<String, String>
editionMap) {
             BookEdition edition = new BookEdition();
              // read form encoded parameters and set values on edition
               System.out.println("Adding " + edition);
               // etc.
       }

Out of curiosity, how do you expect the form data to be deserialized
into JAXB types (i.e. form parameter names would be set to the same
named element/attribute values)?

On Thu, Dec 10, 2009 at 5:02 PM, djna <artusd@uk.ibm.com> wrote:
> 
> My reading of the spec is that REST implementors must implement
> application/x-www-form-urlencoded and so I was expecting with the
> appropriate @Consumes this HTML Form would POST something Wink could process
> 
> <form method="post" action="/LibraryWink/library/editions"
> enctype="application/x-www-form-urlencoded">
> 
> The Wink method being
> 
> @POST
> @Consumes({MediaType.APPLICATION_FORM_URLENCODED,
> MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
> @Produces(MediaType.APPLICATION_JSON)
> public BookEdition addNewEdition(BookEdition edition) {
> System.out.println("Adding " + edition);
> // etc.
> }
> 
> Using the Firefox Poster plugin I've verified that the
> MediaType.APPLICATION_XMLworks fine. But when I post my form I get:
> 
> [03/12/09 13:26:08:296 GMT] 00000024 RequestProces I
> org.apache.wink.server.internal.RequestProcessor logException
> WebApplicationException (415 - Unsupported Media Type) occured during the
> handlers chain invocation
> javax.ws.rs.WebApplicationException
> at
> org.apache.wink.server.internal.registry.ServerInjectableFactory$EntityParam.getValue(ServerInjectableFactory.java:200)
>  at
> org.apache.wink.common.internal.registry.InjectableFactory.instantiate(InjectableFactory.java:67)
>  at
> org.apache.wink.server.internal.handlers.CreateInvocationParametersHandler.handleRequest(CreateInvocationParametersHandler.java:44)
>  at
> org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:26)
>  at
> org.apache.wink.server.handlers.RequestHandlersChain.handle(RequestHandlersChain.java:22)
>  at
> org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:61)
>  at
> org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleResourceMethod(FindResourceMethodHandler.java:146)
>  at
> org.apache.wink.server.internal.handlers.FindResourceMethodHandler.handleRequest(FindResourceMethodHandler.java:66)
>  
> So I guess that there's some piece of config I need to do to enable this
> MediaType. My starting point is the SimpleDefects Wink example, which has
> only a very simple config listing an Application. I'm guessing I need to add
> some more handlers but I'm not clear what I need to do to make that happen.
> 
> --
> View this message in context: \
> http://n2.nabble.com/POSTing-from-a-Form-tp4148475p4148475.html Sent from the \
> Apache Wink Users mailing list archive at Nabble.com. 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic