View Javadoc
1   package ejava.examples.ejbwar.inventory.rs;
2   
3   import javax.ws.rs.core.MediaType;
4   import javax.ws.rs.core.Response;
5   import javax.ws.rs.core.Response.ResponseBuilder;
6   
7   import org.slf4j.Logger;
8   
9   /**
10   * This class provides common code build and return standard server responses
11   */
12  public class ResourceHelper {
13  	public static ResponseBuilder serverError(Logger log, String context, Exception ex) {
14  		String message = String.format("unexpected error %s: %s",context, ex.getLocalizedMessage());
15  		log.warn(message, ex);
16  		return Response.serverError()
17  				.entity(message)
18  				.type(MediaType.TEXT_PLAIN);
19  	}
20  }