在Java中创建WADL和WSDL? [英] Creating a WADL and WSDL in Java?

查看:210
本文介绍了在Java中创建WADL和WSDL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作是用Java创建WADL和WSDL.不过我有几个问题.

I have been tasked at work to create a WADL and a WSDL in Java. I have a few questions though.

首先,WSDL是一个XML文档,描述了客户端如何从SOAP系统请求信息. WADL是一个XML文档,描述了客户端如何从REST系统请求信息.两者都是正确的吗?

First a WSDL is an XML document that describes how a client requests information from a SOAP system. A WADL is an XML document that describes how a client request info from a REST system. Are both of those correct?

如果是的话,他们究竟会怎么做?我了解SOAP和REST如何与HTTP正常工作,但是我难以理解WADL和WSDL的确切含义,它们的作用以及如何创建一个. Java.

If so what exactly do they do? I understand how SOAP and REST work normally with HTTP, but I'm having trouble wrapping my head around what exactly is the point of a WADL and a WSDL , what they are for, and how I should go about creating one in java.

推荐答案

当代码中有一个方法需要调用时,如何调用它?您看一下方法签名和javadoc.您会看到参数名称是什么,它们的含义,它们具有什么类型,javadoc会告诉您这些值是否存在某些限制,如果您不遵守这些规定会得到什么异常等等.

When you have a method in your code and you need to call it, how do you call it? You look at the method signature and the javadoc. You see what the parameter names are, what they mean, what type they have, the javadoc tells you if there are some restrictions on the values, what exception you get if you don't respect that, etc.

现在考虑使用Web服务.让我们首先从 SOAP 开始.它的操作通过网络公开.你怎么称呼这只野兽?您所看到的只是一个端点,您必须在该端点上发送格式正确的SOAP有效负载.这能告诉您操作名称吗?参数名称和类型?您的价值观受到限制吗?不!它绝对不会告诉您任何事情.您需要一种方法来告诉客户如何调用此服务.

Now consider a web service. Let's start with SOAP first. It's operations exposed over the network. How do you call this beast? All you can look at is an endpoint where you must send a properly formatted SOAP payload. Does that tell you the operation names? The parameter names and types? Restrictions on your values? No! It tells you absolutely nothing. You need a way to tell clients how to call this service.

您可以拥有文档,就像javadoc一样.您可以使用它来学习如何拨打电话.但这将是XML.您使用XML还是Java编程?您可以使用Java进行编程,但是需要将对象编组为XML,然后将来自XML的响应编组为Java对象.而且,您必须编写执行此操作的所有代码.如果您误解了文档,则可能会出错,并且第一次无法使用.您将不得不再次阅读文档,调整XML,调试,重试,重复直到工作,等等.这无济于事!

You can have documentation, just like the javadoc. You use that to learn how to make the call. But this will be XML. Do you program in XML or in Java? You program in Java but you need to marshall your objects to XML and then unmarshall the response from XML back to Java objects. And you have to write all the code that does that. If you misunderstand the documentation you will build something wrong and it won't work the first time. You will have to read the documentation again, tweak your XMLs, debug it, try again, repeat until working, etc. This is unproductive!

如果您拥有一个为您生成代码的工具,那么您将精力集中在需要完成的实际业务上,而不是浪费XML的时间,那不是很好吗?输入WSDL.

Wouldn't it be nice if you could have a tool to generate the code for you so you concentrate on the actual business that needs to be accomplished instead of wasting time with XML? Enter WSDL.

WSDL 是描述SOAP Web服务的一种方式.它是签名,参数名称和类型,限制和文档,全部合而为一.对此有用的是,您可以将其提供给工具,并让该工具从中生成代码,以为您处理XML编组/解组代码,并向Java代码公开方法和对象.

A WSDL is a way to describe the SOAP web service. It's the signature, parameter names and types, restrictions and documentation, all in one. What's useful about it is that you can feed it to a tool and have the tool generate code from it that handles the XML marshalling/unmarshalling for you and exposes methods and object to your Java code instead.

现在 REST 是另一种野兽.要调用RESTful Web服务,您需要说它的语言",没有要遵循的协议".客户需要了解 MIME类型才能使用该服务.这主要是您必须阅读和理解,然后构建代码的文档.由于这也是大多数样板代码,因此使用SOAP WSDL提供的功能的人们决定为REST创建类似的东西.这就是WADL.

Now REST is a different beast. To call a RESTful web service you need to "speak it's language", there isn't "a protocol" to follow. Clients need to understand MIME types in order to use the service. This is mostly documentation that you have to read and understand and then build the code. Because this too is mostly boilerplate code, people used with the features provided by SOAP WSDLs decided to create something similar for REST. This is the WADL.

WADL 对于REST具有相同的目的,就像WSDL对SOAP一样(请注意,尽管REST不仅是处理SOAP的不同方法,所以当您尝试对REST执行相同的操作时,您使用SOAP所做的事情,您只需减少RESTful Web服务-是由超媒体驱动的-WebAPI).

WADL serves the same purpose for REST, as WSDL does for SOAP (note though that REST is more than a different way to do SOAP so when you try do do the same thing with REST, that you did with SOAP, you just reduce a RESTful web service - which is hypermedia driven - to a WebAPI).

关于创建WSDL和WADL的方式,如果您有知识,则可以手工完成(这称为" JAX-RS JAX-WS 框架,首先为您编写服务并拥有框架会自动为您生成WSDL(称为" contract-last ).

As for the way to create WSDLs and WADLs, you can do it by hand if you have the knowledge (that's called "contract-first") or you could use JAX-RS and JAX-WS frameworks, write you services first and have the frameworks generate the WSDL automatically for you (this is called "contract-last").

这篇关于在Java中创建WADL和WSDL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