I'm migrating a java web app from payara 4 to payara 6, and now when the servlet tries to access the data from the post request the data is always null. This didn't happen when it was running in Payara 4.
I should note when it was running in Payara 4 it was using Java 8 and using the javax imports. Now that its in Payara 6 its using Java 11 and now using jakarta imports.
Here's the code.. The DynamicReq object has a parameters value that is null which is the issue:
import java.util.List;import java.util.logging.Logger;import jakarta.ws.rs.Consumes;import jakarta.ws.rs.GET;import jakarta.ws.rs.POST;import jakarta.ws.rs.Path;import jakarta.ws.rs.PathParam;import jakarta.ws.rs.Produces;import jakarta.ws.rs.core.MediaType; // .. other code .. // @POST @Path("/queries/{userQueryName}") @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public DynamicRes dynamicQuery ( @PathParam("userQueryName") String userQueryName, DynamicReq entity) throws IncompleteQueryException { List<String> parameters = entity.getParameters(); // PROBLEM HERE, it always returns null // .. other code .. // }
Here's the DynamicReq class that is returning the null from its getParameters()
method:
import java.util.List; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement public class DynamicReq { @XmlElement(name = "parameters", required = true) protected List<String> parameters; public List<String> getParameters() { return parameters; // again this method returns NULL in the servlet above } }
As mentioned when this was in Payara 4 server and using the javax.* instead of jakarta.* the code List<String> parameters = entity.getParameters();
is able to extract the data sent from the user.
BUT now the entity.getParamters();
returns null. I have confirmed from the app that sends the post request that there is data being sent across.
The only way I can extract the data is if I update the servlet to have the entity parameter be of type Object instead of DynamicReq and cast it as a HashMap and extract the parameters that way, such as:
public DynamicRes dynamicQuery( @PathParam("userQueryName") String userQueryName, Object entity) throws IncompleteQueryException { HashMap map = null; if (entity instanceof HashMap) { map = (HashMap)entity; } List<String> parameters = (List<String>)map.get("parameters"); // HERE ABLE TO GET THE DATA, ie the data is NOT null. // other code // }
I would prefer to not update the code to use Objects and HashMaps and for it to use the DynamicReq parameter type. Any help would be great.