为什么VersionOne无法识别资产类型?

时间:2015-07-16 18:33:16

标签: java http versionone

更新:问题(如下;请参阅"原始问题")仍然有效,但我还有其他数据。我能够通过将访问令牌作为字符串放入源代码中来成功检索资产,其中services字段被实例化。即,这有效:

String token = "[mysecrettoken]";
try{
    connector = V1Connector
        .withInstanceUrl(V1_LOC)
        .withUserAgentHeader(APPLICATION_NAME, APPLICATION_VERSION)
        .withAccessToken(token)
        .build();
}

但是,当我使用我创建的类来从加密的文本文件中检索令牌时,它会因我在下面指定的错误而失败。

String token = TokenUtils.getAccessToken();

我已使用System.out.println直观地验证令牌是否被完美解密。为什么TokenUtils返回的解密字符串(看起来是正确的)与字符串直接包含在源代码中的字符串有什么不同?

原始问题:

我遇到与Griffin's类似的问题,但我使用的是Java,而且到目前为止我还无法找出根本原因。值得注意的是,该程序的早期版本能够成功连接到VersionOne并检索资产,但是当我检索到该提交并使用当前访问令牌(自提交后已更改)再次尝试时,我得到了与下面相同的错误。

这是相关方法; services变量是包含类的字段:

private Asset findTeam(String teamName){

        assert teamName != null;

        Asset result = null;
        IAssetType assetType = services.getMeta().getAssetType("Team");
        Query query = new Query(assetType);
        IAttributeDefinition nameAttr = 
            assetType.getAttributeDefinition("Name");
        query.getSelection().add(nameAttr);

        try{
            QueryResult queryResult = services.retrieve(query);

            for (Asset team: queryResult.getAssets()){
                String str = team.getAttribute(nameAttr).getValue().toString();
                assert str != null;
                if (teamName.equals(str)){
                    result = team;
                    break;
                }
            }           
        }
        catch(Exception e){
            assert false;
            e.printStackTrace();
        }
        return result;

    }

这是由此产生的错误:

com.versionone.apiclient.exceptions.ConnectionException: 
HTTP/1.1 400 Bad Request error code: 400 VersionOne could not process the request.
    at com.versionone.apiclient.V1Connector.manageErrors(V1Connector.java:420)
    at com.versionone.apiclient.V1Connector.getData(V1Connector.java:368)
    at com.versionone.apiclient.MetaModel.createDocument(MetaModel.java:252)
    at com.versionone.apiclient.MetaModel.hookupAssetType(MetaModel.java:185)
    at com.versionone.apiclient.MetaModel.findAssetType(MetaModel.java:140)
    at com.versionone.apiclient.MetaModel.getAssetType(MetaModel.java:85)
    at com.billhorvath.v1mods.TeamModder.addToTeam(TeamModder.java:63)
    at com.billhorvath.v1mods.TeamModder.main(TeamModder.java:38)
com.versionone.apiclient.exceptions.MetaException: Error creating Document: Team
    at com.versionone.apiclient.MetaModel.createDocument(MetaModel.java:259)
    at com.versionone.apiclient.MetaModel.hookupAssetType(MetaModel.java:185)
    at com.versionone.apiclient.MetaModel.findAssetType(MetaModel.java:140)
    at com.versionone.apiclient.MetaModel.getAssetType(MetaModel.java:85)
    at com.billhorvath.v1mods.TeamModder.addToTeam(TeamModder.java:63)
    at com.billhorvath.v1mods.TeamModder.main(TeamModder.java:38)
Caused by: com.versionone.apiclient.exceptions.ConnectionException: 
HTTP/1.1 400 Bad Request error code: 400 VersionOne could not process the request.
    at com.versionone.apiclient.V1Connector.manageErrors(V1Connector.java:420)
    at com.versionone.apiclient.V1Connector.getData(V1Connector.java:368)
    at com.versionone.apiclient.MetaModel.createDocument(MetaModel.java:252)
    ... 5 more
Exception in thread "main" com.versionone.apiclient.exceptions.MetaException: Unknown AssetType: Team
    at com.versionone.apiclient.MetaModel.getAssetType(MetaModel.java:88)
    at com.billhorvath.v1mods.TeamModder.addToTeam(TeamModder.java:63)
    at com.billhorvath.v1mods.TeamModder.main(TeamModder.java:38)
Caused by: com.versionone.apiclient.exceptions.MetaException: Error creating Document: Team
    at com.versionone.apiclient.MetaModel.createDocument(MetaModel.java:259)
    at com.versionone.apiclient.MetaModel.hookupAssetType(MetaModel.java:185)
    at com.versionone.apiclient.MetaModel.findAssetType(MetaModel.java:140)
    at com.versionone.apiclient.MetaModel.getAssetType(MetaModel.java:85)
    ... 2 more
Caused by: com.versionone.apiclient.exceptions.ConnectionException: 
HTTP/1.1 400 Bad Request error code: 400 VersionOne could not process the request.
    at com.versionone.apiclient.V1Connector.manageErrors(V1Connector.java:420)
    at com.versionone.apiclient.V1Connector.getData(V1Connector.java:368)
    at com.versionone.apiclient.MetaModel.createDocument(MetaModel.java:252)
    ... 5 more

除了常规搜索之外,我还审核了VersionOne Java API的源代码以及RFC for the 400 error code;我还没找到任何答案。有人有什么建议吗?

1 个答案:

答案 0 :(得分:1)

(帽子提示Mark Irvin以获取二元比较建议。)

事实证明,问题与令牌加密的方式有关:由于令牌长度为30个字符,并且密码算法(本例中为AES)的要求需要32个字节,因此需要两个空白字节在加密过程中附加。我修改了解密周期以去除字符串末尾的整数值为0的字符和wallah!有用。