Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Problem with crest on android: Length Required
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - 1 new - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
metafedora  
View profile  
 More options Mar 11 2012, 3:56 pm
From: metafedora <metafed...@gmail.com>
Date: Sun, 11 Mar 2012 12:56:40 -0700 (PDT)
Local: Sun, Mar 11 2012 3:56 pm
Subject: Problem with crest on android: Length Required
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)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Laurent Gilles  
View profile  
 More options Mar 12 2012, 6:15 am
From: Laurent Gilles <laurent.gil...@codegist.org>
Date: Mon, 12 Mar 2012 03:15:34 -0700 (PDT)
Local: Mon, Mar 12 2012 6:15 am
Subject: Re: Problem with crest on android: Length Required
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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic