Rally中的HTTP / 1.1 401 SSO重定向问题

时间:2015-07-16 05:57:24

标签: java rally

尝试使用以下代码更新Rally Tool中的测试用例结果:

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.testng.annotations.Test;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.rallydev.rest.RallyRestApi;
import com.rallydev.rest.request.CreateRequest;
import com.rallydev.rest.request.GetRequest;
import com.rallydev.rest.request.QueryRequest;
import com.rallydev.rest.response.CreateResponse;
import com.rallydev.rest.response.GetResponse;
import com.rallydev.rest.response.QueryResponse;
import com.rallydev.rest.util.Fetch;
import com.rallydev.rest.util.QueryFilter;
import com.rallydev.rest.util.Ref;

public class RallyStatusUpdate {
  @Test
  public void f() throws IOException, URISyntaxException {


  // Create and configure a new instance of RallyRestApi
  RallyRestApi restApi = new RallyRestApi(new URI("https://rally1.rallydev.com"),"user@company.com", "123");
  restApi.setWsapiVersion("2.0.1");
  restApi.setApplicationName("Add Test Case Result");

  //Query User
  QueryRequest userRequest = new QueryRequest("user");
  userRequest.setFetch(new Fetch("user", "Subscription", "DisplayName"));
  userRequest.setQueryFilter(new QueryFilter("user", "=", "user@company.com"));
  QueryResponse userQueryResponse = restApi.query(userRequest);
  JsonArray userQueryResults = userQueryResponse.getResults();
  JsonElement userQueryElement = userQueryResults.get(0);
  JsonObject userQueryObject = userQueryElement.getAsJsonObject();
  String userRef = userQueryObject.get("_ref").getAsString();

  // Query for Test Case to which we want to add results
  QueryRequest testCaseRequest = new QueryRequest("TC_001_Automation_Sample_Test");
  testCaseRequest.setFetch(new Fetch("FormattedID","TC_001_Automation_Sample_Test"));
  testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TC5238"));
  QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);
  JsonObject testCaseJsonObject = testCaseQueryResponse.getResults().get(0).getAsJsonObject();
  String testCaseRef = testCaseQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").getAsString();

  try{
      //Add a Test Case Result
      System.out.println("Creating Test Case Result...");
      JsonObject newTestCaseResult = new JsonObject();
      newTestCaseResult.addProperty("Verdict", "Pass");
      newTestCaseResult.addProperty("Date", "2015-07-16T18:00:00.000Z");
      newTestCaseResult.addProperty("Notes", "Automated Selenium Test Runs");
      newTestCaseResult.addProperty("Build", "2015.07.16.0020101");
      newTestCaseResult.addProperty("Tester", userRef);
      newTestCaseResult.addProperty("TestCase", testCaseRef);

      CreateRequest createRequest = new CreateRequest("testcaseresult", newTestCaseResult);
      CreateResponse createResponse = restApi.create(createRequest);

      if(createResponse.wasSuccessful()){
         // println(String.format("Created %s", createResponse.getObject().get("_ref").getAsString()));
          //Read Test Case
          String ref = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
          System.out.println(String.format("\nReading Test Case Result %s...", ref));
          GetRequest getRequest = new GetRequest(ref);
          getRequest.setFetch(new Fetch("Date", "Verdict"));
          GetResponse getResponse = restApi.get(getRequest);
          JsonObject obj = getResponse.getObject();
          //println(String.format("Read Test Case Result. Date = %s, Verdict = %s", obj.get("Date").getAsString(), obj.get("Verdict").getAsString()));
      } else {
          String[] createErrors;
          createErrors = createResponse.getErrors();
          System.out.println("Error occurred creating Test Case: ");
          for (int i=0; i<createErrors.length;i++) {
              System.out.println(createErrors[i]);
          }
      }

  }
  finally{
      restApi.close();
  }
  }
}

但是我得到了#14; HTTP / 1.1 401 SSO重定向!&#34;错误。 由于SO回答指出401错误可能是由于身份验证问题,我改变了不同的登录/环境它不起作用。

1 个答案:

答案 0 :(得分:2)

如果您的组织使用SSO访问Rally,则使用API​​密钥是通过Java SDK连接到CA Agile Central的好方法,而无需进行SAML握手。 API Key详细信息包含在本文中:

http://www.ca.com/us/services-support/ca-support/ca-support-online/knowledge-base-articles.TEC01000001898.html?intcmp=searchresultclick&resultnum=2

此外,您应该将WSAPI版本字符串设置为&#34; v2.0&#34;因为没有&#34; 2.0.1&#34;