Restlet、CLAP、Ajax和块超时

40

我们正在使用RESTlet为我们的项目搭建一个小型REST服务器。我们在从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;
}

问题: 如果我通过Ajax从JAR文件中请求一个.js文件,并且这个网页也是通过CLAP从这个JAR文件中加载的,那么它只会返回该文件的前7737个字节,然后就挂起了。我无法让它返回文件的其余部分。它总是在恰好相同数量的字节之后挂起。1次中有50次会运行。

有任何想法为什么会挂起吗?我能不能简单地关闭CLAP和静态文件的分块编码(我们所有的文件都非常小)。

这让我们发疯了。


1
你能指出你正在使用的Restlet版本吗?你试过最新的2.2版本(稳定版)吗? - Jerome Louvel
你是直接连接到容器(Jetty,Tomcat等)还是中间有什么东西 - 比如Apache HTTP服务器?我们曾经遇到过这个问题,就是Apache在传输8kb的数据后关闭了连接。 - cheffe
请提供您的部署完整细节,包括JDK版本和Servlet引擎版本。 - Vaibhav Verma
听起来像是超时问题。我会在客户端和服务器上都增加超时时间值。 - Hey StackExchange
抱歉我没有更好的答案,但我们实际上因为这个问题和其他让我们烦恼的问题而放弃了这个框架。我想如果有更多的坚持可能会找到解决办法,但它只是一个次要的小项目,所以... - MarcWan
1个回答

1

我不知道您的应用程序使用哪种服务器连接器,但似乎是默认的。

Restlet在不同级别上可插拔和可扩展。我建议您使用Jetty连接器。只需在类路径中添加Jetty扩展的JAR文件(org.restlet.ext.jetty.jar),连接器将自动注册并替代默认连接器。

我还建议您升级到最新版本(2.3)。

要查看Restlet引擎中注册了哪些连接器,可以使用以下代码:

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

在做完这些之后,你不应该再有这样的问题了。

希望能对你有所帮助, Thierry


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接