3

How do I create a GET rest method that accept "@" sign parameter? Currently it doesn't like this because of the @ sign. I am passing in /resource/user/my@email.com/password

@Path("/user/{Email}/{Password}")
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public JResponse<DtoUser> ValidateUser(@PathParam("Email") String email,@PathParam("Password") String password) {
    logger.log(Level.INFO, "Validating user {0}", email);
    IUserRepository repo =  new UserRepository();
    return JResponse.ok(repo.ValidateUser(email, password)).build();

}
user1688346
  • 1,846
  • 5
  • 26
  • 48

3 Answers3

2

Look at this answer. Seems that you could encode your '@' with '%40' in your call. I hope it helps you.

Community
  • 1
  • 1
Aito
  • 6,812
  • 3
  • 30
  • 41
1

you would need to encode the values that are going to be added to the string. for example the @ symbol is converted to %40.

URLEncoder.encode(string,"UTF-8"); would encode the string to

/resource/user/my%40email.com/password

more information of this can be found in the javadocs of the jdk http://docs.oracle.com/javase/7/docs/api/java/net/URLEncoder.html

Gigaquad
  • 153
  • 4
0

Please read this before using the URLEncoder class: http://www.subbu.org/blog/2008/02/uri-escaping-and-javaneturlencoder

A good alternative is Google's PercentEscaper: http://gdata-java-client.googlecode.com/svn/tags/2.0.0-alpha/javadoc/com/google/api/data/client/v2/escape/PercentEscaper.html

uldall
  • 2,458
  • 1
  • 17
  • 31