如何从axis1存根获取传输的响应头

时间:2016-06-21 02:23:27

标签: java soap header wsdl axis

我是否知道如何从第1轴肥皂存根获取响应标题?

响应记录

HTTP/1.1 200 OK
Server: Jetty(8.1.17.v20150415)
Content-Type: text/xml;charset=UTF-8
Content-Length: 1547
MyHeader: test
Date: Mon, 20 Jun 2016 04:41:20 GMT

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body>
........
</soap:Body>
</soap:Envelope>

从java开始,我使用invoke2方法并传递messageContext来获取响应头。但未能获得上面提供的标题。

invoke2(soapBindingStub._getCall().getMessageContext());

public void invoke2(org.apache.axis.MessageContext context) throws AxisFault {   
        System.out.println("invoke 2 called");
        Iterator pros = context.getAllPropertyNames();
        while (pros.hasNext())
            System.out.println("Name : " + pros.next());
        if (!(context.getProperty("transport.http.servletResponse") instanceof HttpServletResponse)) return;

        StringBuilder headers = new StringBuilder();
        HttpServletResponse request = (HttpServletResponse)context.getProperty(MessageContext.HTTP_RESPONSE_HEADERS);

        Collection c = request.getHeaderNames();
        Iterator e = c.iterator();
        while (e.hasNext()) {
          String headerName = (String)e.next();
          headers.append(String.format("%s: %s%n", headerName, request.getHeader(headerName)));
        }

        // log 
        System.out.println(headers.toString());
      }

请能帮助我获取回复标题&#34; MyHeader &#34;来自axis1 soap stub?

谢谢..

1 个答案:

答案 0 :(得分:0)

现在工作正常。

String[] header1 = soapBindingStub._getCall().getMessageContext().getResponseMessage().getMimeHeaders().getHeader("MyHeader");
logger.info(loggerHeader + "header1[0] ="+header1[0]);

感谢。