带有标题的Spring WS客户端问题:javax.xml.transform.TransformerException:org.xml.sax.SAXParseException

时间:2018-08-23 19:23:05

标签: java spring web-services

当我尝试使用Web服务时遇到绑定错误错误   来自Spring Rest服务。我正在使用WebServiceTemplate调用WS服务   并且我还需要在请求中添加一些标头内容。   我在下面给出了描述我正在尝试的信封快照   加上。我在这方面有一些线索可以添加http://www.w3.org/2001/XMLSchema \“>”,尽管添加了但仍然无法 致电服务。

错误:

[Fatal Error] :1:90: The prefix "ext1" for element "ext1:ExternalPrincipalIdentity" is not bound.
ERROR:  'The prefix "ext1" for element "ext1:ExternalPrincipalIdentity" is not bound.'
javax.xml.transform.TransformerException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 90; The prefix "ext1" for element "ext1:ExternalPrincipalIdentity" is not bound.
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:749)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:351)
    at com.totalbanksolutions.service.custodianservice.adapter.impl.FidelityCustodianAdapterImpl$1.doWithMessage(FidelityCustodianAdapterImpl.java:102)
    at org.springframework.ws.client.core.WebServiceTemplate$2.doWithMessage(WebServiceTemplate.java:401)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:590)
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:383)
    at com.totalbanksolutions.service.custodianservice.adapter.impl.FidelityCustodianAdapterImpl.processAccountSearch(FidelityCustodianAdapterImpl.java:84)
    at com.totalbanksolutions.service.custodianservice.adapter.impl.FidelityCustodianAdapterImpl.processAccountANDDetails(FidelityCustodianAdapterImpl.java:134)
    at com.totalbanksolutions.service.custodianservice.adapter.impl.FidelityCustodianAdapterImpl$$FastClassBySpringCGLIB$$81f73fcf.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:656)
    at com.totalbanksolutions.service.custodianservice.adapter.impl.FidelityCustodianAdapterImpl$$EnhancerBySpringCGLIB$$929ae54.processAccountANDDetails(<generated>)
    at com.totalbanksolutions.service.custodianservice.service.impl.CustodianServiceImpl.processAccountDetails(CustodianServiceImpl.java:284)
    at com.totalbanksolutions.service.custodianservice.controller.CustodianServiceController.processAccountDetails(CustodianServiceController.java:48)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 90; The prefix "ext1" for element "ext1:ExternalPrincipalIdentity" is not bound.
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1239)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:641)
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:737)
    ... 73 more
--------- 

**Envelop** 
 <soapenv:Header>
      <ext:ExternalProcessingDirectives>
         <ext:LogTrackingId>Internal Testing</ext:LogTrackingId>
      </ext:ExternalProcessingDirectives>
      <ext1:ExternalPrincipalIdentity>
         <ext1:B2BPartnerPrincipalId>6060000606</ext1:B2BPartnerPrincipalId>
         <!--<ext1:RequestorId>3771050420</ext1:RequestorId> -->
         <ext1:AuthMethod>Certificate</ext1:AuthMethod>
         <ext1:PrincipalDomain>Correspondent</ext1:PrincipalDomain>
         <ext1:PrincipalRole>Correspondent</ext1:PrincipalRole>
      </ext1:ExternalPrincipalIdentity>
   </soapenv:Header>

**Java Code:** 


        getAccountsResponseAccountsHolder = 
                         (Holder<GetAccountsResponse.Accounts>) 

    newWebServiceTemplate.marshalSendAndReceive(getAccounts, new 
             WebServiceMessageCallback() {

                    public void doWithMessage(WebServiceMessage message) {
                        try {
                            SoapMessage soapMessage = (SoapMessage)message;
                            SoapHeader header = soapMessage.getSoapHeader();
                            StringBuilder headerBuilder = new StringBuilder("<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
                                    + "     <ext1:ExternalPrincipalIdentity>\r\n" + 
                                    "         <ext1:B2BPartnerPrincipalId>6060000606</ext1:B2BPartnerPrincipalId>\r\n" + 
                                    "          <ext1:RequestorId>3771050420</ext1:RequestorId>\r\n "+
                                    "         <ext1:AuthMethod>Certificate</ext1:AuthMethod>\r\n" + 
                                    "         <ext1:PrincipalDomain>Correspondent</ext1:PrincipalDomain>\r\n" + 
                                    "         <ext1:PrincipalRole>Correspondent</ext1:PrincipalRole>\r\n" + 
                                    "      </ext1:ExternalPrincipalIdentity> "
                                    + "     </xs:schema>");

                            StringSource headerSource = new StringSource(headerBuilder.toString());
                            Transformer transformer = TransformerFactory.newInstance().newTransformer();
                            transformer.transform(headerSource, header.getResult());

                        } catch (Exception e) {
                           e.printStackTrace();
                        }
                    }
                });

0 个答案:

没有答案