Rally 拉力:无法使用Java更新自定义字段

Rally 拉力:无法使用Java更新自定义字段,rally,Rally,我正在尝试更新测试用例上的自定义字段,以下是我的代码: JsonObject update_story = new JsonObject(); update_story.addProperty("c_UTMSURI",url); //url is a string UpdateRequest updateReq = new UpdateRequest(ref,update_story); try{ UpdateResponse response = rest.update(upd

我正在尝试更新测试用例上的自定义字段,以下是我的代码:

JsonObject update_story = new JsonObject();
update_story.addProperty("c_UTMSURI",url); //url is a string
UpdateRequest updateReq = new UpdateRequest(ref,update_story);
try{
        UpdateResponse response = rest.update(update);
        return (response.wasSuccessful());      
    }
catch(Exception e){
        String errorMsg = "Caught exception while updating external ID for "+ref+"\n More Details "+e.getMessage();
        Logger.Log(errorMsg);
        System.out.println(errorMsg);
        return false;
    }
我很困惑,因为这段代码在几天前还可以正常工作,而现在脚本刚刚中断,并导致我出现以下错误:

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.client.utils.URLEncodedUtils.parse(Ljava/lang/String;Ljava/nio/charset/Charset;)Ljava/util/List;

如果这些是您拥有的外部罐子:

httpcore-4.2.4.jar
httpclient-4.2.5.jar
commons-logging-1.1.1.jar
commons-codec-1.6.jar
gson-2.2.4.jar
rally-rest-api-2.0.4.jar
此列表与我的项目中的内容相匹配。 例如,在Eclipse中,有用于外部库的访问规则。如果您的IDE有类似的功能,那么访问是否有限制?此错误可能表示httpclient库的版本错误或存在冲突

您是否测试了以下各项

  • 同一自定义字段的不同值,例如拉力赛主机url,如下代码所示
  • 字符串类型的其他自定义字段
  • 任何类型的其他自定义字段
  • 任何领域
我尝试了下面的代码,成功地更新了字符串类型的自定义字段

import com.google.gson.JsonObject;
import com.rallydev.rest.RallyRestApi;
import com.rallydev.rest.request.CreateRequest;
import com.rallydev.rest.request.UpdateRequest;
import com.rallydev.rest.response.CreateResponse;
import com.rallydev.rest.response.UpdateResponse;
import com.rallydev.rest.util.Ref;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class CreateUpdateTC {

    public static void main(String[] args) throws URISyntaxException, IOException {


            String url = "https://rally1.rallydev.com";
            String username = "user@co.com";
            String password = "secret";
            String projectRef = "/project/12345";
            String applicationName = "create update test case";


        RallyRestApi restApi = new RallyRestApi(
                new URI(url),
                username,
                password);
        restApi.setApplicationName(applicationName);   


        try {
            for (int i=0; i<1; i++) { 
                System.out.println("Creating a test case...");
                JsonObject newTC = new JsonObject();
                newTC.addProperty("Name", "some testcase");
                newTC.addProperty("Project", projectRef); 


                CreateRequest createRequest = new CreateRequest("testcase", newTC);
                CreateResponse createResponse = restApi.create(createRequest);  
                if (createResponse.wasSuccessful()) {

                    System.out.println(String.format("Created %s", createResponse.getObject().get("_ref").getAsString()));          

                    //Read tc
                    String tcRef = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
                    System.out.println(String.format("\nReading test case %s...", tcRef));
                    //Update tc
                    JsonObject tcUpdate = new JsonObject();
                    tcUpdate.addProperty("c_CustomString", url);
                    UpdateRequest updateRequest = new UpdateRequest(tcRef,tcUpdate);
                    UpdateResponse updateResponse = restApi.update(updateRequest);
                    if (updateResponse.wasSuccessful()) {
                        System.out.println("Successfully updated test case: " + newTC.get("Name") +
                                " CustomString: " + tcUpdate.get("c_CustomString"));
                    }
                    else {
                        String[] updateErrors;
                        updateErrors = createResponse.getErrors();
                        System.out.println("Error");
                        for (int j=0; i<updateErrors.length;j++) {
                            System.out.println(updateErrors[j]);
                        }
                    }

                } else {
                    String[] createErrors;
                    createErrors = createResponse.getErrors();
                    System.out.println("Error");
                    for (int j=0; i<createErrors.length;j++) {
                        System.out.println(createErrors[j]);
                    }
                }
            }

        } finally {
            //Release all resources
            restApi.close();
        }   

} 
import com.google.gson.JsonObject;
导入com.rallydev.rest.RallyRestApi;
导入com.rallydev.rest.request.CreateRequest;
导入com.rallydev.rest.request.UpdateRequest;
导入com.rallydev.rest.response.CreateResponse;
导入com.rallydev.rest.response.UpdateResponse;
导入com.rallydev.rest.util.Ref;
导入java.io.IOException;
导入java.net.URI;
导入java.net.URISyntaxException;
公共类等{
公共静态void main(字符串[]args)抛出URISyntaxException、IOException{
字符串url=”https://rally1.rallydev.com";
字符串用户名=”user@co.com";
字符串password=“secret”;
字符串projectRef=“/project/12345”;
String applicationName=“创建更新测试用例”;
RallyRestApi restApi=新的RallyRestApi(
新URI(url),
用户名,
密码);
restApi.setApplicationName(applicationName);
试一试{

对于(int i=0;i谢谢@nickm。问题是我的工具在运行时添加了另一个lbapi jar文件。这是导致问题的原因。更新现在已经完成。感谢您的帮助