0

我正在研究基于 SOAP 的 Web 服务。我需要测试一个场景,如果由于任何网络问题或登录问题而发生 Web 服务连接错误。

apache cxf 的问题在于无论 web 服务抛出什么异常

 "java.lang.UnsupportedOperationException: This class does not support SAAJ 1.1".

错误响应代码返回 500,但堆栈跟踪显示“UnsupportedOperationException”。我可以捕获异常并打印堆栈跟踪,但我需要知道它是连接错误还是其他一些不同的错误。错误日志如下

    ID: 12117
Response-Code: 500
Encoding: UTF-8
Content-Type: application/soap+xml; charset=utf-8
Headers: {connection=[close], Content-Length=[6380], content-type=[application/soap+xml; charset=utf-8], Date=[Fri, 27 Feb 2015 16:43:47 GMT], Server=[Microsoft-HTTPAPI/2.0]}
Payload: <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault</a:Action><a:RelatesTo>urn:uuid:9f063eed-af54-4074-86cf-35f360a6e4d0</a:RelatesTo></s:Header><s:Body><s:Fault><s:Code><s:Value>s:Receiver</s:Value><s:Subcode><s:Value xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</s:Value></s:Subcode></s:Code><s:Reason><s:Text xml:lang="en-US">A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - The wait operation timed out.)</s:Text></s:Reason><s:Detail><ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><HelpLink i:nil="true"/><InnerException><HelpLink i:nil="true"/><InnerException i:nil="true"/><Message>The wait operation timed out</Message><StackTrace i:nil="true"/><Type>System.ComponentModel.Win32Exception</Type></InnerException><Message>A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - The wait operation timed out.)</Message><StackTrace>   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)&#xD;
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)&#xD;
   at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover)&#xD;
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)&#xD;
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)&#xD;
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)&#xD;
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData)&#xD;
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)&#xD;
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)&#xD;
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)&#xD;
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)&#xD;
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal&amp; connection)&#xD;
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal&amp; connection)&#xD;
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal&amp; connection)&#xD;
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)&#xD;
   at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)&#xD;
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)&#xD;
   at System.Data.SqlClient.SqlConnection.Open()&#xD;
   at BB.Core.Libraries.Data.DataContext.Connect(IsolationLevel isolationLevel, Boolean useTransaction)&#xD;
   at BB.EBT.Libraries.Services.UniversalInterface2012.GetMissingData(String&amp; houseHoldId, Decimal&amp; cardNumber)&#xD;
   at BB.EBT.Libraries.Services.UniversalInterface2012.AddUpdateBenefits(String ActionCode, String CardNumber, String WICMISAccountID, String ReasonCode, List`1 MonthlyFoodBenefits, MessageHeader MessageHeader)&#xD;
   at SyncInvokeAddUpdateBenefits(Object , Object[] , Object[] )&#xD;
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp; outputs)&#xD;
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace><Type>System.Data.SqlClient.SqlException</Type></ExceptionDetail></s:Detail></s:Fault></s:Body></s:Envelope>
--------------------------------------]
java.lang.UnsupportedOperationException: This class does not support SAAJ 1.1
    at weblogic.webservice.core.soap.SOAPElementImpl.getNamespaceURI(SOAPElementImpl.java:496)
    at org.apache.cxf.jaxws.JaxWsClientProxy.createSoapFault(JaxWsClientProxy.java:208)
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:154)
    at $Proxy97.addUpdateBenefits(Unknown Source)
    at gov.mass.eos.web.service.wiccardclient.EWICCardServiceClient.addUpdateBenefits(EWICCardServiceClient.java:168)
    at gov.mass.eos.web.service.wiccardclient.EWICCardServiceClient.addBenefits(EWICCardServiceClient.java:132)
    at gov.mass.eos.web.controllers.ce.benefits.EBenefitPreparationUtils.processBenefitsIssue(EBenefitPreparationUtils.java:108)
    at gov.mass.eos.web.controllers.ce.benefits.EIssueController.issueBenefits(EIssueController.java:501)
    at sun.reflect.GeneratedMethodAccessor184377.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:138)
    at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:62)
    at javax.faces.component.UICommand.broadcast(UICommand.java:106)
    at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:110)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:184)
    at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:271)
    at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:102)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:109)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
    at com.sun.identity.agents.filter.AmAgentBaseFilter.allowRequestToContinue(AmAgentBaseFilter.java:87)
    at com.sun.identity.agents.filter.AmAgentBaseFilter.doFilter(AmAgentBaseFilter.java:43)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
    at gov.mass.eos.web.servlet.filter.Log4jFilter.doFilter(Log4jFilter.java:138)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3242)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2010)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1916)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1366)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
[27 Feb 2015 11:43:46,700] [ERROR] [EosRTException] [This class does not support SAAJ 1.1]
gov.mass.eos.common.exception.EosRTException.

有人可以指导我或帮助我如何在 try catch 块中捕获此特定连接错误或错误 500。

4

2 回答 2

1

SAAJ API 符合简单对象访问协议 (SOAP) 1.1 和 1.2 规范以及 SOAP with Attachments 规范。在您的情况下,xcf 不支持您正在使用的 SOAP 版本。

于 2015-03-12T20:14:35.043 回答
1

这个响应有点晚了,但它在 weblogic 11g 中对我有用,而无需更改服务器的配置(https://blogs.oracle.com/sravansarraju/entry/weblogic_saaj_version_problem_javalangunsupportedoperationexception_this_class_does_not_support_saaj)。

只需在创建 SOAPMessage 时添加 SOAPConstants.SOAP_1_2_PROTOCOL

SOAPMessage sm = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
于 2016-10-18T17:26:40.150 回答