如何修复没有SOAPAction标头!错误

时间:2017-07-24 10:06:12

标签: java web-services soap wsdl axis

请在下面找到我用来调用我的soap端点的html soap客户端代码 我的soap webservice部署在tomcat中作为轴项目。

请在下面找到客户代码

<html>
<head>
    <title>SOAP JavaScript Client Test</title>
    <script type="text/javascript">
        function soap() {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open('POST', 'http://localhost:9090/SMSSoapInterface/services/smsxmlpushservicewsSoap11', true);

            // build SOAP request
            var sr =
                '<?xml version="1.0" encoding="utf-8"?>' +
                '<soapenv:Envelope ' + 
                    'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
                    'xmlns:urn="urn:mm7pushinterface' +
                    'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">' +
                    '<soapenv:Body>' +
                            '<urn:SubmitReq>' +
                            '<urn:MM7Version>5.3.0</urn:MM7Version>' +
                            '<urn:SenderIdentification>' +
                            '<urn:VASPID>1234</urn:VASPID>'+
                            '<urn:VASID>12345</urn:VASID>'+
                            '<urn:CampaignName>SOAP Campaign</urn:CampaignName>'+
                            '<urn:CampaignDesc>test</urn:CampaignDesc>'+
                            '<urn:MsgCategory>1</urn:MsgCategory>'+
                            '<urn:SenderAddress>'+
                            '<urn:RFC2822Address >1244</urn:RFC2822Address>'+
                            '<urn:Number>919901251515</urn:Number>'+
                            '<urn:ShortCode >1234</urn:ShortCode>'+
                            '</urn:SenderAddress>'+
                            '</urn:SenderIdentification>'+
                            '<urn:Recipients>'+
                            '<urn:To>'+
                            '<urn:RFC2822Address >6789</urn:RFC2822Address>'+
                            '<urn:Number >919901251516</urn:Number>'+
                            '<urn:ShortCode >7896</urn:ShortCode>'+
                            '</urn:To>'+
                            '</urn:Recipients>'+
                            '</urn:Recipients>'+
                    '</soapenv:Body>' +
                '</soapenv:Envelope>';

            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {
                    if (xmlhttp.status == 200) {
                        alert('done. use firebug/console to see network response');
                    }
                }
            }
            // Send the POST request
            xmlhttp.setRequestHeader('Content-Type', 'text/xml');
            xmlhttp.setRequestHeader('SOAPAction', "");
            xmlhttp.setRequestHeader('Access-Control-Allow-Headers', 'Authorization');
            xmlhttp.setRequestHeader('Access-Control-Allow-Methods', 'POST');
            xmlhttp.setRequestHeader('Access-Control-Allow-Origin', '*');
            xmlhttp.setRequestHeader('username', 'ecpDemoUser');
            xmlhttp.setRequestHeader('password', 'ecpDemo');
            xmlhttp.setRequestHeader('SOAPAction', "");
            xmlhttp.send(sr);
            // send request
            // ...
        }
    </script>
</head>
<body>
    <form name="Demo" action="" method="post">
        <div>
            <input type="button" value="Soap" onclick="soap();" />
        </div>
    </form>
</body>
</html> <!-- typo -->

以下是我尝试点击soap webservice时遇到的错误/堆栈跟踪

no SOAPAction header!
       at org.apache.axis.transport.http.AxisServlet.getSoapAction(AxisServlet.java:1013)
       at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:678)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
       at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
       at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
       at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
       at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
       at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
       at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
       at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
       at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
       at java.lang.Thread.run(Thread.java:745)

以下是wsdl中的soap动作

<soap:operation soapAction=""/>

请告诉我如何解决此问题?

1 个答案:

答案 0 :(得分:0)

请参阅SOAP 1.1 specification

  

SOAPAction HTTP请求标头字段可用于指示   SOAP HTTP请求的意图。该值是标识的URI   意图。 SOAP对格式或特异性没有限制   URI或它是可解析的。 HTTP客户端必须使用此标头   发出SOAP HTTP请求时的字段。   可以使用SOAPAction头字段的存在和内容   防火墙等服务器可以适当地过滤SOAP请求   HTTP中的消息。空字符串的标题字段值(&#34;&#34;)表示   SOAP消息的意图由HTTP提供   Request-URI中。没有价值意味着没有意图的迹象   消息。

您正在使用需要肥皂操作的AxisServlet

  

从技术上讲,如果我们找不到这个标题,我们应该错了。   它是SOAP HTTP绑定所必需的。

代码:

private String More ...getSoapAction(HttpServletRequest req) throws AxisFault {

String soapAction = req.getHeader(HTTPConstants.HEADER_SOAP_ACTION);
if (soapAction == null) {
    String contentType = req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE);
    if(contentType != null) {
        int index = contentType.indexOf("action");
        if(index != -1){
            soapAction = contentType.substring(index + 7);
        }
    }
}

...

   if (soapAction == null) {
        AxisFault af = new AxisFault("Client.NoSOAPAction",
                                     Messages.getMessage("noHeader00",
                "SOAPAction"),
                                     null, null);