Permalink
Browse files

update doco

git-svn-id: file:///Users/billburke/jboss/resteasy/resteasy-git/svn-server-sync/resteasy/trunk/jaxrs@540 2b1ed4c4-5db3-0410-90e4-80a7a6204c25
  • Loading branch information...
1 parent 4a93194 commit ab6450fb4a3b5e0cbfdf43b70b966809c2afc714 patriot1burke committed Jan 6, 2009
@@ -1,29 +1,30 @@
-package org.jboss.resteasy.client;
+package org.jboss.resteasy.annotations;
+
+import org.jboss.resteasy.client.EntityTypeFactory;
+import org.jboss.resteasy.client.core.VoidEntityTypeFactory;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.jboss.resteasy.client.core.VoidEntityTypeFactory;
-
/**
* This is an annotation that you can add to a RESTEasy client interface that
* has a return type of Response.
- * <p>
- *
+ * <p/>
+ * <p/>
* You have two options:
* <ol>
* <li>use the entityType property to set a Class that will always be returned
* <li>use the entityTypeFactory to determine which Class to use based on a
* factory that determines which class to use based on logic that uses the
* headers and status of the result.
* </ol>
- *
+ * <p/>
* Note: if you want to use generic types, you can't use this annotation. You'll
* have to either use ClientResponse as part of your interface, or cast the
* resulting Response object as a ClientResponse.
- *
+ *
* @author <a href="mailto:sduskis@gmail.com">Solomon Duskis</a>
* @version $Revision: 1 $
*/
@@ -34,5 +35,6 @@
public @interface ClientResponseType
{
Class entityType() default Void.class;
+
Class<? extends EntityTypeFactory> entityTypeFactory() default VoidEntityTypeFactory.class;
}
@@ -55,7 +55,7 @@
* <p/>
* For example:
* <pre>
- * List<String> list = response.getBody(new GenericType<List<String>() {});
+ * List<String> list = response.getEntity(new GenericType<List<String>() {});
* <p/>
* <p/>
* This method actually does the reading on the OutputStream. It will only do the read once. Afterwards, it will
@@ -1,25 +1,24 @@
package org.jboss.resteasy.client.core;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.net.URI;
-
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Providers;
-
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethodBase;
+import org.jboss.resteasy.annotations.ClientResponseType;
import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.client.ClientResponseType;
import org.jboss.resteasy.client.EntityTypeFactory;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.util.HttpHeaderNames;
import org.jboss.resteasy.util.MediaTypeHelper;
import org.jboss.resteasy.util.Types;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Providers;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.net.URI;
+
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
@@ -42,7 +41,7 @@ public ClientInvoker(Class<?> declaring, Method method, ResteasyProviderFactory
this.declaring = declaring;
this.method = method;
Marshaller[] marshallers = ClientMarshallerFactory.createMarshallers(method,
- providerFactory);
+ providerFactory);
this.providerFactory = providerFactory;
this.urlRetriever = new WebRequestIntializer(marshallers);
accepts = MediaTypeHelper.getProduces(declaring, method);
@@ -132,20 +131,20 @@ private Object extractEntity(ClientResponseImpl clientResponse)
return clientResponse.getResponseStatus();
}
- if( Response.class.isAssignableFrom(returnType))
+ if (Response.class.isAssignableFrom(returnType))
{
ClientResponseType responseHint = method.getAnnotation(ClientResponseType.class);
if (responseHint != null)
{
handleResponseHint(clientResponse, responseHint);
- }
+ }
else
{
clientResponse.releaseConnection();
}
return clientResponse;
}
-
+
clientResponse.checkFailureStatus();
if (returnType == null || isVoidReturnType(returnType))
@@ -176,7 +175,7 @@ private boolean isVoidReturnType(final Class<?> returnType)
}
private void handleResponseHint(ClientResponseImpl clientResponse,
- ClientResponseType responseHint)
+ ClientResponseType responseHint)
{
Class returnType = responseHint.entityType();
Class<? extends EntityTypeFactory> entityTypeFactory = responseHint.entityTypeFactory();
@@ -190,20 +189,20 @@ private void handleResponseHint(ClientResponseImpl clientResponse,
catch (InstantiationException e)
{
throw clientResponse
- .createResponseFailure("Could not create a default entity type factory of type "
- + entityTypeFactory.getClass().getName());
+ .createResponseFailure("Could not create a default entity type factory of type "
+ + entityTypeFactory.getClass().getName());
}
catch (IllegalAccessException e)
{
throw clientResponse
- .createResponseFailure("Could not create a default entity type factory of type "
- + entityTypeFactory.getClass().getName()
- + ". "
- + e.getMessage());
+ .createResponseFailure("Could not create a default entity type factory of type "
+ + entityTypeFactory.getClass().getName()
+ + ". "
+ + e.getMessage());
}
returnType = factory.getEntityType(clientResponse.getStatus(), clientResponse.getMetadata());
}
- if(!isVoidReturnType(returnType))
+ if (!isVoidReturnType(returnType))
{
clientResponse.setReturnType(returnType);
}
@@ -1,41 +1,34 @@
package org.jboss.resteasy.test.finegrain.client;
-import static org.jboss.resteasy.test.TestPortProvider.createClientRequest;
-import static org.jboss.resteasy.test.TestPortProvider.createProxy;
-import static org.jboss.resteasy.test.TestPortProvider.createURI;
-import static org.jboss.resteasy.test.TestPortProvider.createURL;
-import static org.jboss.resteasy.test.TestPortProvider.generateBaseUrl;
-import static org.jboss.resteasy.test.TestPortProvider.generateURL;
-
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.Arrays;
-import java.util.Map;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-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.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-
+import org.jboss.resteasy.annotations.ClientResponseType;
import org.jboss.resteasy.client.ClientResponse;
-import org.jboss.resteasy.client.ClientResponseType;
import org.jboss.resteasy.client.EntityTypeFactory;
import org.jboss.resteasy.client.ProxyFactory;
import org.jboss.resteasy.client.core.ClientResponseImpl;
import org.jboss.resteasy.core.Dispatcher;
import org.jboss.resteasy.test.EmbeddedContainer;
+import static org.jboss.resteasy.test.TestPortProvider.*;
import org.jboss.resteasy.test.smoke.SimpleResource;
import org.jboss.resteasy.util.HttpResponseCodes;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+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.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Map;
+
/**
* Simple smoke test
*
@@ -58,12 +51,12 @@
@GET
@Path("basic")
- @ClientResponseType(entityType=String.class)
+ @ClientResponseType(entityType = String.class)
Response getBasicResponseString();
@GET
@Path("basic")
- @ClientResponseType(entityTypeFactory=StringEntityTypeFactory.class)
+ @ClientResponseType(entityTypeFactory = StringEntityTypeFactory.class)
Response getBasicResponseStringFactory();
@GET
@@ -104,23 +97,23 @@
@GET
@Path("basic")
- @ClientResponseType(entityType=byte[].class)
+ @ClientResponseType(entityType = byte[].class)
Response getBasicResponse();
@GET
@Path("error")
ClientResponse<String> getError();
}
-
+
public static class StringEntityTypeFactory implements EntityTypeFactory
{
public Class getEntityType(int status,
- MultivaluedMap<String, Object> metadata)
+ MultivaluedMap<String, Object> metadata)
{
return String.class;
}
-
+
}
@BeforeClass
@@ -162,7 +155,7 @@ public void testClientResponse() throws Exception
Assert.assertEquals(Response.Status.NO_CONTENT, putResponse.getResponseStatus());
- Assert.assertEquals("headervalue", ((ClientResponseImpl)client.getHeaderClientResponse()).getHeaders().getFirst("header"));
+ Assert.assertEquals("headervalue", ((ClientResponseImpl) client.getHeaderClientResponse()).getHeaders().getFirst("header"));
Assert.assertEquals("headervalue", createClientRequest("/header").get().getHeaders().getFirst("header"));
Assert.assertEquals("headervalue", client.getHeaderResponse().getMetadata().getFirst("header"));
@@ -173,7 +166,7 @@ public void testClientResponse() throws Exception
ClientResponse<byte[]> getBasicResponse = createClientRequest("/basic").get(byte[].class);
Assert.assertTrue(Arrays.equals("basic".getBytes(), getBasicResponse.getEntity()));
-
+
Assert.assertEquals("basic", client.getBasic2().getEntity(String.class, null));
getBasicResponse = createClientRequest("/basic").get(byte[].class);

0 comments on commit ab6450f

Please sign in to comment.