I'm writing integration tests for a Mule ESB application which connects to an external API via HTTPS. I'd like to mock the external API and run an end-to-end integration test during the Maven build. My question is about setting up an embedded HTTPS server. I've tried to use Jersey, but it only provides HTTP. I was looking at this example
https://github.com/jersey/jersey/tree/master/examples/https-clientserver-grizzly
and I was wondering if there is still some manual step involved, or if it works automatically setting everything up every time the build is kicked off.
Any suggestions or ideas?
Edit. My final goal is to deploy a JAX-RS service in an embedded server which is accessible via HTTPS. And that needs no client-side keys/certificate configuration.
Edit 2. Now my problem concerns certificates. The point of integration tests is to mock external components and verify that my application works. Now, if I set up an embedded HTTPS server and use a cmd-line built certificate, I need to add SSL configuration in the client (as @Ryan Hoegg pointed out). This is not what I would ideally want: Is there a solution to get it working without having to modify my client application code? This should be a general Java question that goes beyond Mule.
I use confluex-mock-http for this. Under the hood it uses Jetty, but it does all the configuration for you. Creating the MockHttpsServer immediately starts the HTTPS server:
You can set up your Mule application to trust the certificate used by the mock server. A JKS formatted truststore is available on the classpath, and you can provide it to your HTTPS connector like so:
I think some older versions of mule have trouble with this approach, because I needed to use the workaround here.
EDIT: You can include this configuration for the HTTPS Connector only when tests are running by using a Spring profile:
One way to make sure the profile is indeed active when the tests run is to simply set it in a @BeforeClass method: