简体   繁体   中英

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 . I've recently been given a RESTful end point which uses XML as the payload type. So far as I can see there is no WADL\\ Swagger YML file I can access to get a definition of the service.

All I know so far is:
1. The endpoint
2. It operates behind HTTP basic auth
3. It accepts a 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
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)

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

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?

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?

We eventually went for using the Feign which is a Java to HTTP client binder. It's Netflix OSS but seems to be an older library (osslifecycle=archived).

Wrapping the HTTP service was extremely easy as it only has one URI which we POST an XML payload to. 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. Feign has a concept of encoders and decoders which you can use to write your own mappers or use a provided mapper (JAXBEncoder\\ JAXBDecoder).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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