简体   繁体   English

如何从现有的基于XML的RESTful服务创建Java Jersey客户端

[英]How do I create a Java Jersey client from an existing XML based RESTful service

I'm used to integrating with SOAP Webservices where the wsdl is accessible and can be used to generate a java client using wsimport . 我习惯于与SOAP Webservices集成,其中wsdl是可访问的,并且可以用于使用wsimport生成java客户端。 I've recently been given a RESTful end point which uses XML as the payload type. 我最近获得了一个RESTful端点,它使用XML作为有效负载类型。 So far as I can see there is no WADL\\ Swagger YML file I can access to get a definition of the service. 到目前为止,我看到没有WADL \\ Swagger YML文件,我可以访问以获取服务的定义。

All I know so far is: 到目前为止我所知道的是:
1. The endpoint 1.端点
2. It operates behind HTTP basic auth 2.它在HTTP基本身份验证之后运行
3. It accepts a POST 3.它接受一个POST
4. The 3 test XML payloads I have all seem to "work" returning an XML response relating to what I am trying to do 4.我所有的三个测试XML有效负载似乎都“工作”,返回与我想要做的事情相关的XML响应
5. The URI does not change depending on the the action I am perform, the service reacts differently based on varying XML input (the request contains a payload-id attribute which seems to indicate the type of operation being performed) 5.根据我执行的操作,URI不会改变,服务会根据不同的XML输入做出不同的反应(请求包含一个payload-id属性,它似乎表示正在执行的操作类型)

From the above the service doesn't seem very "REST-like" it could just be a process listening on port for a specific request and doing crude string manipulations to parse values and then use string concatenations to crudely build a response. 从上面看,服务看起来并不像“类似REST”,它可能只是一个进程侦听特定请求的端口并执行原始字符串操作来解析值,然后使用字符串连接来粗略地构建响应。 I get that for the most part REST is just that at a low level but I am hoping to somehow manage the apparent crudeness of the service a bit better. 我得到的大部分REST只是在较低的水平,但我希望以某种方式管理服务的明显粗糙度更好。

How I can generate a "clean" Java client for this service (something akin to what can be done with wsimport) given that I have the XML sample requests for the 3 different operations that appear to be exposed? 我如何为这项服务生成一个“干净的”Java客户端(类似于wsimport可以做什么),因为我有3个不同操作的XML样本请求似乎是暴露的?

For the above I was thinking that I'd somehow need to create the WADL\\ Swagger YML myself, or perhaps there is a tool which could use the requests I have to build these definitions dynamically? 对于上面我觉得我自己需要创建WADL \\ Swagger YML ,或者有一个工具可以使用我有动态构建这些定义的请求?

We eventually went for using the Feign which is a Java to HTTP client binder. 我们最终使用了Feign ,这是一个Java到HTTP客户端绑定器。 It's Netflix OSS but seems to be an older library (osslifecycle=archived). 它是Netflix OSS,但似乎是一个较旧的库(osslifecycle = archived)。

Wrapping the HTTP service was extremely easy as it only has one URI which we POST an XML payload to. 包装HTTP服务非常简单,因为它只有一个URI,我们将XML有效负载发送到。 We received XSD's from the service owner which we have converted into JAXB object which are then marshaled and un-marshaled within the Feign call. 我们从服务所有者处收到XSD,我们已将其转换为JAXB对象,然后在Feign调用中进行封送和取消封送。 Feign has a concept of encoders and decoders which you can use to write your own mappers or use a provided mapper (JAXBEncoder\\ JAXBDecoder). Feign有编码器和解码器的概念,您可以使用它来编写自己的映射器或使用提供的映射器(JAXBEncoder \\ JAXBDecoder)。

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

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