3

I have done this tutorial and now I want to throw an error from this webservice, like HTTP error code 403 or 400.

How can i do this? I noticed that i have an interface of type HttpServletResponse, but I don't know how I can use it. Do I have to import something else?

import java.util.Date;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;

import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.xml.ws.http.HTTPException;

import sun.awt.RequestFocusController;

import com.sun.jersey.spi.resource.Singleton;
import com.sun.research.ws.wadl.Request;
import com.sun.research.ws.wadl.Response;

1 Answer 1

4

You can do it like this.

@GET
public Response check(@QueryParam("username") String username) {
   if (facade.checkUser(username)) {
      return Response.status(Response.Status.NOT_FOUND).build();
   }
   return Response.ok().build();
}
Sign up to request clarification or add additional context in comments.

3 Comments

and if i want to return a string or an int or one of this codes?
Set the entity of the response. Response.status(Response.Status.OK).entity("HELLO").build()
Sorry about this, but I've downloaded the sources on the Tutorial link, been looking at this entry, and I cant figure what Response object you are using here. This import com.sun.research.ws.wadl.Response; doesn't have the status() method. Can you please help me here figure out what you two have seen that eluded me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.