cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Konrad Windszus (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (CXF-6122) JAX-RS proxy client with @QueryParam is not encoding the parameter value
Date Mon, 01 Dec 2014 18:32:12 GMT

    [ https://issues.apache.org/jira/browse/CXF-6122?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14230192#comment-14230192
] 

Konrad Windszus edited comment on CXF-6122 at 12/1/14 6:31 PM:
---------------------------------------------------------------

This will not work either, as the replacePath will do an additional escaping on the already
URL encoded query.

{code}
private static final String ADMIN_PREFIX = "/admin";

@Test
	public void testStripAdminPrefixFromUri() throws URISyntaxException, UnsupportedEncodingException
{
		String authority = "www.test.com";
		String value = "+ ÄÖÜ value";
		String path = "/admin/path";
		String query = "param=" + URLEncoder.encode(value, "UTF-8");
		URI oldUri = new URI("http", authority, path, query, null);
		URI newUri = stripAdminPrefixFromUri(oldUri);
		
		Assert.assertThat(newUri.getPath(), Matchers.equalTo("/path"));
		String newQuery = newUri.getRawQuery();
		String encodedValue = newQuery.substring("param=".length());
// this will fail already due to the double escaping here
		Assert.assertThat(URLDecoder.decode(encodedValue, "UTF-8"), Matchers.equalTo(value));
		Assert.assertThat(newUri.getRawQuery(), Matchers.equalTo(oldUri.getRawQuery()));
		
	}
	
	protected static URI stripAdminPrefixFromUri(URI uri) {
		String path = uri.getPath().substring(ADMIN_PREFIX.length());
		URI newUri = UriBuilder.fromUri(uri).replacePath(path).build();
		//URI newUri = new URI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(), uri.getRawFragment());
		return newUri;
	}

{code}

Just execute the attached test case to verify that.


was (Author: kwin):
This will not work either, as the replacePath will do an additional escaping on the already
URL encoded query.

{code}
@Test
	public void testStripAdminPrefixFromUri() throws URISyntaxException, UnsupportedEncodingException
{
		String authority = "www.test.com";
		String value = "+ ÄÖÜ value";
		String path = "/admin/path";
		String query = "param=" + URLEncoder.encode(value, "UTF-8");
		URI oldUri = new URI("http", authority, path, query, null);
		URI newUri = stripAdminPrefixFromUri(oldUri);
		
		Assert.assertThat(newUri.getPath(), Matchers.equalTo("/path"));
		String newQuery = newUri.getRawQuery();
		String encodedValue = newQuery.substring("param=".length());
// this will fail already due to the double escaping here
		Assert.assertThat(URLDecoder.decode(encodedValue, "UTF-8"), Matchers.equalTo(value));
		Assert.assertThat(newUri.getRawQuery(), Matchers.equalTo(oldUri.getRawQuery()));
		
	}
	
	protected static URI stripAdminPrefixFromUri(URI uri) {
		String path = uri.getPath().substring(ADMIN_PREFIX.length());
		URI newUri = UriBuilder.fromUri(uri).replacePath(path).build();
		//URI newUri = new URI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(), uri.getRawFragment());
		return newUri;
	}

{code}

Just execute the attached test case to verify that.

> JAX-RS proxy client with @QueryParam is not encoding the parameter value
> ------------------------------------------------------------------------
>
>                 Key: CXF-6122
>                 URL: https://issues.apache.org/jira/browse/CXF-6122
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.0.2
>            Reporter: Konrad Windszus
>
> If I create a JAX-RS client with the proxy pattern outlined at http://cxf.apache.org/docs/jax-rs-client-api.html#JAX-RSClientAPI-Proxy-basedAPI
and the proxy interface looks like this
> {code}
> @PUT
> 	@Path("/admin/user/{id}.json")
> 	@Produces(value = { "application/json" })
> 	public User updateUser(@PathParam("id") String userId, @QueryParam("country") String
country, @QueryParam("description") String role, @QueryParam("telephone") String phone);
> {code}
> all URL parameters are not correctly encoded.
> E.g. if phone contains a "+" this will not be converted to %2B or if the role contains
an umlaut this will not be encoded either.
> Another related question is: Which character set will be used here (I guess UTF-8 makes
sense) once that bug is fixed? Also how would it be possible to override the character set?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message