我试图使用VersionOne Java和V1访问令牌对V1实例进行身份验证。我按照创建访问令牌和创建连接的文档进行了准备,以使其正常工作。
问题是,我一直遇到一个ConnectionException,说明"401无法验证“消息(下面的堆栈跟踪)。是什么导致了这一切?
开发环境
源代码
// build the connector using an access token
V1Connector connector = V1Connector.withInstanceUrl("https://servername/instancetoauthenticate")
.withUserAgentHeader("Application", "1.0")
.withAccessToken("1.WkEciqwKNW7Pnvw9CNmPgQWIdL4=")
.build();
// use the connector to instantiate a Services object
IServices services = new Services(connector);
// check the logged in member
Oid oid = services.loggedIn;
System.out.println("Member Oid: " + oid);堆栈跟踪
Exception in thread "main" com.versionone.apiclient.exceptions.ConnectionException:
HTTP/1.1 401 Unauthorized error code: 401 Could not authenticate. The VersionOne credentials may be incorrect or the access tokens may have expired.
at com.versionone.apiclient.V1Connector.manageErrors(V1Connector.java:423)
at com.versionone.apiclient.V1Connector.getData(V1Connector.java:368)
at com.versionone.apiclient.Services.retrieve(Services.java:114)
at com.versionone.apiclient.Services.getLoggedIn(Services.java:254)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.MethodMetaProperty$GetBeanMethodMetaProperty.getProperty(MethodMetaProperty.java:73)
at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:61)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)
at com.netsuite.versionone.exporttasks.Authenticator.main(Authenticator.groovy:30)发布于 2015-07-16 22:18:21
在Java的15.1.0版本中,您可以使用访问令牌连接到VersionOne实例,即使该实例被配置为使用。诀窍是使用新的useOAuthEndpoints()方法的V1Connector:
V1Connector connector = V1Connector
.withInstanceUrl("<Server Base URI>")
.withUserAgentHeader("AppName", "1.0")
.withAccessToken("1.rWM8lKLk+PnyFxkEWVX5Kl2u6Jk=")
.useOAuthEndpoints()
.build();注意,您只需要对NTLM配置的实例使用useOAuthEndpoints()方法。
VersionOne Java连接文档可以在这里找到:连接
https://stackoverflow.com/questions/30973649
复制相似问题