CXF JAX-RS proxy server does not support cookies

I use CXF to generate client code for the JAX-RS REST service. This REST service, unfortunately, uses cookies to authenticate each request and maintain a different session state. Access to user account information includes two requests: one to enter the system and one to receive account information. Session cookies received in the first request must be sent with the second request.

Here is my code.

// Login (POST /sessions)
Response response = proxy.login(userCredentials);
assertEquals(200, response.getStatus());

// Get user account info (GET /user)
response = proxy.getUser();
User user = response.readEntity(User.class);

The second request does not authenticate because it does not include the necessary session cookies that were returned by the previous login procedure.

I believe that there is a way to configure WebClient to support cookies through requests. I searched high and low, but I cannot figure out how to do this. I hope someone can point me to an example. Thanks in advance!

+5
source share
1 answer

I finally found a solution. I had to do the following before using a proxy.

WebClient.getConfig(proxy).getRequestContext().put(
        org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
+7
source

All Articles