0

I have the following code always returning null when calling getParameter()`

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Response;
import javax.ws.rs.Path;

@Path("/path")
public class MyResource {

    protected ResponseBuilder response;
    protected HttpServletRequest request;

    public MyResource(@Context HttpServletRequest request) {
        this.request = request;
        this.response = Response.ok();
    }

    @POST
    public Response postTest() {
        JSONObject responseObj = new JSONObject();

        String test = request.getParameter("test");

        log.debug(test);

        return response.entity(responseObj.toString()).build();
    }
}

I'm using this curl to trigger it:

curl -X POST -H "Cache-Control: no-cache" -H "Postman-Token: b7a3801f-b9d7-c7a1-004e-ac70b835d436" -H "Content-Type: application/x-www-form-urlencoded" -d 'test=12345' 'http://localhost:8180/path'

What am I doing wrong?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Charles
  • 11,367
  • 10
  • 77
  • 114

1 Answers1

0

Thanks for the help.

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Response;
import javax.ws.rs.Path;

@Path("/path")
public class MyResource {

    protected ResponseBuilder response;
    protected HttpServletRequest request;

    public MyResource(@Context HttpServletRequest request) {
        this.request = request;
        this.response = Response.ok();
    }

    @POST
    public Response postTest(@FormParam("test") String test) {
        JSONObject responseObj = new JSONObject();

        log.debug(test);

        return response.entity(responseObj.toString()).build();
    }
}
Charles
  • 11,367
  • 10
  • 77
  • 114