mule-restlet 可以将 URL 模式映射到特定方法吗?

发布于 2024-12-21 08:31:15 字数 1598 浏览 0 评论 0原文

将传入的 http 请求转换为 Play! Web 框架中的特定方法非常简单向前,如下所示:

GET    /users/{userId}  UserController.getUser   
POST   /users           UserController.addUser
PUT    /users           UserController.updateUser
DELETE /users/{userId}  UserController.deleteUser

但我发现在 Mule-Restlet 中很难做到这一点。

<model name="userModel">
    <service name="userService">
        <inbound>
            <inbound-endpoint address="http://localhost:63080"/>
        </inbound>
        <outbound>
            <filtering-router>
                <outbound-endpoint address="vm://userController"/>
                <or>
                    <restlet:uri-template-filter pattern="/users/{userId}" verbs="GET"/>
                    <restlet:uri-template-filter pattern="/users" verbs="POST"/>
                    <restlet:uri-template-filter pattern="/users" verbs="PUT"/>
                    <restlet:uri-template-filter pattern="/users/{userId}" verbs="DELETE"/>
                </or>
            </filtering-router>
        </outbound>
    </service>
    <service name="userController">
        <inbound>
            <inbound-endpoint address="vm://userController"/>
        </inbound>
        <!-- **TODO: How to implement UserController** -->
        <component class="com.ggd543.mulerestletdemo.user.UserController"/>
    </service>
</model>

To translate an incoming http request to the specific method in Play! web framework is straight forward, which look like as follows:

GET    /users/{userId}  UserController.getUser   
POST   /users           UserController.addUser
PUT    /users           UserController.updateUser
DELETE /users/{userId}  UserController.deleteUser

But I find it hard to do this in Mule-Restlet.

<model name="userModel">
    <service name="userService">
        <inbound>
            <inbound-endpoint address="http://localhost:63080"/>
        </inbound>
        <outbound>
            <filtering-router>
                <outbound-endpoint address="vm://userController"/>
                <or>
                    <restlet:uri-template-filter pattern="/users/{userId}" verbs="GET"/>
                    <restlet:uri-template-filter pattern="/users" verbs="POST"/>
                    <restlet:uri-template-filter pattern="/users" verbs="PUT"/>
                    <restlet:uri-template-filter pattern="/users/{userId}" verbs="DELETE"/>
                </or>
            </filtering-router>
        </outbound>
    </service>
    <service name="userController">
        <inbound>
            <inbound-endpoint address="vm://userController"/>
        </inbound>
        <!-- **TODO: How to implement UserController** -->
        <component class="com.ggd543.mulerestletdemo.user.UserController"/>
    </service>
</model>

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

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

发布评论

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

评论(1

亣腦蒛氧 2024-12-28 08:31:15

根据 Restlet Transport 文档,您应该能够将您的路由映射缩短为:

<or-filter>
    <restlet:uri-template-filter pattern="/users" verbs="POST PUT"/>
    <restlet:uri-template-filter pattern="/users/{userId}" verbs="GET DELETE"/>
</or-filter>

然后要开发您的 UserController 资源,请参阅 Restlet 的用户指南,与传输所使用的版本相关。

According to the Restlet Transport doc, you should be able to shorten your routing map to:

<or-filter>
    <restlet:uri-template-filter pattern="/users" verbs="POST PUT"/>
    <restlet:uri-template-filter pattern="/users/{userId}" verbs="GET DELETE"/>
</or-filter>

Then to develop your UserController resource, refer to the Restlet's user guide that is relevant to the version in use by the transport.

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