mardi 9 janvier 2018

Use CXF JAXRSServerFactoryBean to return simple text for tests of communication failures

I'm working on a codebase that attempts to make a REST call to a remote service, which returns JSON. The call works fine when it gets normal JSON back. In some cases, like when the network blows up, it gets back HTML, which tries to report various network problems.

Our error handling code in the client needs to deal properly with this situation, which is defined as simply obtaining the HTML string and logging it.

I find it's a little hard to write an automated test for this.

In our client code, we use ClientBuilder.newBuilder()... , then call "build()", which returns the Client, and then we call "client.target(url)" and then move forward with getting the response. We have an exception handler that will attempt to read the raw text.

In a test for this kind of thing, I'm used to using the CXF JAXRSServerFactoryBean class to run a server. I know how to connect the client to the server, but I'm not sure what to configure in the server to allow me to return arbitrary text, instead of a "resource class".

It's also possible that using JAXRSServerFactoryBean is overkill for this, as it just needs to return plain text.

What are my options here?

Aucun commentaire:

Enregistrer un commentaire