krtkush
krtkush

Reputation: 1528

Is it possible to retrieve path parameters in an undefined sequence?

Currently the URL I receive as a service request is somewhat like this-

http://192.168.1.223:8080/webservices/test/UserSignUp/FirstName=kk&LastName=test&[email protected]&UUID=1234&EmpCode=18&MobileNo=123456789

And the following code is responsible for data extraction -

    @Path("FirstName={param0}&LastName={param1}&MailId={param2}&UUID={param3}"
            + "&EmployeeCode={param4}&MobileNo={param5}")
    @GET
    @Produces("application/json")
    public Response userSignUpService(
            @PathParam("param0") String firstName, 
            @PathParam("param1") String lastName,
            @PathParam("param2") String mailId,
            @PathParam("param3") String uuId,
            @PathParam("param4") String empCode,
            @PathParam("param5") String mobileNo) {

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("FirstName", firstName);
        jsonObject.put("LastName", lastName);
        jsonObject.put("MailId", mailId);
        jsonObject.put("UUID", uuId);
        jsonObject.put("EmployeeCode", empCode);
        jsonObject.put("MobileNo", mobileNo);

        String result = String.valueOf(jsonObject);

        return Response.status(200).entity(result).build();     
    } 

In the above approach the sequence of the parameters is fixed. i.e. firstname, lastname, mailid, uuid, empcode, and mobileno.

I want the above sequence to be undefined. What I mean is, that, the above parameters should be delivered in any sequence and my code should be able to extract them.

Is it possible?

Upvotes: 1

Views: 82

Answers (1)

vikingsteve
vikingsteve

Reputation: 40418

Sounds like you might want to look at @QueryParam instead of @PathParam.

E.g. http://www.mkyong.com/webservices/jax-rs/jax-rs-queryparam-example/

Upvotes: 4

Related Questions