在Unix中使用java访问UserProfile Web服务
在unix环境中,我试图通过java应用程序使用UserProfile Webservice时遇到了这个问题。在Eclipse中测试时,完全相同的代码在Windows环境中工作。但在Centos 6.3操作系统中测试时,同样会引发如下所示的错误 我已经从WSDL创建了存根并使用它。此外,基于Unix的服务器未在域中注册。我确信这与用户凭据有关。但我不确定如何将其传递给应用程序 Java主程序:在Unix中使用java访问UserProfile Web服务,java,web-services,authentication,sharepoint-2010,Java,Web Services,Authentication,Sharepoint 2010,在unix环境中,我试图通过java应用程序使用UserProfile Webservice时遇到了这个问题。在Eclipse中测试时,完全相同的代码在Windows环境中工作。但在Centos 6.3操作系统中测试时,同样会引发如下所示的错误 我已经从WSDL创建了存根并使用它。此外,基于Unix的服务器未在域中注册。我确信这与用户凭据有关。但我不确定如何将其传递给应用程序 Java主程序: import com.microsoft.webservices.sharepointportalse
import com.microsoft.webservices.sharepointportalserver.userprofileservice.*;
import java.util.List;
import java.util.Properties;
public class TestWebservice{
public static void main(String[] args) {
UserProfileService ups = new UserProfileService();
UserProfileServiceSoap upssoap = ups.getUserProfileServiceSoap();
ArrayOfPropertyData userInfo = upssoap.getUserProfileByName("E12345");
List<PropertyData> listPropertyData = userInfo.getPropertyData();
for (int i=0; i < listPropertyData.size(); i++){
PropertyData tempPropertyData = listPropertyData.get(i);
System.out.println("tempPropertyData.getName = " + tempPropertyData.getName());
ArrayOfValueData tempValues = tempPropertyData.getValues();
List<ValueData> listValueData = tempValues.getValueData();
System.out.println("listValueData.size()= "+listValueData.size());
for (int j=0; j < listValueData.size(); j++){
ValueData tempValueData = listValueData.get(j);
Object aValue = tempValueData.getValue();
System.out.println("aValue = " + aValue);
}//end for j
}//end for i
}
}
Unix中的错误:
Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://SharepointServer/SiteName/_vti_bin/UserProfileService.asmx?WSDL. It failed with:
Got Server returned HTTP response code: 401 for URL: http://SharepointServer/SiteName/_vti_bin/UserProfileService.asmx?WSDL while opening stream from http://SharepointServer/SiteName/_vti_bin/UserProfileService.asmx?WSDL.
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:173)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:155)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:120)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:258)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:221)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:169)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:101)
at javax.xml.ws.Service.<init>(Service.java:77)
at com.microsoft.webservices.sharepointportalserver.userprofileservice.UserProfileService.<init>(UserProfileService.java:44)
at JacobClient.main(JacobClient.java:49)
Caused by: java.io.IOException: Got Server returned HTTP response code: 401 for URL: http://SharepointServer/SiteName/_vti_bin/UserProfileService.asmx?WSDL while opening stream from http://SharepointServer/SiteName/_vti_bin/UserProfileService.asmx?WSDL
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:842)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.resolveWSDL(RuntimeWSDLParser.java:283)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:140)
... 8 more
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://myteamssgp1/sites/PTFApps/FARequest/_vti_bin/UserProfileService.asmx?WSDL
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1627)
at java.net.URL.openStream(URL.java:1041)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:827)
... 10 more
线程“main”javax.xml.ws.WebServiceException中的异常:无法访问位于以下位置的WSDL:http://SharepointServer/SiteName/_vti_bin/UserProfileService.asmx?WSDL. 失败的原因是:
获取服务器返回的URL的HTTP响应代码:401:http://SharepointServer/SiteName/_vti_bin/UserProfileService.asmx?WSDL 当从http://SharepointServer/SiteName/_vti_bin/UserProfileService.asmx?WSDL.
位于com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:173)
位于com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:155)
位于com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:120)
在com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:258)
在com.sun.xml.internal.ws.client.WSServiceDelegate上。(WSServiceDelegate.java:221)
在com.sun.xml.internal.ws.client.WSServiceDelegate上。(WSServiceDelegate.java:169)
位于com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:101)
位于javax.xml.ws.Service。(Service.java:77)
位于com.microsoft.webservices.sharepointportalserver.userprofileservice.userprofileservice。(userprofileservice.java:44)
位于JacobClient.main(JacobClient.java:49)
原因:java.io.IOException:Get服务器返回了URL的HTTP响应代码:401:http://SharepointServer/SiteName/_vti_bin/UserProfileService.asmx?WSDL 当从http://SharepointServer/SiteName/_vti_bin/UserProfileService.asmx?WSDL
位于com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:842)
位于com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.resolveWSDL(RuntimeWSDLParser.java:283)
位于com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:140)
... 8个以上
原因:java.io.IOException:服务器返回了URL的HTTP响应代码:401:http://myteamssgp1/sites/PTFApps/FARequest/_vti_bin/UserProfileService.asmx?WSDL
位于sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1627)
在java.net.URL.openStream(URL.java:1041)
位于com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:827)
... 10多
猜猜看,要让它在Unix服务器上工作,需要额外做些什么?这段代码解决了我的问题
Authenticator myAuth = new Authenticator()
{
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("EMPID", "PASSWORD".toCharArray());
}
};
Authenticator myAuth = new Authenticator()
{
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("EMPID", "PASSWORD".toCharArray());
}
};