You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法修改遗留代码时,命令行运行Apache CXF客户端如何配置超时属性

Solution for CXF Client Timeout Without Modifying Legacy Code

Great question—let's tackle this timeout issue you're facing with your legacy Apache CXF client on RedHat 8.3. Since you can't modify the generated client code or your web app source, we can leverage Apache CXF system properties to adjust timeouts directly via the Java command line. These properties work globally for CXF clients, so they'll apply to your generated code without any code changes.

1. Use CXF System Properties for Timeouts

Apache CXF supports setting connection and receive timeouts via JVM system properties. These work across both older (like 2.1.2) and newer (3.2.7) CXF versions, which is perfect for your setup.

Add these -D parameters to your Java command:

  • -Dorg.apache.cxf.transport.http.connection.timeout=60000: Sets the TCP connection timeout (in milliseconds; 60000 = 60 seconds)
  • -Dorg.apache.cxf.transport.http.receive.timeout=60000: Sets the response read timeout (how long to wait for the server to send data after connection is established)

Your modified Java command will look like this:

java -Dorg.apache.cxf.transport.http.connection.timeout=60000 -Dorg.apache.cxf.transport.http.receive.timeout=60000 -cp "/data/myapp/tomcat-9.0.54/webapps/myapp/WEB-INF/lib/gen-cxf-services-1.2.3.jar:/data/myapp/tomcat-9.0.54/webapps/myapp/WEB-INF/lib/*" com.company.services.XyzServiceHelperInterface_XyzServiceHelperPort_Client "http://xyz.services.company.com/XyzService?wsdl"

Fallback: Older CXF Property Names

If the above properties don't work (unlikely, but possible for very old generated clients), try the legacy property names:

java -Dhttp.connection.timeout=60000 -Dhttp.receive.timeout=60000 -cp "/data/myapp/tomcat-9.0.54/webapps/myapp/WEB-INF/lib/gen-cxf-services-1.2.3.jar:/data/myapp/tomcat-9.0.54/webapps/myapp/WEB-INF/lib/*" com.company.services.XyzServiceHelperInterface_XyzServiceHelperPort_Client "http://xyz.services.company.com/XyzService?wsdl"

2. Enable CXF Logging for Troubleshooting

To debug why the timeout is happening (e.g., is the request even reaching the server? Is the server slow to respond?), enable CXF's built-in logging with another system property:

java -Dorg.apache.cxf.logging.enabled=true -Dorg.apache.cxf.transport.http.connection.timeout=60000 -Dorg.apache.cxf.transport.http.receive.timeout=60000 -cp "/data/myapp/tomcat-9.0.54/webapps/myapp/WEB-INF/lib/gen-cxf-services-1.2.3.jar:/data/myapp/tomcat-9.0.54/webapps/myapp/WEB-INF/lib/*" com.company.services.XyzServiceHelperInterface_XyzServiceHelperPort_Client "http://xyz.services.company.com/XyzService?wsdl"

This will print SOAP request/response details to the console, helping you confirm if the issue is network-related or server-side.

3. Quick Network Check

Even though curl works, Java sometimes uses different network configurations (e.g., proxy settings). If timeouts persist, verify if your server requires a proxy by adding these properties if needed:

-Dhttp.proxyHost=your-proxy-host -Dhttp.proxyPort=your-proxy-port

Why This Works

The generated CXF client code uses CXF's underlying HTTP transport layer, which automatically picks up these system properties at runtime. Since you're running against CXF 3.2.7, these global configurations will override the default 30-second timeout without touching your legacy JAR or web app code.

内容的提问来源于stack exchange,提问作者maxxyme

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.01 03:18:13