How does Restlet handle the HTTP Accept header?
 

The Restlet framework is supposed to handle automatic content negotiation; however, it doesn't seem to do it properly.

When a client sends and HTTP GET request with the Accept header with a value, Restlet doesn't automatically negotiates the content.

Does anyone know how the Accept header is treated?

http://www.stackoverflow.com/questions/938174/

        

There are 1 answer(s) to this question.


Hi Steve,

The Restlet API has extensive support for the "Accept" header. The information is parsed and available via the Request.getClientInfo().getAcceptedMediaTypes() : List> method.

Now, in order to automatically negotiate content for you, the Restlet engine needs to have information about the available variants. This is the purpose org.restlet.resource.Resource class in Restlet 1.1 and the new org.restlet.resource.ServerResource class in the Restlet 2.0 version being developed.

In Restlet 1.1, you create a subclass of Resource, declare variants like this:

getVariants().add(new Variant(MediaType.TEXT_PLAIN));

getVariants().add(new Variant(MediaType.APPLICATION_XML));

Then override the represent(Variant) method like this:

public Representation represent(Variant){

  if(MediaType.TEXT_PLAIN.equals(variant.getMediaType()){

     ...

  else if(...)

     ...

Best regards, Jerome

PS: please use our mailing list for future questions and look in the archives: http://www.restlet.org/community/lists

Related Questions

Restlet image processing
Restlet image processing I need to pass the image from restlet client to server. I am passing the image bytes in the request but the image is getting distorted
Restlet POST using JSON
Restlet POST using JSON Hi, How do I implement Restlet function which accepts JSON post? And how do I test this using curl? Thanks Here is a good and complete example of a Restlet that accepts JSON via POST: Creating a simple web service with Restlet And a basic guide on how to test RESTful web services with cURL: REST-esting with cURL With Restlet 2, you can either: test the entity media-type compatibility in @Post acceptRepresentation(Representation entity): @Post public Representation acceptRepresentation(Representation entity) throws ResourceException...=4447&dsMessageId=2585586 http://www.restlet.org/documentation/2.0/jse/api/org/restlet/resource/Post.html (With Restlet 1, you would need to test the type of the entity
Helloworld webservice using RESTLet
Helloworld webservice using RESTLet Can any one please provide the required setup and steps to develop a sample web service program using RESTLet. How about the documentation on RESTLets site? http://www.restlet.org/documentation/1.1/firstSteps#part02
org.restlet.ext.crypto not in Restlet Maven Repo
org.restlet.ext.crypto not in Restlet Maven Repo I cannot find the org.restlet.ext.crypto package in the Restlet maven repo http://maven.restlet.org/ Strange that the examples use it though its nowhere to be found in the maven repo. Anyone know why this is or have a similar experience. I am trying to fit Restlet into an existing GWT project using maven. nvermind I found it. They dont have it under the gwt dir. Its under the other editions, jee, jse etc
Problem with Restlet on GAE
Problem with Restlet on GAE I'm trying to implement a calculator web service on GAE using Java Restlets... it works perfectly fine on localhost but when I upload my project to the Google App Engine everytime I try the web service link it says the link is broken. Here's the code I used: public Restlet createInboundRoot() { Router router = new Router(getContext()); Restlet restlet = new Restlet() { public void handle(Request request, Response response) { // Print the requested URI path String parameters = request.getResourceRef().getRemainingPart...); } }; // Defines only one route router.attachDefault(restlet); return router; } The Application it's on is mapped to the /calcservice but as I said when I upload to GAE it comes back with a broken link error. I'm developing on Eclipse 3.4 and I'm wondering if there are any parameters I
In Restlet, what's the difference between a Restlet class and a Resource class?
In Restlet, what's the difference between a Restlet class and a Resource class? I've gone through the firstResource bit of the Restlet 1.1 tutorial and put together a web service that handles GET, POST, DELETE, PUT by subclassing the Resource class and overriding the appropriate methods and using a Router to attach the subclassed Resource classes. So I'm left thinking - what's the point of a Restlet? I can attach a Resource or a Restlet to an Application Router A Resource has methods to handle HTTP GET POST etc. A Restlet has a handle method - do I somehow forward that on to a Resource class? What's the difference? When do I use one or the other? What would I put in a Restlet handle method? Thanks. Restlet is the base class for various restlet server facilities, among them Application and Router. When its handle() method is called it's supposed to interpret the request, dispatch
Restlet XML parsing xstream
Restlet XML parsing xstream Hi, I'm new to restlet and quite confused. A rest server returns the following xml response: <posts user="a" dt="2010-01-21T08:00:00Z" tag=""> <post href="http://www.opensatnav.org/" hash="a" description="OpenSatNav" tag="android osm" time="2010-01-21T20:55:54Z" extended=""/> <post href="http://www.openrouteservice.org/" hash="a" description="OpenRouteService" tag="routing" time="2010-01-21T20:55:24Z" extended=""/> </posts> How do I use xstream to turn that xml stream into a Java list with Post objects? I know that I could use a DOMRepresentation, but I want to use xstream instead. Thanks
Parameter parsing with Java Restlet
Parameter parsing with Java Restlet I'm trying to make a calculator web service that has more than 10 parameters. Is there any function in the Java Restlet or in Java itself that allows you to see the parameter ids? e.g. http://mywebsite.com/calculator?id1=value1&id2=value2&id3=value3 => I'm trying to access the values of id1, id2, and id3 so that I don't have to require people using the web service to input all parameters (some of them are likely to be 0). Not familiar with reslets. However, if you have access to the HttpServletRequest object you can make use of the getParameterMap method. This method will return a Map, which will allow you to access the parameter names using the getKeySet method. Be sure to take note that the Map that is returned uses a string array as its value type and not an ordinary string (this is so you can see multiple parameters which have the same
Fine-grained Authentication with RESTlet
Fine-grained Authentication with RESTlet Hi, I want to expose a resource using RESTlet with a fine-grained authentication. My ServerResource should be accessable via GET only for authenticated members (using BASIC Authentication). However, requests using POST should be available also for callers without any authentication. In order to clearify: http://path/myapp/user should allow anyone to register using POST, but only registered members should be able to GET a list of all users. I'm unfortunately not much into RESTlet and I only find examples using coarser authentication for whole Restlets or Routers. So how do I enable optional authentication for resources and check them on a per-method level? Thanks in advance! To do basic authentication in RESTlet 2.0 (I assume you're using 2.0 since you mention ServerResource), you need to use a ChallengeAuthenticator
Sending binary data with the Restlet client
Sending binary data with the Restlet client I'm trying to send a byte[] (using PUT) with Restlet but I can't find any info on how to do it. My code looks like this: Request request = new Request(Method.PUT, url); request.setEntity( WHAT DO I PUT HERE?, MediaType.APPLICATION_OCTET_STREAM); I had expected to find something along the lines of ByteArrayRepresentation, just like there's a JsonRepresentation and a a StringRepresentation but I couldn't find anything. I'm not familiar with restlet, but one way to do it would be to base64 encode the data. Then you could handle it like a regular string. I believe you want to use an InputRepresentation, like so: Representation representation = new InputRepresentation(new ByteArrayInputStream(bytes), MediaType.APPLICATION_OCTET_STREAM); request.setEntity(representation); you can try subclassing WritableRepresentation that is especially
How to use a ThrottlingFilter for Jetty in Restlet
How to use a ThrottlingFilter for Jetty in Restlet I would like to configure a webservice so that once the accept queue is full the service returns 503. Currently, these requests seem to just time out. I did set paramters like maxThreads and acceptQueuesize (as described here: http://www.restlet.org/documentation/1.1/ext/com/noelios/restlet/ext/jetty/JettyServerHelper). But the service does not respond with 503 once the acceptQueue is full. It seems jetty's ThrottlingFilter (http://www.mortbay.org/jetty/jetty-6/apidocs/index.html?index-all.html) is what I'm looking for, but I don't know how to apply within my restlet service. You won't be able to take advantage of ThrottlingFilter unless you deploy your application as a WAR file into Jetty. JettyServerHelper bootstraps Restlet as a standalone server using Jetty to accept HTTP connections and hence cannot utilize a Servlet Filter
How does Restlet handle the HTTP Accept header?
How does Restlet handle the HTTP Accept header? The Restlet framework is supposed to handle automatic content negotiation; however, it doesn't seem to do it properly. When a client sends and HTTP GET request with the Accept header with a value, Restlet doesn't automatically negotiates the content. Does anyone know how the Accept header is treated? Hi Steve, The Restlet API has extensive support for the "Accept" header. The information is parsed and available via the Request.getClientInfo().getAcceptedMediaTypes() : List> method. Now, in order to automatically negotiate content for you, the Restlet engine needs to have information about the available variants. This is the purpose org.restlet.resource.Resource class in Restlet 1.1 and the new org.restlet.resource.ServerResource class in the Restlet 2.0 version being developed. In Restlet 1.1, you create a subclass of Resource
Restlet - serving up static content
Restlet - serving up static content Using Restlet I needed to serve some simple static content in the same context as my web service. I've configured the component with a Directory, but in testing, I've found it will only serve 'index.html', everything else results in a 404. router.attach("/", new... a reverse proxy and serve all static content off another web server, but for now I need this to work as is. Well, I figured out the issue. Actually Restlet appears to route requests based on prefix, but does not handle longest matching prefix correctly, it also seems to ignore file extensions. So... it, I'd love to know. It's not a big deal, just for testing. I think we'll be putting apache or nginx in front of this in production anyway. Routers in Restlet by default use the "Template.MODE_STARTS_WITH" matching mode. You could always set the Router default by doing router.setMatchingMode
Running JUnit Tests on a Restlet Router
Running JUnit Tests on a Restlet Router Using Restlet I have created a router for my Java application. From using curl, I know that each of the different GET, POST & DELETE requests work for each of the URIs and return the correct JSON response. I'm wanting to set-up JUnit tests for each of the URI's to make the testing process easier. However, I'm not to sure the best way to make the request to each of the URIs in order to get the JSON response which I can then compare to make sure the results are as expected. Any thoughts on how to do this? You could just use a Restlet Client to make requests, then check each response and its representation. For example: Client client = new Client(Protocol.HTTP); Request request = new Request(Method.GET, resourceRef); Response response = client.handle(request); assert response.getStatus().getCode() == 200; assert response.isEntityAvailable
Restlet ClientResource Post Chunked Encoding - WCF Unsuported
Restlet ClientResource Post Chunked Encoding - WCF Unsuported Hello All, I'm developing a product that will use extensively of Restlet for consume WCF Rest Services. I had created a method to post a XML of a class containing 2 attributes. Restlet post my xml with Transfer-Encoding: chunked, and my WCF service, can't to interpret posted content, unfortunately WCF continues can't to deserialize my class parameters. I tried to use the solution described here: http://osdir.com/ml/java.restlet/2007-05/msg00097.html but it won't work for me. My restlet client continues to post my request content using Transfer-Encoding: chunked. =( Anybody had a problem like this? Can anybody help-me??? Thanks all and sorry by bad bad english =) Hi there, I suggest that you contact Restlet community directly: http://www.restlet.org/community/lists Try to provide sample code reproducing the issue

Related restlet Video tutorials from Youtube.

Post you comment here

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

There are 0 comment(s) to this page.



The questions and answers taken from stackoverflow.com's public data dump which is licensed under the cc-wiki license.
Logo, website design and layout ©2011 CodingTiger.com