问题描述
给出一个 application.wadl
文件,如何从wadl文件生成客户端应用程序(Spring或任何)和域对象?
Given an application.wadl
file, how do I generate Client app (Spring or any) and domain objects from a wadl file?
我尝试过:
wadl2java https://genologics.com/files/permanent/API/2.5/application.wadl
WADLToJava Error: java.lang.IllegalStateException: Single WADL resources element is expected
推荐答案
这是我通过查看源代码得到的发现:
This is my findings by reviewing the source-code:
作为,wadltojava试图获取
As SourceGenerator.java, wadltojava is trying to get the "resources" element from the "application" element and expects it to be one only.
private void generateResourceClasses(Application app, GrammarInfo gInfo,
Set<String> typeClassNames, File src) {
Element appElement = app.getAppElement();
List<Element> resourcesEls = getWadlElements(appElement, "resources");
if (resourcesEls.size() != 1) {
throw new IllegalStateException("Single WADL resources element is expected");
}
List<Element> resourceEls = getWadlElements(resourcesEls.get(0), "resource");
if (resourceEls.size() == 0) {
throw new IllegalStateException("WADL has no resource elements");
}
........
}
我检查了您提供的WADL,似乎只有一个资源元素。
I checked the WADL you provided and seems like there is only one "resources" element.
进一步检查 getWadlElements()
方法正在使用 getWadlNamespace()
:
On checking further in getWadlElements()
method is using getWadlNamespace()
:
private List<Element> getWadlElements(Element parent, String name) {
List<Element> elements = parent != null
? DOMUtils.getChildrenWithName(parent, getWadlNamespace(), name)
: CastUtils.cast(Collections.emptyList(), Element.class);
if (!"resource".equals(name)) {
for (int i = 0; i < elements.size(); i++) {
Element el = elements.get(i);
Element realEl = getWadlElement(el);
if (el != realEl) {
elements.set(i, realEl);
}
}
}
return elements;
}
在是
public static final String WADL_NS = "http://wadl.dev.java.net/2009/02";
但是在您的WADL中,命名空间似乎如下所示,可能会引起问题。
But in your WADL the namespace seems to be different as below, and may be causing issue.
<wadl:application xmlns:wadl="http://research.sun.com/wadl/2006/10" xmlns:xs="http://www.w3.org/2001/XMLSchema">
似乎您正在使用CXF,根据我的理解,我建议您使用相同的
It seems that you are using CXF so as per my understanding, I would suggest you to use the same framework which is used to generate the WADL.
更新:
或者,将WADL和XSD放在本地,然后在WADL中手动将名称空间修改为最新的一个,然后再试一次。
Update:Or, have the WADL and XSD's on your local and modify the namespace manually in WADL to the latest one and try again.
这篇关于如何从wadl为RESTful服务创建客户端应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!