2

我有一个调用网络服务的客户端。部分调用的方法可能需要很长时间才能在服务器上完成(甚至长达 1 小时)。我希望客户端等待那个时间的响应,从而保持连接活跃!

我尝试在客户端中设置以下属性,但没有成功:

((BindingProvider)port).getRequestContext().put("com.sun.xml.internal.ws.request.timeout", 0); //0 for disabling any timeouts

一段时间后我仍然收到超时异常。必须设置哪个属性以防止出现以下错误?

org.apache.cxf.interceptor.Fault: Transaction was rolled back, presumably because setRollbackOnly was called during a synchronization while invoking public abstract boolean my.method
    at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:166)
    at org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.createFault(AbstractJAXWSMethodInvoker.java:213)
    at org.apache.openejb.server.cxf.ejb.EjbMethodInvoker.preEjbInvoke(EjbMethodInvoker.java:146)
    at org.apache.openejb.server.cxf.ejb.EjbMethodInvoker.invoke(EjbMethodInvoker.java:72)
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:75)
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:107)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:211)
    at org.apache.openejb.server.cxf.CxfWsContainer.onMessage(CxfWsContainer.java:73)
    at org.apache.openejb.server.webservices.WsServlet.service(WsServlet.java:98)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.openejb.core.transaction.TransactionRolledbackException: Transaction was rolled back, presumably because setRollbackOnly was called during a synchronization
    at org.apache.openejb.core.transaction.JtaTransactionPolicy.completeTransaction(JtaTransactionPolicy.java:335)
    at org.apache.openejb.core.transaction.TxRequired.commit(TxRequired.java:75)
    at org.apache.openejb.core.transaction.EjbTransactionUtil.afterInvoke(EjbTransactionUtil.java:73)
    at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:258)
    at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:190)
    at org.apache.openejb.server.cxf.ejb.EjbMethodInvoker.preEjbInvoke(EjbMethodInvoker.java:119)
    ... 30 more
Caused by: javax.transaction.RollbackException: Unable to commit: transaction marked for rollback
    at org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:272)
    at org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:252)
    at org.apache.openejb.core.transaction.JtaTransactionPolicy.completeTransaction(JtaTransactionPolicy.java:328)
    ... 35 more
Caused by: java.lang.Exception: Transaction has timed out
    at org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:266)
    ... 37 more
4

1 回答 1

12

您确定这是客户端超时吗?您是否正确配置了服务器事务超时?

对于客户端超时,您需要在 cxf 配置中:

<http-conf:conduit name="*.http-conduit">
    <http-conf:client ConnectionTimeout="your connection timeout" ReceiveTimeout="your receive timeout"/>
</http-conf:conduit>

超时以毫秒为单位。

在 Java 代码中,您需要获取 HTTPConduit,然后设置 HTTPClientPolicy:

http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html

  import org.apache.cxf.endpoint.Client;
  import org.apache.cxf.frontend.ClientProxy;
  import org.apache.cxf.transport.http.HTTPConduit;
  import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
  ...

  URL wsdl = getClass().getResource("wsdl/greeting.wsdl");
  SOAPService service = new SOAPService(wsdl, serviceName);
  Greeter greeter = service.getPort(portName, Greeter.class);

  // Okay, are you sick of configuration files ?
  // This will show you how to configure the http conduit dynamically
  Client client = ClientProxy.getClient(greeter);
  HTTPConduit http = (HTTPConduit) client.getConduit();

  HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();

  httpClientPolicy.setConnectionTimeout(your connection timeout); 
  httpClientPolicy.setAllowChunking(false);
  httpClientPolicy.setReceiveTimeout(your receive timeout);

  http.setClient(httpClientPolicy);

  ...
  greeter.sayHi("Hello");

更新

为了java.lang.ClassCastException确保它com.sun.xml.ws.client.sei.SEIStub不在类路径中或确保 cxf jar 在类路径中 Sun 的 jaxws RI jar 之前。例如,尝试从类路径中删除 jaxws-rt*.jar。

于 2012-10-16T09:33:54.760 回答