Restlet, CLAP, Ajax, and chunk timeouts
Asked Answered
A

1

40

We're using RESTlet to do a small little REST server for a project we have. We set up a bunch of routes in a class inheriting from Application:

public static void createRestServer(ApplicationContext appCtx, String propertiesPath) throws Exception {

  // Create a component
  Component component = new Component();
  component.getServers().add(Protocol.HTTP, 8081);
  component.getClients().add(Protocol.FILE);
  component.getClients().add(Protocol.CLAP);

  Context context = component.getContext().createChildContext();
  RestServer application = new RestServer(context);

  application.getContext().getParameters().add("useForwardedForHeader", "true");

  application.getContext().getAttributes().put("appCtx", appCtx);
  application.getContext().getAttributes().put("file", propertiesPath);

  // Attach the application to the component and start it
  component.getDefaultHost().attach(application);
  component.start();
}

private RestServer(Context context) {
  super(context);
}

public synchronized Restlet createInboundRoot() {
  Router router = new Router(getContext());

  // we then have a bunch of these
  router.attach("/accounts/{accountId}", AccountFetcher.class); //LIST Account level
  // blah blah blah

  // finally some stuff for static files:
  //
  Directory directory = new Directory(getContext(),
     LocalReference.createClapReference(LocalReference.CLAP_CLASS, "/"));
  directory.setIndexName("index.html");
  router.attach("/", directory);

  return router;
}

The problem: If I request a .js file in the JAR via Ajax from a web page (also loaded via CLAP from this JAR), it'll only return the first 7737 bytes of that file and then hang. I can't get it to return the rest of the file. It always hangs after exactly the same number of bytes. 1 in 50 times it works.

Any ideas why it's hanging? Can I just turn off chunked encoding for CLAP and static files (all ours are quite small).

This is driving us nuts.

Absenteeism answered 24/1, 2014 at 18:31 Comment(5)
Can you indicate which version of Restlet you are using. Did you try with latest 2.2 version (stable)?Hijacker
Are you connecting directly to the container (Jetty, Tomcat, ...) or is there something in between - like an Apache HTTP Server? We had the problem that this one closed the connection after 8kb of data.Legendre
GIve complete details of you deployment including JDK version, Servlet Engine Version ?Koo
Sounds to me a timeout issue. I would increase the timeout value both on the client and server.Corliss
I'm sorry I don't have a better answer, but we effectively abandoned this framework because of this and other annoyances that were driving us nuts. I suppose w some more persistence the issue could have been found, but it was a minor secondary project, so …Absenteeism
E
1

I don't know which server connector you use for your application but it seems that it's the default one.

Restlet is pluggable and extensible at different levels. I recommend you to use the Jetty one. To do that simply add the JAR file for the Jetty extension (org.restlet.ext.jetty.jar) within your classpath. The connector will be automatically registered and use instead of the default one.

I also recommend you to upgrade to the latest version (2.3).

To see which connectors are registered in the Restlet engine, you can use the following code:

List<ConnectorHelper<Server>> serverConnectors
       = Engine.getInstance().getRegisteredServers();
for (ConnectorHelper<Server> connectorHelper : serverConnectors) {
    System.out.println("Server connector: "+connectorHelper);
}

You shouldn't have such problems after doing this.

Hope it helps you, Thierry

Extinct answered 20/1, 2016 at 10:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.