java 如何在 Flex/BlazeDS 中同时支持 HTTP 和 HTTPS 通道?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1009675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to support both HTTP and HTTPS channels in Flex/BlazeDS?
提问by digitalsanctum
I've been trying to find the right configuration for supporting both http/s requests in a Flex app. I've read all the docs and they allude to doing something like the following:
我一直在努力寻找在 Flex 应用程序中支持两个 http/s 请求的正确配置。我已经阅读了所有的文档,他们暗示要做如下事情:
<default-channels>
<channel ref="my-secure-amf">
<serialization>
<log-property-errors>true</log-property-errors>
</serialization>
</channel>
<channel ref="my-amf">
<serialization>
<log-property-errors>true</log-property-errors>
</serialization>
</channel>
This works great when hitting the app via https but get intermittent communication failures when hitting the same app via http. Here's an abbreviated services-config.xml:
这在通过 https 访问应用程序时非常有效,但在通过 http 访问同一应用程序时会出现间歇性通信故障。这是一个缩写的 services-config.xml:
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf"
class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<!-- HTTPS requests don't work on IE when pragma "no-cache" headers are set so you need to set the add-no-cache-headers property to false -->
<add-no-cache-headers>false</add-no-cache-headers>
<!-- Use to limit the client channel's connect attempt to the specified time interval. -->
<connect-timeout-seconds>10</connect-timeout-seconds>
</properties>
</channel-definition>
<channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
<!--<endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>-->
<endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure"
class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<add-no-cache-headers>false</add-no-cache-headers>
<connect-timeout-seconds>10</connect-timeout-seconds>
</properties>
</channel-definition>
I'm running with Tomcat 5.5.17 and Java 5.
我正在运行 Tomcat 5.5.17 和 Java 5。
- The BlazeDS docs say this is the best practice. Is there a better way?
- With this config, there seems to be 2-3 retries associated with each channel defined in the default-channels element so it always takes ~20s before the my-amf channel connects via a http request. Is there a way to override the 2-3 retries to say, 1 retry for each channel?
- BlazeDS 文档说这是最佳实践。有没有更好的办法?
- 使用此配置,似乎有 2-3 次重试与 default-channels 元素中定义的每个通道相关联,因此在 my-amf 通道通过 http 请求连接之前总是需要大约 20 秒。有没有办法覆盖 2-3 次重试,说每个通道重试 1 次?
Thanks in advance for answers.
提前感谢您的回答。
回答by Philip
I have http and https working, although I've only tested it on Firefox and IE7. So far, I'm only using BlazeDS for remoting. Here is my set up:
我有 http 和 https 工作,虽然我只在 Firefox 和 IE7 上测试过。到目前为止,我只使用 BlazeDS 进行远程处理。这是我的设置:
<channel-definition id="my-amf"
class="mx.messaging.channels.AMFChannel">
<endpoint
url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf"
class="flex.messaging.endpoints.AMFEndpoint" />
<properties>
<polling-enabled>false</polling-enabled>
</properties>
</channel-definition>
<channel-definition id="my-secure-amf"
class="mx.messaging.channels.SecureAMFChannel">
<endpoint
url="https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure"
class="flex.messaging.endpoints.SecureAMFEndpoint" />
<properties>
<add-no-cache-headers>false</add-no-cache-headers>
</properties>
</channel-definition>
You don't specify the app server you're using; it may be an issue. I had some issues when switching from HTTPS to HTTP (secure logins) under Tomcat. One thing I did to troubleshoot was install Jetty and try it there. I'd never used it before, but it was very quick to set up and deploy to, even through Eclipse. I then knew I had a Tomcat specific-problem, which made finding a solution easier (by which I mean possible).
您没有指定您正在使用的应用服务器;这可能是一个问题。在 Tomcat 下从 HTTPS 切换到 HTTP(安全登录)时遇到了一些问题。我为排除故障所做的一件事是安装 Jetty 并在那里尝试。我以前从未使用过它,但即使通过 Eclipse,它的设置和部署也非常快。然后我知道我有一个 Tomcat 特定问题,这使得找到解决方案更容易(我的意思是可能)。
回答by Java Bug
This was driving us nuts too. To solve it make the http (my-amf) first in the default-channels tag and then https (my-secure-amf)
这也让我们发疯了。为了解决这个问题,首先在 default-channels 标签中使用 http (my-amf),然后在 https (my-secure-amf)
<default-channels>
<channel ref="my-amf">
<serialization>
<log-property-errors>true</log-property-errors>
</serialization>
</channel>
<channel ref="my-secure-amf">
<serialization>
<log-property-errors>true</log-property-errors>
</serialization>
</channel>
回答by maniacneron
If the destinations that use http and https are different destination you can define the channels with order to use for that destination.For example mySecureDestination and myDestination are two different destinations. For mySecureDestination :
如果使用 http 和 https 的目的地是不同的目的地,您可以按顺序定义用于该目的地的通道。例如 mySecureDestination 和 myDestination 是两个不同的目的地。对于 mySecureDestination :
<destination id="mySecureDestination" channels="httpsChannel"></destination>
and for non secure http channel
和非安全 http 通道
<destination id="myDestination" channels="httpChannel"></destination>

