Flex HttpService:附加到目标

发布于 2024-07-07 05:27:38 字数 723 浏览 6 评论 0原文

我正在使用 Flex 连接到 Rest 服务。 例如,要访问订单 #32,我可以调用 URL http://[service]/orders/32< /a>. URL必须配置为目标 - 因为客户端将连接到服务的不同实例。 所有这些都使用 Blaze 代理,因为它涉及 GET、PUT、DELETE 和 POST 调用。 问题是:- 使用 HttpService 时如何将“32”附加到目的地的末尾? 我所做的就是设置目的地,并在某个时刻将其转换为 URL。 我已经追踪了代码,但我不知道这是在哪里完成的,所以无法替换它。

选项有: 1. 将目标解析为 Flex 客户端内的 URL,然后将该 URL(带有附加数据)设置为 URL。 2. 编写我自己的 java Flex Adapter 来覆盖标准代理,并将参数映射到 url,如下所示: http:// /[service]/order/{id}?id=32 至 http://[service] /order/32

有没有人遇到过这个问题,有什么简单的方法可以解决这个问题吗?

I am using Flex to connect to a Rest service. To access order #32, for instance, I can call the URL http://[service]/orders/32.
The URL must be configured as a destination - since the client will connect to different instances of the service. All of this is using the Blaze Proxy, since it involves GET, PUT, DELETE and POST calls.
The problem is:- how do I append the "32" to the end of a destination when using HttpService? All I do is set the destination, and at some point this is converted into a URL. I have traced the code, but I don't know where this is done, so can't replace it.

Options are:
1. Resolve the destination to a URL within the Flex client, and then set the URL (with the appended data) as the URL.
2. Write my own java Flex Adapter that overrides the standard Proxy, and map parameters to the url like the following: http://[service]/order/{id}?id=32 to http://[service]/order/32

Has anyone come across this problem before, and are there any simple ways to resolve this?

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

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

发布评论

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

评论(2

空城之時有危險 2024-07-14 05:27:38

大家都知道,这就是我解决此问题的方法:

我在服务器上创建了一个自定义 HTTPProxyAdapter

public MyHTTPProxyAdapter extends flex.messaging.services.http.HTTPProxyAdapter {

public Object invoke(Message message) {
    // modify the message - if required
    process(message);
    return super.invoke(message);
}

private void process(Message message) {
        HTTPMessage http = (HTTPMessage)message;
        if(http != null) {
            String url = http.getUrl();
            ASObject o = (ASObject)http.getBody();
            if(o != null) {
                Set keys = o.keySet();
                Iterator it = keys.iterator();
                while(it.hasNext()) {
                    String key = (String)it.next();
                    String token = "[" + key +"]";
                    if(url.contains(token)) {
                        url = url.replace(token, o.get(key).toString());
                        o.remove(key);
                    }

                }
                http.setUrl(url);
            }
        }
    }
}

然后将目标适配器替换为我的适配器。
我现在可以在 config.xml 中使用以下 URL,方括号中的任何内容都将替换为查询字符串:

<destination id="user-getbytoken">
        <properties>
            <url>http://localhost:8080/myapp/public/client/users/token/[id]</url>
        </properties>
</destination>

在此示例中,将目标设置为 user-getbytoken 且参数 {id:123} 将生成以下 url http://localhost:8080/myapp/public/client/users/token/ 123

Just so everyone knows, this is how I resolved this issue:

I created a custom HTTPProxyAdapter on the server

public MyHTTPProxyAdapter extends flex.messaging.services.http.HTTPProxyAdapter {

public Object invoke(Message message) {
    // modify the message - if required
    process(message);
    return super.invoke(message);
}

private void process(Message message) {
        HTTPMessage http = (HTTPMessage)message;
        if(http != null) {
            String url = http.getUrl();
            ASObject o = (ASObject)http.getBody();
            if(o != null) {
                Set keys = o.keySet();
                Iterator it = keys.iterator();
                while(it.hasNext()) {
                    String key = (String)it.next();
                    String token = "[" + key +"]";
                    if(url.contains(token)) {
                        url = url.replace(token, o.get(key).toString());
                        o.remove(key);
                    }

                }
                http.setUrl(url);
            }
        }
    }
}

Then replaced the destination adapter to my adapter.
I can now use the following URL in the config.xml and anything in square brackets will be replaced by the Query string:

<destination id="user-getbytoken">
        <properties>
            <url>http://localhost:8080/myapp/public/client/users/token/[id]</url>
        </properties>
</destination>

In this example, setting the destination to user-getbytoken and the parameters {id:123} will result in the url of http://localhost:8080/myapp/public/client/users/token/123

孤独岁月 2024-07-14 05:27:38

下面是通过单击事件的处理程序将 URL 解析为 Flex 中的 HTTPService 的简单方法。

这是一个服务:

<mx:HTTPService
    id="UCService"
    result="UCServiceHandler(event)" 
    showBusyCursor="true"
    resultFormat="e4x"
    />

然后是处理程序:

        private function UCmainHandler(UCurl:String) {

            UCService.url = UCurl;
            UCService.send();

        }

这是一个示例单击事件:

<mx:Button label="add to cart" click="UCmainHandler('http://sampleurl.com/cart/add/p18_q1?destination=cart')" />

当然,您可以将其他值传递给单击处理程序,甚至让处理程序根据其他当前设置等向 url 添加内容...

希望有帮助!

Here's a simple way to resolve the url to the HTTPService within Flex via the click event's handler.

here's a service:

<mx:HTTPService
    id="UCService"
    result="UCServiceHandler(event)" 
    showBusyCursor="true"
    resultFormat="e4x"
    />

Then here's the handler:

        private function UCmainHandler(UCurl:String) {

            UCService.url = UCurl;
            UCService.send();

        }

And here's a sample click event:

<mx:Button label="add to cart" click="UCmainHandler('http://sampleurl.com/cart/add/p18_q1?destination=cart')" />

Of course you could pass other values to the click handler, or even have the handler add things to the url based on other current settings etc...

Hope that helps!

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