How can I refuse to respond to a request in a Java web service?

Suppose we have a webservice request that we don’t even want to justify with an answer:

@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 way not to respond to a given Java web service request?

+3
source share
2 answers

Why not return anything at all? It just makes your connection remain open until it expires, wasting time on your server and user.

I don’t know how easy it is to do in Java web services, but can you return 202 (“Accepted”, but processing is not completed, and can be rejected later) or 204 (“No response”)?

+3
source

I think you can think of several options:

(, ):

} else {
  return "";
}

:

} else {
  throw new Exception("whatevah....");
}

, # 1 # 2:

} else {
  Thread.sleep(90000);  // 90 seconds!
  return "";
}

HTTP- 403-Forbidden 4- .

+1

Source: https://habr.com/ru/post/1784131/


All Articles