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

Community Beginner ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

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.

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

 

 

Views

85

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

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 (server troubleshooter, carehart.org)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

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. 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 24, 2021 Apr 24, 2021

Copy link to clipboard

Copied

@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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 24, 2021 Apr 24, 2021

Copy link to clipboard

Copied

There is a break in backward compatibility. So, all said and done, what you have observed might be a bug.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 24, 2021 Apr 24, 2021

Copy link to clipboard

Copied

LATEST

Oh, @Phil5C93 , an incompatibility:

 

/*
...
* @Return JSON
*/
remote void function save(...)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines