I want to do something like, I should allow user to request for 3 times. After that only it should throw error.
I have go through many articles, they said to use something like :
for(int i=0;i<3;i++)
{
try
{
}
catch(Exception e)
{
if(count<3)
{
count++;
countinue;
}
}
I tried implementing this, but this executed in just one request.
What I want to do is that for each request made it should check for count.
e.g when I make a request through postman once, it should check for one.
When I again made request through postman it should increase count to 2 and at last for 3rd time it should throw error.
Here is the sample code here :
@PUT
@Path("/{containerId}/assignnexttask")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response somemethod(@Context HttpHeaders headers, @PathParam("containerId") String containerId,
@RequestBody String payload) throws JSONException {
Variant v = RestUtils.getVariant(headers);
String contentType = RestUtils.getContentType(headers);
MarshallingFormat format = MarshallingFormat.fromType(contentType);
// for loop is for maximum 3 attempts ,
int count=0;
for (int i = 0; i < 3; i++) {
try {
//here is some code
}
catch(Exception e )
{
if(count<3)
{
count++;
continue;
}
}
}
}
Hope i am able to explain.Thanks in Advance.