Attempt to retrieve Sharepoint WSDL fails with "Server redirected too many times"
I am trying to connect to a Sharepoint server through Java code. My code works fine with some Sharepoint servers, but fails when I try to connect to my Comcast provided account. The classes ListsSoap
and Lists
were generated from a Sharepoint WSDL using wsimport.
I read this may be caused by not using doman\username as the Sharepoint username. I tried prepending different domains to the username parameter, things like mycompany.comcastbiz.net\\me@mycompany.comcastbiz.net
, but I received a 401 error for all domain names I tried.
BasicHTTPAuthenticator auth = new BasicHTTPAuthenticator("me@mycompany.comcastbiz.net", password);
Authenticator.setDefault(auth);
Lists listsService = new com.microsoft.schemas.sharepoint.soap.Lists();
listsSoap = listsService.getListsSoap12();
import java.net.Authenticator;
import java.net.PasswordAuthentication;
class BasicHTTPAuthenticator extends Authenticator
{
private String userName;
private String password;
public BasicHTTPAuthenticator(String userName, String password)
{
this.userName = userName;
this.password = password;
}
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(userName, password.toCharArray());
}
public String getUserName()
{
return userName;
}
public void setUserName(String userName)
{
this.userName = userName;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
}
public class Lists extends Service
{
private final static URL LISTS_WSDL_LOCATION;
private final static Logger logger = Logger.getLogger(com.microsoft.schemas.sharepoint.soap.Lists.class.getName());
static {
URL url = null;
try {
URL baseUrl;
baseUrl = com.microsoft.schemas.sharepoint.soap.Lists.class.getResource(".");
url = new URL(baseUrl, SharepointService.getServerUrl()+"/_vti_bin/Lists.asmx?WSDL");
} catch (MalformedURLException e) {
logger.warning("Failed to create URL for the wsdl Location: " + SharepointService.getServerUrl()+"/_vti_bin/Lists.asmx?WSDL");
logger.warning(e.getMessage());
}
LISTS_WSDL_LOCATION = url;
}
public Lists() {
super(LISTS_WSDL_LOCATION, new QName("http://schemas.microsoft.com/sharepoint/soap/", "Lists"));
}
...
}
It failed with:
javax.xml.ws.WebServiceException: Failed to access the WSDL at: htt开发者_C百科ps://www.po1.comcast.net/sites/mycompany//_vti_bin/Lists.asmx?WSDL.
Server redirected too many times (20).
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:162)
at com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:144)
at com.sun.xml.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:265)
at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:228)
at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:176)
at com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:104)
The proper user name for you will be "mycompany.comcastbiz.net\\me".
I tried without the domain before the user and i have not this error, maybe it does'nt understand the domain, try with soapUI to test coonection, if it is ok, it is just the way to conncting with webservice is not good, so ther is another way to , REST API to access sharepoint...
精彩评论