java - 如何使用 RallyRestApi 在 Rally 中创建新项目

标签 java rally

在下面的代码中,我尝试使用 RallyRestApi 创建一个新项目,

RallyMain {

    public static void main(String[] a) {

        BasicConfigurator.configure();
        try {
            RallyRestApi restApi = new RallyRestApi(new URI(
                    "https://rally1.rallydev.com"), "_APIKey");
            restApi.setApplicationName("RallyRestExample");
            restApi.setWsapiVersion("v2.0");

            JsonObject newProject = new JsonObject();
            newProject.addProperty("Name", "Sample Project One");
            newProject.addProperty("Description", "Sample project for testing API");
            //newProject.addProperty("Owner", "nmuthusamy");
            newProject.addProperty("Workspace", "/workspace/Workspace 1");

            CreateRequest createRequest = new CreateRequest("Project", newProject);
            CreateResponse createResponse = restApi.create(createRequest); 
            System.out.println("Response "+createResponse.wasSuccessful());
        } catch (Exception e) {
            System.out.println("Exception \n"+e);
        }
    }
}

当我运行上述代码时,Rally 工作区上未创建新项目。System.out.println("Response "+createResponse.wasSuccessful()); 始终打印 false。这里ScreenShot of my rally workspace我还附加了我的工作区的屏幕

我什至遵循了此链接 Stackoverflow 中给出的答案但它没有醒来。

以下是我运行 main 方法时得到的控制台日志。

