玩!框架:是什么Router.getFullUrl(QUOT;动作&QUOT)之间的差)绝对(和Router.reverse(QUOT;动作&QUOT)? [英] Play! framework : what is the difference between Router.getFullUrl("action") and Router.reverse("action").absolute()?

查看:290
本文介绍了玩!框架:是什么Router.getFullUrl(QUOT;动作&QUOT)之间的差)绝对(和Router.reverse(QUOT;动作&QUOT)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的游戏绝对URL! 1.2.4应用程序作为一个OAuth认证的回调(使用抄写

I need an absolute URL on my Play! 1.2.4 application as a callback for an OAuth authentication (using Scribe.

我的应用程序正在运行的背后一个Apache虚拟代理,通过与子的网址,如http://myapp.mydomain.com,代理http://127.0.0.1:9000访问。 代理preserveHost 设置为。在我玩游戏!应用程序的配置,我有以下属性: application.baseUrl = HTTP://myapp.mydomain.com/

My application is running behind an Apache virtual proxy, to be accessible through an URL with subdomain like "http://myapp.mydomain.com", proxying "http://127.0.0.1:9000". ProxyPreserveHost is set to On. In my Play! application configuration, I have the following property : application.baseUrl=http://myapp.mydomain.com/.

要计算这个绝对URL,我用像一块code的:

To compute this absolute URL, I used a piece of code like :

Router.ActionDefinition ad = Router.reverse("Controller.callback");
ad.absolute();
return ad.url;

这code正常工作与游戏! 1.2.3:它返回http://myapp.mydomain.com/callback

This code worked fine with Play! 1.2.3 : it returned "http://myapp.mydomain.com/callback".

现在,我使用的游戏! 1.2.4,这个code现在返回http://www.mydomain.com:9000/callback(译URL由虚拟代理无子域),因为如果游戏!现在使用的HTTP请求的URL建立这个绝对URL。

Now that I use Play! 1.2.4, this code now returns "http://www.mydomain.com:9000/callback" (translated URL by the virtual proxy without subdomain), as if Play! now used HTTP request's URL to build this absolute URL.

我凭经验取代这个code到 Router.getFullUrl(Controller.callback),它修正了我的问题。

I empirically replaced this code to Router.getFullUrl("Controller.callback"), which fixes my issue.

这两种方法 Router.getFullUrl() Router.absolute()不记录(booo!) ,我想知道的细微差别来了解我的问题。
我想, Router.absolute()使用当前的HTTP请求来构建绝对URL,而 Router.getFullUrl()用途 application.baseUrl 配置属性。
我也可能有一个Apache配置问题(因为它显然不是我的技能之一!),但与代理preserveHost 设置为,我认为我的虚拟代理是透明的玩!应用程序,我不明白为什么它从播放切换时会出现! 1.2.3 1.2.4。

Those two methods Router.getFullUrl() and Router.absolute() are not documented (booo!), and I was wondering the subtle differences to understand my issue. I suppose that Router.absolute() uses current HTTP request to build absolute URL, and Router.getFullUrl() uses application.baseUrl configuration property. I also may have an Apache configuration issue (as it is clearly not one of my skills!), but with ProxyPreserveHost set to On, I assumed that my virtual proxy would be transparent to Play! application, and I don't understand why it appears when switching from Play! 1.2.3 to 1.2.4.

感谢您的帮助。

推荐答案

您让我好奇,所以我去寻找到code(点击查看直接在github上相关的函数)。我同意播放!文档还远远没有完成:),其实code将有利于更多的javadoc的!

You got me curious so I went looking into the code (click to see the relevant functions directly in github). And I agree that Play! documentation is far from complete :), actually code would benefit of some more javadocs!

在任何情况下,这可能是一个错误......或误用!有一对夫妇的测试,你应该做的:

In any case, this might be a bug... or a misuse!, there's a couple of tests you should do:

有一件事你应该尝试的模板绝对符号: @@ {...} 。大多数时候,你并不需要扭转的URL在code,只是模板。这是否正确与否?

One thing you should try is the template absolute notation: @@{…}. Most of the time you do not need to reverse urls in your code, just in templates. Is that correct or not?

你有没有尝试 Router.reverse(行动,真)

如果你直接访问的本地主机:9000会发生什么情况?从你的浏览器的网址,所有不同的绝对选项

And what happens if you access directly the "localhost:9000" url from your browser, with all the different 'absolute' options?

在1.2.4 code:

In the 1.2.4 code:

字符串getFullUrl(...) 就等于 getBaseUrl()+ actionDefinition =反转(...)


字符串getBaseUrl( ) 被定义为 application.baseUrl 仅在没有要求 - 否则,使用 Http.Request。电流()。getBase()

and String getBaseUrl() is defined as application.baseUrl ONLY IF there's no request - otherwise it uses Http.Request.current().getBase().

ActionDefinition.absolute 使用从的 逆转 结果。

在1.2.3 code:

In 1.2.3 code:

<一个href=\"https://github.com/playframework/play/blob/711eb01e89c455ff69429db977c0fa973bc2e6d5/framework/src/play/mvc/Router.java#L380\"相对=nofollow> 逆转

<一个href=\"https://github.com/playframework/play/blob/711eb01e89c455ff69429db977c0fa973bc2e6d5/framework/src/play/mvc/Router.java#L584\"相对=nofollow> 绝对

@@ 标记<一个href=\"https://github.com/playframework/play/blob/711eb01e89c455ff69429db977c0fa973bc2e6d5/framework/src/play/templates/GroovyTemplate.java#L446\"相对=nofollow>基本上使用:

private String __reverseWithCheck(String action, boolean absolute) {
    return Router.reverseWithCheck(action, Play.getVirtualFile(action), absolute);
}

具有绝对真实的,那就是直接调用反转(动作,绝对= TRUE),但接收字符串,而不是ActionDefinition

with absolute true, that is calling directly reverse(action, absolute=true) but receiving a string rather than an ActionDefinition

也许有些戏开发商将介入......但我想对大家有点帮助,并在这个过程:)我会让你步入比较这两种功能的全部细节学习,但他们有完全不同在deliverying的腹肌的方法。网址...

Maybe some play developer will step in... but i tried to help a bit, and learn in the process :) I'll let you step into the full details of comparing the two functions, but they have quite a different approach in deliverying an abs. url...

这篇关于玩!框架:是什么Router.getFullUrl(QUOT;动作&QUOT)之间的差)绝对(和Router.reverse(QUOT;动作&QUOT)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