gpt4 book ai didi

java - ReSTLet、CLAP、Ajax 和 block 超时

转载 作者:IT老高 更新时间:2023-10-28 12:47:05 24 4
gpt4 key购买 nike

我们正在使用 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 从网页(也通过 CLAP 从此 JAR 加载)请求 JAR 中的 .js 文件,它只会返回该文件的前 7737 个字节文件,然后挂起。我无法让它返回文件的其余部分。它总是在完全相同的字节数之后挂起。 50 次中有 1 次有效。

任何想法为什么它挂起?我可以关闭 CLAP 和静态文件的分 block 编码吗(我们的文件都很小)。

这让我们发疯了。

最佳答案

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

ReSTLet 可在不同级别上进行插拔和扩展。我建议你使用 jetty 一号。为此,只需在类路径中添加 Jetty 扩展 (org.reSTLet.ext.jetty.jar) 的 JAR 文件。连接器将自动注册并使用,而不是默认连接器。

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

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

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

这样做后你不应该有这样的问题。

希望对你有帮助蒂埃里

关于java - ReSTLet、CLAP、Ajax 和 block 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21339855/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com