REST client API: Polishing (SPRNET-1345)

This commit is contained in:
bbaia
2011-01-17 16:59:12 +00:00
parent 0791565b30
commit 7d635d6d83
8 changed files with 99 additions and 91 deletions

View File

@@ -19,8 +19,8 @@ namespace Spring.HttpMessageConverterQuickStart
{
RestTemplate rt = new RestTemplate("http://twitter.com");
rt.MessageConverters.Add(new NJsonHttpMessageConverter());
rt.GetForObjectAsync<JArray>("/statuses/user_timeline.json?screen_name={name}&count={count}", new string[] { "SpringForNet", "10" },
#if SILVERLIGHT
rt.GetForObjectAsync<JArray>("/statuses/user_timeline.json?screen_name={name}&count={count}",
r =>
{
if (r.Error == null)
@@ -37,7 +37,17 @@ namespace Spring.HttpMessageConverterQuickStart
{
Console.WriteLine(r.Error);
}
});
}, "SpringForNet", 10);
#else
JArray jArray = rt.GetForObject<JArray>("/statuses/user_timeline.json?screen_name={name}&count={count}", "SpringForNet", 10);
var tweets = from el in jArray.Children()
select el.Value<string>("text");
foreach (string tweet in tweets)
{
Console.WriteLine(String.Format("* {0}", tweet));
Console.WriteLine();
}
#endif
}
catch (Exception ex)
{

View File

@@ -22,7 +22,7 @@ namespace Spring.RestQuickStart
}
// Exemple async call
rt.GetForObjectAsync<string>("/statuses/user_timeline.xml?screen_name={name}&count={count}", new string[] { "SpringForNet", "5" },
rt.GetForObjectAsync<string>("/statuses/user_timeline.xml?screen_name={name}&count={count}",
delegate(MethodCompletedEventArgs<string> eventArgs)
{
if (eventArgs.Error != null)
@@ -33,7 +33,7 @@ namespace Spring.RestQuickStart
{
Console.WriteLine(eventArgs.Response);
}
});
}, "SpringForNet", 5);
}
catch (Exception ex)
{

View File

@@ -25,7 +25,7 @@ namespace Spring.RestQuickStart
}
// Exemple async call
rt.GetForObjectAsync<XElement>("/statuses/user_timeline.xml?screen_name={name}", new string[] { "SpringForNet" },
rt.GetForObjectAsync<XElement>("/statuses/user_timeline.xml?screen_name={name}",
r =>
{
if (r.Error != null)
@@ -43,7 +43,7 @@ namespace Spring.RestQuickStart
}
}
});
}, "SpringForNet");
}
catch (Exception ex)
{

View File

@@ -19,7 +19,7 @@ namespace Spring.RestSilverlightQuickStart
{
RestTemplate rt = new RestTemplate("http://localhost:12345/Services/Service.svc/");
rt.PostForMessageAsync<string>("user", "Lisa Baia", new string[] { },
rt.PostForMessageAsync<string>("user", "Lisa Baia",
r =>
{
if (r.Error != null)

View File

@@ -21,16 +21,16 @@ namespace Spring.RestWindowsPhoneQuickStart
{
RestTemplate rt = new RestTemplate("http://twitter.com");
rt.GetForObjectAsync<TwitterStatuses>("/statuses/user_timeline.xml?screen_name={name}", new string[] { this.TwitterAccountTextBox.Text },
rt.GetForObjectAsync<TwitterStatuses>("/statuses/user_timeline.xml?screen_name={name}",
args =>
{
if (args.Error == null)
{
this.StatusesListBox.ItemsSource = args.Response;
}
});
}, this.TwitterAccountTextBox.Text);
//rt.GetForObjectAsync<XElement>("/1/statuses/user_timeline.xml?screen_name={name}", new string[] { this.TwitterAccountTextBox.Text },
//rt.GetForObjectAsync<XElement>("/statuses/user_timeline.xml?screen_name={name}",
// args =>
// {
// if (args.Error == null)
@@ -43,7 +43,7 @@ namespace Spring.RestWindowsPhoneQuickStart
// UserName = tweet.Element("user").Element("screen_name").Value
// };
// }
// });
// }, this.TwitterAccountTextBox.Text);
}
}

View File

@@ -32,6 +32,12 @@ namespace Spring.Http.Client
/// <author>Bruno Baia</author>
public class WebClientHttpRequestFactory : IClientHttpRequestFactory
{
/// <summary>
/// The .NET <see cref="HttpWebRequest"/> used by this factory
/// or <see langword="null"/> if not created.
/// </summary>
private HttpWebRequest httpWebRequest;
#region Properties
#if !SILVERLIGHT_3
@@ -116,27 +122,17 @@ namespace Spring.Http.Client
}
#endif
private HttpWebRequest httpWebRequest;
/// <summary>
/// Gets the .NET <see cref="HttpWebRequest"/> used by this factory
/// or <see langword="null"/> if not created.
/// </summary>
public HttpWebRequest HttpWebRequest
{
get { return this.httpWebRequest; }
}
#endregion
#if SILVERLIGHT && !WINDOWS_PHONE
/// <summary>
/// Creates a new instance of <see cref="WebClientHttpRequestFactory"/>.
/// </summary>
public WebClientHttpRequestFactory()
{
#if SILVERLIGHT && !WINDOWS_PHONE
this._webRequestCreator = WebRequestCreatorType.Unknown;
#endif
}
#endif
#region IClientHttpRequestFactory Membres

View File

@@ -48,11 +48,11 @@ namespace Spring.Http.Rest
/// </remarks>
/// <typeparam name="T">The type of the response value.</typeparam>
/// <param name="url">The URL.</param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="getCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous GET method completes.
/// </param>
void GetForObjectAsync<T>(string url, object[] uriVariables, Action<MethodCompletedEventArgs<T>> getCompleted) where T : class;
/// <param name="uriVariables">The variables to expand the template.</param>
void GetForObjectAsync<T>(string url, Action<MethodCompletedEventArgs<T>> getCompleted, params object[] uriVariables) where T : class;
/// <summary>
/// Asynchronously retrieve a representation by doing a GET on the specified URL.
@@ -89,11 +89,11 @@ namespace Spring.Http.Rest
/// </remarks>
/// <typeparam name="T">The type of the response value.</typeparam>
/// <param name="url">The URL.</param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="getCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous GET method completes.
/// </param>
void GetForMessageAsync<T>(string url, object[] uriVariables, Action<MethodCompletedEventArgs<HttpResponseMessage<T>>> getCompleted) where T : class;
/// <param name="uriVariables">The variables to expand the template.</param>
void GetForMessageAsync<T>(string url, Action<MethodCompletedEventArgs<HttpResponseMessage<T>>> getCompleted, params object[] uriVariables) where T : class;
/// <summary>
/// Asynchronously retrieve an entity by doing a GET on the specified URL.
@@ -132,11 +132,11 @@ namespace Spring.Http.Rest
/// URI Template variables are expanded using the given URI variables, if any.
/// </remarks>
/// <param name="url">The URL.</param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="headCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous HEAD method completes.
/// </param>
void HeadForHeadersAsync(string url, object[] uriVariables, Action<MethodCompletedEventArgs<HttpHeaders>> headCompleted);
/// <param name="uriVariables">The variables to expand the template.</param>
void HeadForHeadersAsync(string url, Action<MethodCompletedEventArgs<HttpHeaders>> headCompleted, params object[] uriVariables);
/// <summary>
/// Asynchronously retrieve all headers of the resource specified by the URI template.
@@ -178,11 +178,11 @@ namespace Spring.Http.Rest
/// <param name="request">
/// The object to be POSTed, may be a <see cref="HttpEntity"/> in order to add additional HTTP headers.
/// </param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="postCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous POST method completes.
/// </param>
void PostForLocationAsync(string url, object request, object[] uriVariables, Action<Uri> postCompleted);
/// <param name="uriVariables">The variables to expand the template.</param>
void PostForLocationAsync(string url, object request, Action<Uri> postCompleted, params object[] uriVariables);
/// <summary>
/// Asynchronously create a new resource by POSTing the given object to the URI template,
@@ -232,11 +232,11 @@ namespace Spring.Http.Rest
/// <param name="request">
/// The object to be POSTed, may be a <see cref="HttpEntity"/> in order to add additional HTTP headers.
/// </param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="postCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous POST method completes.
/// </param>
void PostForObjectAsync<T>(string url, object request, object[] uriVariables, Action<MethodCompletedEventArgs<T>> postCompleted) where T : class;
/// <param name="uriVariables">The variables to expand the template.</param>
void PostForObjectAsync<T>(string url, object request, Action<MethodCompletedEventArgs<T>> postCompleted, params object[] uriVariables) where T : class;
/// <summary>
/// Asynchronously create a new resource by POSTing the given object to the URI template,
@@ -286,11 +286,11 @@ namespace Spring.Http.Rest
/// <param name="request">
/// The object to be POSTed, may be a <see cref="HttpEntity"/> in order to add additional HTTP headers.
/// </param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="postCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous POST method completes.
/// </param>
void PostForMessageAsync<T>(string url, object request, object[] uriVariables, Action<MethodCompletedEventArgs<HttpResponseMessage<T>>> postCompleted) where T : class;
/// <param name="uriVariables">The variables to expand the template.</param>
void PostForMessageAsync<T>(string url, object request, Action<MethodCompletedEventArgs<HttpResponseMessage<T>>> postCompleted, params object[] uriVariables) where T : class;
/// <summary>
/// Asynchronously create a new resource by POSTing the given object to the URI template,
@@ -339,11 +339,11 @@ namespace Spring.Http.Rest
/// <param name="request">
/// The object to be POSTed, may be a <see cref="HttpEntity"/> in order to add additional HTTP headers.
/// </param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="postCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous POST method completes.
/// </param>
void PostForMessageAsync(string url, object request, object[] uriVariables, Action<MethodCompletedEventArgs<HttpResponseMessage>> postCompleted);
/// <param name="uriVariables">The variables to expand the template.</param>
void PostForMessageAsync(string url, object request, Action<MethodCompletedEventArgs<HttpResponseMessage>> postCompleted, params object[] uriVariables);
/// <summary>
/// Asynchronously create a new resource by POSTing the given object to the URI template,
@@ -393,11 +393,11 @@ namespace Spring.Http.Rest
/// <param name="request">
/// The object to be POSTed, may be a <see cref="HttpEntity"/> in order to add additional HTTP headers.
/// </param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="putCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous PUT method completes.
/// </param>
void PutAsync(string url, object request, object[] uriVariables, Action<MethodCompletedEventArgs<object>> putCompleted);
/// <param name="uriVariables">The variables to expand the template.</param>
void PutAsync(string url, object request, Action<MethodCompletedEventArgs<object>> putCompleted, params object[] uriVariables);
/// <summary>
/// Asynchronously create or update a resource by PUTting the given object to the URI.
@@ -440,11 +440,11 @@ namespace Spring.Http.Rest
/// URI Template variables are expanded using the given URI variables, if any.
/// </remarks>
/// <param name="url">The URL.</param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="deleteCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous PUT method completes.
/// </param>
void DeleteAsync(string url, object[] uriVariables, Action<MethodCompletedEventArgs<object>> deleteCompleted);
/// <param name="uriVariables">The variables to expand the template.</param>
void DeleteAsync(string url, Action<MethodCompletedEventArgs<object>> deleteCompleted, params object[] uriVariables);
/// <summary>
/// Asynchronously delete the resources at the specified URI.
@@ -479,11 +479,11 @@ namespace Spring.Http.Rest
/// URI Template variables are expanded using the given URI variables, if any.
/// </remarks>
/// <param name="url">The URL.</param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="optionsCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous OPTIONS method completes.
/// </param>
void OptionsForAllowAsync(string url, object[] uriVariables, Action<IList<HttpMethod>> optionsCompleted);
/// <param name="uriVariables">The variables to expand the template.</param>
void OptionsForAllowAsync(string url, Action<IList<HttpMethod>> optionsCompleted, params object[] uriVariables);
/// <summary>
/// Asynchronously return the value of the Allow header for the given URI.
@@ -525,11 +525,11 @@ namespace Spring.Http.Rest
/// <param name="requestEntity">
/// The HTTP entity (headers and/or body) to write to the request, may be <see langword="null"/>.
/// </param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="methodCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous method completes.
/// </param>
void ExchangeAsync<T>(string url, HttpMethod method, HttpEntity requestEntity, object[] uriVariables, Action<MethodCompletedEventArgs<HttpResponseMessage<T>>> methodCompleted) where T : class;
/// <param name="uriVariables">The variables to expand the template.</param>
void ExchangeAsync<T>(string url, HttpMethod method, HttpEntity requestEntity, Action<MethodCompletedEventArgs<HttpResponseMessage<T>>> methodCompleted, params object[] uriVariables) where T : class;
/// <summary>
/// Asynchronously execute the HTTP method to the given URI template, writing the given request message to the request,
@@ -577,11 +577,11 @@ namespace Spring.Http.Rest
/// <param name="requestEntity">
/// The HTTP entity (headers and/or body) to write to the request, may be <see langword="null"/>.
/// </param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="methodCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous method completes.
/// </param>
void ExchangeAsync(string url, HttpMethod method, HttpEntity requestEntity, object[] uriVariables, Action<MethodCompletedEventArgs<HttpResponseMessage>> methodCompleted);
/// <param name="uriVariables">The variables to expand the template.</param>
void ExchangeAsync(string url, HttpMethod method, HttpEntity requestEntity, Action<MethodCompletedEventArgs<HttpResponseMessage>> methodCompleted, params object[] uriVariables);
/// <summary>
/// Asynchronously execute the HTTP method to the given URI template, writing the given request message to the request,
@@ -631,11 +631,11 @@ namespace Spring.Http.Rest
/// <param name="method">The HTTP method (GET, POST, etc.)</param>
/// <param name="requestCallback">Object that prepares the request.</param>
/// <param name="responseExtractor">Object that extracts the return value from the response.</param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="methodCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous method completes.
/// </param>
void ExecuteAsync<T>(string url, HttpMethod method, IRequestCallback requestCallback, IResponseExtractor<T> responseExtractor, object[] uriVariables, Action<MethodCompletedEventArgs<T>> methodCompleted) where T : class;
/// <param name="uriVariables">The variables to expand the template.</param>
void ExecuteAsync<T>(string url, HttpMethod method, IRequestCallback requestCallback, IResponseExtractor<T> responseExtractor, Action<MethodCompletedEventArgs<T>> methodCompleted, params object[] uriVariables) where T : class;
/// <summary>
/// Asynchronously execute the HTTP method to the given URI template, preparing the request with the

View File

@@ -998,15 +998,15 @@ namespace Spring.Http.Rest
/// </remarks>
/// <typeparam name="T">The type of the response value.</typeparam>
/// <param name="url">The URL.</param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="getCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous GET method completes.
/// </param>
public void GetForObjectAsync<T>(string url, object[] uriVariables, Action<MethodCompletedEventArgs<T>> getCompleted) where T : class
/// <param name="uriVariables">The variables to expand the template.</param>
public void GetForObjectAsync<T>(string url, Action<MethodCompletedEventArgs<T>> getCompleted, params object[] uriVariables) where T : class
{
AcceptHeaderRequestCallback requestCallback = new AcceptHeaderRequestCallback(typeof(T), this._messageConverters);
MessageConverterResponseExtractor<T> responseExtractor = new MessageConverterResponseExtractor<T>(this._messageConverters);
this.ExecuteAsync<T>(url, HttpMethod.GET, requestCallback, responseExtractor, uriVariables, getCompleted);
this.ExecuteAsync<T>(url, HttpMethod.GET, requestCallback, responseExtractor, getCompleted, uriVariables);
}
/// <summary>
@@ -1054,15 +1054,15 @@ namespace Spring.Http.Rest
/// </remarks>
/// <typeparam name="T">The type of the response value.</typeparam>
/// <param name="url">The URL.</param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="getCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous GET method completes.
/// </param>
public void GetForMessageAsync<T>(string url, object[] uriVariables, Action<MethodCompletedEventArgs<HttpResponseMessage<T>>> getCompleted) where T : class
/// <param name="uriVariables">The variables to expand the template.</param>
public void GetForMessageAsync<T>(string url, Action<MethodCompletedEventArgs<HttpResponseMessage<T>>> getCompleted, params object[] uriVariables) where T : class
{
AcceptHeaderRequestCallback requestCallback = new AcceptHeaderRequestCallback(typeof(T), this._messageConverters);
HttpMessageResponseExtractor<T> responseExtractor = new HttpMessageResponseExtractor<T>(this._messageConverters);
this.ExecuteAsync<HttpResponseMessage<T>>(url, HttpMethod.GET, requestCallback, responseExtractor, uriVariables, getCompleted);
this.ExecuteAsync<HttpResponseMessage<T>>(url, HttpMethod.GET, requestCallback, responseExtractor, getCompleted, uriVariables);
}
/// <summary>
@@ -1112,13 +1112,13 @@ namespace Spring.Http.Rest
/// URI Template variables are expanded using the given URI variables, if any.
/// </remarks>
/// <param name="url">The URL.</param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="headCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous HEAD method completes.
/// </param>
public void HeadForHeadersAsync(string url, object[] uriVariables, Action<MethodCompletedEventArgs<HttpHeaders>> headCompleted)
/// <param name="uriVariables">The variables to expand the template.</param>
public void HeadForHeadersAsync(string url, Action<MethodCompletedEventArgs<HttpHeaders>> headCompleted, params object[] uriVariables)
{
this.ExecuteAsync<HttpHeaders>(url, HttpMethod.HEAD, null, this.headersExtractor, uriVariables, headCompleted);
this.ExecuteAsync<HttpHeaders>(url, HttpMethod.HEAD, null, this.headersExtractor, headCompleted, uriVariables);
}
/// <summary>
@@ -1167,18 +1167,19 @@ namespace Spring.Http.Rest
/// <param name="request">
/// The object to be POSTed, may be a <see cref="HttpEntity"/> in order to add additional HTTP headers.
/// </param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="postCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous POST method completes.
/// </param>
public void PostForLocationAsync(string url, object request, object[] uriVariables, Action<Uri> postCompleted)
/// <param name="uriVariables">The variables to expand the template.</param>
public void PostForLocationAsync(string url, object request, Action<Uri> postCompleted, params object[] uriVariables)
{
HttpEntityRequestCallback requestCallback = new HttpEntityRequestCallback(request, this._messageConverters);
this.ExecuteAsync<HttpHeaders>(url, HttpMethod.POST, requestCallback, this.headersExtractor, uriVariables,
this.ExecuteAsync<HttpHeaders>(url, HttpMethod.POST, requestCallback, this.headersExtractor,
delegate (MethodCompletedEventArgs<HttpHeaders> args)
{
postCompleted(args.Response.Location);
});
},
uriVariables);
}
/// <summary>
@@ -1245,15 +1246,15 @@ namespace Spring.Http.Rest
/// <param name="request">
/// The object to be POSTed, may be a <see cref="HttpEntity"/> in order to add additional HTTP headers.
/// </param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="postCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous POST method completes.
/// </param>
public void PostForObjectAsync<T>(string url, object request, object[] uriVariables, Action<MethodCompletedEventArgs<T>> postCompleted) where T : class
/// <param name="uriVariables">The variables to expand the template.</param>
public void PostForObjectAsync<T>(string url, object request, Action<MethodCompletedEventArgs<T>> postCompleted, params object[] uriVariables) where T : class
{
HttpEntityRequestCallback requestCallback = new HttpEntityRequestCallback(request, typeof(T), this._messageConverters);
MessageConverterResponseExtractor<T> responseExtractor = new MessageConverterResponseExtractor<T>(this._messageConverters);
this.ExecuteAsync<T>(url, HttpMethod.POST, requestCallback, responseExtractor, uriVariables, postCompleted);
this.ExecuteAsync<T>(url, HttpMethod.POST, requestCallback, responseExtractor, postCompleted, uriVariables);
}
/// <summary>
@@ -1314,15 +1315,15 @@ namespace Spring.Http.Rest
/// <param name="request">
/// The object to be POSTed, may be a <see cref="HttpEntity"/> in order to add additional HTTP headers.
/// </param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="postCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous POST method completes.
/// </param>
public void PostForMessageAsync<T>(string url, object request, object[] uriVariables, Action<MethodCompletedEventArgs<HttpResponseMessage<T>>> postCompleted) where T : class
/// <param name="uriVariables">The variables to expand the template.</param>
public void PostForMessageAsync<T>(string url, object request, Action<MethodCompletedEventArgs<HttpResponseMessage<T>>> postCompleted, params object[] uriVariables) where T : class
{
HttpEntityRequestCallback requestCallback = new HttpEntityRequestCallback(request, typeof(T), this._messageConverters);
HttpMessageResponseExtractor<T> responseExtractor = new HttpMessageResponseExtractor<T>(this._messageConverters);
this.ExecuteAsync<HttpResponseMessage<T>>(url, HttpMethod.POST, requestCallback, responseExtractor, uriVariables, postCompleted);
this.ExecuteAsync<HttpResponseMessage<T>>(url, HttpMethod.POST, requestCallback, responseExtractor, postCompleted, uriVariables);
}
/// <summary>
@@ -1382,15 +1383,15 @@ namespace Spring.Http.Rest
/// <param name="request">
/// The object to be POSTed, may be a <see cref="HttpEntity"/> in order to add additional HTTP headers.
/// </param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="postCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous POST method completes.
/// </param>
public void PostForMessageAsync(string url, object request, object[] uriVariables, Action<MethodCompletedEventArgs<HttpResponseMessage>> postCompleted)
/// <param name="uriVariables">The variables to expand the template.</param>
public void PostForMessageAsync(string url, object request, Action<MethodCompletedEventArgs<HttpResponseMessage>> postCompleted, params object[] uriVariables)
{
HttpEntityRequestCallback requestCallback = new HttpEntityRequestCallback(request, this._messageConverters);
HttpMessageResponseExtractor responseExtractor = new HttpMessageResponseExtractor();
this.ExecuteAsync<HttpResponseMessage>(url, HttpMethod.POST, requestCallback, responseExtractor, uriVariables, postCompleted);
this.ExecuteAsync<HttpResponseMessage>(url, HttpMethod.POST, requestCallback, responseExtractor, postCompleted, uriVariables);
}
/// <summary>
@@ -1451,14 +1452,14 @@ namespace Spring.Http.Rest
/// <param name="request">
/// The object to be POSTed, may be a <see cref="HttpEntity"/> in order to add additional HTTP headers.
/// </param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="putCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous PUT method completes.
/// </param>
public void PutAsync(string url, object request, object[] uriVariables, Action<MethodCompletedEventArgs<object>> putCompleted)
/// <param name="uriVariables">The variables to expand the template.</param>
public void PutAsync(string url, object request, Action<MethodCompletedEventArgs<object>> putCompleted, params object[] uriVariables)
{
HttpEntityRequestCallback requestCallback = new HttpEntityRequestCallback(request, this._messageConverters);
this.ExecuteAsync<object>(url, HttpMethod.PUT, requestCallback, null, uriVariables, putCompleted);
this.ExecuteAsync<object>(url, HttpMethod.PUT, requestCallback, null, putCompleted, uriVariables);
}
/// <summary>
@@ -1510,13 +1511,13 @@ namespace Spring.Http.Rest
/// URI Template variables are expanded using the given URI variables, if any.
/// </remarks>
/// <param name="url">The URL.</param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="deleteCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous PUT method completes.
/// </param>
public void DeleteAsync(string url, object[] uriVariables, Action<MethodCompletedEventArgs<object>> deleteCompleted)
/// <param name="uriVariables">The variables to expand the template.</param>
public void DeleteAsync(string url, Action<MethodCompletedEventArgs<object>> deleteCompleted, params object[] uriVariables)
{
this.ExecuteAsync<object>(url, HttpMethod.DELETE, null, null, uriVariables, deleteCompleted);
this.ExecuteAsync<object>(url, HttpMethod.DELETE, null, null, deleteCompleted, uriVariables);
}
/// <summary>
@@ -1558,17 +1559,18 @@ namespace Spring.Http.Rest
/// URI Template variables are expanded using the given URI variables, if any.
/// </remarks>
/// <param name="url">The URL.</param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="optionsCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous OPTIONS method completes.
/// </param>
public void OptionsForAllowAsync(string url, object[] uriVariables, Action<IList<HttpMethod>> optionsCompleted)
/// <param name="uriVariables">The variables to expand the template.</param>
public void OptionsForAllowAsync(string url, Action<IList<HttpMethod>> optionsCompleted, params object[] uriVariables)
{
this.ExecuteAsync<HttpHeaders>(url, HttpMethod.OPTIONS, null, this.headersExtractor, uriVariables,
this.ExecuteAsync<HttpHeaders>(url, HttpMethod.OPTIONS, null, this.headersExtractor,
delegate(MethodCompletedEventArgs<HttpHeaders> args)
{
optionsCompleted(args.Response.Allow);
});
},
uriVariables);
}
/// <summary>
@@ -1625,15 +1627,15 @@ namespace Spring.Http.Rest
/// <param name="requestEntity">
/// The HTTP entity (headers and/or body) to write to the request, may be <see langword="null"/>.
/// </param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="methodCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous method completes.
/// </param>
public void ExchangeAsync<T>(string url, HttpMethod method, HttpEntity requestEntity, object[] uriVariables, Action<MethodCompletedEventArgs<HttpResponseMessage<T>>> methodCompleted) where T : class
/// <param name="uriVariables">The variables to expand the template.</param>
public void ExchangeAsync<T>(string url, HttpMethod method, HttpEntity requestEntity, Action<MethodCompletedEventArgs<HttpResponseMessage<T>>> methodCompleted, params object[] uriVariables) where T : class
{
HttpEntityRequestCallback requestCallback = new HttpEntityRequestCallback(requestEntity, typeof(T), this._messageConverters);
HttpMessageResponseExtractor<T> responseExtractor = new HttpMessageResponseExtractor<T>(this._messageConverters);
this.ExecuteAsync<HttpResponseMessage<T>>(url, method, requestCallback, responseExtractor, uriVariables, methodCompleted);
this.ExecuteAsync<HttpResponseMessage<T>>(url, method, requestCallback, responseExtractor, methodCompleted, uriVariables);
}
/// <summary>
@@ -1692,15 +1694,15 @@ namespace Spring.Http.Rest
/// <param name="requestEntity">
/// The HTTP entity (headers and/or body) to write to the request, may be <see langword="null"/>.
/// </param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="methodCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous method completes.
/// </param>
public void ExchangeAsync(string url, HttpMethod method, HttpEntity requestEntity, object[] uriVariables, Action<MethodCompletedEventArgs<HttpResponseMessage>> methodCompleted)
/// <param name="uriVariables">The variables to expand the template.</param>
public void ExchangeAsync(string url, HttpMethod method, HttpEntity requestEntity, Action<MethodCompletedEventArgs<HttpResponseMessage>> methodCompleted, params object[] uriVariables)
{
HttpEntityRequestCallback requestCallback = new HttpEntityRequestCallback(requestEntity, this._messageConverters);
HttpMessageResponseExtractor responseExtractor = new HttpMessageResponseExtractor();
this.ExecuteAsync<HttpResponseMessage>(url, method, requestCallback, responseExtractor, uriVariables, methodCompleted);
this.ExecuteAsync<HttpResponseMessage>(url, method, requestCallback, responseExtractor, methodCompleted, uriVariables);
}
/// <summary>
@@ -1761,11 +1763,11 @@ namespace Spring.Http.Rest
/// <param name="method">The HTTP method (GET, POST, etc.)</param>
/// <param name="requestCallback">Object that prepares the request.</param>
/// <param name="responseExtractor">Object that extracts the return value from the response.</param>
/// <param name="uriVariables">The variables to expand the template.</param>
/// <param name="methodCompleted">
/// The <code>Action&lt;T&gt;</code> to perform when the asynchronous method completes.
/// </param>
public void ExecuteAsync<T>(string url, HttpMethod method, IRequestCallback requestCallback, IResponseExtractor<T> responseExtractor, object[] uriVariables, Action<MethodCompletedEventArgs<T>> methodCompleted) where T : class
/// <param name="uriVariables">The variables to expand the template.</param>
public void ExecuteAsync<T>(string url, HttpMethod method, IRequestCallback requestCallback, IResponseExtractor<T> responseExtractor, Action<MethodCompletedEventArgs<T>> methodCompleted, params object[] uriVariables) where T : class
{
this.DoExecuteAsync<T>(BuildUri(this._baseAddress, url, uriVariables), method,
requestCallback, responseExtractor, methodCompleted);
@@ -1986,7 +1988,7 @@ namespace Spring.Http.Rest
/// <param name="uriVariables">The variables to expand the template.</param>
/// <returns>The absolute build URI.</returns>
/// <exception cref="ArgumentException">If an absolute URI can't be build.</exception>
protected virtual Uri BuildUri(Uri baseAddress, string url, object[] uriVariables)
protected virtual Uri BuildUri(Uri baseAddress, string url, params object[] uriVariables)
{
UriTemplate uriTemplate = new UriTemplate(url);
Uri uri = uriTemplate.Expand(uriVariables);