0

I have an API where it accepts 4 Queryparams. Here the problem is, it is accepting only first QueryParam and not accepting other QueryParams

Sample Curl:

1) curl -vk -X GET http://localhost:8080/sample-application/employee?empname=sat&empId=3438&designation=developer

Here its not accepting empId & designation i.e in the O/P printing null values

2) curl -vk -X GET http://localhost:8080/sample-application/employee?empId=3438&empname=sat&designation=developer

Here its not accepting empname & designation i.e in the O/P printing null values

3) curl -vk -X GET http://localhost:8080/sample-application/employee?designation=developer&empname=sat&empId=3438

Here its not accepting empname & empId i.e in the O/P printing null values

Here is my code

 @Path("/employee")
 @Produces(MediaType.APPLICATION_JSON)
 @Consumes(MediaType.APPLICATION_JSON)
 public class EmployeeRS {

 private static final Logger logger = LoggerFactory.getLogger(EmployeeRS.class);

 @GET
 @ApiOperation(value = "Get Employee Details", response = Employee.class)
 public Response getEmployee(
        @ApiParam(value = "Employee Name", required = false) @QueryParam(value = "empname") final String empname,
        @ApiParam(value = "Employee Id", required = false) @QueryParam("empId") String empId,
        @ApiParam(value = "Designation", required = false) @QueryParam("designation") String designation) {

        logger.info("Get Employee for empname:{}, empId:{}, designation:{}",
                empname, empId, designation);
        //Functionality to get Data
 }
}
Sat
  • 3,520
  • 9
  • 39
  • 66
  • add double quotation in your curl url else it will not take the value after the &. That's why it's taking only one parameter. – Shivang Agarwal Aug 02 '18 at 10:39
  • [The `&` has a special meaning in the terminal](https://stackoverflow.com/q/13338870/2587435), that's why it stops after the first parameter. – Paul Samsotha Aug 02 '18 at 18:32

1 Answers1

0

I figure out the problem, the issue is with the curl command. In order to consider more than 1 Query Param, we have to add quotes (" or ') just before URL i.e http and at the end of URL. So we have to place URL between the quotes.

curl -vk -X GET "http://localhost:8080/sample-application/employee?empId=3438&empname=sat&designation=developer"
Sat
  • 3,520
  • 9
  • 39
  • 66