Flex/Java Web 应用程序的外部化客户端 ChannelSet 配置

发布于 2024-10-07 02:36:53 字数 884 浏览 2 评论 0原文

我正在寻找一种方法,允许我(以某种方式)动态地将服务器名称、服务器端口和 Web 上下文传递到我的 Flex 客户端,以便它可以创建一个 ChannelSet 供其 RemoteObjects 使用。当然,我的 Java 服务器端代码可以轻松使用这三个属性,因此我只需要一种将它们传递给客户端的方法。

默认情况下,Adobe 表示 您应该根据服务器配置文件“services-config.xml”编译 Flex 应用程序。 Spring 说 应该避免(我同意)。

一种流行方法< /a> 是使用Flex的http服务下载XML配置文件。我喜欢这个想法,但我不想硬编码 XML 文件并将其保存在我的 WAR 文件中。有没有办法从 Java 代码动态生成它?

我的另一个想法是以某种方式使用 flashvars 将属性从包含的 HTML 页面传递到 SWF 文件。但同样,我不想将它们硬编码到 HTML 页面中。有没有办法(也许用Javascript?)在页面加载时动态设置这些值?

I am looking for an approach that will allow me to (somehow) dynamically pass the server name, server port, and web context to my Flex client so it can create a ChannelSet for it's RemoteObjects to use. These three properties are, of course, readily available to my Java server-side code so I just need a way to get them to the client.

By default, Adobe says you should compile your Flex application against the server configuration file "services-config.xml". This is a highly inflexible practice that Spring says should be avoided (I agree).

One popular approach is to use Flex's http service to download an XML configuration file. I like this idea, but I don't want to hard-code an XML file and keep it inside my WAR file. Is there a way to dynamically generate this from Java code?

Another idea I had is to somehow use flashvars to pass the properties in from the containing HTML page to the SWF file. But again, I don't want to hard code them into the HTML page. Is there a way (maybe with Javascript?) to dynamically set the value of these when the page loads?

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

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

发布评论

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

评论(1

分分钟 2024-10-14 02:36:53

我就是这样做的。我希望您会发现它很有用:

public static function getRemoteObject(destination:String, channelName:String,
    showBusyCursor:Boolean=true):RemoteObject{
    var remoteService:RemoteObject=new RemoteObject(destination);
    var channelSet:ChannelSet=new ChannelSet();
    var url:String = Application(Application.application).url;
    var secure:Boolean = URLUtil.isHttpsURL(url);
    var protocol:String = URLUtil.getProtocol(url);
    var amf:AMFChannel;
    if (secure){
        amf = new SecureAMFChannel(channelName, protocol +
            "://{server.name}:{server.port}" +
            (Application.application as Application).parameters.contextRoot +
            "/graniteamf/amf");
    }else{
        amf = new AMFChannel(channelName, protocol +
            "://{server.name}:{server.port}" +
            (Application.application as Application).parameters.contextRoot
            + "/graniteamf/amf");
    }
    channelSet.addChannel(amf);
    remoteService.channelSet=channelSet;
    remoteService.showBusyCursor=showBusyCursor;
    return remoteService;
}

因此,正如您所看到的,您需要提供的唯一内容是目标 - 必须在服务器端 XML 和 contextRoot 中配置 - 作为 flashVar 传递。在我的例子中(通过 JSP)作为 flashVar 传递看起来像这样:

String flashVariables = "contextRoot=" + request.getContextPath() +
    "&locale=" + request.getLocale().getLanguage(); 

This is how I do it. I hope you'll find it useful:

public static function getRemoteObject(destination:String, channelName:String,
    showBusyCursor:Boolean=true):RemoteObject{
    var remoteService:RemoteObject=new RemoteObject(destination);
    var channelSet:ChannelSet=new ChannelSet();
    var url:String = Application(Application.application).url;
    var secure:Boolean = URLUtil.isHttpsURL(url);
    var protocol:String = URLUtil.getProtocol(url);
    var amf:AMFChannel;
    if (secure){
        amf = new SecureAMFChannel(channelName, protocol +
            "://{server.name}:{server.port}" +
            (Application.application as Application).parameters.contextRoot +
            "/graniteamf/amf");
    }else{
        amf = new AMFChannel(channelName, protocol +
            "://{server.name}:{server.port}" +
            (Application.application as Application).parameters.contextRoot
            + "/graniteamf/amf");
    }
    channelSet.addChannel(amf);
    remoteService.channelSet=channelSet;
    remoteService.showBusyCursor=showBusyCursor;
    return remoteService;
}

So as you can see the only things you need to provide are destination - which must be configured in server side XML and contextRoot - passed as flashVar. Passing as flashVar in my case (through JSP) looks like this:

String flashVariables = "contextRoot=" + request.getContextPath() +
    "&locale=" + request.getLocale().getLanguage(); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文