Restlet: How can I retrieve DTO with setting custom MediaType?

How can I send GET request for entity with custom MediaType?

For example I want to retrieve MyUserDTO and set MediaType to application/user+yml.

For now I have two separated actions. I can retrieve entity:


and can retrieve string:

resource.get(new MediaType("application", "user+yml");

But how to combine them? Or maybe there is some trick to configure Restlet to teach him how to work with custom MediaTypes.


In fact, you have the right approach but you don't use the right constructor of the class MediaType (new MediaType(name, description)).

To make your code work, you need to change it to this:

resource.get(new MediaType("application/user+yml"));

On the server side, you will get this:

@Get public Representation getSomething() { System.out.println(">> media types = " + getRequest().getClientInfo().getAcceptedMediaTypes()); // Display this: media types = [application/user+yml:1.0] (...) }

You can leverage the extension support of Restlet by adding a value within the annotation Get. In your case, you need to add a custom extension as described below:

public class MyApplication extends Application { public MyApplication() { getMetadataService().addExtension( "myextension", new MediaType("application/user+yml")); (...) } @Override public Restlet createInboundRoot() { (...) } }

Now you can use the extension within your server resource:

@Get("myextension") public Representation getSomething() { (...) }

This method will be used with the expected media type is application/user+yml.

Hope it helps you, Thierry


  • Restlet javax.net.ssl.SSLHandshakeException: null cert chain
  • Sending HTML data through AJAX using Spring MVC
  • Book suggestion for Spring framework [closed]
  • Can someone please explain me how to write an xpath for selenium on python?
  • Solaris: Mounting a file system on an application's handlers
  • Good algorithm/technique to find overlapping values from objects' properties?
  • Logcat continously shows messages
  • In metro, what's the difference between FolderInformation and StorageFolder
  • java rest client: jax-rs & automatic type mapping
  • How to specify Restlet customer HTTP header with key as “Authorization”
  • Is it possible to specialize on a static lifetime?
  • Quick Question About Get and Set
  • redirect_to root_url and return unless @user.activated
  • Configure Spring's MappingJacksonHttpMessageConverter
  • How do I retrieve the user information of a user authenticated with Apache's mod_ldap?
  • Ember.js model to be organised as a tree structure
  • How do I configure context broker accept post requests from my remote sensor?
  • Create DicomImage from scratch using Dcmtk
  • WPF - CanExecute dosn't fire when raising Commands from a UserControl
  • Jackson Parser: ignore deserializing for type mismatch
  • OpenGL ES texture problem, 4 duplicate columns and horizontal lines (Android)
  • How to do unit test for HttpContext.Current.Server.MapPath
  • Why is an OPTIONS request sent to the server?
  • Is there any way to access browser form field suggestions from JavaScript?
  • What is the “return” in scheme?
  • swift auto completion not working in Xcode6-Beta
  • Resize panoramic image to fixed size
  • Volusion's generic SQL folder, functionality
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • How can I estimate amount of memory left with calling System.gc()?
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Comma separated Values
  • How do you join a server to an Active Directory (domain)?
  • What are the advantages and disadvantages of reading an entire file into a single String as opposed
  • coudnt use logback because of log4j
  • How does Linux kernel interrupt the application?
  • Django query for large number of relationships
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How to load view controller without button in storyboard?