-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathApiKeyClient.java
More file actions
50 lines (43 loc) · 1.46 KB
/
ApiKeyClient.java
File metadata and controls
50 lines (43 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.rallydev.rest.client;
import java.io.IOException;
import java.net.URI;
import org.apache.http.client.methods.HttpRequestBase;
/**
* A HttpClient which authenticates using an API Key.
*/
public class ApiKeyClient extends HttpClient {
protected String apiKey;
protected static final String API_KEY_HEADER = "zsessionid";
/**
* Construct a new client.
* @param server the server to connect to
* @param apiKey the key to be used for authentication
*/
public ApiKeyClient(URI server, String apiKey) {
super(server);
this.apiKey = apiKey;
}
/**
* Construct a new client with a pre-configured HttpClient.
*
* @param server the server to connect to
* @param apiKey the key to be used for authentication
*/
public ApiKeyClient(URI server, String apiKey, org.apache.http.client.HttpClient httpClient) {
super(server, httpClient);
this.apiKey = apiKey;
}
/**
* Execute a request against the WSAPI
*
* @param request the request to be executed
* @return the JSON encoded string response
* @throws java.io.IOException if a non-200 response code is returned or if some other
* problem occurs while executing the request
*/
@Override
protected String doRequest(HttpRequestBase request) throws IOException {
request.setHeader(API_KEY_HEADER, this.apiKey);
return super.doRequest(request);
}
}