I guess the service you're hitting requires the HTTP Content-Length
header to be set. see
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.12
Have you tried hitting hit manually or using any REST client (ie:
Firefox's Poster etc..), with and without the content length header?
If the problem is the content length, then by default CRest is not
currently setting it for performance reasons. If this is a requirement
for your app you could do something like this:
Given that you're service accepts Url Encoded Form requests:
https://github.com/codegist/crest/blob/master/core/src/main/java/org/...
public class ContentLengthAwareUrlEncodedFormEntityWriter extends
UrlEncodedFormEntityWriter {
public int getContentLength(Request request) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
writeTo(request, out);
return out.toByteArray().length;
}
}
and use it as follow
@EndPoint("http://my.api.com")
@Path("/users")
@Consumes("application/json")
@EntityWriter(ContentLengthAwareUrlEncodedFormEntityWriter.class)
public interface Users {
@POST
User createUser(
@FormParam("Name") String Name);
@GET
User getUser(
@QueryParam("UserId") String UserId);
}
Haven't tried it but fairly sure this would fix your problem.
Please let me know how that goes,
Thanks,
Laurent
On Mar 11, 7:56 pm, metafedora <metafed...@gmail.com> wrote:
> I'm using codegist-crest-2.0.0-RC1-all.jar in my android application
> (SDK version 4.0.3, targeting 2.3 Gingerbread).
> Also referencing jackson-core-asl-1.9.5.jar, jackson-mapper-
> asl-1.9.5.jar, jsr311-api-1.1.1.jar.
> Here are my code files, and the exception I'm getting.
> // User.cs
> public class User
> {
> @JsonProperty("Id")
> public String Id;
> @JsonProperty("Name")
> public String Name;
> }
> //Users.cs - the API is a RESTFUL web service that uses JSON
> @EndPoint("http://my.api.com")
> @Path("/users")
> @Consumes("application/json")
> public interface Users {
> @POST
> User createUser(
> @FormParam("Name") String Name);
> @GET
> User getUser(
> @QueryParam("UserId") String UserId);
> }
> //SomeActivity.cs
> CRest crest = new
> CRestBuilder().setHttpChannelFactory(HttpClientHttpChannelFactory.class)
> .build();
> Users users = crest.build(Users.class);
> User user = users.createUser(name);
> Exception:
> 03-11 14:55:22.794: E/UserService(30270): Caused by:
> org.codegist.crest.io.RequestException: Length Required
> 03-11 14:55:22.794: E/UserService(30270): at
> org.codegist.crest.io.http.HttpRequestExecutor.execute(HttpRequestExecutor. java:
> 79)
> 03-11 14:55:22.794: E/UserService(30270): at
> org.codegist.crest.io.RetryingRequestExecutor.execute(RetryingRequestExecut or.java:
> 52)
> 03-11 14:55:22.794: E/UserService(30270): at
> org.codegist.crest.DefaultCRest
> $CRestInvocationHandler.doInvoke(DefaultCRest.java:81)