Apache CXF Simple Frontend: Connection Issue with 'Already connected' Error

I’m new to Apache CXF and I’m trying to set up a connection using the Simple Frontend. I’ve configured both the server and client sides, but I’m running into a strange error when calling service methods.

Here’s what I’ve done:

  1. Set up a server configuration with a Spring/JPA service bean
  2. Created a client configuration to connect to the service
  3. Injected the generated service into my web app (using Wicket)

When I try to call any service method, I get an IllegalStateException saying ‘Already connected’. This happens on the first service call, right after the WSDL is fetched.

I’ve looked online for similar issues but haven’t found anything that matches my problem. I’m using the Simple Frontend because I don’t want to annotate my service with JAX-WS.

Has anyone run into this before or know what might be causing it? I’m really stuck and could use some help figuring this out.

Here’s a simplified version of the error I’m seeing:

java.lang.IllegalStateException: Already connected
    at java.net.HttpURLConnection.setFixedLengthStreamingMode(HttpURLConnection.java:103)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.thresholdNotReached(HTTPConduit.java:1889)
    at org.apache.cxf.io.AbstractThresholdOutputStream.close(AbstractThresholdOutputStream.java:99)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1980)

Any ideas on how to fix this? Thanks!

This ‘Already connected’ error often stems from mishandling of connection states in CXF. One potential solution is to ensure you’re properly closing connections after each service call. Consider implementing a custom ClientLifeCycleManager to manage connection lifecycles more effectively. Additionally, check your client configuration for any settings that might be causing premature connection attempts. If you’re using Spring, review your bean configurations to ensure they’re not inadvertently creating multiple client instances. Lastly, enable CXF logging at the DEBUG level to get more insight into the connection process and pinpoint where exactly the error is occurring.

yo, i had a similar issue. try disabling connection keepalive in ur client config. it fixed it for me. also, check if ur using any proxy settings that might interfere. sometimes those can mess with connections. good luck!

hey, have you looked into whether connection pooling might be causing this? it might be a bug in the version of cxf ur usin. have u tried updating? sometimes these issues vanish after a version bump. what do u think might be affecting the connection state?