From 7a439668aaed3fdb79b045e47805f275968d968f Mon Sep 17 00:00:00 2001 From: Kyle Morse Date: Tue, 22 Apr 2014 08:08:20 -0600 Subject: [PATCH 1/4] Add API Key support --- .gitignore | 4 +- RallyRestToolkitForJava.iml | 29 +++ RallyRestToolkitForJava.ipr | 235 ++++++++++++++++++ src/main/java/META-INF/MANIFEST.MF | 8 +- .../java/com/rallydev/rest/RallyRestApi.java | 36 ++- src/main/resources/doc/allclasses-frame.html | 4 +- .../resources/doc/allclasses-noframe.html | 4 +- .../doc/com/rallydev/rest/RallyRestApi.html | 26 +- .../rallydev/rest/class-use/RallyRestApi.html | 6 +- .../doc/com/rallydev/rest/package-frame.html | 4 +- .../com/rallydev/rest/package-summary.html | 6 +- .../doc/com/rallydev/rest/package-tree.html | 6 +- .../doc/com/rallydev/rest/package-use.html | 6 +- .../rallydev/rest/request/CreateRequest.html | 6 +- .../rallydev/rest/request/DeleteRequest.html | 6 +- .../com/rallydev/rest/request/GetRequest.html | 6 +- .../rallydev/rest/request/QueryRequest.html | 6 +- .../com/rallydev/rest/request/Request.html | 6 +- .../rallydev/rest/request/UpdateRequest.html | 6 +- .../rest/request/class-use/CreateRequest.html | 6 +- .../rest/request/class-use/DeleteRequest.html | 6 +- .../rest/request/class-use/GetRequest.html | 6 +- .../rest/request/class-use/QueryRequest.html | 6 +- .../rest/request/class-use/Request.html | 6 +- .../rest/request/class-use/UpdateRequest.html | 6 +- .../rallydev/rest/request/package-frame.html | 4 +- .../rest/request/package-summary.html | 6 +- .../rallydev/rest/request/package-tree.html | 6 +- .../rallydev/rest/request/package-use.html | 6 +- .../rest/response/CreateResponse.html | 6 +- .../rest/response/DeleteResponse.html | 6 +- .../rallydev/rest/response/GetResponse.html | 6 +- .../rallydev/rest/response/QueryResponse.html | 6 +- .../com/rallydev/rest/response/Response.html | 6 +- .../rest/response/UpdateResponse.html | 6 +- .../response/class-use/CreateResponse.html | 6 +- .../response/class-use/DeleteResponse.html | 6 +- .../rest/response/class-use/GetResponse.html | 6 +- .../response/class-use/QueryResponse.html | 6 +- .../rest/response/class-use/Response.html | 6 +- .../response/class-use/UpdateResponse.html | 6 +- .../rallydev/rest/response/package-frame.html | 4 +- .../rest/response/package-summary.html | 6 +- .../rallydev/rest/response/package-tree.html | 6 +- .../rallydev/rest/response/package-use.html | 6 +- .../doc/com/rallydev/rest/util/Fetch.html | 6 +- .../rest/util/InvalidURLException.html | 6 +- .../com/rallydev/rest/util/QueryFilter.html | 6 +- .../doc/com/rallydev/rest/util/Ref.html | 6 +- .../rallydev/rest/util/class-use/Fetch.html | 38 +-- .../util/class-use/InvalidURLException.html | 6 +- .../rest/util/class-use/QueryFilter.html | 6 +- .../com/rallydev/rest/util/class-use/Ref.html | 6 +- .../com/rallydev/rest/util/package-frame.html | 4 +- .../rallydev/rest/util/package-summary.html | 6 +- .../com/rallydev/rest/util/package-tree.html | 6 +- .../com/rallydev/rest/util/package-use.html | 6 +- src/main/resources/doc/constant-values.html | 6 +- src/main/resources/doc/deprecated-list.html | 6 +- src/main/resources/doc/help-doc.html | 6 +- .../resources/doc/index-files/index-1.html | 6 +- .../resources/doc/index-files/index-10.html | 6 +- .../resources/doc/index-files/index-11.html | 6 +- .../resources/doc/index-files/index-12.html | 6 +- .../resources/doc/index-files/index-13.html | 6 +- .../resources/doc/index-files/index-2.html | 6 +- .../resources/doc/index-files/index-3.html | 6 +- .../resources/doc/index-files/index-4.html | 6 +- .../resources/doc/index-files/index-5.html | 6 +- .../resources/doc/index-files/index-6.html | 6 +- .../resources/doc/index-files/index-7.html | 6 +- .../resources/doc/index-files/index-8.html | 6 +- .../resources/doc/index-files/index-9.html | 10 +- src/main/resources/doc/index.html | 2 +- src/main/resources/doc/overview-frame.html | 5 +- src/main/resources/doc/overview-summary.html | 6 +- src/main/resources/doc/overview-tree.html | 6 +- src/main/resources/doc/serialized-form.html | 6 +- 78 files changed, 612 insertions(+), 177 deletions(-) create mode 100644 RallyRestToolkitForJava.iml create mode 100644 RallyRestToolkitForJava.ipr diff --git a/.gitignore b/.gitignore index d402d68..c745262 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,5 @@ out/ .DS_Store -*.iws -*.ipr -*.iml /target .idea +*.iws diff --git a/RallyRestToolkitForJava.iml b/RallyRestToolkitForJava.iml new file mode 100644 index 0000000..f575ae7 --- /dev/null +++ b/RallyRestToolkitForJava.iml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RallyRestToolkitForJava.ipr b/RallyRestToolkitForJava.ipr new file mode 100644 index 0000000..d091dbd --- /dev/null +++ b/RallyRestToolkitForJava.ipr @@ -0,0 +1,235 @@ + + + + + $PROJECT_DIR$/out/artifacts/rally_rest_api_2_0_5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF index b5db7bb..c503ed5 100644 --- a/src/main/java/META-INF/MANIFEST.MF +++ b/src/main/java/META-INF/MANIFEST.MF @@ -1,9 +1,9 @@ Manifest-Version: "1.2" Implementation-Vendor: "Rally Software, Inc." -Implementation-Title: "com.rallydev.rest" -Implementation-Version: "2.0.3" +Implementation-Title: "com.rallydev.rest" +Implementation-Version: "2.0.5" Class-Path: "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" Specification-Vendor: "Rally Software, Inc." Name: "com/rallydev/rest/" -Specification-Title: "Rally Rest API for Java" -Specification-Version: "2.0.3" +Specification-Title: "Rally Rest API for Java" +Specification-Version: "2.0.5" diff --git a/src/main/java/com/rallydev/rest/RallyRestApi.java b/src/main/java/com/rallydev/rest/RallyRestApi.java index 13b02ba..8e5eabf 100644 --- a/src/main/java/com/rallydev/rest/RallyRestApi.java +++ b/src/main/java/com/rallydev/rest/RallyRestApi.java @@ -64,6 +64,7 @@ private enum Header { protected static final String SECURITY_TOKEN_PARAM_KEY = "key"; private static final String SECURITY_TOKEN_URL = "/security/authorize"; protected static final String SECURITY_TOKEN_KEY = "SecurityToken"; + protected static final String API_KEY_HEADER = "zsessionid"; protected URI server; protected URI proxy; @@ -71,14 +72,15 @@ private enum Header { protected String wsapiVersion = DEFAULT_WSAPI_VERSION; protected DefaultHttpClient httpClient; private UsernamePasswordCredentials usernamePasswordCredentials; + private String apiKey; private String securityToken; protected Map headers = new HashMap() { { - put(Header.Library, "Rally Rest API for Java v2.0.3"); + put(Header.Library, "Rally Rest API for Java v2.0.5"); put(Header.Name, "Rally Rest API for Java"); put(Header.Vendor, "Rally Software, Inc."); - put(Header.Version, "2.0.3"); + put(Header.Version, "2.0.5"); } }; @@ -90,9 +92,24 @@ private enum Header { * @param password The password to be used for authentication. */ public RallyRestApi(URI server, String userName, String password) { + this(server); + setClientCredentials(server, userName, password); + } + + /** + * Creates a new instance for the specified server using the specified API Key. + * + * @param server The server to connect to, e.g. {@code new URI("https://rally1.rallydev.com")} + * @param apiKey The API Key to be used for authentication. + */ + public RallyRestApi(URI server, String apiKey) { + this(server); + this.apiKey = apiKey; + } + + private RallyRestApi(URI server) { this.server = server; httpClient = new DefaultHttpClient(); - setClientCredentials(server, userName, password); } /** @@ -162,7 +179,7 @@ public void setApplicationName(String value) { * @throws IOException if an error occurs during the creation. */ public CreateResponse create(CreateRequest request) throws IOException { - return create(request, true); + return create(request, apiKey == null); } private CreateResponse create(CreateRequest request, boolean retryOnFail) throws IOException { @@ -182,7 +199,7 @@ private CreateResponse create(CreateRequest request, boolean retryOnFail) throws * @throws IOException if an error occurs during the update. */ public UpdateResponse update(UpdateRequest request) throws IOException { - return update(request, true); + return update(request, apiKey == null); } private UpdateResponse update(UpdateRequest request, boolean retryOnFail) throws IOException { @@ -202,7 +219,7 @@ private UpdateResponse update(UpdateRequest request, boolean retryOnFail) throws * @throws IOException if an error occurs during the deletion. */ public DeleteResponse delete(DeleteRequest request) throws IOException { - return delete(request, true); + return delete(request, apiKey == null); } private DeleteResponse delete(DeleteRequest request, boolean retryOnFail) throws IOException { @@ -306,6 +323,9 @@ protected String doRequest(HttpRequestBase request) throws IOException { for (Map.Entry header : headers.entrySet()) { request.setHeader("X-RallyIntegration" + header.getKey().name(), header.getValue()); } + if(this.apiKey != null) { + request.setHeader(API_KEY_HEADER, this.apiKey); + } HttpResponse response = httpClient.execute(request); HttpEntity entity = response.getEntity(); @@ -345,7 +365,7 @@ protected String doForceReauthRequest(HttpRequestBase request) throws IOExceptio */ private String doSecuredRequest(HttpRequestBase request) throws IOException { if (!request.getMethod().equals(HttpGet.METHOD_NAME) && - !this.getWsapiVersion().matches("^1[.]\\d+")) { + !this.getWsapiVersion().matches("^1[.]\\d+") && apiKey == null) { try { attachSecurityInfo(request); } catch (URISyntaxException e) { @@ -416,7 +436,7 @@ protected String doPost(String url, String body) throws IOException { httpPost.setEntity(new StringEntity(body, "utf-8")); return doSecuredRequest(httpPost); } - + /** * Perform a put against the WSAPI diff --git a/src/main/resources/doc/allclasses-frame.html b/src/main/resources/doc/allclasses-frame.html index 95c9880..c533fd9 100644 --- a/src/main/resources/doc/allclasses-frame.html +++ b/src/main/resources/doc/allclasses-frame.html @@ -2,9 +2,9 @@ - + All Classes (Rally Rest API for Java 2.0) - + diff --git a/src/main/resources/doc/allclasses-noframe.html b/src/main/resources/doc/allclasses-noframe.html index 28857f4..a8998b0 100644 --- a/src/main/resources/doc/allclasses-noframe.html +++ b/src/main/resources/doc/allclasses-noframe.html @@ -2,9 +2,9 @@ - + All Classes (Rally Rest API for Java 2.0) - + diff --git a/src/main/resources/doc/com/rallydev/rest/RallyRestApi.html b/src/main/resources/doc/com/rallydev/rest/RallyRestApi.html index c354c4f..6972313 100644 --- a/src/main/resources/doc/com/rallydev/rest/RallyRestApi.html +++ b/src/main/resources/doc/com/rallydev/rest/RallyRestApi.html @@ -2,9 +2,9 @@ - + RallyRestApi (Rally Rest API for Java 2.0) - + @@ -33,6 +33,7 @@
  • Index
  • Help
  • +
    Rally Rest API for Java 2.0