Axis2 1.3调用SharePoint WebService遇SOAPProcessingException问题求助
Hey there, let's break down this problem and fix it step by step! You're hitting the SOAPProcessingException because your Axis2 client expects a valid SOAP Envelope in response, but instead it's receiving HTML content—almost certainly a login page or error page from SharePoint. Let's walk through the causes and fixes.
你的测试代码
ListsStub proxy = new ListsStub(); HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); List schemes = new ArrayList(); schemes.add(HttpTransportProperties.Authenticator.NTLM); auth.setAuthSchemes(schemes); auth.setUsername("username"); auth.setPassword("password"); auth.setDomain("domain"); auth.setHost("host"); /*proxy._getServiceClient().getOptions().setProperty( org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);*/ proxy._getServiceClient().getOptions().setProperty( org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth); GetListItems getListItems = new com.microsoft.schemas.sharepoint.soap.ListsStub.GetListItems(); GetListItemsResponse response = new GetListItemsResponse(); response = proxy.GetListItems(getListItems);
完整异常栈
[INFO] OMException in getSOAPBuilder org.apache.axiom.soap.SOAPProcessingException: First Element must contain the local name, Envelope , but found html at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.constructNode(StAXSOAPModelBuilder.java:219) at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createOMElement(StAXSOAPModelBuilder.java:177) at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:163) at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:161) at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:110) at org.apache.axis2.builder.BuilderUtil.getSOAPBuilder(BuilderUtil.java:609) at org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:178) at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:111) at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:87) at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:326) at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:389) at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:211) at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163) at com.microsoft.schemas.sharepoint.soap.ListsStub.GetListItems(ListsStub.java:2288) at com.uboc.test.TestingWS.main(TestingWS.java:40) Exception in thread "main" org.apache.axis2.AxisFault: First Element must contain the local name, Envelope , but found html at org.apache.axis2.AxisFault.makeFault(AxisFault.java:417) at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:89) at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:326) at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:389) at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:211) at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163) at com.microsoft.schemas.sharepoint.soap.ListsStub.GetListItems(ListsStub.java:2288) at com.uboc.test.TestingWS.main(TestingWS.java:40) Caused by: org.apache.axiom.soap.SOAPProcessingException: First Element must contain the local name, Envelope , but found html at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.constructNode(StAXSOAPModelBuilder.java:219) at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createOMElement(StAXSOAPModelBuilder.java:177) at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:163) at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:161) at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:110) at org.apache.axis2.builder.BuilderUtil.getSOAPBuilder(BuilderUtil.java:609) at org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:178)
问题原因
The core issue is that your Axis2 client isn't successfully authenticating with SharePoint, so SharePoint is returning an HTML login page instead of the expected SOAP Envelope response. This could also happen if you're pointing the stub to the wrong endpoint URL.
解决方案
1. 确保设置了正确的WebService Endpoint
When you create the ListsStub, you need to pass the full URL to SharePoint's Lists WebService. The default no-arg constructor might not point to the correct address. Update your stub initialization:
// Replace with your actual SharePoint site URL String listsWsUrl = "http://your-sharepoint-site/_vti_bin/Lists.asmx"; ListsStub proxy = new ListsStub(listsWsUrl);
You can verify this URL by visiting it in a browser—you should see the SharePoint Lists WebService description page.
2. Fix NTLM Authentication Configuration
Axis2 1.3's NTLM auth has specific requirements. Adjust your authentication setup like this:
HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); auth.setUsername("your-username"); auth.setPassword("your-password"); auth.setDomain("your-domain"); // e.g., CORP auth.setPreemptiveAuthentication(true); // Send auth headers upfront to avoid redirects List<String> schemes = new ArrayList<>(); schemes.add(HttpTransportProperties.Authenticator.NTLM); auth.setAuthSchemes(schemes); Options options = proxy._getServiceClient().getOptions(); options.setProperty(HTTPConstants.AUTHENTICATE, auth); options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE); // Disable chunked encoding (some SP environments don't support it)
- Ensure the
domainvalue is your Active Directory domain name, not the server hostname. - Preemptive authentication helps avoid being redirected to a login page before sending credentials.
3. Enable Debug Logging to Verify Requests
To confirm you're getting a login page, enable Axis2's debug logging to see the actual response content:
// Add this at the start of your main method System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "debug");
This will show you the HTTP status code and response body—if you see a 302 redirect or 200 OK with HTML content, that confirms the auth issue.
4. Verify SharePoint Permissions
Make sure the account you're using has read access to the target list in SharePoint. Also, confirm SharePoint isn't using Form-Based Authentication (FBA)—NTLM won't work with FBA, so you'd need to adjust your auth method if that's the case.
内容的提问来源于stack exchange,提问作者Pallav Khare

