在 Tapestry 5 中返回非 HTML、非 JSON http 正文?

发布于 2024-09-14 13:19:40 字数 295 浏览 2 评论 0原文

我必须在使用Tapestry5的项目中实现OAuth协议的服务提供者。因此,我只需要返回一个非常简单的 HTTP 响应正文,它既不是 HTML 也不是 JSON。

起初我尝试使用标准 tml & pojo (java class, page) 方法但这不起作用,因为 Tapestry 尝试解析模板。

所以我想我必须尝试一些不同的东西。也许可以在页面中使用 render() 方法?但我找不到任何可以回答这个问题的文档。

或者我应该使用另一个更适合我的需求的框架?

谢谢你的建议,

理查德

I have to implement the service provider of the OAuth protocol in a project that uses Tapestry5. Therefor I just need to return a very simple HTTP response body that is neither HTML or JSON.

At first I tried to use the standard tml & pojo (java class, page) approach but this doesn't work because Tapestry tries to parse the templates.

So I think I have to try something different. Maybe it is possible to use a render() method in a page? But I couldn't find any documentation that would answer this question.

Or should I just use another framework that would better fit my needs?

Thank you for your advice,

Richard

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小情绪 2024-09-21 13:19:40

Brian 将我推向了正确的方向,但问题的实际解决方案甚至更简单:

StreamResponse onActivate() {
     return new TextStreamResponse("text/plain", "foo=bar");
}

Brian pushed me in the right direction, but the actual solution to the problem was even simpler:

StreamResponse onActivate() {
     return new TextStreamResponse("text/plain", "foo=bar");
}
记忆之渊 2024-09-21 13:19:40

您可以直接从页面流式传输文本,而无需使用模板:

StreamResponse onActivate() {
  return new StreamResponse(
    public String getContentType() {
      return "text/plain";
    }

    public InputStream getStream() {
      return new ByteArrayInputStream("foo=bar".getBytes());
    }

    public void prepareResponse(Response response) {
      // response.setHeader(...
    }
}

如果您要为很多页面执行此操作,我认为您可以贡献自己的 DocumentLinker,它可以让您绕过 Tapestry 添加到页面的所有 xml/html/head 内容默认情况下。然后您可以返回使用模板。

You can stream text directly from the page without using a template:

StreamResponse onActivate() {
  return new StreamResponse(
    public String getContentType() {
      return "text/plain";
    }

    public InputStream getStream() {
      return new ByteArrayInputStream("foo=bar".getBytes());
    }

    public void prepareResponse(Response response) {
      // response.setHeader(...
    }
}

If you were doing it for a lot of pages, I think you could contribute your own DocumentLinker that lets you bypass all the xml/html/head stuff that Tapestry adds to the page by default. Then you could go back to using templates.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文