You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@wink.apache.org by djna <ar...@uk.ibm.com> on 2009/12/11 00:02:27 UTC

POSTing from a Form

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.

Re: POSTing from a Form

Posted by Bryant Luk <br...@gmail.com>.
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 <ar...@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.
>