title: How to re-write request URI along with path variable in Spring?
body: <p>I'm using Spring 4 right now and I have a controller defined a such:</p>
  
  <pre><code>@RequestMapping(value = "/{id}/definitions", method = RequestMethod.PUT)
  @ResponseBody
  public List&lt;ResponseDTO&gt; update(@PathVariable(value = "id") String id,
                                  HttpServletRequest iRequest) throws Exception 
  { ... }
  </code></pre>
  
  <p>I am expecting to receive an encrypted 'id' String coming as part of a path variable in the request itself. But what I need to do is re-write this request URI and decrypt it to another value (an integer, for example) and form another HTTP request with the original URI only with the transformed/decrypted value.</p>
  
  <p>How can I get a hold of the entire URI and substitute the {id} with an integer?</p>
  
  <p>For example, if the original request coming in looks like:</p>
  
  <pre><code>http://mycompany.com/my-service/kjAISOhalkjZjakmbbb/definitions
  </code></pre>
  
  <p>I want to transform everything after the context path:</p>
  
  <pre><code>/kjAISOhalkjZjakmbbb/definitions
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>/123456/definitions 
  </code></pre>
  
  <p>So finally, I can form a request to another service that might look like this:</p>
  
  <pre><code>http://mycompany.com/my-service-2/123456/definitions
  </code></pre>
  
  <p>Thank you!</p>