DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How to Verify Domain Ownership: A Technical Deep Dive
  • How to Identify the Underlying Causes of Connection Timeout Errors for MongoDB With Java
  • Utilizing Multiple Vectors and Advanced Search Data Model Design for City Data
  • How To Connect a Heroku Java App to a Cloud-Native Database

Trending

  • PII Detection Before RAG Ingestion: Screening Documents in C#
  • OpenCode: Setting Up an Open-Source AI Coding Assistant
  • To Switch, or Not to Switch the AI Model
  • How You Clear Your HTML5 Canvas Matters

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Using UriTemplate to Change Path Parameters in a URI

Using UriTemplate to Change Path Parameters in a URI

By 
Gerard Davison
·
Mar. 01, 13 · Interview
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
43.9K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

I have been recently working on a client generator in the wadl.java.net project and I was solving a bug where I wanted to change path parameter on a URI. This turned out to be quite easy with existing classes that are part of the Jersey project.

First of all you need a instance of UriTemplate, depending on the very of Jersey this is in a slightly different package - you IDE's automatic import will do the work for you. 

String template = "http://example.com/name/{name}/age/{age}";
UriTemplate uriTemplate = new UriTemplate(template);
 Then you use match(...) to extract them:
  String uri = "http://example.com/name/Bob/age/47";
  Map<String, String> parameters = new HashMap<>();

  // Not this method returns false if the URI doesn't match, ignored
  // for the purposes of the this blog.
  uriTemplate.match(uri, parameters);
 Then you can replace the parameters at will and rebuild the URI:
  parameters.put("name","Arnold");

  UriBuilder builder = UriBuilder.fromPath(template);
  URI output = builder.build(parameters);



Uniform Resource Identifier

Published at DZone with permission of Gerard Davison. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How to Verify Domain Ownership: A Technical Deep Dive
  • How to Identify the Underlying Causes of Connection Timeout Errors for MongoDB With Java
  • Utilizing Multiple Vectors and Advanced Search Data Model Design for City Data
  • How To Connect a Heroku Java App to a Cloud-Native Database

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook