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.

Vizllx
  • 8,843
  • 1
  • 36
  • 77
MarcWan
  • 2,873
  • 3
  • 25
  • 40
  • 1
    Can you indicate which version of Restlet you are using. Did you try with latest 2.2 version (stable)? – Jerome Louvel May 10 '14 at 04:52
  • 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. – cheffe Sep 23 '15 at 09:41
  • GIve complete details of you deployment including JDK version, Servlet Engine Version ? – Vaibhav Verma Oct 18 '15 at 11:49
  • Sounds to me a timeout issue. I would increase the timeout value both on the client and server. – Hey StackExchange Oct 23 '15 at 17:28
  • 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 … – MarcWan Nov 07 '15 at 12:28

1 Answers1

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

Thierry Templier
  • 182,931
  • 35
  • 372
  • 339