package brooklyn.rest.util;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import brooklyn.rest.domain.ApiError;

public class WebResourceUtils {

    private static final Logger log = LoggerFactory.getLogger(WebResourceUtils.class);
    
    public static WebApplicationException notFound(String format, Object... args) {
        String msg = String.format(format, args);
        if (log.isInfoEnabled()) log.info("returning 404 notFound("+msg+")");
        throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
                .entity(new ApiError(msg)).build());
    }

    public static WebApplicationException preconditionFailed(String format, Object... args) {
        String msg = String.format(format, args);
        if (log.isInfoEnabled()) log.info("returning 412 preconditionFailed("+msg+")");
        throw new WebApplicationException(Response.status(Response.Status.PRECONDITION_FAILED)
                .entity(new ApiError(msg)).build());
    }

}

@@ -66,16 +66,51 @@
 eption;%0A
+import javax.ws.rs.core.MediaType;%0A
 import j
@@ -135,16 +135,16 @@
 sponse;%0A
-
 %0Aimport 
@@ -502,36 +502,37 @@
       if (log.is
-Info
+Debug
 Enabled()) log.i
@@ -522,36 +522,37 @@
 gEnabled()) log.
-info
+debug
 (%22returning 404 
@@ -560,32 +560,65 @@
 otFound(%22+msg+%22)
+ - may be a stale browser session
 %22);%0A        thro
@@ -690,16 +690,71 @@
 _FOUND)%0A
+                .type(MediaType.APPLICATION_JSON_TYPE)%0A
         
@@ -971,12 +971,13 @@
 g.is
-Info
+Debug
 Enab
@@ -991,12 +991,13 @@
 log.
-info
+debug
 (%22re
@@ -1134,16 +1134,71 @@
 FAILED)%0A
+                .type(MediaType.APPLICATION_JSON_TYPE)%0A
         

fix serialization of errors problem, and reduce warning level for stale browsers