开发者社区> 问答> 正文

webservice 客户端发送报文报错An error was discove?报错

在实习公司对接第三方公司软件用到webservice完全零基础,遇到个报错不知如何处理求帮助

报错信息

 AxisFault
 faultCode: {http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}InvalidSecurity
 faultSubcode: 
 faultString: An error was discovered processing the <wsse:Security> header
 faultActor: 
 faultNode: 
 faultDetail: 
        {http://xml.apache.org/axis/}stackTrace:An error was discovered processing the <wsse:Security> header
        at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
        at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
        at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
        at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
        at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
        at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
        at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
        at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
        at org.apache.axis.client.Call.invoke(Call.java:2767)
        at org.apache.axis.client.Call.invoke(Call.java:2443)
        at org.apache.axis.client.Call.invoke(Call.java:2366)
        at org.apache.axis.client.Call.invoke(Call.java:1812)
        at com.landray.kmss.sys.notify.webservice.spring.SysNotifyMainWebServiceImpServiceSoapBindingStub.addSysNotifyMain(SysNotifyMainWebServiceImpServiceSoapBindingStub.java:402)
        at com.landray.kmss.sys.notify.webservice.ISysNotifyMainWebServiceProxy.addSysNotifyMain(ISysNotifyMainWebServiceProxy.java:50)
        at xmodule.msgService.MsgHttpApi.testMsgService(MsgHttpApi.java:61)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at xserver.service.http.protocol.JsonProtocol.invoke(JsonProtocol.java:126)
        at xmodule.auth.AuthedJsonProtocol.process(AuthedJsonProtocol.java:74)
        at xserver.service.http.ApiGateway._service(ApiGateway.java:157)
        at xserver.service.http.ApiGateway.service(ApiGateway.java:131)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:769)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:226)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
        at org.eclipse.jetty.server.Server.handle(Server.java:483)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:290)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248)
        at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:606)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:535)
        at java.lang.Thread.run(Thread.java:745)


        {http://xml.apache.org/axis/}hostname:localhost.localdomain


An error was discovered processing the <wsse:Security> header
        at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
        at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
        at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
        at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
        at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
        at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
        at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
        at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
        at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
        at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
        at org.apache.axis.client.Call.invoke(Call.java:2767)
        at org.apache.axis.client.Call.invoke(Call.java:2443)
        at org.apache.axis.client.Call.invoke(Call.java:2366)
        at org.apache.axis.client.Call.invoke(Call.java:1812)
        at com.landray.kmss.sys.notify.webservice.spring.SysNotifyMainWebServiceImpServiceSoapBindingStub.addSysNotifyMain(SysNotifyMainWebServiceImpServiceSoapBindingStub.java:402)
        at com.landray.kmss.sys.notify.webservice.ISysNotifyMainWebServiceProxy.addSysNotifyMain(ISysNotifyMainWebServiceProxy.java:50)
        at xmodule.msgService.MsgHttpApi.testMsgService(MsgHttpApi.java:61)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at xserver.service.http.protocol.JsonProtocol.invoke(JsonProtocol.java:126)
        at xmodule.auth.AuthedJsonProtocol.process(AuthedJsonProtocol.java:74)
        at xserver.service.http.ApiGateway._service(ApiGateway.java:157)
        at xserver.service.http.ApiGateway.service(ApiGateway.java:131)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:769)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:226)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
        at org.eclipse.jetty.server.Server.handle(Server.java:483)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:290)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248)
        at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:606)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:535)
        at java.lang.Thread.run(Thread.java:745)

我的代码

     SysNotifyMainWebServiceImpServiceLocator serviceLocator = new 
    SysNotifyMainWebServiceImpServiceLocator();
    serviceLocator.setSysNotifyMainWebServiceImpPortEndpointAddress(endpoint);
    SysNotifyMainWebServiceImpServiceSoapBindingStub stub = 
    (SysNotifyMainWebServiceImpServiceSoapBindingStub) serviceLocator.getSysNotifyMainWebServiceImpPort();
   
    // 构造soap头信息
    String WSSE_PREFIX = "wsse";  
        String WSSE_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
        try{


        SOAPFactory sf = SOAPFactory.newInstance();
        SOAPElement ehl = sf.createElement("Header", "soap", "http://schemas.xmlsoap.org/soap/envelope/");
        SOAPElement wsSecHeaderElm = sf.createElement("Security", WSSE_PREFIX, WSSE_NS);
wsSecHeaderElm.setAttribute("soap:mustUnderstand", "1");

        QName qname = wsSecHeaderElm.createQName("wsu", "xmlns");
        wsSecHeaderElm.addAttribute(qname, "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");

        SOAPElement userNameTokenElm = sf.createElement("UsernameToken", WSSE_PREFIX, WSSE_NS);
        userNameTokenElm.setAttribute("wsu:Id", "UsernameToken-1");
    
        SOAPElement userNameElm = sf.createElement("Username", WSSE_PREFIX, WSSE_NS);
        SOAPElement passwdElm = sf.createElement("Password", WSSE_PREFIX, WSSE_NS);
        passwdElm.setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");  
            
      userNameElm.addTextNode(name);  
      passwdElm.addTextNode(password); 
      
      userNameTokenElm.addChildElement(userNameElm);
      userNameTokenElm.addChildElement(passwdElm);
      wsSecHeaderElm.addChildElement(userNameTokenElm);
      ehl.addChildElement(wsSecHeaderElm);
      
      SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement(ehl);
      stub.setHeader(soapHeaderElement);
      
        }catch(Exception e) {  
            logger.err("Set Soap Header failed! ");
        }

展开
收起
爱吃鱼的程序员 2020-06-10 14:54:45 769 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    建议使用cxf来实现

    2020-06-10 14:55:04
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载