users@jersey.java.net

Re: [Jersey] Base64 problem (I guess)

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 07 Oct 2009 22:14:12 +0200

On Oct 7, 2009, at 8:04 PM, Felipe Gaścho wrote:

> I have this confirmation email, with an a URL containing a hashed
> key...
>
> http://fgaucho.dyndns.org:8080/arena-dwr/confirm?key=JkOgm11BWssuU3e%2Fnt23GYr4gQeLCHu344VhBQaV3%2BhPgrMl1AhnGA%3D%3DJkOgm11BWssuU3e%2Fnt23GYr4gQeLCHu344VhBQaV3%2BhPgrMl1AhnGA%3D%3D
>

The above is a query parameter not a form parameter.


> it works if I click on the email URL, normally..
>
> but, I am trying to simulate the same behaviou in a Unit Test class,
> using the Jersey Client.
>
> public int confirmRegistration() throws IOException {
> Form formData = new Form();
> formData
> .add(
> RegistrationConstants.CONFIRMATION_KEY.value(),
> "JkOgm11BWssuU3e%2Fnt23GYr4gQeLCHu344VhBQaV3%2BhPgrMl1AhnGA%3D
> %3DJkOgm11BWssuU3e%2Fnt23GYr4gQeLCHu344VhBQaV3%2BhPgrMl1AhnGA%3D%3D");

The problem is the value is already encoded, so it is going to be
encoded again, so all those '%' characters will be percent encoded as
"%25"

Try

String encodedFormData = "key=JkOgm11BWssuU3e
%2Fnt23GYr4gQeLCHu344VhBQaV3%2BhPgrMl1AhnGA%3D%3DJkOgm11BWssuU3e
%2Fnt23GYr4gQeLCHu344VhBQaV3%2BhPgrMl1AhnGA%3D%3D";
ClientResponse response = arena.path("user").type(
                                "application/x-www-form-urlencoded").post(ClientResponse.class,
                                encodedFormData);

Or use the decoded key version. If you want to decode that you can do:

  keyValue = UriComponent.decode(encodedKeyValue,
UriComponent.Type.QUERY_PARAM);

If you want to know what the Jersey client will send and receive you
can add a logging filter.

   arena.addFilter(new LoggingFilter());

Paul.

> ClientResponse response = arena.path("user").type(
> "application/x-www-form-urlencoded").post(ClientResponse.class,
> formData);
> return response.getStatus();
> }
>
>
> Problem is: my deobfuscator method throw an invalid key exception ...
>
> I guess it is because the Base64 and URLEnconder applied by the
> browser, but I am not sure what the Jersey Client do with the form
> parameters before to send it to the server...
>
> any help is welcome........
>
>
>
> --
> Looking for a client application for this service:
> http://fgaucho.dyndns.org:8080/arena-http/wadl
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>