Skip to content

Commit 29fe72b

Browse files
committed
Add http headers to log messages
Added documentation about null workspaceRef handling Added two tracking headers to all http requests Rev ver number to 1.0.17.0
1 parent 5c3f894 commit 29fe72b

3 files changed

Lines changed: 77 additions & 12 deletions

File tree

Rally.RestApi/HttpService.cs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,41 +77,64 @@ WebClient GetWebClient(IEnumerable<KeyValuePair<string, string>> headers = null)
7777
public string Post(Uri target, string data, IDictionary<string, string> headers = null)
7878
{
7979
String response = "<No response>";
80+
DateTime startTime = DateTime.Now;
81+
String requestHeaders = "";
82+
String responseHeaders = "";
8083
try
8184
{
8285
using (var webClient = GetWebClient(headers))
8386
{
87+
requestHeaders = webClient.Headers.ToString();
8488
response = webClient.UploadString(target, data);
89+
responseHeaders = webClient.ResponseHeaders.ToString();
8590
return response;
8691
}
8792
}
8893
finally
8994
{
90-
Trace.TraceInformation("Rally.RestApi Post: {0}\r\n{1}\r\nResponse:\r\n{2}", target.ToString(), data, response);
95+
Trace.TraceInformation("Post Url ({0}):\r\n{1}\r\nRequest Headers:\r\n{2}Request Data:\r\n{3}\r\nResponse Headers:\r\n{4}Response Data\r\n{5}",
96+
DateTime.Now.Subtract(startTime).ToString(),
97+
target.ToString(),
98+
requestHeaders,
99+
data,
100+
responseHeaders,
101+
response);
91102
}
92103
}
93104

94105
public string Get(Uri target, IDictionary<string, string> headers = null)
95106
{
96107
String response = "<No response>";
97108
DateTime startTime = DateTime.Now;
109+
String requestHeaders = "";
110+
String responseHeaders = "";
98111
try
99112
{
100113
using (var webClient = GetWebClient(headers))
101114
{
115+
requestHeaders = webClient.Headers.ToString();
102116
response = webClient.DownloadString(target);
117+
responseHeaders = webClient.ResponseHeaders.ToString();
103118
return response;
104119
}
105120
}
106121
finally
107122
{
108-
Trace.TraceInformation("Rally.RestApi Get({0}): {1}\r\nResponse:\r\n{2}", DateTime.Now.Subtract(startTime).ToString(), target.ToString(), response);
123+
Trace.TraceInformation("Get Url ({0}):\r\n{1}\r\nRequest Headers:\r\n{2}Response Headers:\r\n{3}Response Data\r\n{4}",
124+
DateTime.Now.Subtract(startTime).ToString(),
125+
target.ToString(),
126+
requestHeaders,
127+
responseHeaders,
128+
response);
109129
}
110130
}
111131

112132
public string Delete(Uri target, IDictionary<string, string> headers = null)
113133
{
114134
String response = "<No response>";
135+
DateTime startTime = DateTime.Now;
136+
String requestHeaders = "";
137+
String responseHeaders = "";
115138
try
116139
{
117140
var request = WebRequest.Create(target);
@@ -124,7 +147,9 @@ public string Delete(Uri target, IDictionary<string, string> headers = null)
124147
request.Headers.Add(pairs.Key, pairs.Value);
125148
}
126149
}
150+
requestHeaders = request.Headers.ToString();
127151
var httpResponse = (HttpWebResponse)request.GetResponse();
152+
responseHeaders = httpResponse.Headers.ToString();
128153
httpResponse.StatusCode.ToString();
129154
var enc = Encoding.ASCII;
130155
var responseStream = new StreamReader(httpResponse.GetResponseStream(), enc);
@@ -134,7 +159,12 @@ public string Delete(Uri target, IDictionary<string, string> headers = null)
134159
}
135160
finally
136161
{
137-
Trace.TraceInformation("Rally.RestApi Delete: {0}\r\nResponse:\r\n{1}", target.ToString(), response);
162+
Trace.TraceInformation("Delete Url ({0}):\r\n{1}\r\nRequest Headers:\r\n{2}Response Headers:\r\n{3}Response Data\r\n{4}",
163+
DateTime.Now.Subtract(startTime).ToString(),
164+
target.ToString(),
165+
requestHeaders,
166+
responseHeaders,
167+
response);
138168
}
139169
}
140170
}

