Hi,
I have created a test case for checking this functionality.
Please find my test service class.
--------------------------------------------------------------------------------------------------
@Path( "/encodedTest" )
public class TestEncodedAnnotation
{
@GET
@Path( "/encoded/testPath/{param}" )
public String testEncodedPathParam( @PathParam( "param" ) @Encoded
String param )
{
System.out.println( "The path param should be encoded.. : " +
param );
return param;
}
@GET
@Path( "/encoded/testMatrix" )
public String testEncodedMatrixParam( @MatrixParam( "param" ) @Encoded
String param )
{
System.out.println( "The matrix param should be encoded.. : " +
param );
return param;
}
@GET
@Path( "/encoded/testQuery" )
public String testEncodedQueryParam( @QueryParam( "param" ) @Encoded
String param )
{
System.out.println( "The query param should be encoded.. : " +
param );
return param;
}
@POST
@Path( "/encoded/testForm" )
public String testEncodedFormParam( @FormParam( "param" ) String param )
{
System.out.println( "The form param should be encoded.. : " +
param );
return param;
}
@GET
@Path( "/testPath/{param}" )
public String testNotEncodedPathParam( @PathParam( "param" ) String
param )
{
System.out.println( "The path param should not be encoded.. : " +
param );
return param;
}
@GET
@Path( "/testMatrix" )
public String testNotEncodedMatrixParam( @MatrixParam( "param" ) String
param )
{
System.out.println( "The matrix param should not be encoded.. : "
+ param );
return param;
}
@GET
@Path( "/testQuery" )
public String testNotEncodedQueryParam( @QueryParam( "param" ) String
param )
{
System.out.println( "The query param should not be encoded.. : " +
param );
return param;
}
@POST
@Path( "/testForm" )
public String testNotEncodedFormParam( @FormParam( "param" ) String
param )
{
System.out.println( "The form param should not be encoded.. : " +
param );
return param;
}
}
--------------------------------------------------------------------------------------------------
My test client is
--------------------------------------------------------------------------------------------------
public class TestEncoded
{
public static void main( String [] args )
{
ClientConfig config = new DefaultClientConfig();
Client client = Client.create( config );
WebResource service = client.resource( getBaseURI() );
// Verifying path param
ClientResponse clientResponse = service.path( "encoded" ).path(
"testPath" ).path( "Test Value" )
.get( ClientResponse.class );
System.out.println( clientResponse.getEntity( String.class ) );
// Verifying query param
clientResponse = service.path( "encoded" ).path( "testQuery"
).queryParam( "param", "Test Value" )
.get( ClientResponse.class );
System.out.println( clientResponse.getEntity( String.class ) );
// Verifying form param
Form form = new Form();
form.add( "param", "Test Value" );
clientResponse = service.path( "encoded" ).path( "testForm" ).post(
ClientResponse.class, form );
System.out.println( clientResponse.getEntity( String.class ) );
// Verifying matrix param
service = client.resource( UriBuilder.fromUri(
"
http://localhost:8080/RestTest/rest/encodedTest/encoded/testMatrix;param=Test%20Value"
).build() );
clientResponse = service.get( ClientResponse.class );
System.out.println( clientResponse.getEntity( String.class ) );
/*
* The rest of the test cases invoke params that does not specify
* encoded attribute.
*/
service = client.resource( getBaseURI() );
// Verifying path param
clientResponse = service.path( "testPath" ).path( "Test Value"
).get( ClientResponse.class );
System.out.println( clientResponse.getEntity( String.class ) );
// Verifying query param
clientResponse = service.path( "testQuery" ).queryParam( "param",
"Test Value" ).get( ClientResponse.class );
System.out.println( clientResponse.getEntity( String.class ) );
// Verifying form param
form = new Form();
form.add( "param", "Test Value" );
clientResponse = service.path( "testForm" ).post(
ClientResponse.class, form );
System.out.println( clientResponse.getEntity( String.class ) );
// Verifying matrix param
service = client.resource( UriBuilder.fromUri(
"
http://localhost:8080/RestTest/rest/encodedTest/testMatrix;param=Test%20Value"
).build() );
clientResponse = service.get( ClientResponse.class );
System.out.println( clientResponse.getEntity( String.class ) );
}
private static URI getBaseURI()
{
return UriBuilder.fromUri(
"
http://localhost:8080/RestTest/rest/encodedTest/" ).build();
}
}
--------------------------------------------------------------------------------------------------
If you try this test case, you can see that the encoded annotation does not
have any effect for from param.
If I am doing something wrong, please let me know.
Thanks,
Paul
--
View this message in context: http://jersey.576304.n2.nabble.com/Encoded-attribute-does-not-seems-to-work-for-all-the-param-types-tp6473003p6478670.html
Sent from the Jersey mailing list archive at Nabble.com.