我们正在使用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和静态文件的分块编码(我们所有的文件都非常小)。
这让我们发疯了。