Skip to content

FunctionBean doesn't seem to support @Consumes annotation #1020

Closed
@gwolverson

Description

It seems the FunctionBean doesn't support the @Consumes annotation. Doing some comparison work between a Function and a Controller, it appears the routing builder for FunctionBeans (AnnotatedFunctionRouteBuilder) doesn't take into account any @Consumes annotation that may have been supplied on the function method. Whereas the AnnotatedMethodRouteBuilder which handles routing for Controllers does. Not sure if this is a defect or if there's a reason FunctionBeans don't support @Consumes, however the documentation for @Consumes does state it should be applicable to any component.

Task List

  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. Create a FunctionBean with a single method (apply) in this case, which takes a single argument (a single 'name' parameter was being used in this case). Annotate the method with @Consumes(MediaType.APPLICATION_FORM_URLENCODED). (see feedbackform function in provided github project)

  2. Send a request from a standard HTML form POST method with encoding type set to application/x-www-form-urlencoded, with the action going to your function endpoint. (see html form created in feedbackprocessor project in provided github project)

Expected Behaviour

As I understand the behaviour of @Consumes, the AnnotatedFunctionRouteBuilder should build the route with a list of acceptedMediaTypes from the media types passed into the @Consumes annotation set on the function method. This should then allow the function to accept incoming requests which have the encoding type of application/x-www-form-urlencoded.

Actual Behaviour

The @Consumes annotation appears to be ignored completely (can't see anything in the core code which does a look up on that annotation to set values on the route), and the default application/json is used - which in this scenario causes an error due to the media type being used is; application/x-www-form-urlencoded.

Error thrown is Matched route is not a supported media type: application/x-www-form-urlencoded

Environment Information

  • Operating System: Windows 10
  • Micronaut Version: 1.0.1
  • JDK Version: 1.9

Example Application

  • https://github.com/gwolverson/micronaut-functions

  • feedbackform: contains simple code to build up a HTML form (which sends data to the processor function)

  • feedbackprocessor: should accept the incoming form data and process it (this fails with the above issue)

Metadata

Assignees

Labels

status: under considerationThe issue is being considered, but has not been accepted yettype: improvementA minor improvement to an existing feature

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions