cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r917070 - /cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Response.java
Date Sat, 27 Feb 2010 23:02:13 GMT
Author: bluk
Date: Sat Feb 27 23:02:13 2010
New Revision: 917070

URL: http://svn.apache.org/viewvc?rev=917070&view=rev
Log:
Update for JAX-RS Response methods

Modified:
    cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Response.java

Modified: cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Response.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Response.java?rev=917070&r1=917069&r2=917070&view=diff
==============================================================================
--- cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Response.java (original)
+++ cxf/sandbox/geronimo-jaxrs_1.0_spec/src/main/java/javax/ws/rs/core/Response.java Sat Feb
27 23:02:13 2010
@@ -20,13 +20,14 @@
 package javax.ws.rs.core;
 
 import java.net.URI;
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Locale;
 
 import javax.ws.rs.ext.RuntimeDelegate;
 
-public class Response {
+public abstract class Response {
 
     private final static RuntimeDelegate delegate = RuntimeDelegate.getInstance();
 
@@ -133,4 +134,114 @@
             return reasonPhrase;
         }
     }
+
+    protected Response() {
+        // do nothing
+    }
+
+    public static Response.ResponseBuilder created(java.net.URI location) {
+        if (location == null) {
+            throw new IllegalArgumentException();
+        }
+        return status(Status.CREATED).location(location);
+    }
+
+    public static Response.ResponseBuilder fromResponse(Response response) {
+        ResponseBuilder builder = delegate.createResponseBuilder();
+        builder.status(response.getStatus());
+        builder.entity(response.getEntity());
+        MultivaluedMap<String, Object> metadata = response.getMetadata();
+        for (String key : metadata.keySet()) {
+            List<Object> values = metadata.get(key);
+            for (Object value : values) {
+                builder.header(key, value);
+            }
+        }
+        return builder;
+    }
+
+    public abstract Object getEntity();
+
+    public abstract MultivaluedMap<String, Object> getMetadata();
+
+    public abstract int getStatus();
+
+    public static Response.ResponseBuilder noContent() {
+        return status(Status.NO_CONTENT);
+    }
+
+    public static Response.ResponseBuilder notAcceptable(List<Variant> values) {
+        ResponseBuilder builder = status(Status.NOT_ACCEPTABLE);
+        if (values == null) {
+            return builder.variants(Collections.EMPTY_LIST);
+        }
+        return builder.variants(values);
+    }
+
+    public static Response.ResponseBuilder notModified() {
+        return status(Status.NOT_MODIFIED);
+    }
+
+    public static Response.ResponseBuilder notModified(EntityTag value) {
+        if (value == null) {
+            throw new IllegalArgumentException();
+        }
+        return status(Status.NOT_MODIFIED).tag(value);
+    }
+
+    public static Response.ResponseBuilder notModified(String value) {
+        if (value == null) {
+            throw new IllegalArgumentException();
+        }
+        return status(Status.NOT_MODIFIED).tag(value);
+    }
+
+    public static Response.ResponseBuilder ok() {
+        return status(Status.OK);
+    }
+
+    public static Response.ResponseBuilder ok(Object entity) {
+        return status(Status.OK).entity(entity);
+    }
+
+    public static Response.ResponseBuilder ok(Object entity, MediaType mediaType) {
+        return status(Status.OK).entity(entity).type(mediaType);
+    }
+
+    public static Response.ResponseBuilder ok(Object entity, String mediaType) {
+        return status(Status.OK).entity(entity).type(mediaType);
+    }
+
+    public static Response.ResponseBuilder ok(Object entity, Variant variant) {
+        return status(Status.OK).entity(entity).variant(variant);
+    }
+
+    public static Response.ResponseBuilder seeOther(URI location) {
+        if (location == null) {
+            throw new IllegalArgumentException();
+        }
+        return status(Status.SEE_OTHER).location(location);
+    }
+
+    public static Response.ResponseBuilder serverError() {
+        return status(Status.INTERNAL_SERVER_ERROR);
+    }
+
+    public static Response.ResponseBuilder status(int status) {
+        if (status < 100 || status > 599) {
+            throw new IllegalArgumentException();
+        }
+        return ResponseBuilder.newInstance().status(status);
+    }
+
+    public static Response.ResponseBuilder status(Response.Status status) {
+        if (status == null) {
+            throw new IllegalArgumentException();
+        }
+        return ResponseBuilder.newInstance().status(status);
+    }
+
+    public static Response.ResponseBuilder temporaryRedirect(URI location) {
+        return status(Status.TEMPORARY_REDIRECT).location(location);
+    }
 }



Mime
View raw message