java调用wadl,在Java中创建WADL和WSDL?

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

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?

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.

解决方案

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.

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.

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!

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.

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.

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 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).

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").

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值