Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass null value in RESTful web service for a GET Method?

I Currently have a RESTFul web Service exposed using CXF. The Method looks like this.

@GET
@Path("/getProfile/{memberno}/{userid}/{channelid}")
@Consumes("application/xml")
public MaintainCustomerProductResponse getUserDetails(
        @PathParam("memberno") String membernumber,
        @PathParam("userid") String userid,
        @PathParam("channelid") String channelid){
//DO Some Logic here.
}

This can be accessed via following URL & on submitting valid data I get response.

http://server.com:8080/UserService/getProfile/{memberno}/{userid}/{channelid}

Question: How can I pass null value for userid ?

If I simple ignore the {userId} the request is'nt hitting on the server side web service.

Example

http://server.com:8080/UserService/getProfile/1001//1

Note: I'm using SOAPUi for Testing and without giving userId value I see following response on SOAPUI and Request doesn't hit the server.

SOAPUI Response

<data contentType="null" contentLength="0"><![CDATA[]]></data>
like image 773
Jags Avatar asked Dec 21 '12 11:12

Jags


1 Answers

The default match of a variable is [^/]+? (at least one character) you can manually set the match to [^/]*? and it should also match empty strings.

Just add the format to the userid variable:

@Path("/getProfile/{memberno}/{userid: [^/]*?}/{channelid}")
like image 113
Aviram Segal Avatar answered Sep 23 '22 14:09

Aviram Segal