Grails 中的 Web 服务脚手架

发布于 2024-07-21 08:45:31 字数 312 浏览 4 评论 0原文

我需要实现一个 Web 应用程序,但我需要使用不同的 SOAP Web 服务作为后端,而不是使用关系数据库。 应用程序的一个重要部分仅调用 Web 服务并显示结果。 由于 Web 服务以操作的形式明确定义:在参数和返回类型中,在我看来,可以轻松构建基本 GUI,就像基于域实体的脚手架一样。

例如,在 SearchProducts Web 服务操作中,我需要输入搜索参数作为输入,以便可以构建搜索页面。 操作将返回产品列表,因此我需要一个页面来在某种表格中显示此列表。

grails 中是否已经有一些库可以让您实现这一目标。 如果没有,您将如何创建一个?

I need to implement a web app, but instead of using relational database I need to use different SOAP Web Services as a back-end. An important part of application only calls web services and displays the result. Since Web Services are clearly defined in form of Operation: In parameters and Return Type it seems to me that basic GUI could be easily constructed just like in the case of scaffolding based on Domain Entities.

For example in case of SearchProducts web service operation I need to enter search parameters as input, so the search page can be constructed. Operation will return a list of products, so I need a page that will display this list in some kind of table.

Is there already some library in grails that let you achieve this. If not, how would you go about creating one?

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

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

发布评论

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

评论(2

清风夜微凉 2024-07-28 08:45:31

最简单的方法可能是在 WSDL 文件上使用 wsimport 来生成客户端存根。 然后,您可以从 Groovy 调用存根中的方法,就像从 Java 调用它们一样。

例如,考虑 Microsoft TerraServer 的 WSDL 文件,位于 http://terraservice.net/TerraService.asmx ?wsdl 。 然后运行类似的命令

wsimport -d src -keep http://terraservice.net/TerraService.asmx?WSDL

,将所有已编译的存根放入 src 目录中。 然后您可以编写 Groovy 代码,例如

import com.terraserver_usa.terraserver.*;

TerraServiceSoap sei = new TerraService().getTerraServiceSoap()
Place home = new Place(city:'Boston',state:'MA',country:'US')
def pt = sei.convertPlaceToLonLatPt(home)
println "$pt.lat, $pt.lon"
assert Math.abs(pt.lat - 42.360000) < 0.001
assert Math.abs(pt.lon - -71.05000) < 0.001

如果您想访问大量 Web 服务,请为所有服务生成存根。 或者您可以使用动态代理。

不过,底线是让 Java 做它已经擅长的事情,并使用 Groovy 让您的生活更轻松。

Probably the easiest approach is to use wsimport on the WSDL files to generate the client-side stubs. Then you can call methods in the stubs from Groovy just as you would have called them from Java.

For example, consider the WSDL file for Microsoft's TerraServer, located at http://terraservice.net/TerraService.asmx?wsdl . Then you run something like

wsimport -d src -keep http://terraservice.net/TerraService.asmx?WSDL

which puts all the compiled stubs in the src directory. Then you can write Groovy code like

import com.terraserver_usa.terraserver.*;

TerraServiceSoap sei = new TerraService().getTerraServiceSoap()
Place home = new Place(city:'Boston',state:'MA',country:'US')
def pt = sei.convertPlaceToLonLatPt(home)
println "$pt.lat, $pt.lon"
assert Math.abs(pt.lat - 42.360000) < 0.001
assert Math.abs(pt.lon - -71.05000) < 0.001

If you want to access a lot of web services, generate the stubs for all of them. Or you can use dynamic proxies instead.

The bottom line, though, is to let Java do what it already does well, and use Groovy where it makes your life easier.

感情废物 2024-07-28 08:45:31

您应该能够使用 XFireCXF 插件。 对于自动脚手架,请修改脚手架模板中的 Controller.groovy 模板,以便它自动生成您需要的方法。

You should be able to use XFire or CXF Plugins. For automatic scaffolding, modify your Controller.groovy template in scaffolding templates so it auto-generates methods you need.

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