Skip to main content
Inspiring
April 22, 2021
Question

Having issue with migrated REST API from CF2010 to CF2018. Complaining about @FormParam.

  • April 22, 2021
  • 2 replies
  • 636 views

I've migrated the app and only one endpoint is having an issue. Java server does a form post to it. Every time I get this error. It looks like its failing where it validates data being passed in so my try catch inside the endpoint isn't catching it.

 

The @FormParam is utilized when the content type of the request entity is not application/x-www-form-urlencoded The specific sequence of files included or processed is: d:\xx\xx.cfc
java.lang.IllegalStateException: The @FormParam is utilized when the content type of the request entity is not application/x-www-form-urlencoded
at org.glassfish.jersey.server.internal.inject.FormParamValueFactoryProvider$FormParamValueFactory.ensureValidRequest(FormParamValueFactoryProvider.java:176)
at org.glassfish.jersey.server.internal.inject.FormParamValueFactoryProvider$FormParamValueFactory.getForm(FormParamValueFactoryProvider.java:160)
at org.glassfish.jersey.server.internal.inject.FormParamValueFactoryProvider$FormParamValueFactory.provide(FormParamValueFactoryProvider.java:116)
at org.glassfish.jersey.server.spi.internal.ParameterValueHelper.getParameterValues(ParameterValueHelper.java:81)

 

The opening of my endpoint looks like this.

/**
* @1079745 save
* @10091119 POST
* @DESCRIPTION
* @Return JSON
*/
remote void function save( build='{"null":"null"}' restargsource='form' ) httpmethod='POST' restpath='save' {

 

 

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    April 24, 2021

    Oh, @Phil5C93 , an incompatibility:

     

    /*
    ...
    * @Return JSON
    */
    remote void function save(...)
    Charlie Arehart
    Community Expert
    April 22, 2021

    Phil, what update of cf2018 is this? And have you confirmed there were 0 fatalerrors in the install log for the latest update? That's in the update's folder in the hf-updates directory. 

    /Charlie (troubleshooter, carehart. org)
    Phil5C93Author
    Inspiring
    April 22, 2021

    This is happening on CF2018 update 11.

     

    I kept digging and found this in the Adobe bug tracker. https://tracker.adobe.com/#/view/CF-4158293

     

    Looks like there was an issue with CF 2016 about needing to use APPLICATION/X-WWW-FORM-URLENCODED

    I then looked into our Java app and saw that its using application/json. I tested calling the endpoint with application/json and it failed, I then changed it to APPLICATION/X-WWW-FORM-URLENCODED and it worked with out issue.

     

    My guess is this may have to do with the Eclipse Jersey implementation in CF that took place after CF10. Thats expected considering the length of time between upgrading. 

     

    BKBK
    Community Expert
    April 24, 2021

    @FormParam is shorthand for the annotation @javax.ws.rs.FormParam in Java's standard REST API, JAX-RS. ColdFusion 2018's REST API ia an implementation of JAX-RS.

     

    @FormParam requires that the request body of the input be of type application/x-www-form-urlencoded. That is, it requires that your service receive input from an HTML form. This in turn implies that the value of the request's Content-Type header must be application/x-www-form-urlencoded.

     

    The 2 most likely causes of the error are therefore:

    1. when the REST service expects input from a form (@FormParam), but the request-body/Content-Type is of a type different from application/x-www-form-urlencoded, often application/json;
    2. when the request-body/Content-Type is of type application/x-www-form-urlencoded, but the REST service expects input other than from a form.

     

    The likeliest scenario, to cut a long story short:

    • ensure that the form structure isn't first serialized to JSON before it reaches the REST service;
    • where necessary, deserialize the JSON input to a (form) structure and use this in the request to the REST service.