Reputation: 85
In my resteasy service i want to return media files on clients' requests, like this:
From server side (tomcat 6):
@GET
@Path("/getXML/{skinId}/{key}")
@Produces("text/xml")
public Response getXMLResource(@PathParam("key") String key, @PathParam("skinId") String skinId) {
// Reading a file from disk...
return Response.ok(file, type).build();
}
And from clients' side:
final URL uri = new URL("http://localhost:8080/service/getXML");
final InputStream stream = uri.openStream();
The problem:
I want to return custom HTTP error (resource isn't exist; server is busy, try later).
@GET
@Path("/getError")
@Produces("text/xml")
public Response getError() {
return Response.serverError().status(333).build();
}
But when i'm trying to access the error method, i get 500 (!) (in any case) internal server error.
Could you guys help me with this? Thanks in advance!
Upvotes: 1
Views: 906
Reputation: 85
I've coped with this. The problem was in using
.serverError()
that automaticaly means 500 error code as a server internal.
We can just set status of response to return right status:
@GET
@Path("/getError")
public Response getError() {
return Response.status(412).build();
}
Upvotes: 2