title: How to force URIBuilder.path(...) to encode parameters like "%AD"? This method doesn't always encode parameters with percentage, correctly
body: <p>How to force <code>URIBuilder.path(...)</code> to encode parameters like <code>"%AD"</code>?</p>
  
  <p>The methods <code>path</code>, <code>replacePath</code> and <code>segment</code> of <code>URIBuilder</code> do not always encode parameters with percentage, correctly.</p>
  
  <p>When a parameter contains the character "%" followed by two characters that together form an URL-encoded character, the "%" is not encoded as "%25".</p>
  
  <p>For example</p>
  
  <pre><code>URI uri = UriBuilder.fromUri("https://dummy.com").queryParam("param", "%AD");
  String test = uri.build().toString();
  </code></pre>
  
  <p>"test" is "<a href="https://dummy.com?param=%AD" rel="noreferrer">https://dummy.com?param=%AD</a>"<br>
  But it should be "<a href="https://dummy.com?param=%25AD" rel="noreferrer">https://dummy.com?param=%25AD</a>" (with the character "%" encoded as "%25")</p>
  
  <p>The method <code>UriBuilderImpl.queryParam(...)</code> behaves like this when the two characters following the "%" are hexadecimal. I.e, the method "com.sun.jersey.api.uri.UriComponent.isHexCharacter(char)" returns true for the characters following the "%". </p>
  
  <p>I think the behavior of UriBuilderImpl is correct because I guess it tries to not encode parameters that already are encoded. But in my scenario, I will never try to create URLs with parameters that already encoded.</p>
  
  <p><strong>What should I do?</strong></p>
  
  <p>My Web application uses Jersey and in many places I build URIs using the class UriBuilder or invoke the method <code>getBaseUriBuilder</code> of <code>UriInfo</code> objects.</p>
  
  <p>I can replace "%" with "%25", every time I invoke the methods <code>queryParam</code>, <code>replaceQueryParam</code> or <code>segment</code>. But I am looking for a less cumbersome solution.</p>
  
  <p><strong>How can I make Jersey to return my own implementation of UriBuilder?</strong></p>
  
  <p>I thought of creating a class that extends UriBuilderImpl that overrides these methods and that perform this replacing before invoking <code>super.queryParam(...)</code> or whatever.</p>
  
  <p>Is there any way of making Jersey to return my own UriBuilder instead of UriBuilderImpl, when invoking <code>UriBuilder.fromURL(...)</code>, UriInfo.getBaseUriBuilder(...), etc? </p>
  
  <p>Looking at the method <code>RuntimeDelegate</code>, I thought of extending <code>RuntimeDelegateImpl</code>. My implementation would override the method <code>createUriBuilder(...)</code>, which would return my own <code>UriBuilder</code>, instead of <code>UriBuilderImpl</code>.
  Then, I would add the file <code>META-INF/services/javax.ws.rs.ext.RuntimeDelegate</code> and in it, a the full class name of my <code>RuntimeDelegateImpl</code>.</p>
  
  <p>The problem is that the jersey-bundle.jar already contains a <code>META-INF/services/javax.ws.rs.ext.RuntimeDelegate</code> that points to <code>com.sun.jersey.server.impl.provider.RuntimeDelegateImpl</code>, so the container loads that file instead of my <code>javax.ws.rs.ext.RuntimeDelegate</code>. Therefore, it does not load my <code>RuntimeDelegate</code>implementation.</p>
  
  <p>Is it possible to provide my own implementation of <code>RuntimeDelegate</code>?</p>
  
  <p>Should I take a different approach?</p>