문제

I am trying to update a custom field on test case, here's my code:

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;
    }

I am confused because this code was working fine till a couple of days back and now the script just breaks and gets me this error:

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.client.utils.URLEncodedUtils.parse(Ljava/lang/String;Ljava/nio/charset/Charset;)Ljava/util/List;
도움이 되었습니까?

해결책 2

Thanks @nickm . The problem was that my tool was adding another lbapi jar file on run time. This was causing the problem. The update goes through now. Thanks for your help.

다른 팁

If these are the external jars that you have:

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

this list matches what I have in my project. For example in Eclipse there are Access Rules for external libraries. If your IDE has something similar are there restrictions on access? This error may indicate a wrong version of httpclient library or some conflict.

Have you tested the following?

  • different value for the same custom field, e.g. Rally host url, as in the code below.
  • other custom fields of type string
  • other custom fields of any type
  • any fields

I tried with the code below and a custom field of type string was updated successfully.

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();
        }   

} 

}

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top