Rally.RestApi/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.0.16.0")]
35-
[assembly: AssemblyFileVersion("1.0.16.0")]
34+
[assembly: AssemblyVersion("1.0.17.0")]
35+
[assembly: AssemblyFileVersion("1.0.17.0")]
3636

3737
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Rally.RestApi.Test")]

Rally.RestApi/RallyRestApi.cs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,35 @@ public class RallyRestApi
2525
/// </summary>
2626
public enum HeaderType
2727
{
28+
/// <summary>
29+
/// X-RallyIntegrationOperation
30+
/// </summary>
31+
[StringValue("X-RallyIntegrationOperation")]
32+
Operation,
33+
/// <summary>
34+
/// X-Trace-Id
35+
/// </summary>
36+
[StringValue("X-Trace-Id")]
37+
Guid,
2838
/// <summary>
2939
/// X-RallyIntegrationLibrary
3040
/// </summary>
41+
[StringValue("X-RallyIntegrationLibrary")]
3142
Library,
3243
/// <summary>
3344
/// X-RallyIntegrationName
3445
/// </summary>
46+
[StringValue("X-RallyIntegrationName")]
3547
Name,
3648
/// <summary>
3749
/// X-RallyIntegrationVendor
3850
/// </summary>
51+
[StringValue("X-RallyIntegrationVendor")]
3952
Vendor,
4053
/// <summary>
4154
/// X-RallyIntegrationVersion
4255
/// </summary>
56+
[StringValue("X-RallyIntegrationVersion")]
4357
Version
4458
}
4559

@@ -72,21 +86,41 @@ public enum HeaderType
7286
private readonly string wsapiVersion;
7387
internal HttpService Service { get; set; }
7488

75-
internal string DecodeHeaderName(HeaderType type)
76-
{
77-
return "X-RallyIntegration" + type;
78-
}
79-
8089
internal Dictionary<string, string> GetProcessedHeaders()
8190
{
8291
var result = new Dictionary<string, string>();
8392
foreach (var pair in Headers)
8493
{
85-
result.Add(DecodeHeaderName(pair.Key), pair.Value);
94+
result.Add(getStringValue(pair.Key), pair.Value);
8695
}
8796
return result;
8897
}
8998

99+
internal class StringValue : System.Attribute
100+
{
101+
private string _value;
102+
103+
public StringValue(string value)
104+
{
105+
_value = value;
106+
}
107+
108+
public string Value
109+
{
110+
get { return _value; }
111+
}
112+
}
113+
114+
internal static string getStringValue(Enum value)
115+
{
116+
string output = null;
117+
FieldInfo fi = value.GetType().GetField(value.ToString());
118+
StringValue[] attrs = fi.GetCustomAttributes(typeof(StringValue),false) as StringValue[];
119+
if (attrs.Length > 0)
120+
output = attrs[0].Value;
121+
return output;
122+
}
123+
90124
#endregion
91125

92126
/// <summary>
@@ -404,6 +438,7 @@ public OperationResult Delete(string workspaceRef, string typePath, long oid)
404438
/// <summary>
405439
/// Delete the object described by the specified reference.
406440
/// </summary>
441+
/// <param name="workspaceRef">the workspace from which the object will be deleted. Null means that the server will pick a workspace.</param>
407442
/// <param name="aRef">the reference</param>
408443
/// <returns>An OperationResult with information on the status of the request</returns>
409444
public OperationResult Delete(string workspaceRef, string aRef)
@@ -423,7 +458,7 @@ public OperationResult Delete(string workspaceRef, string aRef)
423458
/// <summary>
424459
/// Create an object of the specified type from the specified object
425460
/// </summary>
426-
/// <param name="workspaceRef">the workspace into which the object should be created</param>
461+
/// <param name="workspaceRef">the workspace into which the object should be created. Null means that the server will pick a workspace.</param>
427462
/// <param name="typePath">the type to be created</param>
428463
/// <param name="obj">the object to be created</param>
429464
/// <returns></returns>

0 commit comments

Comments
 (0)