0

我正在使用 Flex 连接到 Rest 服务。例如,要访问订单 #32,我可以调用 URL http://[service]/orders/32。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 to http://[service]/订单/32

以前有没有人遇到过这个问题,有没有简单的方法来解决这个问题?

4

2 回答 2

1

众所周知,这就是我解决此问题的方法:

我在服务器上创建了一个自定义 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,方括号中的任何内容都将替换为 Query 字符串:

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

在此示例中,将目标设置为 user-getbytoken 和参数 {id:123} 将导致http://localhost:8080/myapp/public/client/users/token/123的 url

于 2008-09-26T15:35:56.220 回答
0

这是通过单击事件的处理程序将 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 添加内容......

希望有帮助!

于 2008-09-25T16:11:18.697 回答