0 [main] DEBUG org.apache.http.impl.conn.BasicClientConnectionManager  - Get connection for route {s}->https://rally1.rallydev.com:443
15 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnectionOperator  - Connecting to rally1.rallydev.com:443
448 [main] DEBUG org.apache.http.client.protocol.RequestAddCookies  - CookieSpec selected: default
449 [main] DEBUG org.apache.http.client.protocol.RequestAuthCache  - Auth cache not set in the context
449 [main] DEBUG org.apache.http.client.protocol.RequestTargetAuthentication  - Target auth state: UNCHALLENGED
450 [main] DEBUG org.apache.http.client.protocol.RequestProxyAuthentication  - Proxy auth state: UNCHALLENGED
450 [main] DEBUG com.rallydev.rest.client.ApiKeyClient  - Attempt 1 to execute request
450 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection  - Sending request: POST /slm/webservice/v2.0/project/create.js?fetch=true HTTP/1.1
450 [main] DEBUG org.apache.http.wire  -  >> "POST /slm/webservice/v2.0/project/create.js?fetch=true HTTP/1.1[\r][\n]"
451 [main] DEBUG org.apache.http.wire  -  >> "zsessionid: _F99sUCMTR7OsOz4IpiCWp5Xl1UYRJ0wFqBpg5Wz5kFg[\r][\n]"
451 [main] DEBUG org.apache.http.wire  -  >> "X-RallyIntegrationLibrary: Rally Rest API for Java v2.2.1[\r][\n]"
451 [main] DEBUG org.apache.http.wire  -  >> "X-RallyIntegrationVersion: 2.2.1[\r][\n]"
451 [main] DEBUG org.apache.http.wire  -  >> "X-RallyIntegrationName: RallyRestExample[\r][\n]"
451 [main] DEBUG org.apache.http.wire  -  >> "X-RallyIntegrationVendor: Rally Software, Inc.[\r][\n]"
451 [main] DEBUG org.apache.http.wire  -  >> "Accept-Encoding: gzip,deflate[\r][\n]"
451 [main] DEBUG org.apache.http.wire  -  >> "Content-Length: 125[\r][\n]"
451 [main] DEBUG org.apache.http.wire  -  >> "Content-Type: text/plain; charset=UTF-8[\r][\n]"
451 [main] DEBUG org.apache.http.wire  -  >> "Host: rally1.rallydev.com[\r][\n]"
451 [main] DEBUG org.apache.http.wire  -  >> "Connection: Keep-Alive[\r][\n]"
451 [main] DEBUG org.apache.http.wire  -  >> "User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_40)[\r][\n]"
451 [main] DEBUG org.apache.http.wire  -  >> "[\r][\n]"
452 [main] DEBUG org.apache.http.headers  - >> POST /slm/webservice/v2.0/project/create.js?fetch=true HTTP/1.1
452 [main] DEBUG org.apache.http.headers  - >> zsessionid: _ApiKey
452 [main] DEBUG org.apache.http.headers  - >> X-RallyIntegrationLibrary: Rally Rest API for Java v2.2.1
452 [main] DEBUG org.apache.http.headers  - >> X-RallyIntegrationVersion: 2.2.1
452 [main] DEBUG org.apache.http.headers  - >> X-RallyIntegrationName: RallyRestExample
452 [main] DEBUG org.apache.http.headers  - >> X-RallyIntegrationVendor: Rally Software, Inc.
452 [main] DEBUG org.apache.http.headers  - >> Accept-Encoding: gzip,deflate
452 [main] DEBUG org.apache.http.headers  - >> Content-Length: 125
452 [main] DEBUG org.apache.http.headers  - >> Content-Type: text/plain; charset=UTF-8
452 [main] DEBUG org.apache.http.headers  - >> Host: rally1.rallydev.com
452 [main] DEBUG org.apache.http.headers  - >> Connection: Keep-Alive
452 [main] DEBUG org.apache.http.headers  - >> User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_40)
452 [main] DEBUG org.apache.http.wire  -  >> "{"Project":{"Name":"Sample Project One","Description":"Sample project for testing API","Workspace":"/workspace/Workspace 1"}}"
1719 [main] DEBUG org.apache.http.wire  -  << "HTTP/1.1 200 OK[\r][\n]"
1720 [main] DEBUG org.apache.http.wire  -  << "Date: Sat, 10 Jun 2017 07:59:30 GMT[\r][\n]"
1720 [main] DEBUG org.apache.http.wire  -  << "Content-Type: application/json;  charset=utf-8[\r][\n]"
1720 [main] DEBUG org.apache.http.wire  -  << "Content-Length: 176[\r][\n]"
1720 [main] DEBUG org.apache.http.wire  -  << "Connection: keep-alive[\r][\n]"
1720 [main] DEBUG org.apache.http.wire  -  << "Set-Cookie: __cfduid=dc354f67bed2fd443e4bbd5081140f56d1497081569; expires=Sun, 10-Jun-18 07:59:29 GMT; path=/; domain=.rallydev.com; HttpOnly[\r][\n]"
1720 [main] DEBUG org.apache.http.wire  -  << "X-XSS-Protection: 1; mode=block[\r][\n]"
1720 [main] DEBUG org.apache.http.wire  -  << "RallyRequestID: qd-app-071j56j3qgdx7xfhnyq78y1yxw7.qd-app-075984713[\r][\n]"
1720 [main] DEBUG org.apache.http.wire  -  << "Expires: Thu, 01 Jan 1970 00:00:00 GMT[\r][\n]"
1720 [main] DEBUG org.apache.http.wire  -  << "Set-Cookie: JSESSIONID=qd-app-071j56j3qgdx7xfhnyq78y1yxw7.qd-app-07;Path=/;Secure;HttpOnly[\r][\n]"
1720 [main] DEBUG org.apache.http.wire  -  << "Set-Cookie: SUBBUCKETID=108;Path=/;Domain=rally1.rallydev.com;Secure;HttpOnly[\r][\n]"
1720 [main] DEBUG org.apache.http.wire  -  << "Set-Cookie: SUBSCRIPTIONID=122108;Path=/;Domain=rally1.rallydev.com;Secure;HttpOnly[\r][\n]"
1720 [main] DEBUG org.apache.http.wire  -  << "Vary: Accept-Encoding[\r][\n]"
1720 [main] DEBUG org.apache.http.wire  -  << "Content-Encoding: gzip[\r][\n]"
1721 [main] DEBUG org.apache.http.wire  -  << "P3P: CP="NON DSP COR CURa PSAa PSDa OUR NOR BUS PUR COM NAV STA"[\r][\n]"
1721 [main] DEBUG org.apache.http.wire  -  << "Cache-Control: private,max-age=0,must-revalidate[\r][\n]"
1721 [main] DEBUG org.apache.http.wire  -  << "Strict-Transport-Security: max-age=31536000; includeSubDomains; preload;[\r][\n]"
1721 [main] DEBUG org.apache.http.wire  -  << "Set-Cookie: SERVERID=2dd8f75e6436014e8021e4a12eb0016859253e05; path=/[\r][\n]"
1721 [main] DEBUG org.apache.http.wire  -  << "Server: cloudflare-nginx[\r][\n]"
1721 [main] DEBUG org.apache.http.wire  -  << "CF-RAY: 36cacaa1dd7c2ee7-DEL[\r][\n]"
1721 [main] DEBUG org.apache.http.wire  -  << "[\r][\n]"
1722 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection  - Receiving response: HTTP/1.1 200 OK
1722 [main] DEBUG org.apache.http.headers  - << HTTP/1.1 200 OK
1722 [main] DEBUG org.apache.http.headers  - << Date: Sat, 10 Jun 2017 07:59:30 GMT
1722 [main] DEBUG org.apache.http.headers  - << Content-Type: application/json;  charset=utf-8
1722 [main] DEBUG org.apache.http.headers  - << Content-Length: 176
1722 [main] DEBUG org.apache.http.headers  - << Connection: keep-alive
1722 [main] DEBUG org.apache.http.headers  - << Set-Cookie: __cfduid=dc354f67bed2fd443e4bbd5081140f56d1497081569; expires=Sun, 10-Jun-18 07:59:29 GMT; path=/; domain=.rallydev.com; HttpOnly
1722 [main] DEBUG org.apache.http.headers  - << X-XSS-Protection: 1; mode=block
1722 [main] DEBUG org.apache.http.headers  - << RallyRequestID: qd-app-071j56j3qgdx7xfhnyq78y1yxw7.qd-app-075984713
1722 [main] DEBUG org.apache.http.headers  - << Expires: Thu, 01 Jan 1970 00:00:00 GMT
1722 [main] DEBUG org.apache.http.headers  - << Set-Cookie: JSESSIONID=_jsessionid;Path=/;Secure;HttpOnly
1722 [main] DEBUG org.apache.http.headers  - << Set-Cookie: SUBBUCKETID=108;Path=/;Domain=rally1.rallydev.com;Secure;HttpOnly
1722 [main] DEBUG org.apache.http.headers  - << Set-Cookie: SUBSCRIPTIONID=122108;Path=/;Domain=rally1.rallydev.com;Secure;HttpOnly
1722 [main] DEBUG org.apache.http.headers  - << Vary: Accept-Encoding
1723 [main] DEBUG org.apache.http.headers  - << Content-Encoding: gzip
1723 [main] DEBUG org.apache.http.headers  - << P3P: CP="NON DSP COR CURa PSAa PSDa OUR NOR BUS PUR COM NAV STA"
1723 [main] DEBUG org.apache.http.headers  - << Cache-Control: private,max-age=0,must-revalidate
1723 [main] DEBUG org.apache.http.headers  - << Strict-Transport-Security: max-age=31536000; includeSubDomains; preload;
1723 [main] DEBUG org.apache.http.headers  - << Set-Cookie: SERVERID=_serverid; path=/
1723 [main] DEBUG org.apache.http.headers  - << Server: cloudflare-nginx
1723 [main] DEBUG org.apache.http.headers  - << CF-RAY: 36cacaa1dd7c2ee7-DEL
1736 [main] DEBUG org.apache.http.client.protocol.ResponseProcessCookies  - Cookie accepted [__cfduid="_cfduid", version:0, domain:rallydev.com, path:/, expiry:Sun Jun 10 13:29:29 IST 2018]
1736 [main] DEBUG org.apache.http.client.protocol.ResponseProcessCookies  - Cookie accepted [JSESSIONID="_jsessionid", version:0, domain:rally1.rallydev.com, path:/, expiry:null]
1736 [main] DEBUG org.apache.http.client.protocol.ResponseProcessCookies  - Cookie accepted [SUBBUCKETID="108", version:0, domain:rally1.rallydev.com, path:/, expiry:null]
1737 [main] DEBUG org.apache.http.client.protocol.ResponseProcessCookies  - Cookie accepted [SUBSCRIPTIONID="999999", version:0, domain:rally1.rallydev.com, path:/, expiry:null]
1737 [main] DEBUG org.apache.http.client.protocol.ResponseProcessCookies  - Cookie accepted [SERVERID="_serverid", version:0, domain:rally1.rallydev.com, path:/, expiry:null]
1738 [main] DEBUG com.rallydev.rest.client.ApiKeyClient  - Connection can be kept alive indefinitely
1750 [main] DEBUG org.apache.http.wire  -  << "[0x1f]"
1750 [main] DEBUG org.apache.http.wire  -  << "[0x8b]"
1750 [main] DEBUG org.apache.http.wire  -  << "[0x8]"
1750 [main] DEBUG org.apache.http.wire  -  << "[0x0]"
1750 [main] DEBUG org.apache.http.wire  -  << "[0x0][0x0][0x0][0x0][0x0][0x3]"
1750 [main] DEBUG org.apache.http.wire  -  << "M[0xce][0xb1][\n]"
1751 [main] DEBUG org.apache.http.wire  -  << "[0xc2]@[0xc][0x6][0xe0]W[0x9][0x99][0xa5][0x88]c7[0xa9][0xe][0x1d]D[0xd1][0xa1][0x83]-r[0xb6][0xb1][0xb4][0x1c]I[0xc9][0xdd][\r]R[0xfa][0xee]FEp[0x9][0xe4]#[0xf9][0x93][0x19][0xb]%[0x17][0xe9]L![0xf9][0x88]9[0xcc]xS[0xe7][0xfd]s{*[0xf]n[0x14]5[0xc2][\r][0xae][0xe0][0x8f][0x7][0xfe][0xf2][0xfa][0xcd]{U[0xd1]`[0xed][0x15][0xb]I[0xbe][0x3][0x96][0x8][0x16][0xd9][0xe5]p[0xbc][0x8f][0xd4][0xc6][0xf]<$qgUX[0xee]r[0xe0][0xe4]=6[0x96]Q9[0xe5][0x81][0xfb]oJ[0x19]a[0x8][0xb6][0x4]^[0xb8]'[0x5][0xa6][0x96]Bp[0xfa][0x84]([0xe0][0xa6][0x89],[0xa8][0xc6]l[0xc]5[0xbe][0xa5][0xba][0xd8]Kv0HR[0x1b][0xcc][0xb0]Y[0x96][0x17][0xef][0xff][0xd1]?[0xd5][0x0][0x0][0x0]"
1751 [main] DEBUG org.apache.http.impl.conn.BasicClientConnectionManager  - Releasing connection org.apache.http.impl.conn.ManagedClientConnectionImpl@23986957
1751 [main] DEBUG org.apache.http.impl.conn.BasicClientConnectionManager  - Connection can be kept alive indefinitely
Response false

谢谢, 尼西亚南斯

最佳答案

检查您的回复中的错误。 wasSuccessful 返回 false 的事实意味着您的创建存在问题。

String errors = createResponse.getErrors();
System.out.println(errors[0]);

一个问题是您的工作区引用是按名称进行的 - 它们需要按引用进行(格式为/[type]/[objectid])

newProject.addProperty("Workspace", "/workspace/12345");

关于java - 如何使用 RallyRestApi 在 Rally 中创建新项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44471069/

相关文章:

java - 有没有办法使用 Rally Rest API 通过标签获取某个项目的所有用户故事?

java - Rally中如何获取测试集中测试用例的执行状态

json - Rally JSON I/O 错误创建测试用例结果

rally - SDK 2 : % done column

javascript - 无论如何要在拉力赛网络 API 中查询某个日期?

java - 如果我们有一 block 蛋糕,那么找到数组中最高平均值的最有效算法是什么?

java - 如何在 java 中处理一长串异常

java - 404 运行简单 Spring MVC HelloWeb 时请求的资源不可用

java - Spring Boot - 处理 NoHandlerFoundException

java - 包装应用程序以在 Ubuntu Linux 中创建 sh 文件