简体   繁体   English

如何从WSDL动态自动生成Java Bean?

[英]How to dynamically autogenerate Java Beans from WSDL?

I would like to develop an application to test Web Services, which will automatically generate a JSF form using parameters from the provided WSDL. 我想开发一个测试Web服务的应用程序,它将使用提供的WSDL中的参数自动生成JSF表单。

The WSDL URL is provided by user and I don't know the names of operations before parsing it. WSDL URL由用户提供,在解析之前我不知道操作的名称。 I would like the app to go through the parsed operations and its parameters, and autogenerate the appropriate Java Beans, which I will use to generate a JSF form. 我希望应用程序完成解析后的操作及其参数,并自动生成相应的Java Bean,我将使用它来生成JSF表单。

I have tested CXF and JAX-WS, but I think they need to know the operation names before generating Java beans. 我测试了CXF和JAX-WS,但我认为他们需要在生成Java bean之前知道操作名称。 How to transparently generate Java Beans for any WSDL? 如何透明地为任何WSDL生成Java Bean? Manually running wsdl2java is not a solution. 手动运行wsdl2java不是解决方案。

CXF does have a "DynamicClient" (see: http://cxf.apache.org/javadoc/latest-2.6.x/org/apache/cxf/jaxws/endpoint/dynamic/JaxWsDynamicClientFactory.html ) that can be used for this. CXF确实有一个“DynamicClient”(参见: http//cxf.apache.org/javadoc/latest-2.6.x/org/apache/cxf/jaxws/endpoint/dynamic/JaxWsDynamicClientFactory.html )可用于此。 It parses the wsdl, generated JAXB objects and compiles them, and returns a client that can be used to get the operations and types and such associated with them. 它解析wsdl,生成JAXB对象并对其进行编译,并返回一个客户端,该客户端可用于获取操作和类型以及与之关联的类型。

If you are using Maven (and you should be) you can use the CXF codegen plugin to generate classes from the WSDL. 如果您正在使用Maven(并且您应该使用),则可以使用CXF codegen插件从WSDL生成类。 There's an example on my blog; 我的博客上有一个例子;

http://qwerky-qwerky.blogspot.co.uk/2011/12/programming-without-programming-1.html http://qwerky-qwerky.blogspot.co.uk/2011/12/programming-without-programming-1.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM