You could use the Response builder instead:
Response r = Response.status(Status.BAD_REQUEST).entity("must provide
username and email").type(MediaType.TEXT_PLAIN_TYPE).build();
throw new WebApplicationException(r);
You could also just return the Response instance if your resource
method return type allows that.
Marc.
On Aug 11, 2008, at 4:55 AM, Reto Bachmann-Gmür wrote:
> I'm sure there is an easier way than this to give a bad-request
> answer.
>
> if ((userName == null) || (email == null)) {
> throw new WebApplicationException(new Response() {
> @Override
> public Object getEntity() {
> return "must provide username and email";
> }
>
> @Override
> public int getStatus() {
> return Status.BAD_REQUEST.getStatusCode();
> }
>
> @Override
> public MultivaluedMap<String, Object> getMetadata() {
> return null;
> }
> });
> }
>
> Since the last methos should probably return an empty MultivalueMap
> instead of null, having a default implementation in JaxRs would be
> handy.
>
> Reto
>
---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.