Reputation: 5717
Suppose we have a webservice request we don't even want to dignify with a response:
@WebMethod(operationName = "doSomethingForNicePeopleOnly")
public String doSomethingForNicePeopleOnly(@WebParam(name="username") String user) {
if (userIsNice(user)) {
return "something nice";
} else {
// I'd prefer not to return anything at all, not even a 404...
}
}
What is the best technique for not responding to a given Java webservice request?
Upvotes: 3
Views: 195
Reputation: 4155
I think can think of a few choices here:
Return useless response (e.g. empty string):
} else {
return "";
}
Or throw an exception:
} else {
throw new Exception("whatevah....");
}
Or try some delaying tactics followed by #1 or #2:
} else {
Thread.sleep(90000); // 90 seconds!
return "";
}
Also HTTP code 403-Forbidden might be appropriate here as a 4th option.
Upvotes: 1
Reputation: 46203
Why return nothing at all? That just forces your connection to stay open until it times out, wasting both your server's time and the user's.
I don't know how easy this is to do in Java web services, but can you return 202 ("Accepted" but processing not complete, and may be rejected silently later) or 204 ("No response") maybe?
Upvotes: 3