Removed Spring.Http project (moved to GitHub project spring-net-rest) (SPRNET-1345)
This commit is contained in:
@@ -106,11 +106,6 @@ Rebuilding Solutions using Nant and "solutions.build":
|
||||
<!-- <include name="*.2005.sln" /> -->
|
||||
<include name="*.2008.sln" />
|
||||
<exclude name="Spring.NET.2008.sln"/>
|
||||
<!-- Exclude REST quickstart -->
|
||||
<exclude name="examples/Spring/Spring.HttpMessageConverterQuickStart/**/*.sln"/>
|
||||
<exclude name="examples/Spring/Spring.RestQuickStart/**/*.sln"/>
|
||||
<exclude name="examples/Spring/Spring.RestSilverlightQuickStart/**/*.sln"/>
|
||||
<exclude name="examples/Spring/Spring.RestWindowsPhoneQuickStart/**/*.sln"/>
|
||||
</items>
|
||||
</in>
|
||||
<do>
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual Studio 2008
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.HttpMessageConverterQuickStart", "src\Spring.HttpMessageConverterQuickStart\Spring.HttpMessageConverterQuickStart.csproj", "{FAD4F098-21BF-4FDC-85CE-7DB6A27D6179}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Http.2008", "..\..\..\src\Spring\Spring.Http\Spring.Http.2008.csproj", "{FAC04F79-4B1F-1D13-B30F-00EE04EC0FBC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Http.Tests.2008", "..\..\..\test\Spring\Spring.Http.Tests\Spring.Http.Tests.2008.csproj", "{F04CEE18-3897-A399-46BF-459437475B21}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{FAD4F098-21BF-4FDC-85CE-7DB6A27D6179}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FAD4F098-21BF-4FDC-85CE-7DB6A27D6179}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FAD4F098-21BF-4FDC-85CE-7DB6A27D6179}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FAD4F098-21BF-4FDC-85CE-7DB6A27D6179}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FAC04F79-4B1F-1D13-B30F-00EE04EC0FBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FAC04F79-4B1F-1D13-B30F-00EE04EC0FBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FAC04F79-4B1F-1D13-B30F-00EE04EC0FBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FAC04F79-4B1F-1D13-B30F-00EE04EC0FBC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F04CEE18-3897-A399-46BF-459437475B21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F04CEE18-3897-A399-46BF-459437475B21}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F04CEE18-3897-A399-46BF-459437475B21}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F04CEE18-3897-A399-46BF-459437475B21}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -1,80 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Spring.Http;
|
||||
using Spring.Http.Converters;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Spring.HttpMessageConverterQuickStart.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="IHttpMessageConverter"/> that can read and write JSON
|
||||
/// using the Json.NET (Newtonsoft.Json) library.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This implementation supports getting/setting values from JSON directly,
|
||||
/// without the need to deserialize/serialize to a .NET class.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// By default, this converter supports 'application/json' media type.
|
||||
/// This can be overridden by setting the <see cref="P:SupportedMediaTypes"/> property.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <author>Bruno Baia</author>
|
||||
public class NJsonHttpMessageConverter : IHttpMessageConverter
|
||||
{
|
||||
private IList<MediaType> supportedMediaTypes;
|
||||
|
||||
public NJsonHttpMessageConverter()
|
||||
{
|
||||
this.supportedMediaTypes = new List<MediaType>(1);
|
||||
this.supportedMediaTypes.Add(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
|
||||
#region IHttpMessageConverter Membres
|
||||
|
||||
public bool CanRead(Type type, MediaType mediaType)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanWrite(Type type, MediaType mediaType)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public IList<MediaType> SupportedMediaTypes
|
||||
{
|
||||
get { return this.supportedMediaTypes; }
|
||||
}
|
||||
|
||||
public T Read<T>(IHttpInputMessage message) where T : class
|
||||
{
|
||||
// Read from the message stream
|
||||
using (StreamReader reader = new StreamReader(message.Body))
|
||||
using (JsonTextReader jsonReader = new JsonTextReader(reader))
|
||||
{
|
||||
JsonSerializer jsonSerializer = new JsonSerializer();
|
||||
return jsonSerializer.Deserialize<T>(jsonReader);
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(object content, MediaType contentType, IHttpOutputMessage message)
|
||||
{
|
||||
// Write to the message stream
|
||||
message.Body = delegate(Stream stream)
|
||||
{
|
||||
using (StreamWriter writer = new StreamWriter(stream))
|
||||
using (JsonTextWriter jsonWriter = new JsonTextWriter(writer))
|
||||
{
|
||||
JsonSerializer jsonSerializer = new JsonSerializer();
|
||||
jsonSerializer.Serialize(jsonWriter, content);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
||||
using Spring.Http;
|
||||
using Spring.Http.Client;
|
||||
using Spring.Http.Rest;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using Spring.HttpMessageConverterQuickStart.Converters;
|
||||
|
||||
namespace Spring.HttpMessageConverterQuickStart
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
RestTemplate rt = new RestTemplate("http://twitter.com");
|
||||
rt.MessageConverters.Add(new NJsonHttpMessageConverter());
|
||||
#if SILVERLIGHT
|
||||
rt.GetForObjectAsync<JArray>("/statuses/user_timeline.json?screen_name={name}&count={count}",
|
||||
r =>
|
||||
{
|
||||
if (r.Error == null)
|
||||
{
|
||||
var tweets = from el in r.Response.Children()
|
||||
select el.Value<string>("text");
|
||||
foreach (string tweet in tweets)
|
||||
{
|
||||
Console.WriteLine(String.Format("* {0}", tweet));
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Console.WriteLine("--- hit <return> to quit ---");
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{FAD4F098-21BF-4FDC-85CE-7DB6A27D6179}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Spring.HttpMessageConverterQuickStart</RootNamespace>
|
||||
<AssemblyName>Spring.HttpMessageConverterQuickStart</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\net-3.5\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Converters\NJsonHttpMessageConverter.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\..\src\Spring\Spring.Http\Spring.Http.2008.csproj">
|
||||
<Project>{FAC04F79-4B1F-1D13-B30F-00EE04EC0FBC}</Project>
|
||||
<Name>Spring.Http.2008</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -1,34 +0,0 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual Studio 2005
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Http.2005", "..\..\..\src\Spring\Spring.Http\Spring.Http.2005.csproj", "{EE04EC0F-4B1F-1D13-B30F-00FAC04F79BC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Http.Tests.2005", "..\..\..\test\Spring\Spring.Http.Tests\Spring.Http.Tests.2005.csproj", "{9437475B-3897-A399-46BF-45F04CEE1821}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.RestQuickStart.2005", "src\Spring.RestQuickStart.2005\Spring.RestQuickStart.2005.csproj", "{5B47D309-31C9-4282-86E2-11FC63DFF55B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{EE04EC0F-4B1F-1D13-B30F-00FAC04F79BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EE04EC0F-4B1F-1D13-B30F-00FAC04F79BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EE04EC0F-4B1F-1D13-B30F-00FAC04F79BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EE04EC0F-4B1F-1D13-B30F-00FAC04F79BC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9437475B-3897-A399-46BF-45F04CEE1821}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9437475B-3897-A399-46BF-45F04CEE1821}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9437475B-3897-A399-46BF-45F04CEE1821}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9437475B-3897-A399-46BF-45F04CEE1821}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5B47D309-31C9-4282-86E2-11FC63DFF55B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5B47D309-31C9-4282-86E2-11FC63DFF55B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5B47D309-31C9-4282-86E2-11FC63DFF55B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5B47D309-31C9-4282-86E2-11FC63DFF55B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
NAntAddinLastFileName = Spring.build
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,34 +0,0 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual Studio 2008
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Http.2008", "..\..\..\src\Spring\Spring.Http\Spring.Http.2008.csproj", "{FAC04F79-4B1F-1D13-B30F-00EE04EC0FBC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.RestQuickStart.2008", "src\Spring.RestQuickStart\Spring.RestQuickStart.2008.csproj", "{5B47D309-31C9-4282-86E2-11FC63DFF55B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Http.Tests.2008", "..\..\..\test\Spring\Spring.Http.Tests\Spring.Http.Tests.2008.csproj", "{F04CEE18-3897-A399-46BF-459437475B21}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{FAC04F79-4B1F-1D13-B30F-00EE04EC0FBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FAC04F79-4B1F-1D13-B30F-00EE04EC0FBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FAC04F79-4B1F-1D13-B30F-00EE04EC0FBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FAC04F79-4B1F-1D13-B30F-00EE04EC0FBC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5B47D309-31C9-4282-86E2-11FC63DFF55B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5B47D309-31C9-4282-86E2-11FC63DFF55B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5B47D309-31C9-4282-86E2-11FC63DFF55B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5B47D309-31C9-4282-86E2-11FC63DFF55B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F04CEE18-3897-A399-46BF-459437475B21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F04CEE18-3897-A399-46BF-459437475B21}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F04CEE18-3897-A399-46BF-459437475B21}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F04CEE18-3897-A399-46BF-459437475B21}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
NAntAddinLastFileName = Spring.build
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,34 +0,0 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Http.2010", "..\..\..\src\Spring\Spring.Http\Spring.Http.2010.csproj", "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.RestQuickStart.2010", "src\Spring.RestQuickStart\Spring.RestQuickStart.2010.csproj", "{5B47D309-31C9-4282-86E2-11FC63DFF55B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Http.Tests.2010", "..\..\..\test\Spring\Spring.Http.Tests\Spring.Http.Tests.2010.csproj", "{4594CEE7-3897-A3BF-9946-5B4374F01821}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5B47D309-31C9-4282-86E2-11FC63DFF55B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5B47D309-31C9-4282-86E2-11FC63DFF55B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5B47D309-31C9-4282-86E2-11FC63DFF55B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5B47D309-31C9-4282-86E2-11FC63DFF55B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4594CEE7-3897-A3BF-9946-5B4374F01821}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4594CEE7-3897-A3BF-9946-5B4374F01821}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4594CEE7-3897-A3BF-9946-5B4374F01821}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4594CEE7-3897-A3BF-9946-5B4374F01821}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
NAntAddinLastFileName = Spring.build
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
using Spring.Http;
|
||||
using Spring.Http.Rest;
|
||||
|
||||
namespace Spring.RestQuickStart
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
RestTemplate rt = new RestTemplate("http://twitter.com");
|
||||
|
||||
// Exemple sync call
|
||||
Console.WriteLine("Allowed methods : ");
|
||||
foreach (HttpMethod method in rt.OptionsForAllow("/statuses/"))
|
||||
{
|
||||
Console.WriteLine(method);
|
||||
}
|
||||
|
||||
// Exemple async call
|
||||
rt.GetForObjectAsync<string>("/statuses/user_timeline.xml?screen_name={name}&count={count}",
|
||||
delegate(MethodCompletedEventArgs<string> eventArgs)
|
||||
{
|
||||
if (eventArgs.Error != null)
|
||||
{
|
||||
Console.WriteLine(eventArgs.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(eventArgs.Response);
|
||||
}
|
||||
}, "SpringForNet", 5);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Console.WriteLine("--- hit <return> to quit ---");
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{5B47D309-31C9-4282-86E2-11FC63DFF55B}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Spring.RestQuickStart</RootNamespace>
|
||||
<AssemblyName>Spring.RestQuickStart</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.XML" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\..\src\Spring\Spring.Http\Spring.Http.2005.csproj">
|
||||
<Project>{EE04EC0F-4B1F-1D13-B30F-00FAC04F79BC}</Project>
|
||||
<Name>Spring.Http.2005</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -1,59 +0,0 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
using Spring.Http;
|
||||
using Spring.Http.Rest;
|
||||
|
||||
namespace Spring.RestQuickStart
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
RestTemplate rt = new RestTemplate("http://twitter.com");
|
||||
|
||||
// Exemple sync call
|
||||
Console.WriteLine("Resource headers : ");
|
||||
HttpHeaders headers = rt.HeadForHeaders("/statuses/");
|
||||
foreach (string header in headers)
|
||||
{
|
||||
Console.WriteLine(String.Format("{0}: {1}", header, headers[header]));
|
||||
}
|
||||
|
||||
// Exemple async call
|
||||
rt.GetForObjectAsync<XElement>("/statuses/user_timeline.xml?screen_name={name}",
|
||||
r =>
|
||||
{
|
||||
if (r.Error != null)
|
||||
{
|
||||
Console.WriteLine(r.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
var tweets = from el in r.Response.Elements("status")
|
||||
select el.Element("text").Value;
|
||||
foreach (string tweet in tweets)
|
||||
{
|
||||
Console.WriteLine(String.Format("* {0}", tweet));
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
}, "SpringForNet");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Console.WriteLine("--- hit <return> to quit ---");
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{5B47D309-31C9-4282-86E2-11FC63DFF55B}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Spring.RestQuickStart</RootNamespace>
|
||||
<AssemblyName>Spring.RestQuickStart</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;NET_2_0;NET_3_0;NET_3_5</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NET_2_0;NET_3_0;NET_3_5</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.XML" />
|
||||
<Reference Include="System.Xml.Linq">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\..\src\Spring\Spring.Http\Spring.Http.2008.csproj">
|
||||
<Project>{FAC04F79-4B1F-1D13-B30F-00EE04EC0FBC}</Project>
|
||||
<Name>Spring.Http.2008</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -1,78 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{5B47D309-31C9-4282-86E2-11FC63DFF55B}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Spring.RestQuickStart</RootNamespace>
|
||||
<AssemblyName>Spring.RestQuickStart</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<UpgradeBackupLocation />
|
||||
<TargetFrameworkProfile />
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;NET_2_0;NET_3_0;NET_3_5;NET_4_0</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NET_2_0;NET_3_0;NET_3_5;NET_4_0</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.XML" />
|
||||
<Reference Include="System.Xml.Linq">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\..\src\Spring\Spring.Http\Spring.Http.2010.csproj">
|
||||
<Project>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Project>
|
||||
<Name>Spring.Http.2010</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -1,38 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual Studio 2008
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.RestSilverlightQuickStart.2008", "src\Spring.RestSilverlightQuickStart\Spring.RestSilverlightQuickStart.2008.csproj", "{0B34E41F-8D4E-427A-A7C4-A3F9ADEE8EB3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Http.2008-SL", "..\..\..\src\Spring\Spring.Http\Spring.Http.2008-SL.csproj", "{5A955F0B-EEC7-427C-9E6B-A26B8B51558D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.RestSilverlightQuickStart.Web.2008", "src\Spring.RestSilverlightQuickStart.Web.2008\Spring.RestSilverlightQuickStart.Web.2008.csproj", "{AFE006E7-F67F-45F9-826C-1273791D1574}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Http.Tests.2008-SL", "..\..\..\test\Spring\Spring.Http.Tests\Spring.Http.Tests.2008-SL.csproj", "{AEA0D437-A442-4381-B682-5873D66DB72C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{0B34E41F-8D4E-427A-A7C4-A3F9ADEE8EB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0B34E41F-8D4E-427A-A7C4-A3F9ADEE8EB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0B34E41F-8D4E-427A-A7C4-A3F9ADEE8EB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0B34E41F-8D4E-427A-A7C4-A3F9ADEE8EB3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5A955F0B-EEC7-427C-9E6B-A26B8B51558D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5A955F0B-EEC7-427C-9E6B-A26B8B51558D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5A955F0B-EEC7-427C-9E6B-A26B8B51558D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5A955F0B-EEC7-427C-9E6B-A26B8B51558D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AFE006E7-F67F-45F9-826C-1273791D1574}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AFE006E7-F67F-45F9-826C-1273791D1574}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AFE006E7-F67F-45F9-826C-1273791D1574}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AFE006E7-F67F-45F9-826C-1273791D1574}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AEA0D437-A442-4381-B682-5873D66DB72C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AEA0D437-A442-4381-B682-5873D66DB72C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AEA0D437-A442-4381-B682-5873D66DB72C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AEA0D437-A442-4381-B682-5873D66DB72C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,38 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Http.2010-SL", "..\..\..\src\Spring\Spring.Http\Spring.Http.2010-SL.csproj", "{01FA5AEB-20A3-42FF-B2E9-A2FE9A7236D1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.RestSilverlightQuickStart.2010", "src\Spring.RestSilverlightQuickStart\Spring.RestSilverlightQuickStart.2010.csproj", "{C11BD449-683C-44CA-B394-CC126DC49EF1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.RestSilverlightQuickStart.Web.2010", "src\Spring.RestSilverlightQuickStart.Web.2010\Spring.RestSilverlightQuickStart.Web.2010.csproj", "{2B40C3B9-E032-417A-9B6F-8AD4ECEE0397}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Http.Tests.2010-SL", "..\..\..\test\Spring\Spring.Http.Tests\Spring.Http.Tests.2010-SL.csproj", "{5964F3BF-D3E0-4890-955A-BD287B834B36}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{01FA5AEB-20A3-42FF-B2E9-A2FE9A7236D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{01FA5AEB-20A3-42FF-B2E9-A2FE9A7236D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{01FA5AEB-20A3-42FF-B2E9-A2FE9A7236D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{01FA5AEB-20A3-42FF-B2E9-A2FE9A7236D1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C11BD449-683C-44CA-B394-CC126DC49EF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C11BD449-683C-44CA-B394-CC126DC49EF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C11BD449-683C-44CA-B394-CC126DC49EF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C11BD449-683C-44CA-B394-CC126DC49EF1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2B40C3B9-E032-417A-9B6F-8AD4ECEE0397}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2B40C3B9-E032-417A-9B6F-8AD4ECEE0397}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2B40C3B9-E032-417A-9B6F-8AD4ECEE0397}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2B40C3B9-E032-417A-9B6F-8AD4ECEE0397}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5964F3BF-D3E0-4890-955A-BD287B834B36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5964F3BF-D3E0-4890-955A-BD287B834B36}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5964F3BF-D3E0-4890-955A-BD287B834B36}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5964F3BF-D3E0-4890-955A-BD287B834B36}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,74 +0,0 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" %>
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" >
|
||||
<head runat="server">
|
||||
<title>Spring.RestSilverlightQuickStart</title>
|
||||
<style type="text/css">
|
||||
html, body {
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
}
|
||||
body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
#silverlightControlHost {
|
||||
height: 100%;
|
||||
text-align:center;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript" src="Silverlight.js"></script>
|
||||
<script type="text/javascript">
|
||||
function onSilverlightError(sender, args) {
|
||||
var appSource = "";
|
||||
if (sender != null && sender != 0) {
|
||||
appSource = sender.getHost().Source;
|
||||
}
|
||||
|
||||
var errorType = args.ErrorType;
|
||||
var iErrorCode = args.ErrorCode;
|
||||
|
||||
if (errorType == "ImageError" || errorType == "MediaError") {
|
||||
return;
|
||||
}
|
||||
|
||||
var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n" ;
|
||||
|
||||
errMsg += "Code: "+ iErrorCode + " \n";
|
||||
errMsg += "Category: " + errorType + " \n";
|
||||
errMsg += "Message: " + args.ErrorMessage + " \n";
|
||||
|
||||
if (errorType == "ParserError") {
|
||||
errMsg += "File: " + args.xamlFile + " \n";
|
||||
errMsg += "Line: " + args.lineNumber + " \n";
|
||||
errMsg += "Position: " + args.charPosition + " \n";
|
||||
}
|
||||
else if (errorType == "RuntimeError") {
|
||||
if (args.lineNumber != 0) {
|
||||
errMsg += "Line: " + args.lineNumber + " \n";
|
||||
errMsg += "Position: " + args.charPosition + " \n";
|
||||
}
|
||||
errMsg += "MethodName: " + args.methodName + " \n";
|
||||
}
|
||||
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<form id="form1" runat="server" style="height:100%">
|
||||
<div id="silverlightControlHost">
|
||||
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
|
||||
<param name="source" value="ClientBin/Spring.RestSilverlightQuickStart.xap"/>
|
||||
<param name="onError" value="onSilverlightError" />
|
||||
<param name="background" value="white" />
|
||||
<param name="minRuntimeVersion" value="3.0.40624.0" />
|
||||
<param name="autoUpgrade" value="true" />
|
||||
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
|
||||
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
|
||||
</a>
|
||||
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,73 +0,0 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" >
|
||||
|
||||
<head>
|
||||
<title>Spring.RestSilverlightQuickStart</title>
|
||||
<style type="text/css">
|
||||
html, body {
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
}
|
||||
body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
#silverlightControlHost {
|
||||
height: 100%;
|
||||
text-align:center;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript" src="Silverlight.js"></script>
|
||||
<script type="text/javascript">
|
||||
function onSilverlightError(sender, args) {
|
||||
var appSource = "";
|
||||
if (sender != null && sender != 0) {
|
||||
appSource = sender.getHost().Source;
|
||||
}
|
||||
|
||||
var errorType = args.ErrorType;
|
||||
var iErrorCode = args.ErrorCode;
|
||||
|
||||
if (errorType == "ImageError" || errorType == "MediaError") {
|
||||
return;
|
||||
}
|
||||
|
||||
var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n" ;
|
||||
|
||||
errMsg += "Code: "+ iErrorCode + " \n";
|
||||
errMsg += "Category: " + errorType + " \n";
|
||||
errMsg += "Message: " + args.ErrorMessage + " \n";
|
||||
|
||||
if (errorType == "ParserError") {
|
||||
errMsg += "File: " + args.xamlFile + " \n";
|
||||
errMsg += "Line: " + args.lineNumber + " \n";
|
||||
errMsg += "Position: " + args.charPosition + " \n";
|
||||
}
|
||||
else if (errorType == "RuntimeError") {
|
||||
if (args.lineNumber != 0) {
|
||||
errMsg += "Line: " + args.lineNumber + " \n";
|
||||
errMsg += "Position: " + args.charPosition + " \n";
|
||||
}
|
||||
errMsg += "MethodName: " + args.methodName + " \n";
|
||||
}
|
||||
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<form id="form1" runat="server" style="height:100%">
|
||||
<div id="silverlightControlHost">
|
||||
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
|
||||
<param name="source" value="ClientBin/Spring.RestSilverlightQuickStart.xap"/>
|
||||
<param name="onError" value="onSilverlightError" />
|
||||
<param name="background" value="white" />
|
||||
<param name="minRuntimeVersion" value="3.0.40624.0" />
|
||||
<param name="autoUpgrade" value="true" />
|
||||
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
|
||||
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
|
||||
</a>
|
||||
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1 +0,0 @@
|
||||
<%@ ServiceHost Language="C#" Debug="true" Service="Spring.RestSilverlightQuickStart.Services.Service" CodeBehind="Service.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
|
||||
@@ -1,106 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Web;
|
||||
using System.ServiceModel.Activation;
|
||||
|
||||
namespace Spring.RestSilverlightQuickStart.Services
|
||||
{
|
||||
[ServiceContract]
|
||||
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
|
||||
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
|
||||
public class Service
|
||||
{
|
||||
private IDictionary<string, string> users;
|
||||
|
||||
public Service()
|
||||
{
|
||||
users = new Dictionary<string, string>();
|
||||
users.Add("1", "Bruno Baïa");
|
||||
users.Add("2", "Marie Baia");
|
||||
}
|
||||
|
||||
[OperationContract]
|
||||
[WebGet(UriTemplate = "user/{id}")]
|
||||
public string GetUser(string id)
|
||||
{
|
||||
WebOperationContext context = WebOperationContext.Current;
|
||||
|
||||
if (!users.ContainsKey(id))
|
||||
{
|
||||
context.OutgoingResponse.SetStatusAsNotFound(String.Format("User with id '{0}' not found", id));
|
||||
return null;
|
||||
}
|
||||
|
||||
return users[id];
|
||||
}
|
||||
|
||||
[OperationContract]
|
||||
[WebGet(UriTemplate = "users")]
|
||||
public string GetUsersCount()
|
||||
{
|
||||
WebOperationContext context = WebOperationContext.Current;
|
||||
|
||||
return users.Count.ToString();
|
||||
}
|
||||
|
||||
[OperationContract]
|
||||
[WebInvoke(UriTemplate = "user", Method = "POST")]
|
||||
public string Post(Stream stream)
|
||||
{
|
||||
WebOperationContext context = WebOperationContext.Current;
|
||||
|
||||
UriTemplateMatch match = context.IncomingRequest.UriTemplateMatch;
|
||||
UriTemplate template = new UriTemplate("/user/{id}");
|
||||
|
||||
string id = (users.Count + 1).ToString(); // generate new ID
|
||||
string name;
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
name = reader.ReadToEnd();
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(name))
|
||||
{
|
||||
context.OutgoingResponse.StatusCode = HttpStatusCode.BadRequest;
|
||||
context.OutgoingResponse.StatusDescription = "Content cannot be null or empty";
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
users.Add(id, name);
|
||||
|
||||
Uri uri = template.BindByPosition(match.BaseUri, id);
|
||||
context.OutgoingResponse.SetStatusAsCreated(uri);
|
||||
context.OutgoingResponse.StatusDescription = String.Format("User id '{0}' created with '{1}'", id, name);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
[OperationContract]
|
||||
[WebInvoke(UriTemplate = "user/{id}", Method = "PUT")]
|
||||
public void Update(string id, Stream stream)
|
||||
{
|
||||
WebOperationContext context = WebOperationContext.Current;
|
||||
|
||||
if (!users.ContainsKey(id))
|
||||
{
|
||||
context.OutgoingResponse.StatusCode = HttpStatusCode.BadRequest;
|
||||
context.OutgoingResponse.StatusDescription = String.Format("User id '{0}' does not exist", id);
|
||||
return;
|
||||
}
|
||||
|
||||
string name;
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
name = reader.ReadToEnd();
|
||||
}
|
||||
users[id] = name;
|
||||
|
||||
context.OutgoingResponse.StatusCode = HttpStatusCode.OK;
|
||||
context.OutgoingResponse.StatusDescription = String.Format("User id '{0}' updated with '{1}'", id, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1,84 +0,0 @@
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{AFE006E7-F67F-45F9-826C-1273791D1574}</ProjectGuid>
|
||||
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Spring.RestSilverlightQuickStart</RootNamespace>
|
||||
<AssemblyName>Spring.RestSilverlightQuickStart.Web</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<SilverlightApplicationList>{0B34E41F-8D4E-427A-A7C4-A3F9ADEE8EB3}|..\Spring.RestSilverlightQuickStart\Spring.RestSilverlightQuickStart.csproj|ClientBin|False</SilverlightApplicationList>
|
||||
<TargetFrameworkSubset>Full</TargetFrameworkSubset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="ClientBin\Spring.RestSilverlightQuickStart.xap" />
|
||||
<Content Include="Services\Service.svc" />
|
||||
<Content Include="Silverlight.js" />
|
||||
<Content Include="Default.aspx" />
|
||||
<Content Include="Default.html" />
|
||||
<Content Include="Web.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Services\Service.svc.cs">
|
||||
<DependentUpon>Service.svc</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ServiceModel">
|
||||
<RequiredTargetFramework>3.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.ServiceModel.Web">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
|
||||
<WebProjectProperties>
|
||||
<UseIIS>False</UseIIS>
|
||||
<AutoAssignPort>False</AutoAssignPort>
|
||||
<DevelopmentServerPort>12345</DevelopmentServerPort>
|
||||
<DevelopmentServerVPath>/</DevelopmentServerVPath>
|
||||
<IISUrl>
|
||||
</IISUrl>
|
||||
<NTLMAuthentication>False</NTLMAuthentication>
|
||||
<UseCustomServer>False</UseCustomServer>
|
||||
<CustomServerUrl>
|
||||
</CustomServerUrl>
|
||||
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
|
||||
</WebProjectProperties>
|
||||
</FlavorProperties>
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
@@ -1,38 +0,0 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectView>ProjectFiles</ProjectView>
|
||||
</PropertyGroup>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
|
||||
<WebProjectProperties>
|
||||
<StartPageUrl>Default.aspx</StartPageUrl>
|
||||
<StartAction>SpecificPage</StartAction>
|
||||
<AspNetDebugging>True</AspNetDebugging>
|
||||
<SilverlightDebugging>True</SilverlightDebugging>
|
||||
<NativeDebugging>False</NativeDebugging>
|
||||
<SQLDebugging>False</SQLDebugging>
|
||||
<PublishCopyOption>RunFiles</PublishCopyOption>
|
||||
<PublishTargetLocation>
|
||||
</PublishTargetLocation>
|
||||
<PublishDeleteAllFiles>False</PublishDeleteAllFiles>
|
||||
<PublishCopyAppData>True</PublishCopyAppData>
|
||||
<ExternalProgram>
|
||||
</ExternalProgram>
|
||||
<StartExternalURL>
|
||||
</StartExternalURL>
|
||||
<StartCmdLineArguments>
|
||||
</StartCmdLineArguments>
|
||||
<StartWorkingDirectory>
|
||||
</StartWorkingDirectory>
|
||||
<EnableENC>False</EnableENC>
|
||||
<AlwaysStartWebServerOnDebug>True</AlwaysStartWebServerOnDebug>
|
||||
<EnableWcfTestClientForSVC>False</EnableWcfTestClientForSVC>
|
||||
<ProjectOutputReferences>
|
||||
<Ref Project="{0B34E41F-8D4E-427A-A7C4-A3F9ADEE8EB3}" Folder="ClientBin">Spring.RestSilverlightQuickStart.xap</Ref>
|
||||
</ProjectOutputReferences>
|
||||
</WebProjectProperties>
|
||||
</FlavorProperties>
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
@@ -1,126 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
|
||||
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
|
||||
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
|
||||
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
|
||||
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
|
||||
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
|
||||
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
|
||||
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
|
||||
</sectionGroup>
|
||||
</sectionGroup>
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
<appSettings/>
|
||||
<connectionStrings/>
|
||||
<system.web>
|
||||
<!--
|
||||
Définissez compilation debug="true" pour insérer des symboles
|
||||
de débogage dans la page compilée. Comme ceci
|
||||
affecte les performances, définissez cette valeur à true uniquement
|
||||
lors du développement.
|
||||
-->
|
||||
<compilation debug="true">
|
||||
<assemblies>
|
||||
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
|
||||
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
|
||||
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
|
||||
</assemblies>
|
||||
</compilation>
|
||||
<!--
|
||||
La section <authentication> permet la configuration
|
||||
du mode d'authentification de sécurité utilisé par
|
||||
ASP.NET pour identifier un utilisateur entrant.
|
||||
-->
|
||||
<authentication mode="Windows"/>
|
||||
<!--
|
||||
La section <customErrors> permet de configurer
|
||||
les actions à exécuter si/quand une erreur non gérée se produit
|
||||
lors de l'exécution d'une demande. Plus précisément,
|
||||
elle permet aux développeurs de configurer les pages d'erreur html
|
||||
pour qu'elles s'affichent à la place d'une trace de la pile d'erreur.
|
||||
|
||||
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
|
||||
<error statusCode="403" redirect="NoAccess.htm" />
|
||||
<error statusCode="404" redirect="FileNotFound.htm" />
|
||||
</customErrors>
|
||||
-->
|
||||
<pages>
|
||||
<controls>
|
||||
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
</controls>
|
||||
</pages>
|
||||
<httpHandlers>
|
||||
<remove verb="*" path="*.asmx"/>
|
||||
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
|
||||
</httpHandlers>
|
||||
<httpModules>
|
||||
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
</httpModules>
|
||||
</system.web>
|
||||
<system.codedom>
|
||||
<compilers>
|
||||
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<providerOption name="CompilerVersion" value="v3.5"/>
|
||||
<providerOption name="WarnAsError" value="false"/>
|
||||
</compiler>
|
||||
</compilers>
|
||||
</system.codedom>
|
||||
<!--
|
||||
La section system.webServer est requise pour exécuter ASP.NET AJAX sur Internet
|
||||
Information Services 7.0. Elle n'est pas nécessaire pour les versions précédentes d'IIS.
|
||||
-->
|
||||
<system.webServer>
|
||||
<validation validateIntegratedModeConfiguration="false"/>
|
||||
<modules>
|
||||
<remove name="ScriptModule"/>
|
||||
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
</modules>
|
||||
<handlers>
|
||||
<remove name="WebServiceHandlerFactory-Integrated"/>
|
||||
<remove name="ScriptHandlerFactory"/>
|
||||
<remove name="ScriptHandlerFactoryAppServices"/>
|
||||
<remove name="ScriptResource"/>
|
||||
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
</handlers>
|
||||
</system.webServer>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
|
||||
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
|
||||
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<!--<system.serviceModel>
|
||||
<services>
|
||||
<service behaviorConfiguration="Default" name="Spring.RestSilverlightQuickStart.Services.Service">
|
||||
<endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding" contract="Spring.RestSilverlightQuickStart.Services.IService" />
|
||||
</service>
|
||||
</services>
|
||||
<behaviors>
|
||||
<endpointBehaviors>
|
||||
<behavior name="webBehavior">
|
||||
<webHttp />
|
||||
</behavior>
|
||||
</endpointBehaviors>
|
||||
<serviceBehaviors>
|
||||
<behavior name="Default">
|
||||
<serviceMetadata httpGetEnabled="true"/>
|
||||
</behavior>
|
||||
</serviceBehaviors>
|
||||
</behaviors>
|
||||
</system.serviceModel>-->
|
||||
</configuration>
|
||||
@@ -1,74 +0,0 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" %>
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" >
|
||||
<head runat="server">
|
||||
<title>Spring.RestSilverlightQuickStart</title>
|
||||
<style type="text/css">
|
||||
html, body {
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
}
|
||||
body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
#silverlightControlHost {
|
||||
height: 100%;
|
||||
text-align:center;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript" src="Silverlight.js"></script>
|
||||
<script type="text/javascript">
|
||||
function onSilverlightError(sender, args) {
|
||||
var appSource = "";
|
||||
if (sender != null && sender != 0) {
|
||||
appSource = sender.getHost().Source;
|
||||
}
|
||||
|
||||
var errorType = args.ErrorType;
|
||||
var iErrorCode = args.ErrorCode;
|
||||
|
||||
if (errorType == "ImageError" || errorType == "MediaError") {
|
||||
return;
|
||||
}
|
||||
|
||||
var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n" ;
|
||||
|
||||
errMsg += "Code: "+ iErrorCode + " \n";
|
||||
errMsg += "Category: " + errorType + " \n";
|
||||
errMsg += "Message: " + args.ErrorMessage + " \n";
|
||||
|
||||
if (errorType == "ParserError") {
|
||||
errMsg += "File: " + args.xamlFile + " \n";
|
||||
errMsg += "Line: " + args.lineNumber + " \n";
|
||||
errMsg += "Position: " + args.charPosition + " \n";
|
||||
}
|
||||
else if (errorType == "RuntimeError") {
|
||||
if (args.lineNumber != 0) {
|
||||
errMsg += "Line: " + args.lineNumber + " \n";
|
||||
errMsg += "Position: " + args.charPosition + " \n";
|
||||
}
|
||||
errMsg += "MethodName: " + args.methodName + " \n";
|
||||
}
|
||||
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<form id="form1" runat="server" style="height:100%">
|
||||
<div id="silverlightControlHost">
|
||||
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
|
||||
<param name="source" value="ClientBin/Spring.RestSilverlightQuickStart.xap"/>
|
||||
<param name="onError" value="onSilverlightError" />
|
||||
<param name="background" value="white" />
|
||||
<param name="minRuntimeVersion" value="4.0.50826.0" />
|
||||
<param name="autoUpgrade" value="true" />
|
||||
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
|
||||
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
|
||||
</a>
|
||||
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,73 +0,0 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" >
|
||||
|
||||
<head>
|
||||
<title>Spring.RestSilverlightQuickStart</title>
|
||||
<style type="text/css">
|
||||
html, body {
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
}
|
||||
body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
#silverlightControlHost {
|
||||
height: 100%;
|
||||
text-align:center;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript" src="Silverlight.js"></script>
|
||||
<script type="text/javascript">
|
||||
function onSilverlightError(sender, args) {
|
||||
var appSource = "";
|
||||
if (sender != null && sender != 0) {
|
||||
appSource = sender.getHost().Source;
|
||||
}
|
||||
|
||||
var errorType = args.ErrorType;
|
||||
var iErrorCode = args.ErrorCode;
|
||||
|
||||
if (errorType == "ImageError" || errorType == "MediaError") {
|
||||
return;
|
||||
}
|
||||
|
||||
var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n" ;
|
||||
|
||||
errMsg += "Code: "+ iErrorCode + " \n";
|
||||
errMsg += "Category: " + errorType + " \n";
|
||||
errMsg += "Message: " + args.ErrorMessage + " \n";
|
||||
|
||||
if (errorType == "ParserError") {
|
||||
errMsg += "File: " + args.xamlFile + " \n";
|
||||
errMsg += "Line: " + args.lineNumber + " \n";
|
||||
errMsg += "Position: " + args.charPosition + " \n";
|
||||
}
|
||||
else if (errorType == "RuntimeError") {
|
||||
if (args.lineNumber != 0) {
|
||||
errMsg += "Line: " + args.lineNumber + " \n";
|
||||
errMsg += "Position: " + args.charPosition + " \n";
|
||||
}
|
||||
errMsg += "MethodName: " + args.methodName + " \n";
|
||||
}
|
||||
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<form id="form1" runat="server" style="height:100%">
|
||||
<div id="silverlightControlHost">
|
||||
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
|
||||
<param name="source" value="ClientBin/Spring.RestSilverlightQuickStart.xap"/>
|
||||
<param name="onError" value="onSilverlightError" />
|
||||
<param name="background" value="white" />
|
||||
<param name="minRuntimeVersion" value="4.0.50826.0" />
|
||||
<param name="autoUpgrade" value="true" />
|
||||
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
|
||||
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
|
||||
</a>
|
||||
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1 +0,0 @@
|
||||
<%@ ServiceHost Language="C#" Debug="true" Service="Spring.RestSilverlightQuickStart.Services.Service" CodeBehind="Service.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
|
||||
@@ -1,82 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Collections.Generic;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Web;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Activation;
|
||||
|
||||
namespace Spring.RestSilverlightQuickStart.Services
|
||||
{
|
||||
[ServiceContract]
|
||||
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
|
||||
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
|
||||
public class Service // : IService
|
||||
{
|
||||
private IDictionary<string, string> users;
|
||||
|
||||
public Service()
|
||||
{
|
||||
users = new Dictionary<string, string>();
|
||||
users.Add("1", "Bruno Baïa");
|
||||
users.Add("2", "Marie Baia");
|
||||
}
|
||||
|
||||
[OperationContract]
|
||||
[WebGet(UriTemplate = "user/{id}")]
|
||||
public Message GetUser(string id)
|
||||
{
|
||||
WebOperationContext context = WebOperationContext.Current;
|
||||
|
||||
if (!users.ContainsKey(id))
|
||||
{
|
||||
context.OutgoingResponse.SetStatusAsNotFound(String.Format("User with id '{0}' not found", id));
|
||||
return context.CreateTextResponse(null);
|
||||
}
|
||||
|
||||
return context.CreateTextResponse(users[id]);
|
||||
}
|
||||
|
||||
[OperationContract]
|
||||
[WebGet(UriTemplate = "users")]
|
||||
public Message GetUsersCount()
|
||||
{
|
||||
WebOperationContext context = WebOperationContext.Current;
|
||||
|
||||
return context.CreateTextResponse(users.Count.ToString());
|
||||
}
|
||||
|
||||
[OperationContract]
|
||||
[WebInvoke(UriTemplate = "user", Method = "POST")]
|
||||
public Message Post(Stream stream)
|
||||
{
|
||||
WebOperationContext context = WebOperationContext.Current;
|
||||
|
||||
UriTemplateMatch match = context.IncomingRequest.UriTemplateMatch;
|
||||
UriTemplate template = new UriTemplate("/user/{id}");
|
||||
|
||||
string id = (users.Count + 1).ToString(); // generate new ID
|
||||
string name;
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
name = reader.ReadToEnd();
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(name))
|
||||
{
|
||||
context.OutgoingResponse.StatusCode = HttpStatusCode.BadRequest;
|
||||
context.OutgoingResponse.StatusDescription = "Content cannot be null or empty";
|
||||
return WebOperationContext.Current.CreateTextResponse("");
|
||||
}
|
||||
|
||||
users.Add(id, name);
|
||||
|
||||
Uri uri = template.BindByPosition(match.BaseUri, id);
|
||||
context.OutgoingResponse.SetStatusAsCreated(uri);
|
||||
context.OutgoingResponse.StatusDescription = String.Format("User id '{0}' created with '{1}'", id, name);
|
||||
|
||||
return WebOperationContext.Current.CreateTextResponse(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1,87 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>
|
||||
</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{2B40C3B9-E032-417A-9B6F-8AD4ECEE0397}</ProjectGuid>
|
||||
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Spring.RestSilverlightQuickStart</RootNamespace>
|
||||
<AssemblyName>Spring.RestSilverlightQuickStart.Web</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<SilverlightApplicationList>{C11BD449-683C-44CA-B394-CC126DC49EF1}|..\Spring.RestSilverlightQuickStart\Spring.RestSilverlightQuickStart.csproj|ClientBin|False</SilverlightApplicationList>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="ClientBin\Spring.RestSilverlightQuickStart.xap" />
|
||||
<Content Include="Services\Service.svc" />
|
||||
<Content Include="Silverlight.js" />
|
||||
<Content Include="Default.aspx" />
|
||||
<Content Include="Default.html" />
|
||||
<Content Include="Web.config" />
|
||||
<Content Include="Web.Debug.config">
|
||||
<DependentUpon>Web.config</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="Web.Release.config">
|
||||
<DependentUpon>Web.config</DependentUpon>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Services\Service.svc.cs">
|
||||
<DependentUpon>Service.svc</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.ServiceModel.Web" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
|
||||
<WebProjectProperties>
|
||||
<UseIIS>False</UseIIS>
|
||||
<AutoAssignPort>False</AutoAssignPort>
|
||||
<DevelopmentServerPort>12345</DevelopmentServerPort>
|
||||
<DevelopmentServerVPath>/</DevelopmentServerVPath>
|
||||
<IISUrl>
|
||||
</IISUrl>
|
||||
<NTLMAuthentication>False</NTLMAuthentication>
|
||||
<UseCustomServer>False</UseCustomServer>
|
||||
<CustomServerUrl>
|
||||
</CustomServerUrl>
|
||||
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
|
||||
</WebProjectProperties>
|
||||
</FlavorProperties>
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -1,33 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectView>ProjectFiles</ProjectView>
|
||||
</PropertyGroup>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
|
||||
<WebProjectProperties>
|
||||
<StartPageUrl>Default.aspx</StartPageUrl>
|
||||
<StartAction>SpecificPage</StartAction>
|
||||
<AspNetDebugging>True</AspNetDebugging>
|
||||
<SilverlightDebugging>True</SilverlightDebugging>
|
||||
<NativeDebugging>False</NativeDebugging>
|
||||
<SQLDebugging>False</SQLDebugging>
|
||||
<ExternalProgram>
|
||||
</ExternalProgram>
|
||||
<StartExternalURL>
|
||||
</StartExternalURL>
|
||||
<StartCmdLineArguments>
|
||||
</StartCmdLineArguments>
|
||||
<StartWorkingDirectory>
|
||||
</StartWorkingDirectory>
|
||||
<EnableENC>False</EnableENC>
|
||||
<AlwaysStartWebServerOnDebug>True</AlwaysStartWebServerOnDebug>
|
||||
<ProjectOutputReferences>
|
||||
<Ref Project="{C11BD449-683C-44CA-B394-CC126DC49EF1}" Folder="ClientBin">Spring.RestSilverlightQuickStart.xap</Ref>
|
||||
</ProjectOutputReferences>
|
||||
</WebProjectProperties>
|
||||
</FlavorProperties>
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
|
||||
|
||||
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
|
||||
<!--
|
||||
In the example below, the "SetAttributes" transform will change the value of
|
||||
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
|
||||
finds an atrribute "name" that has a value of "MyDB".
|
||||
|
||||
<connectionStrings>
|
||||
<add name="MyDB"
|
||||
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
|
||||
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
|
||||
</connectionStrings>
|
||||
-->
|
||||
<system.web>
|
||||
<!--
|
||||
In the example below, the "Replace" transform will replace the entire
|
||||
<customErrors> section of your web.config file.
|
||||
Note that because there is only one customErrors section under the
|
||||
<system.web> node, there is no need to use the "xdt:Locator" attribute.
|
||||
|
||||
<customErrors defaultRedirect="GenericError.htm"
|
||||
mode="RemoteOnly" xdt:Transform="Replace">
|
||||
<error statusCode="500" redirect="InternalError.htm"/>
|
||||
</customErrors>
|
||||
-->
|
||||
</system.web>
|
||||
</configuration>
|
||||
@@ -1,31 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
|
||||
|
||||
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
|
||||
<!--
|
||||
In the example below, the "SetAttributes" transform will change the value of
|
||||
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
|
||||
finds an atrribute "name" that has a value of "MyDB".
|
||||
|
||||
<connectionStrings>
|
||||
<add name="MyDB"
|
||||
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
|
||||
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
|
||||
</connectionStrings>
|
||||
-->
|
||||
<system.web>
|
||||
<compilation xdt:Transform="RemoveAttributes(debug)" />
|
||||
<!--
|
||||
In the example below, the "Replace" transform will replace the entire
|
||||
<customErrors> section of your web.config file.
|
||||
Note that because there is only one customErrors section under the
|
||||
<system.web> node, there is no need to use the "xdt:Locator" attribute.
|
||||
|
||||
<customErrors defaultRedirect="GenericError.htm"
|
||||
mode="RemoteOnly" xdt:Transform="Replace">
|
||||
<error statusCode="500" redirect="InternalError.htm"/>
|
||||
</customErrors>
|
||||
-->
|
||||
</system.web>
|
||||
</configuration>
|
||||
@@ -1,26 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
For more information on how to configure your ASP.NET application, please visit
|
||||
http://go.microsoft.com/fwlink/?LinkId=169433
|
||||
-->
|
||||
|
||||
<configuration>
|
||||
<system.web>
|
||||
<compilation debug="true" targetFramework="4.0" />
|
||||
</system.web>
|
||||
|
||||
<system.serviceModel>
|
||||
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
|
||||
<standardEndpoints>
|
||||
<webHttpEndpoint>
|
||||
<!--
|
||||
Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
|
||||
via the attributes on the <standardEndpoint> element below
|
||||
-->
|
||||
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" />
|
||||
</webHttpEndpoint>
|
||||
</standardEndpoints>
|
||||
</system.serviceModel>
|
||||
|
||||
</configuration>
|
||||
@@ -1,8 +0,0 @@
|
||||
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="Spring.RestSilverlightQuickStart.App"
|
||||
>
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
@@ -1,68 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Spring.RestSilverlightQuickStart
|
||||
{
|
||||
public partial class App : Application
|
||||
{
|
||||
|
||||
public App()
|
||||
{
|
||||
this.Startup += this.Application_Startup;
|
||||
this.Exit += this.Application_Exit;
|
||||
this.UnhandledException += this.Application_UnhandledException;
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Application_Startup(object sender, StartupEventArgs e)
|
||||
{
|
||||
this.RootVisual = new MainPage();
|
||||
}
|
||||
|
||||
private void Application_Exit(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
|
||||
{
|
||||
// If the app is running outside of the debugger then report the exception using
|
||||
// the browser's exception mechanism. On IE this will display it a yellow alert
|
||||
// icon in the status bar and Firefox will display a script error.
|
||||
if (!System.Diagnostics.Debugger.IsAttached)
|
||||
{
|
||||
|
||||
// NOTE: This will allow the application to continue running after an exception has been thrown
|
||||
// but not handled.
|
||||
// For production applications this error handling should be replaced with something that will
|
||||
// report the error to the website and stop the application.
|
||||
e.Handled = true;
|
||||
Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
|
||||
}
|
||||
}
|
||||
|
||||
private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
|
||||
errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
|
||||
|
||||
System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<UserControl x:Class="Spring.RestSilverlightQuickStart.MainPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="600">
|
||||
<Grid x:Name="LayoutRoot" Background="White">
|
||||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" VerticalAlignment="Top">
|
||||
<TextBox Name="TwitterNameTextBox" Width="120" />
|
||||
<Button Name="Button" Width="50" Content="GET" Click="Button_Click" />
|
||||
</StackPanel>
|
||||
<TextBlock Height="570" HorizontalAlignment="Left" Margin="0,30,0,0" Name="TextBlock" VerticalAlignment="Top" Width="800" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -1,37 +0,0 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Net.Browser;
|
||||
|
||||
using Spring.Http.Rest;
|
||||
|
||||
namespace Spring.RestSilverlightQuickStart
|
||||
{
|
||||
public partial class MainPage : UserControl
|
||||
{
|
||||
public MainPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RestTemplate rt = new RestTemplate("http://localhost:12345/Services/Service.svc/");
|
||||
|
||||
rt.PostForMessageAsync<string>("user", "Lisa Baia",
|
||||
r =>
|
||||
{
|
||||
if (r.Error != null)
|
||||
{
|
||||
TextBlock.Text = r.Error.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
TextBlock.Text = String.Format("{0}; {1}; {2}; {3}",
|
||||
r.Response.Body, r.Response.Headers.Location, r.Response.StatusCode, r.Response.StatusDescription);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
>
|
||||
<Deployment.Parts>
|
||||
</Deployment.Parts>
|
||||
</Deployment>
|
||||
@@ -1,103 +0,0 @@
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{0B34E41F-8D4E-427A-A7C4-A3F9ADEE8EB3}</ProjectGuid>
|
||||
<ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Spring.RestSilverlightQuickStart</RootNamespace>
|
||||
<AssemblyName>Spring.RestSilverlightQuickStart</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<SilverlightApplication>true</SilverlightApplication>
|
||||
<SupportedCultures>fr</SupportedCultures>
|
||||
<XapOutputs>true</XapOutputs>
|
||||
<GenerateSilverlightManifest>true</GenerateSilverlightManifest>
|
||||
<XapFilename>Spring.RestSilverlightQuickStart.xap</XapFilename>
|
||||
<SilverlightManifestTemplate>Properties\AppManifest.xml</SilverlightManifestTemplate>
|
||||
<SilverlightAppEntry>Spring.RestSilverlightQuickStart.App</SilverlightAppEntry>
|
||||
<TestPageFileName>TestPage.html</TestPageFileName>
|
||||
<CreateTestPage>true</CreateTestPage>
|
||||
<ValidateXaml>true</ValidateXaml>
|
||||
<EnableOutOfBrowser>false</EnableOutOfBrowser>
|
||||
<OutOfBrowserSettingsFile>Properties\OutOfBrowserSettings.xml</OutOfBrowserSettingsFile>
|
||||
<UsePlatformExtensions>false</UsePlatformExtensions>
|
||||
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
|
||||
<LinkedServerProject>
|
||||
</LinkedServerProject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>Bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<NoConfig>true</NoConfig>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>Bin\Release</OutputPath>
|
||||
<DefineConstants>TRACE;SILVERLIGHT</DefineConstants>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<NoConfig>true</NoConfig>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Windows" />
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="system" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Net" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Windows.Browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="MainPage.xaml.cs">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:MarkupCompilePass1</Generator>
|
||||
</ApplicationDefinition>
|
||||
<Page Include="MainPage.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:MarkupCompilePass1</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Properties\AppManifest.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\..\src\Spring\Spring.Http\Spring.Http.2008-SL.csproj">
|
||||
<Project>{5A955F0B-EEC7-427C-9E6B-A26B8B51558D}</Project>
|
||||
<Name>Spring.Http.2008-SL</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
|
||||
<SilverlightProjectProperties />
|
||||
</FlavorProperties>
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
@@ -1,30 +0,0 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectView>ProjectFiles</ProjectView>
|
||||
</PropertyGroup>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
|
||||
<SilverlightProjectProperties>
|
||||
<StartPageUrl>
|
||||
</StartPageUrl>
|
||||
<StartAction>DynamicPage</StartAction>
|
||||
<AspNetDebugging>True</AspNetDebugging>
|
||||
<NativeDebugging>False</NativeDebugging>
|
||||
<SQLDebugging>False</SQLDebugging>
|
||||
<ExternalProgram>
|
||||
</ExternalProgram>
|
||||
<StartExternalURL>
|
||||
</StartExternalURL>
|
||||
<StartCmdLineArguments>
|
||||
</StartCmdLineArguments>
|
||||
<StartWorkingDirectory>
|
||||
</StartWorkingDirectory>
|
||||
<ShowWebRefOnDebugPrompt>True</ShowWebRefOnDebugPrompt>
|
||||
<OutOfBrowserProjectToDebug>Spring.RestSilverlightQuickStart.Web.2008</OutOfBrowserProjectToDebug>
|
||||
<ShowRiaSvcsOnDebugPrompt>True</ShowRiaSvcsOnDebugPrompt>
|
||||
</SilverlightProjectProperties>
|
||||
</FlavorProperties>
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
@@ -1,113 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{C11BD449-683C-44CA-B394-CC126DC49EF1}</ProjectGuid>
|
||||
<ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Spring.RestSilverlightQuickStart</RootNamespace>
|
||||
<AssemblyName>Spring.RestSilverlightQuickStart</AssemblyName>
|
||||
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
|
||||
<SilverlightApplication>true</SilverlightApplication>
|
||||
<SupportedCultures>
|
||||
</SupportedCultures>
|
||||
<XapOutputs>true</XapOutputs>
|
||||
<GenerateSilverlightManifest>true</GenerateSilverlightManifest>
|
||||
<XapFilename>Spring.RestSilverlightQuickStart.xap</XapFilename>
|
||||
<SilverlightManifestTemplate>Properties\AppManifest.xml</SilverlightManifestTemplate>
|
||||
<SilverlightAppEntry>Spring.RestSilverlightQuickStart.App</SilverlightAppEntry>
|
||||
<TestPageFileName>Spring.RestSilverlightQuickStartTestPage.html</TestPageFileName>
|
||||
<CreateTestPage>true</CreateTestPage>
|
||||
<ValidateXaml>true</ValidateXaml>
|
||||
<EnableOutOfBrowser>false</EnableOutOfBrowser>
|
||||
<OutOfBrowserSettingsFile>Properties\OutOfBrowserSettings.xml</OutOfBrowserSettingsFile>
|
||||
<UsePlatformExtensions>false</UsePlatformExtensions>
|
||||
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
|
||||
<LinkedServerProject>
|
||||
</LinkedServerProject>
|
||||
</PropertyGroup>
|
||||
<!-- This property group is only here to support building this project using the
|
||||
MSBuild 3.5 toolset. In order to work correctly with this older toolset, it needs
|
||||
to set the TargetFrameworkVersion to v3.5 -->
|
||||
<PropertyGroup Condition="'$(MSBuildToolsVersion)' == '3.5'">
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>Bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<NoConfig>true</NoConfig>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>Bin\Release</OutputPath>
|
||||
<DefineConstants>TRACE;SILVERLIGHT</DefineConstants>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<NoConfig>true</NoConfig>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="System.Windows" />
|
||||
<Reference Include="system" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Net" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Windows.Browser" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="MainPage.xaml.cs">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</ApplicationDefinition>
|
||||
<Page Include="MainPage.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Properties\AppManifest.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\..\src\Spring\Spring.Http\Spring.Http.2010-SL.csproj">
|
||||
<Project>{01FA5AEB-20A3-42FF-B2E9-A2FE9A7236D1}</Project>
|
||||
<Name>Spring.Http.2010-SL</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
|
||||
<SilverlightProjectProperties />
|
||||
</FlavorProperties>
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
@@ -1,29 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
|
||||
<SilverlightProjectProperties>
|
||||
<StartPageUrl>
|
||||
</StartPageUrl>
|
||||
<StartAction>DynamicPage</StartAction>
|
||||
<AspNetDebugging>True</AspNetDebugging>
|
||||
<NativeDebugging>False</NativeDebugging>
|
||||
<SQLDebugging>False</SQLDebugging>
|
||||
<ExternalProgram>
|
||||
</ExternalProgram>
|
||||
<StartExternalURL>
|
||||
</StartExternalURL>
|
||||
<StartCmdLineArguments>
|
||||
</StartCmdLineArguments>
|
||||
<StartWorkingDirectory>
|
||||
</StartWorkingDirectory>
|
||||
<ShowWebRefOnDebugPrompt>True</ShowWebRefOnDebugPrompt>
|
||||
<OutOfBrowserProjectToDebug>
|
||||
</OutOfBrowserProjectToDebug>
|
||||
<ShowRiaSvcsOnDebugPrompt>True</ShowRiaSvcsOnDebugPrompt>
|
||||
</SilverlightProjectProperties>
|
||||
</FlavorProperties>
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
@@ -1,34 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010 Express for Windows Phone
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.RestWindowsPhoneQuickStart.2010", "src\Spring.RestWindowsPhoneQuickStart.2010.csproj", "{0D706C31-4D8C-468A-A49F-073AC3E23D3F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Http.2010-WP", "..\..\..\src\Spring\Spring.Http\Spring.Http.2010-WP.csproj", "{36227431-B822-461E-A7AF-651E34F23A8C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Http.Tests.2010-WP", "..\..\..\test\Spring\Spring.Http.Tests\Spring.Http.Tests.2010-WP.csproj", "{83D8AF31-6DF1-4D2F-BFD2-865E91E6976E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{0D706C31-4D8C-468A-A49F-073AC3E23D3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0D706C31-4D8C-468A-A49F-073AC3E23D3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0D706C31-4D8C-468A-A49F-073AC3E23D3F}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{0D706C31-4D8C-468A-A49F-073AC3E23D3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0D706C31-4D8C-468A-A49F-073AC3E23D3F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0D706C31-4D8C-468A-A49F-073AC3E23D3F}.Release|Any CPU.Deploy.0 = Release|Any CPU
|
||||
{36227431-B822-461E-A7AF-651E34F23A8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{36227431-B822-461E-A7AF-651E34F23A8C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{36227431-B822-461E-A7AF-651E34F23A8C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{36227431-B822-461E-A7AF-651E34F23A8C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{83D8AF31-6DF1-4D2F-BFD2-865E91E6976E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{83D8AF31-6DF1-4D2F-BFD2-865E91E6976E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{83D8AF31-6DF1-4D2F-BFD2-865E91E6976E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{83D8AF31-6DF1-4D2F-BFD2-865E91E6976E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,19 +0,0 @@
|
||||
<Application
|
||||
x:Class="Spring.RestWindowsPhoneQuickStart.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
|
||||
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
|
||||
|
||||
<!--Application Resources-->
|
||||
<Application.Resources>
|
||||
</Application.Resources>
|
||||
|
||||
<Application.ApplicationLifetimeObjects>
|
||||
<!--Required object that handles lifetime events for the application-->
|
||||
<shell:PhoneApplicationService
|
||||
Launching="Application_Launching" Closing="Application_Closing"
|
||||
Activated="Application_Activated" Deactivated="Application_Deactivated"/>
|
||||
</Application.ApplicationLifetimeObjects>
|
||||
|
||||
</Application>
|
||||
@@ -1,135 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using Microsoft.Phone.Controls;
|
||||
using Microsoft.Phone.Shell;
|
||||
|
||||
namespace Spring.RestWindowsPhoneQuickStart
|
||||
{
|
||||
public partial class App : Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides easy access to the root frame of the Phone Application.
|
||||
/// </summary>
|
||||
/// <returns>The root frame of the Phone Application.</returns>
|
||||
public PhoneApplicationFrame RootFrame { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for the Application object.
|
||||
/// </summary>
|
||||
public App()
|
||||
{
|
||||
// Global handler for uncaught exceptions.
|
||||
UnhandledException += Application_UnhandledException;
|
||||
|
||||
// Show graphics profiling information while debugging.
|
||||
if (System.Diagnostics.Debugger.IsAttached)
|
||||
{
|
||||
// Display the current frame rate counters.
|
||||
Application.Current.Host.Settings.EnableFrameRateCounter = true;
|
||||
|
||||
// Show the areas of the app that are being redrawn in each frame.
|
||||
//Application.Current.Host.Settings.EnableRedrawRegions = true;
|
||||
|
||||
// Enable non-production analysis visualization mode,
|
||||
// which shows areas of a page that are being GPU accelerated with a colored overlay.
|
||||
//Application.Current.Host.Settings.EnableCacheVisualization = true;
|
||||
}
|
||||
|
||||
// Standard Silverlight initialization
|
||||
InitializeComponent();
|
||||
|
||||
// Phone-specific initialization
|
||||
InitializePhoneApplication();
|
||||
}
|
||||
|
||||
// Code to execute when the application is launching (eg, from Start)
|
||||
// This code will not execute when the application is reactivated
|
||||
private void Application_Launching(object sender, LaunchingEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
// Code to execute when the application is activated (brought to foreground)
|
||||
// This code will not execute when the application is first launched
|
||||
private void Application_Activated(object sender, ActivatedEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
// Code to execute when the application is deactivated (sent to background)
|
||||
// This code will not execute when the application is closing
|
||||
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
// Code to execute when the application is closing (eg, user hit Back)
|
||||
// This code will not execute when the application is deactivated
|
||||
private void Application_Closing(object sender, ClosingEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
// Code to execute if a navigation fails
|
||||
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
|
||||
{
|
||||
if (System.Diagnostics.Debugger.IsAttached)
|
||||
{
|
||||
// A navigation has failed; break into the debugger
|
||||
System.Diagnostics.Debugger.Break();
|
||||
}
|
||||
}
|
||||
|
||||
// Code to execute on Unhandled Exceptions
|
||||
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
|
||||
{
|
||||
if (System.Diagnostics.Debugger.IsAttached)
|
||||
{
|
||||
// An unhandled exception has occurred; break into the debugger
|
||||
System.Diagnostics.Debugger.Break();
|
||||
}
|
||||
}
|
||||
|
||||
#region Phone application initialization
|
||||
|
||||
// Avoid double-initialization
|
||||
private bool phoneApplicationInitialized = false;
|
||||
|
||||
// Do not add any additional code to this method
|
||||
private void InitializePhoneApplication()
|
||||
{
|
||||
if (phoneApplicationInitialized)
|
||||
return;
|
||||
|
||||
// Create the frame but don't set it as RootVisual yet; this allows the splash
|
||||
// screen to remain active until the application is ready to render.
|
||||
RootFrame = new PhoneApplicationFrame();
|
||||
RootFrame.Navigated += CompleteInitializePhoneApplication;
|
||||
|
||||
// Handle navigation failures
|
||||
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
|
||||
|
||||
// Ensure we don't initialize again
|
||||
phoneApplicationInitialized = true;
|
||||
}
|
||||
|
||||
// Do not add any additional code to this method
|
||||
private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
|
||||
{
|
||||
// Set the root visual to allow the application to render
|
||||
if (RootVisual != RootFrame)
|
||||
RootVisual = RootFrame;
|
||||
|
||||
// Remove this handler since it is no longer needed
|
||||
RootFrame.Navigated -= CompleteInitializePhoneApplication;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.4 KiB |
@@ -1,60 +0,0 @@
|
||||
<phone:PhoneApplicationPage
|
||||
x:Class="Spring.RestWindowsPhoneQuickStart.MainPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
|
||||
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
|
||||
FontFamily="{StaticResource PhoneFontFamilyNormal}"
|
||||
FontSize="{StaticResource PhoneFontSizeNormal}"
|
||||
Foreground="{StaticResource PhoneForegroundBrush}"
|
||||
SupportedOrientations="Portrait" Orientation="Portrait"
|
||||
shell:SystemTray.IsVisible="True">
|
||||
|
||||
<!--LayoutRoot is the root grid where all page content is placed-->
|
||||
<Grid x:Name="LayoutRoot" Background="Transparent">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!--TitlePanel contains the name of the application and page title-->
|
||||
<StackPanel x:Name="TitlePanel" Grid.Row="0">
|
||||
<TextBlock x:Name="ApplicationTitle" Text="TWITTER" HorizontalAlignment="Center" Style="{StaticResource PhoneTextNormalStyle}"/>
|
||||
</StackPanel>
|
||||
|
||||
<!--ContentPanel - place additional content here-->
|
||||
<StackPanel x:Name="ContentPanel" Grid.Row="1" Orientation="Vertical">
|
||||
<TextBox Name="TwitterAccountTextBox" Text="SpringForNet" />
|
||||
<Button Content="GET" Name="GetButton" Width="200" HorizontalAlignment="Center" Click="GetButton_Click" />
|
||||
<ListBox Name="StatusesListBox" Height="450">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal" Height="132">
|
||||
<Image Source="{Binding Path='User.ImageUrl'}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/>
|
||||
<StackPanel Width="370">
|
||||
<TextBlock Text="{Binding Path='User.ScreenName'}" Foreground="#FFC8AB14" FontSize="28" />
|
||||
<TextBlock Text="{Binding Text}" TextWrapping="Wrap" FontSize="24" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!--Sample code showing usage of ApplicationBar-->
|
||||
<!--<phone:PhoneApplicationPage.ApplicationBar>
|
||||
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
|
||||
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
|
||||
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
|
||||
<shell:ApplicationBar.MenuItems>
|
||||
<shell:ApplicationBarMenuItem Text="MenuItem 1"/>
|
||||
<shell:ApplicationBarMenuItem Text="MenuItem 2"/>
|
||||
</shell:ApplicationBar.MenuItems>
|
||||
</shell:ApplicationBar>
|
||||
</phone:PhoneApplicationPage.ApplicationBar>-->
|
||||
|
||||
</phone:PhoneApplicationPage>
|
||||
@@ -1,81 +0,0 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Microsoft.Phone.Controls;
|
||||
|
||||
using Spring.Http.Client;
|
||||
using Spring.Http.Rest;
|
||||
|
||||
namespace Spring.RestWindowsPhoneQuickStart
|
||||
{
|
||||
public partial class MainPage : PhoneApplicationPage
|
||||
{
|
||||
// Constructor
|
||||
public MainPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void GetButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RestTemplate rt = new RestTemplate("http://twitter.com");
|
||||
|
||||
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>("/statuses/user_timeline.xml?screen_name={name}",
|
||||
// args =>
|
||||
// {
|
||||
// if (args.Error == null)
|
||||
// {
|
||||
// this.StatusesListBox.ItemsSource = from tweet in args.Response.Descendants("status")
|
||||
// select new TwitterItem
|
||||
// {
|
||||
// ImageSource = tweet.Element("user").Element("profile_image_url").Value,
|
||||
// Message = tweet.Element("text").Value,
|
||||
// UserName = tweet.Element("user").Element("screen_name").Value
|
||||
// };
|
||||
// }
|
||||
// }, this.TwitterAccountTextBox.Text);
|
||||
}
|
||||
}
|
||||
|
||||
[CollectionDataContract(Name="statuses", ItemName="status", Namespace="")]
|
||||
public class TwitterStatuses : List<TwitterStatus>
|
||||
{
|
||||
}
|
||||
|
||||
[DataContract(Name = "status", Namespace = "")]
|
||||
public class TwitterStatus
|
||||
{
|
||||
[DataMember(Name="text")]
|
||||
public string Text { get; set; }
|
||||
|
||||
[DataMember(Name = "user")]
|
||||
public TwitterUser User { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Name="user", Namespace="")]
|
||||
public class TwitterUser
|
||||
{
|
||||
[DataMember(Name = "screen_name")]
|
||||
public string ScreenName { get; set; }
|
||||
|
||||
[DataMember(Name = "profile_image_url")]
|
||||
public string ImageUrl { get; set; }
|
||||
}
|
||||
|
||||
public class TwitterItem
|
||||
{
|
||||
public string UserName { get; set; }
|
||||
public string Message { get; set; }
|
||||
public string ImageSource { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
>
|
||||
<Deployment.Parts>
|
||||
</Deployment.Parts>
|
||||
</Deployment>
|
||||
@@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<Deployment xmlns="http://schemas.microsoft.com/windowsphone/2009/deployment" AppPlatformVersion="7.0">
|
||||
<App xmlns="" ProductID="{159b8a28-8643-4320-9978-b2fba126b989}" Title="Spring.RestWindowsPhoneQuickStart" RuntimeType="Silverlight" Version="1.0.0.0" Genre="apps.normal" Author="Spring.RestWindowsPhoneQuickStart author" Description="Sample description" Publisher="Spring.RestWindowsPhoneQuickStart">
|
||||
<IconPath IsRelative="true" IsResource="false">ApplicationIcon.png</IconPath>
|
||||
<Capabilities>
|
||||
<Capability Name="ID_CAP_GAMERSERVICES"/>
|
||||
<Capability Name="ID_CAP_IDENTITY_DEVICE"/>
|
||||
<Capability Name="ID_CAP_IDENTITY_USER"/>
|
||||
<Capability Name="ID_CAP_LOCATION"/>
|
||||
<Capability Name="ID_CAP_MEDIALIB"/>
|
||||
<Capability Name="ID_CAP_MICROPHONE"/>
|
||||
<Capability Name="ID_CAP_NETWORKING"/>
|
||||
<Capability Name="ID_CAP_PHONEDIALER"/>
|
||||
<Capability Name="ID_CAP_PUSH_NOTIFICATION"/>
|
||||
<Capability Name="ID_CAP_SENSORS"/>
|
||||
<Capability Name="ID_CAP_WEBBROWSERCOMPONENT"/>
|
||||
</Capabilities>
|
||||
<Tasks>
|
||||
<DefaultTask Name ="_default" NavigationPage="MainPage.xaml"/>
|
||||
</Tasks>
|
||||
<Tokens>
|
||||
<PrimaryToken TokenID="Spring.RestWindowsPhoneQuickStartToken" TaskName="_default">
|
||||
<TemplateType5>
|
||||
<BackgroundImageURI IsRelative="true" IsResource="false">Background.png</BackgroundImageURI>
|
||||
<Count>0</Count>
|
||||
<Title>Spring.RestWindowsPhoneQuickStart</Title>
|
||||
</TemplateType5>
|
||||
</PrimaryToken>
|
||||
</Tokens>
|
||||
</App>
|
||||
</Deployment>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 9.2 KiB |
@@ -1,108 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>10.0.20506</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{0D706C31-4D8C-468A-A49F-073AC3E23D3F}</ProjectGuid>
|
||||
<ProjectTypeGuids>{C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Spring.RestWindowsPhoneQuickStart</RootNamespace>
|
||||
<AssemblyName>Spring.RestWindowsPhoneQuickStart</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
|
||||
<TargetFrameworkProfile>WindowsPhone</TargetFrameworkProfile>
|
||||
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
|
||||
<SilverlightApplication>true</SilverlightApplication>
|
||||
<SupportedCultures>
|
||||
</SupportedCultures>
|
||||
<XapOutputs>true</XapOutputs>
|
||||
<GenerateSilverlightManifest>true</GenerateSilverlightManifest>
|
||||
<XapFilename>Spring.RestWindowsPhoneQuickStart.xap</XapFilename>
|
||||
<SilverlightManifestTemplate>Properties\AppManifest.xml</SilverlightManifestTemplate>
|
||||
<SilverlightAppEntry>Spring.RestWindowsPhoneQuickStart.App</SilverlightAppEntry>
|
||||
<ValidateXaml>true</ValidateXaml>
|
||||
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>Bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<NoConfig>true</NoConfig>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>Bin\Release</OutputPath>
|
||||
<DefineConstants>TRACE;SILVERLIGHT;WINDOWS_PHONE</DefineConstants>
|
||||
<NoStdLib>true</NoStdLib>
|
||||
<NoConfig>true</NoConfig>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Phone" />
|
||||
<Reference Include="Microsoft.Phone.Interop" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Windows" />
|
||||
<Reference Include="system" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Net" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="MainPage.xaml.cs">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</ApplicationDefinition>
|
||||
<Page Include="MainPage.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Properties\AppManifest.xml" />
|
||||
<None Include="Properties\WMAppManifest.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="ApplicationIcon.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Background.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="SplashScreenImage.jpg" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\src\Spring\Spring.Http\Spring.Http.2010-WP.csproj">
|
||||
<Project>{36227431-B822-461E-A7AF-651E34F23A8C}</Project>
|
||||
<Name>Spring.Http.2010-WP</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<ProjectExtensions />
|
||||
</Project>
|
||||
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<FullDeploy>false</FullDeploy>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -1,5 +0,0 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyTitle("Spring.Http")]
|
||||
[assembly: AssemblyDescription("Interfaces and classes that provide REST client API in Spring.NET")]
|
||||
@@ -1,221 +0,0 @@
|
||||
#if SILVERLIGHT
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spring.Collections.Specialized
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of associated string keys and multiple string values.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Silverlight's implementation, based on a dictionary, of the .NET Framework NameValueCollection class.
|
||||
/// </remarks>
|
||||
/// <author>Bruno Baia</author>
|
||||
public class NameValueCollection : IEnumerable<string>
|
||||
{
|
||||
private Dictionary<string, List<string>> innerCollection;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="NameValueCollection"/> class.
|
||||
/// </summary>
|
||||
public NameValueCollection()
|
||||
{
|
||||
innerCollection = new Dictionary<string, List<string>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="NameValueCollection"/> class
|
||||
/// with the specified initial capacity.
|
||||
/// </summary>
|
||||
public NameValueCollection(int capacity)
|
||||
{
|
||||
innerCollection = new Dictionary<string, List<string>>(capacity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="NameValueCollection"/> class
|
||||
/// with the specified comparer.
|
||||
/// </summary>
|
||||
public NameValueCollection(IEqualityComparer<string> comparer)
|
||||
{
|
||||
innerCollection = new Dictionary<string, List<string>>(comparer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="NameValueCollection"/> class
|
||||
/// with the specified initial capacity and comparer.
|
||||
/// </summary>
|
||||
public NameValueCollection(int capacity, IEqualityComparer<string> comparer)
|
||||
{
|
||||
innerCollection = new Dictionary<string, List<string>>(capacity, comparer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given single value to the current list of values for the given key.
|
||||
/// </summary>
|
||||
/// <param name="name">The key to use.</param>
|
||||
/// <param name="value">The value to add.</param>
|
||||
public virtual void Add(string name, string value)
|
||||
{
|
||||
List<string> list;
|
||||
if (!this.innerCollection.TryGetValue(name, out list))
|
||||
{
|
||||
list = new List<string>();
|
||||
}
|
||||
list.Add(value);
|
||||
this.innerCollection[name] = list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns values for the given key as a comma-delimited string.
|
||||
/// </summary>
|
||||
/// <param name="name">The key that contains the values to get.</param>
|
||||
/// <returns>A comma-delimited string, if found; otherwise <see langword="null"/>.</returns>
|
||||
public virtual string Get(string name)
|
||||
{
|
||||
string str = null;
|
||||
List<string> list;
|
||||
if (this.innerCollection.TryGetValue(name, out list))
|
||||
{
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
str = list[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
str = str + list[i];
|
||||
}
|
||||
if (i != (list.Count - 1))
|
||||
{
|
||||
str = str + ",";
|
||||
}
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns values for the given key as a string array.
|
||||
/// </summary>
|
||||
/// <param name="name">The key that contains the values to get.</param>
|
||||
/// <returns>A string array, if found; otherwise, <see langword="null"/>.</returns>
|
||||
public virtual string[] GetValues(string name)
|
||||
{
|
||||
List<string> list;
|
||||
if (this.innerCollection.TryGetValue(name, out list))
|
||||
{
|
||||
return list.ToArray();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the given single value under the given key.
|
||||
/// </summary>
|
||||
/// <param name="name">The key to use.</param>
|
||||
/// <param name="value">The value to set.</param>
|
||||
public virtual void Set(string name, string value)
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
list.Add(value);
|
||||
this.innerCollection[name] = list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the given key from the collection.
|
||||
/// </summary>
|
||||
/// <param name="name">The key to remove.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true"/> if the key have been found and removed from the collection;
|
||||
/// otherwise, <see langword="false"/>.
|
||||
/// </returns>
|
||||
public virtual bool Remove(string name)
|
||||
{
|
||||
return this.innerCollection.Remove(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the keys in the collection.
|
||||
/// </summary>
|
||||
public virtual string[] AllKeys
|
||||
{
|
||||
get
|
||||
{
|
||||
int count = this.innerCollection.Count;
|
||||
string[] array = new string[count];
|
||||
this.innerCollection.Keys.CopyTo(array, 0);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of keys contained in the collection.
|
||||
/// </summary>
|
||||
public virtual int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.innerCollection.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets values as a comma-delimited string or sets a single value for the given key.
|
||||
/// </summary>
|
||||
/// <param name="name">The key to use.</param>
|
||||
/// <returns>A comma-delimited string, if found; otherwise <see langword="null"/>.</returns>
|
||||
public virtual string this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.Get(name);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.Set(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
#region IEnumerable<string> Membres
|
||||
|
||||
IEnumerator<string> IEnumerable<string>.GetEnumerator()
|
||||
{
|
||||
return this.innerCollection.Keys.GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable Membres
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return this.innerCollection.Keys.GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,66 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Spring.Http.Client
|
||||
{
|
||||
// TODO: Rename this to HttpRequestCompletedEventArgs or something ?
|
||||
|
||||
/// <summary>
|
||||
/// Provides data when an asynchronous HTTP request execution completes.
|
||||
/// </summary>
|
||||
/// <see cref="IClientHttpRequest"/>
|
||||
public class ExecuteCompletedEventArgs : AsyncCompletedEventArgs
|
||||
{
|
||||
private IClientHttpResponse response;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IClientHttpResponse">response</see> result of the execution.
|
||||
/// </summary>
|
||||
/// <exception cref="System.InvalidOperationException">If the execution was canceled.</exception>
|
||||
/// <exception cref="System.Reflection.TargetInvocationException">If the execution failed.</exception>
|
||||
public IClientHttpResponse Response
|
||||
{
|
||||
get
|
||||
{
|
||||
// Raise an exception if the operation failed or was canceled.
|
||||
base.RaiseExceptionIfNecessary();
|
||||
|
||||
// If the operation was successful, return the value.
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="ExecuteCompletedEventArgs"/>.
|
||||
/// </summary>
|
||||
/// <param name="response">The response of the execution.</param>
|
||||
/// <param name="exception">Any error that occurred during the asynchronous execution.</param>
|
||||
/// <param name="cancelled">A value indicating whether the asynchronous execution was canceled.</param>
|
||||
/// <param name="userState">The optional user-supplied state object.</param>
|
||||
public ExecuteCompletedEventArgs(IClientHttpResponse response, Exception exception, bool cancelled, object userState)
|
||||
: base(exception, cancelled, userState)
|
||||
{
|
||||
this.response = response;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Spring.Http.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a client-side HTTP request.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Created via an implementation of the <see cref="IClientHttpRequestFactory"/>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// A client HTTP request can be executed,
|
||||
/// getting an <see cref="IClientHttpResponse"/> which can be read from.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <seealso cref="IClientHttpRequestFactory"/>
|
||||
/// <seealso cref="IClientHttpResponse"/>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
public interface IClientHttpRequest : IHttpOutputMessage
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the HTTP method of the request.
|
||||
/// </summary>
|
||||
HttpMethod Method { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the URI of the request.
|
||||
/// </summary>
|
||||
Uri Uri { get; }
|
||||
|
||||
#if !SILVERLIGHT
|
||||
/// <summary>
|
||||
/// Execute this request, resulting in a <see cref="IClientHttpResponse" /> that can be read.
|
||||
/// </summary>
|
||||
/// <returns>The response result of the execution</returns>
|
||||
IClientHttpResponse Execute();
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Execute this request asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="state">
|
||||
/// An optional user-defined object that is passed to the method invoked
|
||||
/// when the asynchronous operation completes.
|
||||
/// </param>
|
||||
/// <param name="executeCompleted">
|
||||
/// The <see cref="Action{ExecuteCompletedEventArgs}"/> to perform when the asynchronous execution completes.
|
||||
/// </param>
|
||||
void ExecuteAsync(object state, Action<ExecuteCompletedEventArgs> executeCompleted);
|
||||
|
||||
/// <summary>
|
||||
/// Cancels a pending asynchronous operation.
|
||||
/// </summary>
|
||||
void CancelAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace Spring.Http.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Factory for <see cref="IClientHttpRequest"/> objects.
|
||||
/// Requests are created by the <see cref="M:CreateRequest"/> method.
|
||||
/// </summary>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
public interface IClientHttpRequestFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a new <see cref="IClientHttpRequest"/> for the specified URI and HTTP method.
|
||||
/// </summary>
|
||||
/// <param name="uri">The URI to create a request for.</param>
|
||||
/// <param name="method">The HTTP method to execute.</param>
|
||||
/// <returns>The created request</returns>
|
||||
IClientHttpRequest CreateRequest(Uri uri, HttpMethod method);
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
|
||||
namespace Spring.Http.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a client-side HTTP response.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Obtained via an 'execution' of the <see cref="IClientHttpRequest"/>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// A client HTTP response must be <see cref="M:Close">closed</see>,
|
||||
/// typically in a <code>finally</code> or via an <code>using</code> block.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <seealso cref="IClientHttpRequest"/>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
public interface IClientHttpResponse : IHttpInputMessage, IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the HTTP status code of the response.
|
||||
/// </summary>
|
||||
HttpStatusCode StatusCode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HTTP status description of the response.
|
||||
/// </summary>
|
||||
string StatusDescription { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Closes this response, freeing any resources created.
|
||||
/// </summary>
|
||||
void Close();
|
||||
}
|
||||
}
|
||||
@@ -1,491 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
|
||||
using Spring.Util;
|
||||
|
||||
namespace Spring.Http.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="IClientHttpRequest"/> implementation that uses
|
||||
/// .NET <see cref="HttpWebRequest"/>'s class to execute requests.
|
||||
/// </summary>
|
||||
/// <seealso cref="WebClientHttpRequestFactory"/>
|
||||
/// <author>Bruno Baia</author>
|
||||
public class WebClientHttpRequest : IClientHttpRequest
|
||||
{
|
||||
private HttpHeaders headers;
|
||||
private Action<Stream> body;
|
||||
private HttpWebRequest httpWebRequest;
|
||||
|
||||
private bool isExecuted;
|
||||
private bool isCancelled;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="HttpWebRequest"/> instance used by the request.
|
||||
/// </summary>
|
||||
public HttpWebRequest HttpWebRequest
|
||||
{
|
||||
get { return this.httpWebRequest; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="WebClientHttpRequest"/>
|
||||
/// with the given <see cref="HttpWebRequest"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="request">The <see cref="HttpWebRequest"/> instance to use.</param>
|
||||
public WebClientHttpRequest(HttpWebRequest request)
|
||||
{
|
||||
AssertUtils.ArgumentNotNull(request, "HttpWebRequest");
|
||||
|
||||
this.httpWebRequest = request;
|
||||
this.headers = new HttpHeaders();
|
||||
}
|
||||
|
||||
#region IClientHttpRequest Members
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HTTP method of the request.
|
||||
/// </summary>
|
||||
public HttpMethod Method
|
||||
{
|
||||
get
|
||||
{
|
||||
return (HttpMethod)Enum.Parse(typeof(HttpMethod), this.httpWebRequest.Method, true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the URI of the request.
|
||||
/// </summary>
|
||||
public Uri Uri
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.httpWebRequest.RequestUri;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the message headers.
|
||||
/// </summary>
|
||||
public HttpHeaders Headers
|
||||
{
|
||||
get { return headers; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the delegate that writes the body message as a stream.
|
||||
/// </summary>
|
||||
public Action<Stream> Body
|
||||
{
|
||||
set { this.body = value; }
|
||||
}
|
||||
|
||||
#if !SILVERLIGHT
|
||||
/// <summary>
|
||||
/// Execute this request, resulting in a <see cref="IClientHttpResponse" /> that can be read.
|
||||
/// </summary>
|
||||
/// <returns>The response result of the execution</returns>
|
||||
/// <see cref="InvalidOperationException">If the request is already executed or is currently executing.</see>
|
||||
public IClientHttpResponse Execute()
|
||||
{
|
||||
this.EnsureNotExecuted();
|
||||
|
||||
try
|
||||
{
|
||||
// Prepare
|
||||
this.PrepareForExecution();
|
||||
|
||||
// Write
|
||||
if (this.body != null)
|
||||
{
|
||||
using (Stream stream = this.httpWebRequest.GetRequestStream())
|
||||
{
|
||||
this.body(stream);
|
||||
}
|
||||
}
|
||||
|
||||
// Read
|
||||
HttpWebResponse httpWebResponse = this.httpWebRequest.GetResponse() as HttpWebResponse;
|
||||
if (this.httpWebRequest.HaveResponse && httpWebResponse != null)
|
||||
{
|
||||
return this.CreateClientHttpResponse(httpWebResponse);
|
||||
}
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
// This exception can be raised with some status code
|
||||
// Try to retrieve the response from the error
|
||||
HttpWebResponse httpWebResponse = ex.Response as HttpWebResponse;
|
||||
if (httpWebResponse != null)
|
||||
{
|
||||
return this.CreateClientHttpResponse(httpWebResponse);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.isExecuted = true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Execute this request asynchronously.
|
||||
/// </summary>
|
||||
/// <param name="state">
|
||||
/// An optional user-defined object that is passed to the method invoked
|
||||
/// when the asynchronous operation completes.
|
||||
/// </param>
|
||||
/// <param name="executeCompleted">
|
||||
/// The <see cref="Action{ExecuteCompletedEventArgs}"/> to perform when the asynchronous execution completes.
|
||||
/// </param>
|
||||
/// <see cref="InvalidOperationException">If the request is already executed or is currently executing.</see>
|
||||
public void ExecuteAsync(object state, Action<ExecuteCompletedEventArgs> executeCompleted)
|
||||
{
|
||||
this.EnsureNotExecuted();
|
||||
|
||||
AsyncOperation asyncOperation = AsyncOperationManager.CreateOperation(state);
|
||||
ExecuteState executeState = new ExecuteState(executeCompleted, asyncOperation);
|
||||
|
||||
try
|
||||
{
|
||||
// Prepare
|
||||
this.PrepareForExecution();
|
||||
|
||||
// Post request
|
||||
if (this.body != null)
|
||||
{
|
||||
this.httpWebRequest.BeginGetRequestStream(new AsyncCallback(ExecuteRequestCallback), executeState);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get request
|
||||
this.HttpWebRequest.BeginGetResponse(new AsyncCallback(ExecuteResponseCallback), executeState);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
ExecuteAsyncCallback(executeState, null, ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.isExecuted = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancels a pending asynchronous operation.
|
||||
/// </summary>
|
||||
public void CancelAsync()
|
||||
{
|
||||
this.isCancelled = true;
|
||||
try
|
||||
{
|
||||
if (this.httpWebRequest != null)
|
||||
{
|
||||
this.httpWebRequest.Abort();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
if (((exception is OutOfMemoryException) || (exception is StackOverflowException)) || (exception is ThreadAbortException))
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Async methods/classes
|
||||
|
||||
private void ExecuteRequestCallback(IAsyncResult result)
|
||||
{
|
||||
ExecuteState state = (ExecuteState)result.AsyncState;
|
||||
|
||||
try
|
||||
{
|
||||
// Write
|
||||
using (Stream stream = this.httpWebRequest.EndGetRequestStream(result))
|
||||
{
|
||||
this.body(stream);
|
||||
}
|
||||
|
||||
// Read
|
||||
this.httpWebRequest.BeginGetResponse(new AsyncCallback(ExecuteResponseCallback), state);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
ExecuteAsyncCallback(state, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteResponseCallback(IAsyncResult result)
|
||||
{
|
||||
ExecuteState state = (ExecuteState)result.AsyncState;
|
||||
|
||||
IClientHttpResponse response = null;
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
HttpWebResponse httpWebResponse = this.httpWebRequest.EndGetResponse(result) as HttpWebResponse;
|
||||
if (this.httpWebRequest.HaveResponse == true && httpWebResponse != null)
|
||||
{
|
||||
response = this.CreateClientHttpResponse(httpWebResponse);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
exception = ex;
|
||||
// This exception can be raised with some status code
|
||||
// Try to retrieve the response from the error
|
||||
if (ex is WebException)
|
||||
{
|
||||
HttpWebResponse httpWebResponse = ((WebException)ex).Response as HttpWebResponse;
|
||||
if (httpWebResponse != null)
|
||||
{
|
||||
exception = null;
|
||||
response = this.CreateClientHttpResponse(httpWebResponse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ExecuteAsyncCallback(state, response, exception);
|
||||
}
|
||||
|
||||
// This is the method that the underlying, free-threaded asynchronous behavior will invoke.
|
||||
// This will happen on an arbitrary thread.
|
||||
private void ExecuteAsyncCallback(ExecuteState state, IClientHttpResponse response, Exception exception)
|
||||
{
|
||||
// Package the results of the operation
|
||||
ExecuteCompletedEventArgs eventArgs = new ExecuteCompletedEventArgs(response, exception, this.isCancelled, state.AsyncOperation.UserSuppliedState);
|
||||
ExecuteCallbackArgs<ExecuteCompletedEventArgs> callbackArgs = new ExecuteCallbackArgs<ExecuteCompletedEventArgs>(eventArgs, state.ExecuteCompleted);
|
||||
SendOrPostCallback callback = new SendOrPostCallback(ExecuteResponseReceived);
|
||||
|
||||
// End the task. The asyncOp object is responsible for marshaling the call.
|
||||
state.AsyncOperation.PostOperationCompleted(callback, callbackArgs);
|
||||
}
|
||||
|
||||
private static void ExecuteResponseReceived(object arg)
|
||||
{
|
||||
ExecuteCallbackArgs<ExecuteCompletedEventArgs> callbackArgs = (ExecuteCallbackArgs<ExecuteCompletedEventArgs>)arg;
|
||||
if (callbackArgs.Callback != null)
|
||||
{
|
||||
callbackArgs.Callback(callbackArgs.EventArgs);
|
||||
}
|
||||
}
|
||||
|
||||
private class ExecuteCallbackArgs<T> where T : class
|
||||
{
|
||||
public T EventArgs;
|
||||
public Action<T> Callback;
|
||||
|
||||
public ExecuteCallbackArgs(T eventArgs,
|
||||
Action<T> callback)
|
||||
{
|
||||
this.EventArgs = eventArgs;
|
||||
this.Callback = callback;
|
||||
}
|
||||
}
|
||||
|
||||
private class ExecuteState
|
||||
{
|
||||
public Action<ExecuteCompletedEventArgs> ExecuteCompleted;
|
||||
public AsyncOperation AsyncOperation;
|
||||
|
||||
public ExecuteState(
|
||||
Action<ExecuteCompletedEventArgs> executeCompleted,
|
||||
AsyncOperation asyncOperation)
|
||||
{
|
||||
this.ExecuteCompleted = executeCompleted;
|
||||
this.AsyncOperation = asyncOperation;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the request can be executed.
|
||||
/// </summary>
|
||||
/// <see cref="InvalidOperationException">If the request is already executed or is currently executing.</see>
|
||||
protected void EnsureNotExecuted()
|
||||
{
|
||||
if (this.isExecuted)
|
||||
{
|
||||
throw new InvalidOperationException("Client HTTP request already executed or is currently executing.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and returns an <see cref="IClientHttpResponse"/> implementation associated
|
||||
/// with the request.
|
||||
/// </summary>
|
||||
/// <param name="response">The <see cref="HttpWebResponse"/> instance to use.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="IClientHttpResponse"/> implementation associated with the request.
|
||||
/// </returns>
|
||||
protected virtual IClientHttpResponse CreateClientHttpResponse(HttpWebResponse response)
|
||||
{
|
||||
return new WebClientHttpResponse(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prepare the request for execution.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Default implementation copies headers to the .NET request. Can be overridden in subclasses.
|
||||
/// </remarks>
|
||||
protected virtual void PrepareForExecution()
|
||||
{
|
||||
// Copy headers
|
||||
foreach (string header in this.headers)
|
||||
{
|
||||
// Special headers
|
||||
switch (header.ToUpper(CultureInfo.InvariantCulture))
|
||||
{
|
||||
case "ACCEPT":
|
||||
{
|
||||
this.httpWebRequest.Accept = this.headers[header];
|
||||
break;
|
||||
}
|
||||
#if !SILVERLIGHT_3 && !WINDOWS_PHONE
|
||||
case "CONTENT-LENGTH":
|
||||
{
|
||||
this.httpWebRequest.ContentLength = this.headers.ContentLength;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case "CONTENT-TYPE":
|
||||
{
|
||||
this.httpWebRequest.ContentType = this.headers[header];
|
||||
break;
|
||||
}
|
||||
#if NET_4_0
|
||||
case "DATE" :
|
||||
{
|
||||
DateTime? date = this.headers.Date;
|
||||
if (date.HasValue)
|
||||
{
|
||||
this.httpWebRequest.Date = date.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.httpWebRequest.Date = DateTime.MinValue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "HOST" :
|
||||
{
|
||||
this.httpWebRequest.Host = this.headers[header];
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if !SILVERLIGHT
|
||||
case "CONNECTION":
|
||||
{
|
||||
string headerValue = this.headers[header];
|
||||
if (headerValue.Equals("Keep-Alive", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
this.httpWebRequest.KeepAlive = true;
|
||||
}
|
||||
else if (!headerValue.Equals("Close", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
this.httpWebRequest.Connection = headerValue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "EXPECT":
|
||||
{
|
||||
this.httpWebRequest.Expect = this.headers[header];
|
||||
break;
|
||||
}
|
||||
case "IF-MODIFIED-SINCE":
|
||||
{
|
||||
DateTime? date = this.headers.IfModifiedSince;
|
||||
if (date.HasValue)
|
||||
{
|
||||
this.httpWebRequest.IfModifiedSince = date.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.httpWebRequest.IfModifiedSince = DateTime.MinValue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
//case "RANGE":
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
case "REFERER":
|
||||
{
|
||||
this.httpWebRequest.Referer = this.headers[header];
|
||||
break;
|
||||
}
|
||||
case "TRANSFER-ENCODING":
|
||||
{
|
||||
this.httpWebRequest.SendChunked = true;
|
||||
string headerValue = this.headers[header];
|
||||
if (!headerValue.Equals("Chunked", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
this.httpWebRequest.TransferEncoding = headerValue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if !SILVERLIGHT_3
|
||||
case "USER-AGENT":
|
||||
{
|
||||
this.httpWebRequest.UserAgent = this.headers[header];
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
{
|
||||
// Other headers
|
||||
this.httpWebRequest.Headers[header] = this.headers[header];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,228 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace Spring.Http.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="IClientHttpRequestFactory"/> implementation that uses
|
||||
/// .NET <see cref="HttpWebRequest"/>'s class to create requests.
|
||||
/// </summary>
|
||||
/// <see cref="WebClientHttpRequest"/>
|
||||
/// <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
|
||||
private bool? _useDefaultCredentials;
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean value that controls whether default credentials are sent with this request.
|
||||
/// </summary>
|
||||
public bool? UseDefaultCredentials
|
||||
{
|
||||
get { return this._useDefaultCredentials; }
|
||||
set { this._useDefaultCredentials = value; }
|
||||
}
|
||||
#endif
|
||||
|
||||
private ICredentials _credentials;
|
||||
/// <summary>
|
||||
/// Gets or sets authentication information for the request.
|
||||
/// </summary>
|
||||
public ICredentials Credentials
|
||||
{
|
||||
get { return this._credentials; }
|
||||
set { this._credentials = value; }
|
||||
}
|
||||
|
||||
#if !SILVERLIGHT
|
||||
private X509CertificateCollection _clientCertificates;
|
||||
/// <summary>
|
||||
/// Gets or sets the collection of security certificates that are associated with this request.
|
||||
/// </summary>
|
||||
public X509CertificateCollection ClientCertificates
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._clientCertificates == null)
|
||||
{
|
||||
this._clientCertificates = new X509CertificateCollection();
|
||||
}
|
||||
return this._clientCertificates;
|
||||
}
|
||||
}
|
||||
|
||||
private IWebProxy _proxy;
|
||||
/// <summary>
|
||||
/// Gets or sets proxy information for the request.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The default value is set by calling the <see cref="P:System.Net.GlobalProxySelection.Select"/> property.
|
||||
/// </remarks>
|
||||
public IWebProxy Proxy
|
||||
{
|
||||
get { return this._proxy; }
|
||||
set { this._proxy = value; }
|
||||
}
|
||||
|
||||
private int? _timeout;
|
||||
/// <summary>
|
||||
/// Gets or sets the time-out value in milliseconds for synchrone request only.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The default is 100,000 milliseconds (100 seconds).
|
||||
/// </remarks>
|
||||
public int? Timeout
|
||||
{
|
||||
get { return this._timeout; }
|
||||
set { this._timeout = value; }
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SILVERLIGHT && !WINDOWS_PHONE
|
||||
private WebRequestCreatorType _webRequestCreator;
|
||||
/// <summary>
|
||||
/// Gets or sets a value that indicates how HTTP requests and responses will be handled.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// By default, this factory will use the default Silverlight behavior for HTTP methods GET and POST,
|
||||
/// and force the client HTTP stack for other HTTP methods.
|
||||
/// </remarks>
|
||||
public WebRequestCreatorType WebRequestCreator
|
||||
{
|
||||
get { return this._webRequestCreator; }
|
||||
set { this._webRequestCreator = value; }
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
#if SILVERLIGHT && !WINDOWS_PHONE
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="WebClientHttpRequestFactory"/>.
|
||||
/// </summary>
|
||||
public WebClientHttpRequestFactory()
|
||||
{
|
||||
this._webRequestCreator = WebRequestCreatorType.Unknown;
|
||||
}
|
||||
#endif
|
||||
|
||||
#region IClientHttpRequestFactory Membres
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="IClientHttpRequest"/> for the specified URI and HTTP method.
|
||||
/// </summary>
|
||||
/// <param name="uri">The URI to create a request for.</param>
|
||||
/// <param name="method">The HTTP method to execute.</param>
|
||||
/// <returns>The created request</returns>
|
||||
public virtual IClientHttpRequest CreateRequest(Uri uri, HttpMethod method)
|
||||
{
|
||||
#if SILVERLIGHT && !WINDOWS_PHONE
|
||||
switch (this._webRequestCreator)
|
||||
{
|
||||
case WebRequestCreatorType.ClientHttp:
|
||||
this.httpWebRequest = (HttpWebRequest)System.Net.Browser.WebRequestCreator.ClientHttp.Create(uri);
|
||||
break;
|
||||
case WebRequestCreatorType.BrowserHttp:
|
||||
this.httpWebRequest = (HttpWebRequest)System.Net.Browser.WebRequestCreator.BrowserHttp.Create(uri);
|
||||
break;
|
||||
case WebRequestCreatorType.Unknown:
|
||||
if (method == HttpMethod.GET || method == HttpMethod.POST)
|
||||
{
|
||||
this.httpWebRequest = WebRequest.Create(uri) as HttpWebRequest;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Force Client HTTP stack
|
||||
this.httpWebRequest = (HttpWebRequest)System.Net.Browser.WebRequestCreator.ClientHttp.Create(uri);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#else
|
||||
this.httpWebRequest = WebRequest.Create(uri) as HttpWebRequest;
|
||||
#endif
|
||||
|
||||
this.httpWebRequest.Method = method.ToString();
|
||||
|
||||
#if !SILVERLIGHT_3
|
||||
if (this._useDefaultCredentials.HasValue)
|
||||
{
|
||||
this.httpWebRequest.UseDefaultCredentials = this._useDefaultCredentials.Value;
|
||||
}
|
||||
#endif
|
||||
if (this._credentials != null)
|
||||
{
|
||||
this.httpWebRequest.Credentials = this._credentials;
|
||||
}
|
||||
#if !SILVERLIGHT
|
||||
if (this._clientCertificates != null)
|
||||
{
|
||||
foreach (X509Certificate2 certificate in this._clientCertificates)
|
||||
{
|
||||
this.httpWebRequest.ClientCertificates.Add(certificate);
|
||||
}
|
||||
}
|
||||
if (this._proxy != null)
|
||||
{
|
||||
this.httpWebRequest.Proxy = this._proxy;
|
||||
}
|
||||
if (this._timeout != null)
|
||||
{
|
||||
this.httpWebRequest.Timeout = this._timeout.Value;
|
||||
}
|
||||
#endif
|
||||
|
||||
return new WebClientHttpRequest(this.httpWebRequest);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#if SILVERLIGHT && !WINDOWS_PHONE
|
||||
/// <summary>
|
||||
/// Defines identifiers for supported Silverlight HTTP handling stacks.
|
||||
/// </summary>
|
||||
public enum WebRequestCreatorType
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies an unknown HTTP handling stack.
|
||||
/// </summary>
|
||||
Unknown,
|
||||
/// <summary>
|
||||
/// Specifies browser HTTP handling stack.
|
||||
/// </summary>
|
||||
BrowserHttp,
|
||||
/// <summary>
|
||||
/// Specifies client HTTP handling stack.
|
||||
/// </summary>
|
||||
ClientHttp
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -1,163 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
|
||||
using Spring.Util;
|
||||
|
||||
namespace Spring.Http.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="IClientHttpResponse"/> implementation that uses
|
||||
/// .NET <see cref="HttpWebResponse"/>'s class to read responses.
|
||||
/// </summary>
|
||||
/// <author>Bruno Baia</author>
|
||||
public class WebClientHttpResponse : IClientHttpResponse
|
||||
{
|
||||
private HttpHeaders headers;
|
||||
private HttpWebResponse httpWebResponse;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="HttpWebResponse"/> instance used by the response.
|
||||
/// </summary>
|
||||
public HttpWebResponse HttpWebResponse
|
||||
{
|
||||
get { return this.httpWebResponse; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="WebClientHttpResponse"/>
|
||||
/// with the given <see cref="HttpWebResponse"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="response">The <see cref="HttpWebResponse"/> instance to use.</param>
|
||||
public WebClientHttpResponse(HttpWebResponse response)
|
||||
{
|
||||
AssertUtils.ArgumentNotNull(response, "HttpWebResponse");
|
||||
|
||||
this.httpWebResponse = response;
|
||||
this.headers = new HttpHeaders();
|
||||
|
||||
this.Initialize();
|
||||
}
|
||||
|
||||
#region IClientHttpResponse Membres
|
||||
|
||||
/// <summary>
|
||||
/// Gets the message headers.
|
||||
/// </summary>
|
||||
public HttpHeaders Headers
|
||||
{
|
||||
get { return this.headers; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the body of the message as a stream.
|
||||
/// </summary>
|
||||
public Stream Body
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.httpWebResponse.GetResponseStream();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HTTP status code of the response.
|
||||
/// </summary>
|
||||
public HttpStatusCode StatusCode
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.httpWebResponse.StatusCode;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HTTP status description of the response.
|
||||
/// </summary>
|
||||
public string StatusDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.httpWebResponse.StatusDescription;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Closes this response, freeing any resources created.
|
||||
/// </summary>
|
||||
public void Close()
|
||||
{
|
||||
this.httpWebResponse.Close();
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
((IDisposable)this.httpWebResponse).Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the response.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Default implementation copies headers from the .NET response. Can be overridden in subclasses.
|
||||
/// </remarks>
|
||||
protected virtual void Initialize()
|
||||
{
|
||||
#if NET_2_0 || WINDOWS_PHONE
|
||||
foreach (string header in this.httpWebResponse.Headers)
|
||||
{
|
||||
this.headers[header] = this.httpWebResponse.Headers[header];
|
||||
}
|
||||
#endif
|
||||
#if SILVERLIGHT_3
|
||||
try
|
||||
{
|
||||
foreach (string header in this.httpWebResponse.Headers)
|
||||
{
|
||||
this.headers[header] = this.httpWebResponse.Headers[header];
|
||||
}
|
||||
}
|
||||
catch(NotImplementedException)
|
||||
{
|
||||
this.headers.ContentLength = this.httpWebResponse.ContentLength;
|
||||
this.headers["Content-Type"] = this.httpWebResponse.ContentType;
|
||||
}
|
||||
#elif SILVERLIGHT
|
||||
if (this.httpWebResponse.SupportsHeaders)
|
||||
{
|
||||
foreach (string header in this.httpWebResponse.Headers)
|
||||
{
|
||||
this.headers[header] = this.httpWebResponse.Headers[header];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.headers.ContentLength = this.httpWebResponse.ContentLength;
|
||||
this.headers["Content-Type"] = this.httpWebResponse.ContentType;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,260 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spring.Http.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for most <see cref="IHttpMessageConverter"/> implementations.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This base class adds support for setting supported <see cref="MediaType"/>s, through the
|
||||
/// <see cref="P:SupportedMediaTypes"/> property.
|
||||
/// It also adds support for 'Content-Type' when writing to the HTTP message.
|
||||
/// </remarks>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Juergen Hoeller</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
public abstract class AbstractHttpMessageConverter : IHttpMessageConverter
|
||||
{
|
||||
#region Logging
|
||||
#if !SILVERLIGHT
|
||||
private static readonly Common.Logging.ILog LOG = Common.Logging.LogManager.GetLogger(typeof(AbstractHttpMessageConverter));
|
||||
#endif
|
||||
#endregion
|
||||
|
||||
private IList<MediaType> _supportedMediaTypes = new List<MediaType>();
|
||||
|
||||
#region Constructor(s)
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="AbstractHttpMessageConverter"/>
|
||||
/// with no supported media types.
|
||||
/// </summary>
|
||||
protected AbstractHttpMessageConverter()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="AbstractHttpMessageConverter"/>
|
||||
/// with multiple supported media type.
|
||||
/// </summary>
|
||||
/// <param name="supportedMediaTypes">The supported media types.</param>
|
||||
protected AbstractHttpMessageConverter(params MediaType[] supportedMediaTypes)
|
||||
{
|
||||
this._supportedMediaTypes = new List<MediaType>(supportedMediaTypes);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IHttpMessageConverter Membres
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the given class can be read by this converter.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This implementation checks if the given class is <see cref="M:Supports(Type)">supported</see>,
|
||||
/// and if the <see cref="P:SupportedMediaTypes">supported media types</see> <see cref="M:MediaType.Includes(MediaType)">include</see>
|
||||
/// the given media type.
|
||||
/// </remarks>
|
||||
/// <param name="type">The class to test for readability</param>
|
||||
/// <param name="mediaType">
|
||||
/// The media type to read, can be null if not specified. Typically the value of a 'Content-Type' header.
|
||||
/// </param>
|
||||
/// <returns><see langword="true"/> if readable; otherwise <see langword="false"/></returns>
|
||||
public bool CanRead(Type type, MediaType mediaType)
|
||||
{
|
||||
return Supports(type) && CanRead(mediaType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the given class can be written by this converter.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This implementation checks if the given class is <see cref="M:Supports(Type)">supported</see>,
|
||||
/// and if the <see cref="P:SupportedMediaTypes">supported media types</see> <see cref="M:MediaType.Includes(MediaType)">include</see>
|
||||
/// the given media type.
|
||||
/// </remarks>
|
||||
/// <param name="type">The class to test for writability</param>
|
||||
/// <param name="mediaType">
|
||||
/// The media type to write, can be null if not specified. Typically the value of an 'Accept' header.
|
||||
/// </param>
|
||||
/// <returns><see langword="true"/> if writable; otherwise <see langword="false"/></returns>
|
||||
public bool CanWrite(Type type, MediaType mediaType)
|
||||
{
|
||||
return Supports(type) && CanWrite(mediaType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of <see cref="MediaType"/> objects supported by this converter.
|
||||
/// </summary>
|
||||
public IList<MediaType> SupportedMediaTypes
|
||||
{
|
||||
get { return _supportedMediaTypes; }
|
||||
set { _supportedMediaTypes = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read an object of the given type form the given HTTP message, and returns it.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This implementation simple delegates to <see cre="ReadInternal"/> method.
|
||||
/// Future implementations might add some default behavior, however.
|
||||
/// </remarks>
|
||||
/// <typeparam name="T">
|
||||
/// The type of object to return. This type must have previously been passed to the
|
||||
/// <see cref="M:CanRead"/> method of this interface, which must have returned <see langword="true"/>.
|
||||
/// </typeparam>
|
||||
/// <param name="message">The HTTP message to read from.</param>
|
||||
/// <returns>The converted object.</returns>
|
||||
/// <exception cref="HttpMessageNotReadableException">In case of conversion errors</exception>
|
||||
public T Read<T>(IHttpInputMessage message) where T : class
|
||||
{
|
||||
return ReadInternal<T>(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an given object to the given HTTP message.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This implementation delegates to <see cref="M:GetDefaultContentType"/> method if a content
|
||||
/// type was not provided, and calls <see cref="M:WriteInternal"/>.
|
||||
/// </remarks>
|
||||
/// <param name="content">
|
||||
/// The object to write to the HTTP message. The type of this object must have previously been
|
||||
/// passed to the <see cref="M:CanWrite"/> method of this interface, which must have returned <see langword="true"/>.
|
||||
/// </param>
|
||||
/// <param name="contentType">
|
||||
/// The content type to use when writing. May be null to indicate that the default content type of the converter must be used.
|
||||
/// If not null, this media type must have previously been passed to the <see cref="M:CanWrite"/> method of this interface,
|
||||
/// which must have returned <see langword="true"/>.
|
||||
/// </param>
|
||||
/// <param name="message">The HTTP message to write to.</param>
|
||||
/// <exception cref="HttpMessageNotWritableException">In case of conversion errors</exception>
|
||||
public void Write(object content, MediaType contentType, IHttpOutputMessage message)
|
||||
{
|
||||
HttpHeaders headers = message.Headers;
|
||||
if (headers.ContentType == null)
|
||||
{
|
||||
if (contentType == null || contentType.IsWildcardType || contentType.IsWildcardSubtype)
|
||||
{
|
||||
contentType = GetDefaultContentType(content.GetType());
|
||||
}
|
||||
if (contentType != null)
|
||||
{
|
||||
headers.ContentType = contentType;
|
||||
}
|
||||
}
|
||||
WriteInternal(content, message);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if any of the <see cref="P:SupportedMediaTypes">supported media types</see> include the given media type.
|
||||
/// </summary>
|
||||
/// <param name="mediaType">
|
||||
/// The media type to read, can be null if not specified. Typically the value of a 'Content-Type' header.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// <see langword="true"/> if the supported media types include the media type, or if the media type is null.
|
||||
/// </returns>
|
||||
protected bool CanRead(MediaType mediaType)
|
||||
{
|
||||
if (mediaType == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
foreach(MediaType supportedMediaType in this._supportedMediaTypes)
|
||||
{
|
||||
if (supportedMediaType.Includes(mediaType))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the given media type includes any of the <see cref="P:SupportedMediaTypes">supported media types</see>.
|
||||
/// </summary>
|
||||
/// <param name="mediaType">
|
||||
/// The media type to write, can be {@code null} if not specified. Typically the value of an 'Accept' header.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// <see langword="true"/> if the supported media types are compatible with the media type, or if the media type is null.
|
||||
/// </returns>
|
||||
protected bool CanWrite(MediaType mediaType)
|
||||
{
|
||||
if (mediaType == null || mediaType.Equals(MediaType.ALL))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
foreach(MediaType supportedMediaType in this._supportedMediaTypes)
|
||||
{
|
||||
if (supportedMediaType.IsCompatibleWith(mediaType))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the default content type for the given type.
|
||||
/// Called when <see cref="M:Write"/> is invoked without a specified content type parameter.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// By default, this returns the first element of the <see cref="P:SupportedMediaTypes"/> property, if any.
|
||||
/// </remarks>
|
||||
/// <param name="type">The type to return the content type for.</param>
|
||||
/// <returns>The <see cref="MediaType">content type</see>, or null if not known.</returns>
|
||||
protected virtual MediaType GetDefaultContentType(Type type)
|
||||
{
|
||||
return (this._supportedMediaTypes.Count > 0 ? this._supportedMediaTypes[0] : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the given class is supported by this converter.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to test for support.</param>
|
||||
/// <returns><see langword="true"/> if supported; otherwise <see langword="false"/></returns>
|
||||
protected abstract bool Supports(Type type);
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that reads the actualy object. Invoked from <see cref="M:Read"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of object to return.</typeparam>
|
||||
/// <param name="message">The HTTP message to read from.</param>
|
||||
/// <returns>The converted object.</returns>
|
||||
/// <exception cref="HttpMessageNotReadableException">In case of conversion errors</exception>
|
||||
protected abstract T ReadInternal<T>(IHttpInputMessage message) where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that writes the actual body. Invoked from <see cref="M:Write"/>.
|
||||
/// </summary>
|
||||
/// <param name="content">The object to write to the HTTP message.</param>
|
||||
/// <param name="message">The HTTP message to write to.</param>
|
||||
/// <exception cref="HttpMessageNotWritableException">In case of conversion errors</exception>
|
||||
protected abstract void WriteInternal(object content, IHttpOutputMessage message);
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
|
||||
namespace Spring.Http.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="IHttpMessageConverter"/> that can read and write byte arrays.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// By default, this converter supports all media types '*/*', and writes with a 'Content-Type'
|
||||
/// of 'application/octet-stream'.
|
||||
/// This can be overridden by setting the <see cref="P:SupportedMediaTypes"/> property.
|
||||
/// </remarks>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
public class ByteArrayHttpMessageConverter : AbstractHttpMessageConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="ByteArrayHttpMessageConverter"/>
|
||||
/// with 'application/octet-stream', and '*/*' media types.
|
||||
/// </summary>
|
||||
public ByteArrayHttpMessageConverter() :
|
||||
base(new MediaType("application", "octet-stream"), MediaType.ALL)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the given class is supported by this converter.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to test for support.</param>
|
||||
/// <returns><see langword="true"/> if supported; otherwise <see langword="false"/></returns>
|
||||
protected override bool Supports(Type type)
|
||||
{
|
||||
return type.Equals(typeof(byte[]));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that reads the actualy object. Invoked from <see cref="M:Read"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of object to return.</typeparam>
|
||||
/// <param name="message">The HTTP message to read from.</param>
|
||||
/// <returns>The converted object.</returns>
|
||||
/// <exception cref="HttpMessageNotReadableException">In case of conversion errors</exception>
|
||||
protected override T ReadInternal<T>(IHttpInputMessage message)
|
||||
{
|
||||
// Read from the message stream
|
||||
using (BinaryReader reader = new BinaryReader(message.Body))
|
||||
{
|
||||
return reader.ReadBytes((int)message.Headers.ContentLength) as T;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that writes the actual body. Invoked from <see cref="M:Write"/>.
|
||||
/// </summary>
|
||||
/// <param name="content">The object to write to the HTTP message.</param>
|
||||
/// <param name="message">The HTTP message to write to.</param>
|
||||
/// <exception cref="HttpMessageNotWritableException">In case of conversion errors</exception>
|
||||
protected override void WriteInternal(object content, IHttpOutputMessage message)
|
||||
{
|
||||
// Create a byte array of the data we want to send
|
||||
byte[] byteData = content as byte[];
|
||||
|
||||
//#if !SILVERLIGHT
|
||||
// // Set the content length in the message headers
|
||||
// message.Headers.ContentLength = byteData.Length;
|
||||
//#endif
|
||||
|
||||
// Write to the message stream
|
||||
message.Body = delegate(Stream stream)
|
||||
{
|
||||
stream.Write(byteData, 0, byteData.Length);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
#if NET_3_5 && !SILVERLIGHT
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Xml;
|
||||
using System.ServiceModel.Syndication;
|
||||
|
||||
using Spring.Http.Converters.Xml;
|
||||
|
||||
namespace Spring.Http.Converters.Feed
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for Atom and RSS Feed message converters
|
||||
/// using the <see cref="System.ServiceModel.Syndication.SyndicationFeed"/> class.
|
||||
/// </summary>
|
||||
/// <author>Bruno Baia</author>
|
||||
public abstract class AbstractFeedHttpMessageConverter : AbstractXmlHttpMessageConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="AbstractXmlHttpMessageConverter"/>
|
||||
/// with multiple supported media type.
|
||||
/// </summary>
|
||||
/// <param name="supportedMediaTypes">The supported media types.</param>
|
||||
protected AbstractFeedHttpMessageConverter(params MediaType[] supportedMediaTypes) :
|
||||
base(supportedMediaTypes)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the given class is supported by this converter.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to test for support.</param>
|
||||
/// <returns><see langword="true"/> if supported; otherwise <see langword="false"/></returns>
|
||||
protected override bool Supports(Type type)
|
||||
{
|
||||
return type.Equals(typeof(SyndicationFeed)) || type.Equals(typeof(SyndicationItem));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that reads the actualy object using a <see cref="XmlReader"/>. Invoked from <see cref="M:ReadInternal"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of object to return.</typeparam>
|
||||
/// <param name="xmlReader">The XmlReader to use.</param>
|
||||
/// <returns>The converted object.</returns>
|
||||
protected override T ReadXml<T>(XmlReader xmlReader)
|
||||
{
|
||||
if (typeof(SyndicationFeed).Equals(typeof(T)))
|
||||
{
|
||||
return SyndicationFeed.Load(xmlReader) as T;
|
||||
}
|
||||
if (typeof(SyndicationItem).Equals(typeof(T)))
|
||||
{
|
||||
return SyndicationItem.Load(xmlReader) as T;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="XmlReaderSettings">XmlReader settings</see>
|
||||
/// used by this converter to read from the HTTP message.
|
||||
/// </summary>
|
||||
/// <returns>The XmlReader settings.</returns>
|
||||
protected override XmlReaderSettings GetXmlReaderSettings()
|
||||
{
|
||||
XmlReaderSettings settings = new XmlReaderSettings();
|
||||
settings.CloseInput = true;
|
||||
settings.IgnoreProcessingInstructions = true;
|
||||
#if NET_4_0 || SILVERLIGHT
|
||||
settings.DtdProcessing = DtdProcessing.Ignore;
|
||||
#else
|
||||
settings.ProhibitDtd = false;
|
||||
#endif
|
||||
settings.XmlResolver = null;
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,68 +0,0 @@
|
||||
#if NET_3_5 && !SILVERLIGHT
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System.Net;
|
||||
using System.Xml;
|
||||
using System.ServiceModel.Syndication;
|
||||
|
||||
namespace Spring.Http.Converters.Feed
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="IHttpMessageConverter"/> that can read and write Atom feeds
|
||||
/// using the <see cref="System.ServiceModel.Syndication.SyndicationFeed"/> class.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// By default, this converter reads and writes the media type 'application/atom+xml' media type.
|
||||
/// This can be overridden by setting the <see cref="P:SupportedMediaTypes"/> property.
|
||||
/// </remarks>
|
||||
/// <author>Bruno Baia</author>
|
||||
public class Atom10FeedHttpMessageConverter : AbstractFeedHttpMessageConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="Atom10FeedHttpMessageConverter"/>
|
||||
/// with 'application/atom+xml', 'application/xml' and 'text/xml' media types.
|
||||
/// </summary>
|
||||
public Atom10FeedHttpMessageConverter() :
|
||||
base(new MediaType("application", "atom+xml"), new MediaType("application", "xml"), new MediaType("text", "xml"))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that writes the actual body using a <see cref="XmlWriter"/>. Invoked from <see cref="M:WriteInternal"/>.
|
||||
/// </summary>
|
||||
/// <param name="xmlWriter">The XmlWriter to use.</param>
|
||||
/// <param name="content">The object to write to the HTTP message.</param>
|
||||
protected override void WriteXml(XmlWriter xmlWriter, object content)
|
||||
{
|
||||
if (content is SyndicationFeed)
|
||||
{
|
||||
SyndicationFeed atomFeed = content as SyndicationFeed;
|
||||
atomFeed.SaveAsAtom10(xmlWriter);
|
||||
}
|
||||
else if (content is SyndicationItem)
|
||||
{
|
||||
SyndicationItem atomItem = content as SyndicationItem;
|
||||
atomItem.SaveAsAtom10(xmlWriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,68 +0,0 @@
|
||||
#if NET_3_5 && !SILVERLIGHT
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System.Net;
|
||||
using System.Xml;
|
||||
using System.ServiceModel.Syndication;
|
||||
|
||||
namespace Spring.Http.Converters.Feed
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="IHttpMessageConverter"/> that can read and write RSS feeds
|
||||
/// using the <see cref="System.ServiceModel.Syndication.SyndicationFeed"/> class.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// By default, this converter reads and writes the media type 'application/rss+xml' media type.
|
||||
/// This can be overridden by setting the <see cref="P:SupportedMediaTypes"/> property.
|
||||
/// </remarks>
|
||||
/// <author>Bruno Baia</author>
|
||||
public class Rss20FeedHttpMessageConverter : AbstractFeedHttpMessageConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="Rss20FeedHttpMessageConverter"/>
|
||||
/// with 'application/rss+xml', 'application/xml' and 'text/xml' media types.
|
||||
/// </summary>
|
||||
public Rss20FeedHttpMessageConverter() :
|
||||
base(new MediaType("application", "rss+xml"), new MediaType("application", "xml"), new MediaType("text", "xml"))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that writes the actual body using a <see cref="XmlWriter"/>. Invoked from <see cref="M:WriteInternal"/>.
|
||||
/// </summary>
|
||||
/// <param name="xmlWriter">The XmlWriter to use.</param>
|
||||
/// <param name="content">The object to write to the HTTP message.</param>
|
||||
protected override void WriteXml(XmlWriter xmlWriter, object content)
|
||||
{
|
||||
if (content is SyndicationFeed)
|
||||
{
|
||||
SyndicationFeed rssFeed = content as SyndicationFeed;
|
||||
rssFeed.SaveAsRss20(xmlWriter);
|
||||
}
|
||||
else if (content is SyndicationItem)
|
||||
{
|
||||
SyndicationItem rssItem = content as SyndicationItem;
|
||||
rssItem.SaveAsRss20(xmlWriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,195 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Spring.Util;
|
||||
|
||||
namespace Spring.Http.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="IHttpMessageConverter"/> that can write files.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A mapping between file extension and mime types is used to determine the Content-Type of written files.
|
||||
/// If no Content-Type is available, 'application/octet-stream' is used.
|
||||
/// </remarks>
|
||||
/// <author>Bruno Baia</author>
|
||||
public class FileInfoHttpMessageConverter : IHttpMessageConverter
|
||||
{
|
||||
// Pre-defined mapping between file extension and mime types
|
||||
private static IDictionary<string, string> defaultMimeMapping;
|
||||
|
||||
private IList<MediaType> _supportedMediaTypes;
|
||||
private IDictionary<string, string> _mimeMapping;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mapping between file extension and mime types.
|
||||
/// </summary>
|
||||
public IDictionary<string, string> MimeMapping
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._mimeMapping == null)
|
||||
{
|
||||
this._mimeMapping = new Dictionary<string, string>(defaultMimeMapping);
|
||||
}
|
||||
return _mimeMapping;
|
||||
}
|
||||
set { _mimeMapping = value; }
|
||||
}
|
||||
|
||||
static FileInfoHttpMessageConverter()
|
||||
{
|
||||
defaultMimeMapping = new Dictionary<string, string>(9, StringComparer.OrdinalIgnoreCase);
|
||||
defaultMimeMapping.Add(".bmp", "image/bmp");
|
||||
defaultMimeMapping.Add(".gif", "image/gif");
|
||||
defaultMimeMapping.Add(".jpg", "image/jpeg");
|
||||
defaultMimeMapping.Add(".jpeg", "image/jpeg");
|
||||
defaultMimeMapping.Add(".pdf", "application/pdf");
|
||||
defaultMimeMapping.Add(".png", "image/png");
|
||||
defaultMimeMapping.Add(".tif", "image/tiff");
|
||||
defaultMimeMapping.Add(".txt", "text/plain");
|
||||
defaultMimeMapping.Add(".zip", "application/x-zip-compressed");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="FileInfoHttpMessageConverter"/>
|
||||
/// with 'application/octet-stream', and '*/*' media types.
|
||||
/// </summary>
|
||||
public FileInfoHttpMessageConverter()
|
||||
{
|
||||
this._supportedMediaTypes = new List<MediaType>();
|
||||
this._supportedMediaTypes.Add(MediaType.APPLICATION_OCTET_STREAM);
|
||||
this._supportedMediaTypes.Add(MediaType.ALL);
|
||||
}
|
||||
|
||||
#region IHttpMessageConverter Membres
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the given class can be read by this converter.
|
||||
/// </summary>
|
||||
/// <param name="type">The class to test for readability</param>
|
||||
/// <param name="mediaType">
|
||||
/// The media type to read, can be null if not specified. Typically the value of a 'Content-Type' header.
|
||||
/// </param>
|
||||
/// <returns><see langword="true"/> if readable; otherwise <see langword="false"/></returns>
|
||||
public bool CanRead(Type type, MediaType mediaType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the given class can be written by this converter.
|
||||
/// </summary>
|
||||
/// <param name="type">The class to test for writability</param>
|
||||
/// <param name="mediaType">
|
||||
/// The media type to write, can be null if not specified. Typically the value of an 'Accept' header.
|
||||
/// </param>
|
||||
/// <returns><see langword="true"/> if writable; otherwise <see langword="false"/></returns>
|
||||
public bool CanWrite(Type type, MediaType mediaType)
|
||||
{
|
||||
return type.Equals(typeof(FileInfo));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of <see cref="MediaType"/> objects supported by this converter.
|
||||
/// </summary>
|
||||
public IList<MediaType> SupportedMediaTypes
|
||||
{
|
||||
get { return this._supportedMediaTypes; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read an object of the given type form the given HTTP message, and returns it.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// The type of object to return. This type must have previously been passed to the
|
||||
/// <see cref="M:CanRead"/> method of this interface, which must have returned <see langword="true"/>.
|
||||
/// </typeparam>
|
||||
/// <param name="message">The HTTP message to read from.</param>
|
||||
/// <returns>The converted object.</returns>
|
||||
/// <exception cref="HttpMessageNotReadableException">In case of conversion errors</exception>
|
||||
public T Read<T>(IHttpInputMessage message) where T : class
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an given object to the given HTTP message.
|
||||
/// </summary>
|
||||
/// <param name="content">
|
||||
/// The object to write to the HTTP message. The type of this object must have previously been
|
||||
/// passed to the <see cref="M:CanWrite"/> method of this interface, which must have returned <see langword="true"/>.
|
||||
/// </param>
|
||||
/// <param name="contentType">
|
||||
/// The content type to use when writing. May be null to indicate that the default content type of the converter must be used.
|
||||
/// If not null, this media type must have previously been passed to the <see cref="M:CanWrite"/> method of this interface,
|
||||
/// which must have returned <see langword="true"/>.
|
||||
/// </param>
|
||||
/// <param name="message">The HTTP message to write to.</param>
|
||||
/// <exception cref="HttpMessageNotWritableException">In case of conversion errors</exception>
|
||||
public void Write(object content, MediaType contentType, IHttpOutputMessage message)
|
||||
{
|
||||
// Get the content type
|
||||
HttpHeaders headers = message.Headers;
|
||||
if (headers.ContentType == null)
|
||||
{
|
||||
if (contentType == null || contentType.IsWildcardType || contentType.IsWildcardSubtype)
|
||||
{
|
||||
contentType = GetContentType(content as FileInfo);
|
||||
}
|
||||
if (contentType != null)
|
||||
{
|
||||
headers.ContentType = contentType;
|
||||
}
|
||||
}
|
||||
|
||||
// Write to the message stream
|
||||
message.Body = delegate(Stream stream)
|
||||
{
|
||||
using (FileStream fs = ((FileInfo)content).OpenRead())
|
||||
{
|
||||
IoUtils.CopyStream(fs, stream);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private MediaType GetContentType(FileInfo file)
|
||||
{
|
||||
IDictionary<string, string> mimeMapping =
|
||||
(this._mimeMapping == null) ? defaultMimeMapping : this._mimeMapping;
|
||||
|
||||
string mimeType;
|
||||
if (mimeMapping.TryGetValue(file.Extension, out mimeType))
|
||||
{
|
||||
return MediaType.Parse(mimeType);
|
||||
}
|
||||
else
|
||||
{
|
||||
return MediaType.APPLICATION_OCTET_STREAM;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,519 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
#if SILVERLIGHT
|
||||
using Spring.Collections.Specialized;
|
||||
#else
|
||||
using System.Collections.Specialized;
|
||||
#endif
|
||||
using Spring.Util;
|
||||
|
||||
namespace Spring.Http.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="IHttpMessageConverter"/> that can handle form data,
|
||||
/// including multipart form data (i.e. file uploads).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This converter supports the 'application/x-www-form-urlencoded' and 'multipart/form-data' media
|
||||
/// types, and read the 'application/x-www-form-urlencoded' media type (but not 'multipart/form-data').
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// In other words, this converter can read and write 'normal' HTML forms (as <see cref="NameValueCollection"/>),
|
||||
/// and it can write multipart form (as <see cref="IDictionary{String,Object}"/>).
|
||||
/// When writing multipart, this converter uses other <see cref="IHttpMessageConverter"/> to write the respective MIME parts.
|
||||
/// By default, basic converters are registered (supporting <see cref="String"/> and <see cref="FileInfo"/>, for instance);
|
||||
/// these can be overridden by setting <see cref="P:PartConverters"/> property.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// For example, the following snippet shows how to submit an HTML form:
|
||||
/// <code>
|
||||
/// RestTemplate template = new RestTemplate(); // FormHttpMessageConverter is configured by default
|
||||
/// NameValueCollection form = new NameValueCollection();
|
||||
/// form.Add("field 1", "value 1");
|
||||
/// form.Add("field 2", "value 2");
|
||||
/// form.Add("field 2", "value 3");
|
||||
/// template.PostForLocation("http://example.com/myForm", form);
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The following snippet shows how to do a file upload:
|
||||
/// <code>
|
||||
/// RestTemplate template = new RestTemplate();
|
||||
/// IDictionary<string, object> parts = new Dictionary<string, object>();
|
||||
/// parts.Add("field 1", "value 1");
|
||||
/// parts.Add("file", new FileInfo(@"C:\myFile.jpg"));
|
||||
/// template.PostForLocation("http://example.com/myFileUpload", parts);
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
public class FormHttpMessageConverter : IHttpMessageConverter
|
||||
{
|
||||
private static char[] BOUNDARY_CHARS =
|
||||
new char[]{'-', '_', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
|
||||
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A',
|
||||
'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
|
||||
'V', 'W', 'X', 'Y', 'Z'};
|
||||
|
||||
private Random random;
|
||||
private Encoding _charset;
|
||||
private IList<MediaType> _supportedMediaTypes;
|
||||
private IList<IHttpMessageConverter> _partConverters;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the message body converters to use.
|
||||
/// These converters are used to convert objects to MIME parts.
|
||||
/// </summary>
|
||||
public IList<IHttpMessageConverter> PartConverters
|
||||
{
|
||||
get { return _partConverters; }
|
||||
set { _partConverters = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the encoding used for writing form data.
|
||||
/// </summary>
|
||||
public Encoding Charset
|
||||
{
|
||||
get { return this._charset; }
|
||||
set { _charset = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="FormHttpMessageConverter"/>.
|
||||
/// </summary>
|
||||
public FormHttpMessageConverter()
|
||||
{
|
||||
this.random = new Random();
|
||||
#if SILVERLIGHT
|
||||
this._charset = new UTF8Encoding(false); // Remove byte Order Mask (BOM)
|
||||
#else
|
||||
this._charset = Encoding.GetEncoding("ISO-8859-1");
|
||||
#endif
|
||||
this._supportedMediaTypes = new List<MediaType>(2);
|
||||
this._supportedMediaTypes.Add(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
this._supportedMediaTypes.Add(MediaType.MULTIPART_FORM_DATA);
|
||||
|
||||
this._partConverters = new List<IHttpMessageConverter>(3);
|
||||
this._partConverters.Add(new ByteArrayHttpMessageConverter());
|
||||
this._partConverters.Add(new StringHttpMessageConverter());
|
||||
this._partConverters.Add(new FileInfoHttpMessageConverter());
|
||||
//this._partConverters.Add(new ResourceHttpMessageConverter());
|
||||
}
|
||||
|
||||
#region IHttpMessageConverter Membres
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the given class can be read by this converter.
|
||||
/// </summary>
|
||||
/// <param name="type">The class to test for readability</param>
|
||||
/// <param name="mediaType">
|
||||
/// The media type to read, can be null if not specified. Typically the value of a 'Content-Type' header.
|
||||
/// </param>
|
||||
/// <returns><see langword="true"/> if readable; otherwise <see langword="false"/></returns>
|
||||
public bool CanRead(Type type, MediaType mediaType)
|
||||
{
|
||||
if (!typeof(NameValueCollection).IsAssignableFrom(type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (mediaType != null)
|
||||
{
|
||||
return MediaType.APPLICATION_FORM_URLENCODED.Includes(mediaType);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the given class can be written by this converter.
|
||||
/// </summary>
|
||||
/// <param name="type">The class to test for writability</param>
|
||||
/// <param name="mediaType">
|
||||
/// The media type to write, can be null if not specified. Typically the value of an 'Accept' header.
|
||||
/// </param>
|
||||
/// <returns><see langword="true"/> if writable; otherwise <see langword="false"/></returns>
|
||||
public bool CanWrite(Type type, MediaType mediaType)
|
||||
{
|
||||
if (!typeof(NameValueCollection).IsAssignableFrom(type) &&
|
||||
!typeof(IDictionary<string, object>).IsAssignableFrom(type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (mediaType != null)
|
||||
{
|
||||
return MediaType.APPLICATION_FORM_URLENCODED.IsCompatibleWith(mediaType) ||
|
||||
MediaType.MULTIPART_FORM_DATA.IsCompatibleWith(mediaType);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of <see cref="MediaType"/> objects supported by this converter.
|
||||
/// </summary>
|
||||
public IList<MediaType> SupportedMediaTypes
|
||||
{
|
||||
get { return _supportedMediaTypes; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read an object of the given type form the given HTTP message, and returns it.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// The type of object to return. This type must have previously been passed to the
|
||||
/// <see cref="M:CanRead"/> method of this interface, which must have returned <see langword="true"/>.
|
||||
/// </typeparam>
|
||||
/// <param name="message">The HTTP message to read from.</param>
|
||||
/// <returns>The converted object.</returns>
|
||||
/// <exception cref="HttpMessageNotReadableException">In case of conversion errors</exception>
|
||||
public T Read<T>(IHttpInputMessage message) where T : class
|
||||
{
|
||||
// Get the message encoding
|
||||
Encoding encoding;
|
||||
MediaType mediaType = message.Headers.ContentType;
|
||||
if (mediaType == null || !StringUtils.HasText(mediaType.CharSet))
|
||||
{
|
||||
encoding = this._charset;
|
||||
}
|
||||
else
|
||||
{
|
||||
encoding = Encoding.GetEncoding(mediaType.CharSet);
|
||||
}
|
||||
|
||||
// Read from the message stream
|
||||
string body;
|
||||
using (StreamReader reader = new StreamReader(message.Body, encoding))
|
||||
{
|
||||
body = reader.ReadToEnd();
|
||||
}
|
||||
|
||||
string[] pairs = body.Split('&');
|
||||
NameValueCollection result = new NameValueCollection(pairs.Length);
|
||||
foreach (string pair in pairs)
|
||||
{
|
||||
int idx = pair.IndexOf('=');
|
||||
if (idx == -1)
|
||||
{
|
||||
result.Add(UrlDecode(pair, this._charset), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
string name = UrlDecode(pair.Substring(0, idx), this._charset);
|
||||
string value = UrlDecode(pair.Substring(idx + 1), this._charset);
|
||||
result.Add(name, value);
|
||||
}
|
||||
}
|
||||
return result as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an given object to the given HTTP message.
|
||||
/// </summary>
|
||||
/// <param name="content">
|
||||
/// The object to write to the HTTP message. The type of this object must have previously been
|
||||
/// passed to the <see cref="M:CanWrite"/> method of this interface, which must have returned <see langword="true"/>.
|
||||
/// </param>
|
||||
/// <param name="contentType">
|
||||
/// The content type to use when writing. May be null to indicate that the default content type of the converter must be used.
|
||||
/// If not null, this media type must have previously been passed to the <see cref="M:CanWrite"/> method of this interface,
|
||||
/// which must have returned <see langword="true"/>.
|
||||
/// </param>
|
||||
/// <param name="message">The HTTP message to write to.</param>
|
||||
/// <exception cref="HttpMessageNotWritableException">In case of conversion errors</exception>
|
||||
public void Write(object content, MediaType contentType, IHttpOutputMessage message)
|
||||
{
|
||||
if (content is NameValueCollection)
|
||||
{
|
||||
this.WriteForm((NameValueCollection) content, message);
|
||||
}
|
||||
else if (content is IDictionary<string, object>)
|
||||
{
|
||||
this.WriteMultipart((IDictionary<string, object>) content, message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Write Form
|
||||
|
||||
private void WriteForm(NameValueCollection form, IHttpOutputMessage message)
|
||||
{
|
||||
message.Headers.ContentType = MediaType.APPLICATION_FORM_URLENCODED;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < form.AllKeys.Length; i++)
|
||||
{
|
||||
string name = form.AllKeys[i];
|
||||
string[] values = form.GetValues(name);
|
||||
if (values == null)
|
||||
{
|
||||
builder.Append(UrlEncode(name, this._charset));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j = 0; j < values.Length; j++)
|
||||
{
|
||||
string value = values[j];
|
||||
builder.Append(UrlEncode(name, this._charset));
|
||||
builder.Append('=');
|
||||
builder.Append(UrlEncode(value, this._charset));
|
||||
if (j != (values.Length - 1))
|
||||
{
|
||||
builder.Append('&');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i != (form.AllKeys.Length - 1))
|
||||
{
|
||||
builder.Append('&');
|
||||
}
|
||||
}
|
||||
|
||||
// Create a byte array of the data we want to send
|
||||
byte[] byteData = this._charset.GetBytes(builder.ToString());
|
||||
|
||||
//#if !SILVERLIGHT
|
||||
// // Set the content length in the message headers
|
||||
// message.Headers.ContentLength = byteData.Length;
|
||||
//#endif
|
||||
|
||||
// Write to the message stream
|
||||
message.Body = delegate(Stream stream)
|
||||
{
|
||||
stream.Write(byteData, 0, byteData.Length);
|
||||
};
|
||||
}
|
||||
|
||||
private static string UrlDecode(string url, Encoding charset)
|
||||
{
|
||||
#if WINDOWS_PHONE
|
||||
return System.Net.HttpUtility.UrlDecode(url);
|
||||
#elif SILVERLIGHT
|
||||
return System.Windows.Browser.HttpUtility.UrlDecode(url);
|
||||
#else
|
||||
return System.Web.HttpUtility.UrlDecode(url, charset);
|
||||
#endif
|
||||
}
|
||||
|
||||
private static string UrlEncode(string url, Encoding charset)
|
||||
{
|
||||
#if WINDOWS_PHONE
|
||||
return System.Net.HttpUtility.UrlEncode(url);
|
||||
#elif SILVERLIGHT
|
||||
return System.Windows.Browser.HttpUtility.UrlEncode(url);
|
||||
#else
|
||||
return System.Web.HttpUtility.UrlEncode(url, charset);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Write Multipart
|
||||
|
||||
private void WriteMultipart(IDictionary<string, object> parts, IHttpOutputMessage message)
|
||||
{
|
||||
string boundary = this.GenerateMultipartBoundary();
|
||||
|
||||
IDictionary<string, string> parameters = new Dictionary<string, string>(1);
|
||||
parameters.Add("boundary", boundary);
|
||||
MediaType contentType = new MediaType(MediaType.MULTIPART_FORM_DATA, parameters);
|
||||
message.Headers.ContentType = contentType;
|
||||
|
||||
message.Body = delegate(Stream stream)
|
||||
{
|
||||
using (StreamWriter streamWriter = new StreamWriter(stream))
|
||||
{
|
||||
streamWriter.NewLine = "\r\n";
|
||||
this.WriteParts(boundary, parts, streamWriter);
|
||||
this.WriteEnd(boundary, streamWriter);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a multipart boundary.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Default implementation returns a random boundary. Can be overridden in subclasses.
|
||||
/// </remarks>
|
||||
/// <returns>A multipart boundary</returns>
|
||||
protected virtual string GenerateMultipartBoundary()
|
||||
{
|
||||
char[] boundary = new char[random.Next(11) + 30];
|
||||
for (int i = 0; i < boundary.Length; i++)
|
||||
{
|
||||
boundary[i] = BOUNDARY_CHARS[random.Next(BOUNDARY_CHARS.Length)];
|
||||
}
|
||||
return new String(boundary);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the filename of the given multipart part
|
||||
/// to be used for the 'Content-Disposition' header.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Default implementation returns <see cref="P:FileInfo.FullName"/> if the part is a <see cref="FileInfo"/>,
|
||||
/// and <see langword="null"/> in other cases. Can be overridden in subclasses.
|
||||
/// </remarks>
|
||||
/// <param name="part">The part to determine the file name for</param>
|
||||
/// <returns>The filename, or <see langword="null"/> if not known</returns>
|
||||
protected virtual string GetMultipartFilename(object part)
|
||||
{
|
||||
if (part is FileInfo)
|
||||
{
|
||||
return ((FileInfo)part).FullName;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void WriteParts(string boundary, IDictionary<string, object> parts, StreamWriter streamWriter)
|
||||
{
|
||||
foreach(KeyValuePair<string, object> entry in parts)
|
||||
{
|
||||
this.WriteBoundary(boundary, streamWriter);
|
||||
HttpEntity entity = this.GetEntity(entry.Value);
|
||||
this.WritePart(entry.Key, entity, streamWriter);
|
||||
streamWriter.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteBoundary(string boundary, StreamWriter streamWriter)
|
||||
{
|
||||
streamWriter.Write("--");
|
||||
streamWriter.Write(boundary);
|
||||
streamWriter.WriteLine();
|
||||
}
|
||||
|
||||
private void WritePart(String name, HttpEntity partEntity, StreamWriter streamWriter)
|
||||
{
|
||||
object partBody = partEntity.Body;
|
||||
Type partType = partBody.GetType();
|
||||
HttpHeaders partHeaders = partEntity.Headers;
|
||||
MediaType partContentType = partHeaders.ContentType;
|
||||
foreach (IHttpMessageConverter messageConverter in this._partConverters)
|
||||
{
|
||||
if (messageConverter.CanWrite(partType, partContentType))
|
||||
{
|
||||
IHttpOutputMessage multipartMessage = new MultipartHttpOutputMessage(streamWriter);
|
||||
multipartMessage.Headers["Content-Disposition"] = this.GetContentDispositionFormData(name, this.GetMultipartFilename(partBody));
|
||||
foreach (string header in partHeaders)
|
||||
{
|
||||
multipartMessage.Headers[header] = partHeaders[header];
|
||||
}
|
||||
messageConverter.Write(partBody, partContentType, multipartMessage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new HttpMessageNotWritableException(String.Format(
|
||||
"Could not write request: no suitable HttpMessageConverter found for part type [{0}]", partType));
|
||||
}
|
||||
|
||||
private void WriteEnd(string boundary, StreamWriter streamWriter)
|
||||
{
|
||||
streamWriter.Write("--");
|
||||
streamWriter.Write(boundary);
|
||||
streamWriter.Write("--");
|
||||
streamWriter.WriteLine();
|
||||
}
|
||||
|
||||
private HttpEntity GetEntity(object part)
|
||||
{
|
||||
if (part is HttpEntity)
|
||||
{
|
||||
return (HttpEntity)part;
|
||||
}
|
||||
return new HttpEntity(part);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the value of the 'Content-Disposition' header for 'form-data'.
|
||||
/// </summary>
|
||||
/// <param name="name">The field name</param>
|
||||
/// <param name="filename">The filename, may be <see langwrod="null"/></param>
|
||||
/// <returns>The value of the 'Content-Disposition' header</returns>
|
||||
private string GetContentDispositionFormData(string name, string filename)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.AppendFormat("form-data; name=\"{0}\"", name);
|
||||
if (filename != null)
|
||||
{
|
||||
builder.AppendFormat("; filename=\"{0}\"", filename);
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="IHttpOutputMessage"/> used for writing multipart data.
|
||||
/// </summary>
|
||||
private sealed class MultipartHttpOutputMessage : IHttpOutputMessage
|
||||
{
|
||||
private HttpHeaders headers;
|
||||
|
||||
private StreamWriter bodyWriter;
|
||||
|
||||
public MultipartHttpOutputMessage(StreamWriter bodyWriter)
|
||||
{
|
||||
this.headers = new HttpHeaders();
|
||||
this.bodyWriter = bodyWriter;
|
||||
}
|
||||
|
||||
#region IHttpMessage Membres
|
||||
|
||||
public HttpHeaders Headers
|
||||
{
|
||||
get { return this.headers; }
|
||||
}
|
||||
|
||||
public Action<Stream> Body
|
||||
{
|
||||
get { throw new InvalidOperationException(); }
|
||||
set { this.WritePartBody(value); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void WritePartBody(Action<Stream> body)
|
||||
{
|
||||
foreach (string header in this.headers)
|
||||
{
|
||||
bodyWriter.Write(header);
|
||||
bodyWriter.Write(": ");
|
||||
bodyWriter.Write(this.headers[header]);
|
||||
bodyWriter.WriteLine();
|
||||
}
|
||||
bodyWriter.WriteLine();
|
||||
bodyWriter.Flush();
|
||||
Stream stream = bodyWriter.BaseStream;
|
||||
stream.Flush();
|
||||
body(stream);
|
||||
stream.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Spring.Http.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Exception thrown by <see cref="IHttpMessageConverter"/> implementations when the conversion fails.
|
||||
/// </summary>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
#if !SILVERLIGHT
|
||||
[Serializable]
|
||||
#endif
|
||||
public class HttpMessageConversionException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="HttpMessageConversionException"/> class.
|
||||
/// </summary>
|
||||
public HttpMessageConversionException()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="HttpMessageConversionException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="message">
|
||||
/// A message about the exception.
|
||||
/// </param>
|
||||
public HttpMessageConversionException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="HttpMessageConversionException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="message">
|
||||
/// A message about the exception.
|
||||
/// </param>
|
||||
/// <param name="rootCause">
|
||||
/// The root exception that is being wrapped.
|
||||
/// </param>
|
||||
public HttpMessageConversionException(string message, Exception rootCause)
|
||||
: base(message, rootCause)
|
||||
{
|
||||
}
|
||||
|
||||
#if !SILVERLIGHT
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="HttpMessageConversionException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="info">
|
||||
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
|
||||
/// that holds the serialized object data about the exception being thrown.
|
||||
/// </param>
|
||||
/// <param name="context">
|
||||
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
|
||||
/// that contains contextual information about the source or destination.
|
||||
/// </param>
|
||||
protected HttpMessageConversionException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Spring.Http.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Exception thrown by <see cref="IHttpMessageConverter"/> implementations
|
||||
/// when reading from HTTP message fails.
|
||||
/// </summary>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
#if !SILVERLIGHT
|
||||
[Serializable]
|
||||
#endif
|
||||
public class HttpMessageNotReadableException : HttpMessageConversionException
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="HttpMessageNotReadableException"/> class.
|
||||
/// </summary>
|
||||
public HttpMessageNotReadableException()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="HttpMessageNotReadableException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="message">
|
||||
/// A message about the exception.
|
||||
/// </param>
|
||||
public HttpMessageNotReadableException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="HttpMessageNotReadableException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="message">
|
||||
/// A message about the exception.
|
||||
/// </param>
|
||||
/// <param name="rootCause">
|
||||
/// The root exception that is being wrapped.
|
||||
/// </param>
|
||||
public HttpMessageNotReadableException(string message, Exception rootCause)
|
||||
: base(message, rootCause)
|
||||
{
|
||||
}
|
||||
|
||||
#if !SILVERLIGHT
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="HttpMessageNotReadableException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="info">
|
||||
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
|
||||
/// that holds the serialized object data about the exception being thrown.
|
||||
/// </param>
|
||||
/// <param name="context">
|
||||
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
|
||||
/// that contains contextual information about the source or destination.
|
||||
/// </param>
|
||||
protected HttpMessageNotReadableException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Spring.Http.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Exception thrown by <see cref="IHttpMessageConverter"/> implementations
|
||||
/// when writing to HTTP message fails.
|
||||
/// </summary>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
#if !SILVERLIGHT
|
||||
[Serializable]
|
||||
#endif
|
||||
public class HttpMessageNotWritableException : HttpMessageConversionException
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="HttpMessageNotWritableException"/> class.
|
||||
/// </summary>
|
||||
public HttpMessageNotWritableException()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="HttpMessageNotWritableException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="message">
|
||||
/// A message about the exception.
|
||||
/// </param>
|
||||
public HttpMessageNotWritableException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="HttpMessageNotWritableException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="message">
|
||||
/// A message about the exception.
|
||||
/// </param>
|
||||
/// <param name="rootCause">
|
||||
/// The root exception that is being wrapped.
|
||||
/// </param>
|
||||
public HttpMessageNotWritableException(string message, Exception rootCause)
|
||||
: base(message, rootCause)
|
||||
{
|
||||
}
|
||||
|
||||
#if !SILVERLIGHT
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="HttpMessageNotWritableException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="info">
|
||||
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
|
||||
/// that holds the serialized object data about the exception being thrown.
|
||||
/// </param>
|
||||
/// <param name="context">
|
||||
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
|
||||
/// that contains contextual information about the source or destination.
|
||||
/// </param>
|
||||
protected HttpMessageNotWritableException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Spring.Http.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Strategy interface that specifies a converter that can convert from and to HTTP messages.
|
||||
/// </summary>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Juergen Hoeller</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
public interface IHttpMessageConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates whether the given class can be read by this converter.
|
||||
/// </summary>
|
||||
/// <param name="type">The class to test for readability</param>
|
||||
/// <param name="mediaType">
|
||||
/// The media type to read, can be null if not specified. Typically the value of a 'Content-Type' header.
|
||||
/// </param>
|
||||
/// <returns><see langword="true"/> if readable; otherwise <see langword="false"/></returns>
|
||||
bool CanRead(Type type, MediaType mediaType);
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the given class can be written by this converter.
|
||||
/// </summary>
|
||||
/// <param name="type">The class to test for writability</param>
|
||||
/// <param name="mediaType">
|
||||
/// The media type to write, can be null if not specified. Typically the value of an 'Accept' header.
|
||||
/// </param>
|
||||
/// <returns><see langword="true"/> if writable; otherwise <see langword="false"/></returns>
|
||||
bool CanWrite(Type type, MediaType mediaType);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of <see cref="MediaType"/> objects supported by this converter.
|
||||
/// </summary>
|
||||
IList<MediaType> SupportedMediaTypes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Read an object of the given type form the given HTTP message, and returns it.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// The type of object to return. This type must have previously been passed to the
|
||||
/// <see cref="M:CanRead"/> method of this interface, which must have returned <see langword="true"/>.
|
||||
/// </typeparam>
|
||||
/// <param name="message">The HTTP message to read from.</param>
|
||||
/// <returns>The converted object.</returns>
|
||||
/// <exception cref="HttpMessageNotReadableException">In case of conversion errors</exception>
|
||||
T Read<T>(IHttpInputMessage message) where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// Write an given object to the given HTTP message.
|
||||
/// </summary>
|
||||
/// <param name="content">
|
||||
/// The object to write to the HTTP message. The type of this object must have previously been
|
||||
/// passed to the <see cref="M:CanWrite"/> method of this interface, which must have returned <see langword="true"/>.
|
||||
/// </param>
|
||||
/// <param name="contentType">
|
||||
/// The content type to use when writing. May be null to indicate that the default content type of the converter must be used.
|
||||
/// If not null, this media type must have previously been passed to the <see cref="M:CanWrite"/> method of this interface,
|
||||
/// which must have returned <see langword="true"/>.
|
||||
/// </param>
|
||||
/// <param name="message">The HTTP message to write to.</param>
|
||||
/// <exception cref="HttpMessageNotWritableException">In case of conversion errors</exception>
|
||||
void Write(object content, MediaType contentType, IHttpOutputMessage message);
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
#if NET_3_5 || WINDOWS_PHONE
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Xml;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization.Json;
|
||||
|
||||
using Spring.Util;
|
||||
|
||||
namespace Spring.Http.Converters.Json
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="IHttpMessageConverter"/> that can read and write JSON.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// By default, this converter supports 'application/json' media type.
|
||||
/// This can be overridden by setting the <see cref="P:SupportedMediaTypes"/> property.
|
||||
/// </remarks>
|
||||
/// <author>Bruno Baia</author>
|
||||
public class JsonHttpMessageConverter : AbstractHttpMessageConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Default encoding for JSON.
|
||||
/// </summary>
|
||||
public static readonly Encoding DEFAULT_CHARSET = new UTF8Encoding(false); // Remove byte Order Mask (BOM)
|
||||
|
||||
private IEnumerable<Type> _knownTypes;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets types that may be present in the object graph.
|
||||
/// </summary>
|
||||
public IEnumerable<Type> KnownTypes
|
||||
{
|
||||
get { return _knownTypes; }
|
||||
set { _knownTypes = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="JsonHttpMessageConverter"/>
|
||||
/// with the media type 'application/json'.
|
||||
/// </summary>
|
||||
public JsonHttpMessageConverter() :
|
||||
base(new MediaType("application", "json"))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the given class is supported by this converter.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to test for support.</param>
|
||||
/// <returns><see langword="true"/> if supported; otherwise <see langword="false"/></returns>
|
||||
protected override bool Supports(Type type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that reads the actualy object. Invoked from <see cref="M:Read"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of object to return.</typeparam>
|
||||
/// <param name="message">The HTTP message to read from.</param>
|
||||
/// <returns>The converted object.</returns>
|
||||
/// <exception cref="HttpMessageNotReadableException">In case of conversion errors</exception>
|
||||
protected override T ReadInternal<T>(IHttpInputMessage message)
|
||||
{
|
||||
DataContractJsonSerializer serializer = this.GetSerializer(typeof(T));
|
||||
return (T)serializer.ReadObject(message.Body) as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that writes the actual body. Invoked from <see cref="M:Write"/>.
|
||||
/// </summary>
|
||||
/// <param name="content">The object to write to the HTTP message.</param>
|
||||
/// <param name="message">The HTTP message to write to.</param>
|
||||
/// <exception cref="HttpMessageNotWritableException">In case of conversion errors</exception>
|
||||
protected override void WriteInternal(object content, IHttpOutputMessage message)
|
||||
{
|
||||
#if SILVERLIGHT
|
||||
// Write to the message stream
|
||||
message.Body = delegate(Stream stream)
|
||||
{
|
||||
DataContractJsonSerializer serializer = this.GetSerializer(content.GetType());
|
||||
serializer.WriteObject(stream, content);
|
||||
};
|
||||
#else
|
||||
// Get the message encoding
|
||||
Encoding encoding;
|
||||
MediaType mediaType = message.Headers.ContentType;
|
||||
if (mediaType == null || !StringUtils.HasText(mediaType.CharSet))
|
||||
{
|
||||
encoding = DEFAULT_CHARSET;
|
||||
}
|
||||
else
|
||||
{
|
||||
encoding = Encoding.GetEncoding(mediaType.CharSet);
|
||||
}
|
||||
|
||||
DataContractJsonSerializer serializer = this.GetSerializer(content.GetType());
|
||||
|
||||
// Write to the message stream
|
||||
message.Body = delegate(Stream stream)
|
||||
{
|
||||
// Using JsonReaderWriterFactory directly to set encoding
|
||||
using (XmlDictionaryWriter jsonWriter = JsonReaderWriterFactory.CreateJsonWriter(stream, encoding, false))
|
||||
{
|
||||
serializer.WriteObject(jsonWriter, content);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="DataContractJsonSerializer"/> to
|
||||
/// serialize or deserialize an object of the specified type.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of instances to serialize or deserialize.</param>
|
||||
/// <returns>The serializer to use.</returns>
|
||||
protected virtual DataContractJsonSerializer GetSerializer(Type type)
|
||||
{
|
||||
if (this._knownTypes == null)
|
||||
{
|
||||
return new DataContractJsonSerializer(type);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new DataContractJsonSerializer(type, this._knownTypes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,137 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
using Spring.Util;
|
||||
|
||||
namespace Spring.Http.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="IHttpMessageConverter"/> that can read and write strings.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// By default, this converter supports all media types '*/*', and writes with a 'Content-Type'
|
||||
/// of 'text/plain'.
|
||||
/// This can be overridden by setting the <see cref="P:SupportedMediaTypes"/> property.
|
||||
/// </remarks>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
public class StringHttpMessageConverter : AbstractHttpMessageConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Default encoding for strings.
|
||||
/// </summary>
|
||||
#if SILVERLIGHT
|
||||
public static readonly Encoding DEFAULT_CHARSET = new UTF8Encoding(false); // Remove byte Order Mask (BOM)
|
||||
#else
|
||||
public static readonly Encoding DEFAULT_CHARSET = Encoding.GetEncoding("ISO-8859-1");
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="ByteArrayHttpMessageConverter"/>
|
||||
/// with 'text/plain; charset=ISO-8859-1', and '*/*' media types.
|
||||
/// </summary>
|
||||
public StringHttpMessageConverter() :
|
||||
#if SILVERLIGHT
|
||||
base(new MediaType("text", "plain", "UTF-8"), MediaType.ALL)
|
||||
#else
|
||||
base(new MediaType("text", "plain", "ISO-8859-1"), MediaType.ALL)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the given class is supported by this converter.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to test for support.</param>
|
||||
/// <returns><see langword="true"/> if supported; otherwise <see langword="false"/></returns>
|
||||
protected override bool Supports(Type type)
|
||||
{
|
||||
return type.Equals(typeof(string));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that reads the actualy object. Invoked from <see cref="M:Read"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of object to return.</typeparam>
|
||||
/// <param name="message">The HTTP message to read from.</param>
|
||||
/// <returns>The converted object.</returns>
|
||||
/// <exception cref="HttpMessageNotReadableException">In case of conversion errors</exception>
|
||||
protected override T ReadInternal<T>(IHttpInputMessage message)
|
||||
{
|
||||
// Get the message encoding
|
||||
Encoding encoding;
|
||||
MediaType mediaType = message.Headers.ContentType;
|
||||
if (mediaType == null || !StringUtils.HasText(mediaType.CharSet))
|
||||
{
|
||||
encoding = DEFAULT_CHARSET;
|
||||
}
|
||||
else
|
||||
{
|
||||
encoding = Encoding.GetEncoding(mediaType.CharSet);
|
||||
}
|
||||
|
||||
// Read from the message stream
|
||||
using (StreamReader reader = new StreamReader(message.Body, encoding))
|
||||
{
|
||||
return reader.ReadToEnd() as T;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that writes the actual body. Invoked from <see cref="M:Write"/>.
|
||||
/// </summary>
|
||||
/// <param name="content">The object to write to the HTTP message.</param>
|
||||
/// <param name="message">The HTTP message to write to.</param>
|
||||
/// <exception cref="HttpMessageNotWritableException">In case of conversion errors</exception>
|
||||
protected override void WriteInternal(object content, IHttpOutputMessage message)
|
||||
{
|
||||
// Get the message encoding
|
||||
Encoding encoding;
|
||||
MediaType mediaType = message.Headers.ContentType;
|
||||
if (mediaType == null || !StringUtils.HasText(mediaType.CharSet))
|
||||
{
|
||||
encoding = DEFAULT_CHARSET;
|
||||
}
|
||||
else
|
||||
{
|
||||
encoding = Encoding.GetEncoding(mediaType.CharSet);
|
||||
}
|
||||
|
||||
// Create a byte array of the data we want to send
|
||||
byte[] byteData = encoding.GetBytes(content as string);
|
||||
|
||||
//#if !SILVERLIGHT
|
||||
// // Set the content length in the message headers
|
||||
// message.Headers.ContentLength = byteData.Length;
|
||||
//#endif
|
||||
|
||||
// Write to the message stream
|
||||
message.Body = delegate(Stream stream)
|
||||
{
|
||||
stream.Write(byteData, 0, byteData.Length);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
using Spring.Util;
|
||||
|
||||
namespace Spring.Http.Converters.Xml
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for <see cref="IHttpMessageConverter"/> that convert from/to XML.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// By default, subclasses of this converter support 'text/xml', 'application/xml', and 'application/*-xml' media types.
|
||||
/// This can be overridden by setting the <see cref="P:SupportedMediaTypes"/> property.
|
||||
/// </remarks>
|
||||
/// <author>Bruno Baia</author>
|
||||
public abstract class AbstractXmlHttpMessageConverter : AbstractHttpMessageConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Default encoding for XML.
|
||||
/// </summary>
|
||||
public static readonly Encoding DEFAULT_CHARSET = new UTF8Encoding(false); // Remove byte Order Mask (BOM)
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="AbstractHttpMessageConverter"/>
|
||||
/// with multiple supported media type.
|
||||
/// </summary>
|
||||
/// <param name="supportedMediaTypes">The supported media types.</param>
|
||||
protected AbstractXmlHttpMessageConverter(params MediaType[] supportedMediaTypes) :
|
||||
base(supportedMediaTypes)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="AbstractHttpMessageConverter"/> that sets
|
||||
/// the <see cref="P:SupportedMediaTypes"/> to 'text/xml' and 'application/xml', and 'application/*-xml'.
|
||||
/// </summary>
|
||||
protected AbstractXmlHttpMessageConverter() :
|
||||
base(new MediaType("application", "xml"), new MediaType("text", "xml"), new MediaType("application", "*+xml"))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that reads the actualy object. Invoked from <see cref="M:Read"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of object to return.</typeparam>
|
||||
/// <param name="message">The HTTP message to read from.</param>
|
||||
/// <returns>The converted object.</returns>
|
||||
/// <exception cref="HttpMessageNotReadableException">In case of conversion errors</exception>
|
||||
protected override T ReadInternal<T>(IHttpInputMessage message)
|
||||
{
|
||||
XmlReaderSettings settings = this.GetXmlReaderSettings();
|
||||
|
||||
// Read from the message stream
|
||||
using (XmlReader xmlReader = XmlReader.Create(message.Body, settings))
|
||||
{
|
||||
return ReadXml<T>(xmlReader);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that writes the actual body. Invoked from <see cref="M:Write"/>.
|
||||
/// </summary>
|
||||
/// <param name="content">The object to write to the HTTP message.</param>
|
||||
/// <param name="message">The HTTP message to write to.</param>
|
||||
/// <exception cref="HttpMessageNotWritableException">In case of conversion errors</exception>
|
||||
protected override void WriteInternal(object content, IHttpOutputMessage message)
|
||||
{
|
||||
// Get the message encoding
|
||||
Encoding encoding;
|
||||
MediaType mediaType = message.Headers.ContentType;
|
||||
if (mediaType == null || !StringUtils.HasText(mediaType.CharSet))
|
||||
{
|
||||
encoding = DEFAULT_CHARSET;
|
||||
}
|
||||
else
|
||||
{
|
||||
encoding = Encoding.GetEncoding(mediaType.CharSet);
|
||||
}
|
||||
|
||||
XmlWriterSettings settings = this.GetXmlWriterSettings();
|
||||
settings.Encoding = encoding;
|
||||
|
||||
// Write to the message stream
|
||||
message.Body = delegate(Stream stream)
|
||||
{
|
||||
using (XmlWriter xmlWriter = XmlWriter.Create(stream, settings))
|
||||
{
|
||||
WriteXml(xmlWriter, content);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that reads the actualy object using a <see cref="XmlReader"/>. Invoked from <see cref="M:ReadInternal"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of object to return.</typeparam>
|
||||
/// <param name="xmlReader">The XmlReader to use.</param>
|
||||
/// <returns>The converted object.</returns>
|
||||
protected abstract T ReadXml<T>(XmlReader xmlReader) where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that writes the actual body using a <see cref="XmlWriter"/>. Invoked from <see cref="M:WriteInternal"/>.
|
||||
/// </summary>
|
||||
/// <param name="xmlWriter">The XmlWriter to use.</param>
|
||||
/// <param name="content">The object to write to the HTTP message.</param>
|
||||
protected abstract void WriteXml(XmlWriter xmlWriter, object content);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="XmlReaderSettings">XmlReader settings</see>
|
||||
/// used by this converter to read from the HTTP message.
|
||||
/// </summary>
|
||||
/// <returns>The XmlReader settings.</returns>
|
||||
protected virtual XmlReaderSettings GetXmlReaderSettings()
|
||||
{
|
||||
XmlReaderSettings settings = new XmlReaderSettings();
|
||||
settings.ConformanceLevel = ConformanceLevel.Auto;
|
||||
settings.CloseInput = true;
|
||||
settings.IgnoreProcessingInstructions = true;
|
||||
settings.IgnoreWhitespace = true;
|
||||
return settings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="XmlWriterSettings">XmlWriter settings</see>
|
||||
/// used by this converter to write to the HTTP message.
|
||||
/// </summary>
|
||||
/// <returns>The XmlWriter settings.</returns>
|
||||
protected virtual XmlWriterSettings GetXmlWriterSettings()
|
||||
{
|
||||
XmlWriterSettings settings = new XmlWriterSettings();
|
||||
settings.CloseOutput = false;
|
||||
settings.NewLineHandling = NewLineHandling.Entitize;
|
||||
settings.OmitXmlDeclaration = true;
|
||||
settings.CheckCharacters = false;
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
#if NET_3_0 || SILVERLIGHT
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Xml;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Spring.Http.Converters.Xml
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="IHttpMessageConverter"/> that can read and write XML
|
||||
/// using <see cref="DataContractSerializer"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// By default, this converter supports 'text/xml', 'application/xml', and 'application/*-xml' media types.
|
||||
/// This can be overridden by setting the <see cref="P:SupportedMediaTypes"/> property.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This converter can read classes annotated with <see cref="DataContractAttribute"/> and <see cref="CollectionDataContractAttribute"/>, and write classes
|
||||
/// annotated with with {@link XmlRootElement}, or subclasses thereof.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <author>Bruno Baia</author>
|
||||
public class DataContractHttpMessageConverter : AbstractXmlHttpMessageConverter
|
||||
{
|
||||
private IEnumerable<Type> _knownTypes;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets types that may be present in the object graph.
|
||||
/// </summary>
|
||||
public IEnumerable<Type> KnownTypes
|
||||
{
|
||||
get { return _knownTypes; }
|
||||
set { _knownTypes = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="DataContractHttpMessageConverter"/>
|
||||
/// with 'text/xml', 'application/xml', and 'application/*-xml' media types.
|
||||
/// </summary>
|
||||
public DataContractHttpMessageConverter() :
|
||||
base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the given class is supported by this converter.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to test for support.</param>
|
||||
/// <returns><see langword="true"/> if supported; otherwise <see langword="false"/></returns>
|
||||
protected override bool Supports(Type type)
|
||||
{
|
||||
return (
|
||||
Attribute.GetCustomAttributes(type, typeof(DataContractAttribute), true).Length > 0 ||
|
||||
Attribute.GetCustomAttributes(type, typeof(CollectionDataContractAttribute), true).Length > 0
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that reads the actualy object using a <see cref="XmlReader"/>. Invoked from <see cref="M:ReadInternal"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of object to return.</typeparam>
|
||||
/// <param name="xmlReader">The XmlReader to use.</param>
|
||||
/// <returns>The converted object.</returns>
|
||||
protected override T ReadXml<T>(XmlReader xmlReader)
|
||||
{
|
||||
DataContractSerializer serializer = this.GetSerializer(typeof(T));
|
||||
return serializer.ReadObject(xmlReader) as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that writes the actual body using a <see cref="XmlWriter"/>. Invoked from <see cref="M:WriteInternal"/>.
|
||||
/// </summary>
|
||||
/// <param name="xmlWriter">The XmlWriter to use.</param>
|
||||
/// <param name="content">The object to write to the HTTP message.</param>
|
||||
protected override void WriteXml(XmlWriter xmlWriter, object content)
|
||||
{
|
||||
DataContractSerializer serializer = this.GetSerializer(content.GetType());
|
||||
serializer.WriteObject(xmlWriter, content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="DataContractSerializer"/> to
|
||||
/// serialize or deserialize an object of the specified type.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of instances to serialize or deserialize.</param>
|
||||
/// <returns>The serializer to use.</returns>
|
||||
protected virtual DataContractSerializer GetSerializer(Type type)
|
||||
{
|
||||
if (this._knownTypes == null)
|
||||
{
|
||||
return new DataContractSerializer(type);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new DataContractSerializer(type, this._knownTypes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,82 +0,0 @@
|
||||
#if NET_3_5 || WINDOWS_PHONE
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Spring.Http.Converters.Xml
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="IHttpMessageConverter"/> that can read and write XML
|
||||
/// from a <see cref="XElement"/> (Linq to XML).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// By default, this converter supports 'text/xml', 'application/xml', and 'application/*-xml' media types.
|
||||
/// This can be overridden by setting the <see cref="P:SupportedMediaTypes"/> property.
|
||||
/// </remarks>
|
||||
/// <author>Bruno Baia</author>
|
||||
public class XElementHttpMessageConverter : AbstractXmlHttpMessageConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="XElementHttpMessageConverter"/>
|
||||
/// with 'text/xml', 'application/xml', and 'application/*-xml' media types.
|
||||
/// </summary>
|
||||
public XElementHttpMessageConverter() :
|
||||
base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the given class is supported by this converter.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to test for support.</param>
|
||||
/// <returns><see langword="true"/> if supported; otherwise <see langword="false"/></returns>
|
||||
protected override bool Supports(Type type)
|
||||
{
|
||||
return type.Equals(typeof(XElement));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that reads the actualy object using a <see cref="XmlReader"/>. Invoked from <see cref="M:ReadInternal"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of object to return.</typeparam>
|
||||
/// <param name="xmlReader">The XmlReader to use.</param>
|
||||
/// <returns>The converted object.</returns>
|
||||
protected override T ReadXml<T>(XmlReader xmlReader)
|
||||
{
|
||||
return XElement.Load(xmlReader) as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that writes the actual body using a <see cref="XmlWriter"/>. Invoked from <see cref="M:WriteInternal"/>.
|
||||
/// </summary>
|
||||
/// <param name="xmlWriter">The XmlWriter to use.</param>
|
||||
/// <param name="content">The object to write to the HTTP message.</param>
|
||||
protected override void WriteXml(XmlWriter xmlWriter, object content)
|
||||
{
|
||||
XElement xElement = content as XElement;
|
||||
xElement.WriteTo(xmlWriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,83 +0,0 @@
|
||||
#if !SILVERLIGHT
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Xml;
|
||||
using System.Net;
|
||||
|
||||
namespace Spring.Http.Converters.Xml
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="IHttpMessageConverter"/> that can read and write XML
|
||||
/// from a <see cref="XmlDocument"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// By default, this converter supports 'text/xml', 'application/xml', and 'application/*-xml' media types.
|
||||
/// This can be overridden by setting the <see cref="P:SupportedMediaTypes"/> property.
|
||||
/// </remarks>
|
||||
/// <author>Bruno Baia</author>
|
||||
public class XmlDocumentHttpMessageConverter : AbstractXmlHttpMessageConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="XmlDocumentHttpMessageConverter"/>
|
||||
/// with 'text/xml', 'application/xml', and 'application/*-xml' media types.
|
||||
/// </summary>
|
||||
public XmlDocumentHttpMessageConverter() :
|
||||
base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the given class is supported by this converter.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to test for support.</param>
|
||||
/// <returns><see langword="true"/> if supported; otherwise <see langword="false"/></returns>
|
||||
protected override bool Supports(Type type)
|
||||
{
|
||||
return type.Equals(typeof(XmlDocument));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that reads the actualy object using a <see cref="XmlReader"/>. Invoked from <see cref="M:ReadInternal"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of object to return.</typeparam>
|
||||
/// <param name="xmlReader">The XmlReader to use.</param>
|
||||
/// <returns>The converted object.</returns>
|
||||
protected override T ReadXml<T>(XmlReader xmlReader)
|
||||
{
|
||||
XmlDocument document = new XmlDocument();
|
||||
document.Load(xmlReader);
|
||||
return document as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that writes the actual body using a <see cref="XmlWriter"/>. Invoked from <see cref="M:WriteInternal"/>.
|
||||
/// </summary>
|
||||
/// <param name="xmlWriter">The XmlWriter to use.</param>
|
||||
/// <param name="content">The object to write to the HTTP message.</param>
|
||||
protected override void WriteXml(XmlWriter xmlWriter, object content)
|
||||
{
|
||||
XmlDocument document = content as XmlDocument;
|
||||
document.WriteTo(xmlWriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,115 +0,0 @@
|
||||
#if !SILVERLIGHT || WINDOWS_PHONE
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Spring.Http.Converters.Xml
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="IHttpMessageConverter"/> that can read and write XML
|
||||
/// using <see cref="XmlSerializer"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// By default, this converter supports 'text/xml', 'application/xml', and 'application/*-xml' media types.
|
||||
/// This can be overridden by setting the <see cref="P:SupportedMediaTypes"/> property.
|
||||
/// </remarks>
|
||||
/// <author>Bruno Baia</author>
|
||||
public class XmlSerializableHttpMessageConverter : AbstractXmlHttpMessageConverter
|
||||
{
|
||||
private Type[] _knownTypes;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets types that may be present in the object graph.
|
||||
/// </summary>
|
||||
public Type[] KnownTypes
|
||||
{
|
||||
get { return _knownTypes; }
|
||||
set { _knownTypes = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="XmlSerializableHttpMessageConverter"/>
|
||||
/// with 'text/xml', 'application/xml', and 'application/*-xml' media types.
|
||||
/// </summary>
|
||||
public XmlSerializableHttpMessageConverter() :
|
||||
base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the given class is supported by this converter.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to test for support.</param>
|
||||
/// <returns><see langword="true"/> if supported; otherwise <see langword="false"/></returns>
|
||||
protected override bool Supports(Type type)
|
||||
{
|
||||
return true;
|
||||
//return (
|
||||
// AttributeUtils.FindAttribute(type, typeof(XmlRootAttribute)) != null ||
|
||||
// AttributeUtils.FindAttribute(type, typeof(XmlTypeAttribute)) != null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that reads the actualy object using a <see cref="XmlReader"/>. Invoked from <see cref="M:ReadInternal"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of object to return.</typeparam>
|
||||
/// <param name="xmlReader">The XmlReader to use.</param>
|
||||
/// <returns>The converted object.</returns>
|
||||
protected override T ReadXml<T>(XmlReader xmlReader)
|
||||
{
|
||||
XmlSerializer serializer = this.GetSerializer(typeof(T));
|
||||
return serializer.Deserialize(xmlReader) as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract template method that writes the actual body using a <see cref="XmlWriter"/>. Invoked from <see cref="M:WriteInternal"/>.
|
||||
/// </summary>
|
||||
/// <param name="xmlWriter">The XmlWriter to use.</param>
|
||||
/// <param name="content">The object to write to the HTTP message.</param>
|
||||
protected override void WriteXml(XmlWriter xmlWriter, object content)
|
||||
{
|
||||
XmlSerializer serializer = this.GetSerializer(content.GetType());
|
||||
serializer.Serialize(xmlWriter, content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of <see cref="XmlSerializer"/> to
|
||||
/// serialize or deserialize an object of the specified type.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of instances to serialize or deserialize.</param>
|
||||
/// <returns>The serializer to use.</returns>
|
||||
protected virtual XmlSerializer GetSerializer(Type type)
|
||||
{
|
||||
if (this._knownTypes == null)
|
||||
{
|
||||
return new XmlSerializer(type);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new XmlSerializer(type, this._knownTypes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,68 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System.Net;
|
||||
|
||||
namespace Spring.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a HTTP entity message, as defined in the HTTP specification.
|
||||
/// <a href="http://tools.ietf.org/html/rfc2616#section-7">HTTP 1.1, section 7</a>
|
||||
/// </summary>
|
||||
/// <author>Bruno Baia</author>
|
||||
public class HttpEntity : HttpEntity<object>
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new, empty instance of <see cref="HttpEntity"/> with no body or headers.
|
||||
/// </summary>
|
||||
public HttpEntity()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpEntity"/> with the given body.
|
||||
/// </summary>
|
||||
/// <param name="body">The entity body.</param>
|
||||
public HttpEntity(object body) :
|
||||
base(body)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpEntity"/> with the given headers.
|
||||
/// </summary>
|
||||
/// <param name="headers">The entity headers.</param>
|
||||
public HttpEntity(HttpHeaders headers) :
|
||||
base(headers)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpEntity"/> with the given body and headers.
|
||||
/// </summary>
|
||||
/// <param name="body">The entity body.</param>
|
||||
/// <param name="headers">The entity headers.</param>
|
||||
public HttpEntity(object body, HttpHeaders headers) :
|
||||
base(body, headers)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System.Net;
|
||||
|
||||
using Spring.Util;
|
||||
|
||||
namespace Spring.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a HTTP entity message, as defined in the HTTP specification.
|
||||
/// <a href="http://tools.ietf.org/html/rfc2616#section-7">HTTP 1.1, section 7</a>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the entity body.</typeparam>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
public class HttpEntity<T> where T : class
|
||||
{
|
||||
private HttpHeaders headers;
|
||||
private T body;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the entity headers.
|
||||
/// </summary>
|
||||
public HttpHeaders Headers
|
||||
{
|
||||
get { return this.headers; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the entity body. May be null.
|
||||
/// </summary>
|
||||
public T Body
|
||||
{
|
||||
get { return this.body; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether this entity has a body.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool HasBody
|
||||
{
|
||||
get { return (this.body != null); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new, empty instance of <see cref="HttpEntity{T}"/> with no body or headers.
|
||||
/// </summary>
|
||||
public HttpEntity()
|
||||
: this(null, new HttpHeaders())
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpEntity{T}"/> with the given body.
|
||||
/// </summary>
|
||||
/// <param name="body">The entity body.</param>
|
||||
public HttpEntity(T body)
|
||||
: this(body, new HttpHeaders())
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpEntity{T}"/> with the given headers.
|
||||
/// </summary>
|
||||
/// <param name="headers">The entity headers.</param>
|
||||
public HttpEntity(HttpHeaders headers)
|
||||
: this(null, headers)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpEntity{T}"/> with the given body and headers.
|
||||
/// </summary>
|
||||
/// <param name="body">The entity body.</param>
|
||||
/// <param name="headers">The entity headers.</param>
|
||||
public HttpEntity(T body, HttpHeaders headers)
|
||||
{
|
||||
AssertUtils.ArgumentNotNull(headers, "headers");
|
||||
|
||||
this.body = body;
|
||||
this.headers = headers;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,503 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Spring.Util;
|
||||
#if SILVERLIGHT
|
||||
using Spring.Collections.Specialized;
|
||||
#else
|
||||
using System.Collections.Specialized;
|
||||
#endif
|
||||
|
||||
namespace Spring.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents HTTP request and response headers, mapping string header names to list of string values.
|
||||
/// </summary>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
public class HttpHeaders : NameValueCollection
|
||||
{
|
||||
private const string ACCEPT = "Accept";
|
||||
private const string ACCEPT_CHARSET = "Accept-Charset";
|
||||
private const string ALLOW = "Allow";
|
||||
private const string CACHE_CONTROL = "Cache-Control";
|
||||
private const string CONTENT_LENGTH = "Content-Length";
|
||||
private const string CONTENT_TYPE = "Content-Type";
|
||||
private const string DATE = "Date";
|
||||
private const string ETAG = "ETag";
|
||||
private const string EXPIRES = "Expires";
|
||||
private const string IF_MODIFIED_SINCE = "If-Modified-Since";
|
||||
private const string IF_NONE_MATCH = "If-None-Match";
|
||||
private const string LAST_MODIFIED = "Last-Modified";
|
||||
private const string LOCATION = "Location";
|
||||
private const string PRAGMA = "Pragma";
|
||||
|
||||
private static readonly DateTimeFormatInfo DateTimeFormatInfo = new DateTimeFormatInfo();
|
||||
|
||||
#region Constructor(s)
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new, empty instance of the <see cref="HttpHeaders"/> object.
|
||||
/// </summary>
|
||||
public HttpHeaders() :
|
||||
base(8, StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the array of acceptable <see cref="MediaType">media types</see>,
|
||||
/// as specified by the 'Accept' header.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns an empty array when the acceptable media types are unspecified.
|
||||
/// </remarks>
|
||||
public MediaType[] Accept
|
||||
{
|
||||
get
|
||||
{
|
||||
string[] values = this.GetMultiValues(ACCEPT);
|
||||
if (values == null || values.Length == 0)
|
||||
{
|
||||
return new MediaType[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
MediaType[] result = new MediaType[values.Length];
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
{
|
||||
result[i] = MediaType.Parse(values[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
foreach (MediaType mediaType in value)
|
||||
{
|
||||
this.Add(ACCEPT, mediaType.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//**
|
||||
// * Set the list of acceptable {@linkplain Charset charsets}, as specified by the {@code Accept-Charset} header.
|
||||
// * @param acceptableCharsets the acceptable charsets
|
||||
// */
|
||||
//public void setAcceptCharset(List<Charset> acceptableCharsets) {
|
||||
// StringBuilder builder = new StringBuilder();
|
||||
// for (Iterator<Charset> iterator = acceptableCharsets.iterator(); iterator.hasNext();) {
|
||||
// Charset charset = iterator.next();
|
||||
// builder.append(charset.name().toLowerCase(Locale.ENGLISH));
|
||||
// if (iterator.hasNext()) {
|
||||
// builder.append(", ");
|
||||
// }
|
||||
// }
|
||||
// set(ACCEPT_CHARSET, builder.toString());
|
||||
//}
|
||||
|
||||
//**
|
||||
// * Return the list of acceptable {@linkplain Charset charsets}, as specified by the {@code Accept-Charset}
|
||||
// * header.
|
||||
// * @return the acceptable charsets
|
||||
// */
|
||||
//public List<Charset> getAcceptCharset() {
|
||||
// List<Charset> result = new ArrayList<Charset>();
|
||||
// String value = getFirst(ACCEPT_CHARSET);
|
||||
// if (value != null) {
|
||||
// String[] tokens = value.split(",\\s*");
|
||||
// for (String token : tokens) {
|
||||
// int paramIdx = token.indexOf(';');
|
||||
// if (paramIdx == -1) {
|
||||
// result.add(Charset.forName(token));
|
||||
// }
|
||||
// else {
|
||||
// result.add(Charset.forName(token.substring(0, paramIdx)));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the array of allowed <see cref="HttpMethod">HTTP methods</see>,
|
||||
/// as specified by the 'Allow' header.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns an empty array when the allowed methods are unspecified.
|
||||
/// </remarks>
|
||||
public HttpMethod[] Allow
|
||||
{
|
||||
get
|
||||
{
|
||||
string[] values = this.GetMultiValues(ALLOW);
|
||||
if (values == null || values.Length == 0)
|
||||
{
|
||||
return new HttpMethod[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpMethod[] result = new HttpMethod[values.Length];
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
{
|
||||
result[i] = (HttpMethod)Enum.Parse(typeof(HttpMethod), values[i], true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
foreach (HttpMethod method in value)
|
||||
{
|
||||
this.Add(ALLOW, method.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the 'Cache-Control' header.
|
||||
/// </summary>
|
||||
public string CacheControl
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.Get(CACHE_CONTROL);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.Set(CACHE_CONTROL, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the length of the body in bytes,
|
||||
/// as specified by the 'Content-Length' header.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns -1 when the content-length is unknown.
|
||||
/// </remarks>
|
||||
public long ContentLength
|
||||
{
|
||||
get
|
||||
{
|
||||
string value = this.GetSingleValue(CONTENT_LENGTH);
|
||||
return (value != null ? long.Parse(value) : -1);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.Set(CONTENT_LENGTH, value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="MediaType">media type</see> of the body,
|
||||
/// as specified by the 'Content-Type' header.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns <see langword="null"/> when the content type is unknown.
|
||||
/// </remarks>
|
||||
public MediaType ContentType
|
||||
{
|
||||
get
|
||||
{
|
||||
string value = this.GetSingleValue(CONTENT_TYPE);
|
||||
return (value != null ? MediaType.Parse(value) : null);
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value.IsWildcardType)
|
||||
{
|
||||
throw new ArgumentException("'Content-Type' header cannot contain wildcard type '*'", "Content-Type");
|
||||
}
|
||||
if (value.IsWildcardSubtype)
|
||||
{
|
||||
throw new ArgumentException("'Content-Type' header cannot contain wildcard subtype '*'", "Content-Type");
|
||||
}
|
||||
this.Set(CONTENT_TYPE, value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
//**
|
||||
// * Returns the date and time at which the message was created, as specified by the {@code Date} header.
|
||||
// * <p>The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.
|
||||
// * @return the creation date/time
|
||||
// * @throws IllegalArgumentException if the value can't be converted to a date
|
||||
// */
|
||||
//**
|
||||
// * Sets the date and time at which the message was created, as specified by the {@code Date} header.
|
||||
// * <p>The date should be specified as the number of milliseconds since January 1, 1970 GMT.
|
||||
// * @param date the date
|
||||
// */
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time at which the message was created,
|
||||
/// as specified by the 'Date' header.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns <see langword="null"/> when the date is unknown.
|
||||
/// </remarks>
|
||||
public DateTime? Date
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetSingleDate(DATE);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.SetDate(DATE, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the entity tag of the body, as specified by the 'ETag' header.
|
||||
/// </summary>
|
||||
public string ETag
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.Unquote(this.Get(ETAG));
|
||||
}
|
||||
set
|
||||
{
|
||||
this.Set(ETAG, this.Quote(value));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time at which the message is no longer valid,
|
||||
/// as specified by the 'Expires' header.
|
||||
/// </summary>
|
||||
public string Expires
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.Get(EXPIRES);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.Set(EXPIRES, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time as specified by the 'If-Modified-Since' header.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns <see langword="null"/> when the date is unknown.
|
||||
/// </remarks>
|
||||
public DateTime? IfModifiedSince
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetSingleDate(IF_MODIFIED_SINCE);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.SetDate(IF_MODIFIED_SINCE, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the 'If-None-Match' header.
|
||||
/// </summary>
|
||||
public string[] IfNoneMatch
|
||||
{
|
||||
get
|
||||
{
|
||||
string[] values = this.GetMultiValues(IF_NONE_MATCH);
|
||||
if (values == null || values.Length == 0)
|
||||
{
|
||||
return new string[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] result = new string[values.Length];
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
{
|
||||
result[i] = Unquote(values[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
foreach (string str in value)
|
||||
{
|
||||
this.Add(IF_NONE_MATCH, this.Quote(str));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time the resource was last changed,
|
||||
/// as specified by the 'Last-Modified' header.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns <see langword="null"/> when the date is unknown.
|
||||
/// </remarks>
|
||||
public DateTime? LastModified
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetSingleDate(LAST_MODIFIED);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.SetDate(LAST_MODIFIED, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the (new) location of a resource,
|
||||
/// as specified by the 'Location' header.
|
||||
/// </summary>
|
||||
public Uri Location
|
||||
{
|
||||
get
|
||||
{
|
||||
string value = this.GetSingleValue(LOCATION);
|
||||
return (value != null ? new Uri(value, UriKind.RelativeOrAbsolute) : null);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.Set(LOCATION, value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the 'Pragma' header.
|
||||
/// </summary>
|
||||
public string Pragma
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.Get(PRAGMA);
|
||||
}
|
||||
set
|
||||
{
|
||||
this.Set(PRAGMA, value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
private string Quote(string s)
|
||||
{
|
||||
if (s == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (!s.StartsWith("\"") && !s.EndsWith("\""))
|
||||
{
|
||||
s = "\"" + s + "\"";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private string Unquote(string s)
|
||||
{
|
||||
if (s == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (s.StartsWith("\"") && s.EndsWith("\""))
|
||||
{
|
||||
s = s.Substring(1, s.Length - 2);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private DateTime? GetSingleDate(string headerName)
|
||||
{
|
||||
string headerValue = GetSingleValue(headerName);
|
||||
if (headerValue != null)
|
||||
{
|
||||
return DateTime.Parse(headerValue, DateTimeFormatInfo).ToUniversalTime();
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetDate(string headerName, DateTime? date)
|
||||
{
|
||||
if (date.HasValue)
|
||||
{
|
||||
this.Set(headerName, date.Value.ToUniversalTime().ToString("R", DateTimeFormatInfo));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Remove(headerName);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Return the header value for the given header name, if any.
|
||||
/// </summary>
|
||||
/// <param name="headerName">The header name</param>
|
||||
/// <returns>The first header value; or <see langword="null"/></returns>
|
||||
/// <exception cref="NotSupportedException">
|
||||
/// If multiple values are stored for the given header name.
|
||||
/// </exception>
|
||||
public string GetSingleValue(string headerName)
|
||||
{
|
||||
string[] headerValues = this.GetValues(headerName);
|
||||
if (headerValues == null || headerValues.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (headerValues.Length == 1)
|
||||
{
|
||||
return headerValues[0];
|
||||
}
|
||||
throw new NotSupportedException(String.Format(
|
||||
"Multiple values not supported for header '{0}'", headerName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return an array of header values for the given header name, if any.
|
||||
/// </summary>
|
||||
/// <param name="headerName">The header name</param>
|
||||
/// <returns>The array of header values; or <see langword="null"/></returns>
|
||||
public string[] GetMultiValues(string headerName)
|
||||
{
|
||||
string headerValue = this.Get(headerName);
|
||||
if (headerValue == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return headerValue.Split(',');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumeration of HTTP request methods as defined in the HTTP specification.
|
||||
/// <a href="http://tools.ietf.org/html/rfc2616#section-5.1.1">HTTP 1.1, section 6</a>
|
||||
/// </summary>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
public enum HttpMethod
|
||||
{
|
||||
/// <summary>
|
||||
/// The OPTIONS method.
|
||||
/// </summary>
|
||||
OPTIONS,
|
||||
|
||||
/// <summary>
|
||||
/// The GET method.
|
||||
/// </summary>
|
||||
GET,
|
||||
|
||||
/// <summary>
|
||||
/// The HEAD method.
|
||||
/// </summary>
|
||||
HEAD,
|
||||
|
||||
/// <summary>
|
||||
/// The POST method.
|
||||
/// </summary>
|
||||
POST,
|
||||
|
||||
/// <summary>
|
||||
/// The PUT method.
|
||||
/// </summary>
|
||||
PUT,
|
||||
|
||||
/// <summary>
|
||||
/// The DELETE method.
|
||||
/// </summary>
|
||||
DELETE,
|
||||
|
||||
/// <summary>
|
||||
/// The TRACE method.
|
||||
/// </summary>
|
||||
TRACE,
|
||||
|
||||
/// <summary>
|
||||
/// The CONNECT method.
|
||||
/// </summary>
|
||||
CONNECT
|
||||
}
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System.Net;
|
||||
|
||||
namespace Spring.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a HTTP request message, as defined in the HTTP specification.
|
||||
/// <a href="http://tools.ietf.org/html/rfc2616#section-5">HTTP 1.1, section 5</a>
|
||||
/// </summary>
|
||||
/// <author>Bruno Baia</author>
|
||||
public class HttpRequestMessage
|
||||
{
|
||||
//private string requestUri;
|
||||
//private string httpVersion;
|
||||
private HttpMethod method;
|
||||
private WebHeaderCollection headers;
|
||||
private object body;
|
||||
|
||||
//public string RequestUri
|
||||
//{
|
||||
// get { return this.requestUri; }
|
||||
// set { this.requestUri = value; }
|
||||
//}
|
||||
|
||||
//public string HttpVersion
|
||||
//{
|
||||
// get { return httpVersion; }
|
||||
// set { httpVersion = value; }
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HTTP method.
|
||||
/// </summary>
|
||||
public HttpMethod Method
|
||||
{
|
||||
get { return this.method; }
|
||||
set { this.method = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the request headers.
|
||||
/// </summary>
|
||||
public WebHeaderCollection Headers
|
||||
{
|
||||
get { return this.headers; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the response body.
|
||||
/// </summary>
|
||||
public object Body
|
||||
{
|
||||
get { return this.body; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpRequestMessage"/> with the given Http method.
|
||||
/// </summary>
|
||||
/// <param name="method">The HTTP method.</param>
|
||||
public HttpRequestMessage(HttpMethod method) :
|
||||
this(null, new WebHeaderCollection(), method)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpRequestMessage"/> with the given headers.
|
||||
/// </summary>
|
||||
/// <param name="headers">The request headers.</param>
|
||||
public HttpRequestMessage(WebHeaderCollection headers) :
|
||||
this(null, headers, HttpMethod.GET)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpRequestMessage"/> with the given headers and HTTP method.
|
||||
/// </summary>
|
||||
/// <param name="headers">The request headers.</param>
|
||||
/// <param name="method">The HTTP method.</param>
|
||||
public HttpRequestMessage(WebHeaderCollection headers, HttpMethod method) :
|
||||
this(null, headers, method)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpRequestMessage"/> with the given body.
|
||||
/// </summary>
|
||||
/// <param name="body">The response body.</param>
|
||||
public HttpRequestMessage(object body) :
|
||||
this(body, new WebHeaderCollection(), HttpMethod.GET)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpRequestMessage"/> with the given body and HTTP method.
|
||||
/// </summary>
|
||||
/// <param name="body">The response body.</param>
|
||||
/// <param name="method">The HTTP method.</param>
|
||||
public HttpRequestMessage(object body, HttpMethod method) :
|
||||
this(body, new WebHeaderCollection(), method)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpRequestMessage"/> with the given body and headers.
|
||||
/// </summary>
|
||||
/// <param name="body">The response body.</param>
|
||||
/// <param name="headers">The response headers.</param>
|
||||
public HttpRequestMessage(object body, WebHeaderCollection headers) :
|
||||
this(body, headers, HttpMethod.GET)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpRequestMessage"/> with the given body, headers and HTTP method.
|
||||
/// </summary>
|
||||
/// <param name="body">The response body.</param>
|
||||
/// <param name="headers">The response headers.</param>
|
||||
/// <param name="method">The HTTP method.</param>
|
||||
public HttpRequestMessage(object body, WebHeaderCollection headers, HttpMethod method)
|
||||
{
|
||||
this.method = method;
|
||||
this.body = body;
|
||||
this.headers = headers;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System.Net;
|
||||
|
||||
namespace Spring.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a HTTP response message with no body.
|
||||
/// </summary>
|
||||
/// <author>Bruno Baia</author>
|
||||
public class HttpResponseMessage : HttpResponseMessage<object>
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpResponseMessage"/> with the given status code and status description.
|
||||
/// </summary>
|
||||
/// <param name="statusCode">The HTTP status code.</param>
|
||||
/// <param name="statusDescription">The HTTP status description.</param>
|
||||
public HttpResponseMessage(HttpStatusCode statusCode, string statusDescription) :
|
||||
base(null, null, statusCode, statusDescription)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpResponseMessage"/> with the given headers, status code and status description.
|
||||
/// </summary>
|
||||
/// <param name="headers">The response headers.</param>
|
||||
/// <param name="statusCode">The HTTP status code.</param>
|
||||
/// <param name="statusDescription">The HTTP status description.</param>
|
||||
public HttpResponseMessage(HttpHeaders headers, HttpStatusCode statusCode, string statusDescription) :
|
||||
base(null, headers, statusCode, statusDescription)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System.Net;
|
||||
|
||||
namespace Spring.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a HTTP response message, as defined in the HTTP specification.
|
||||
/// <a href="http://tools.ietf.org/html/rfc2616#section-6">HTTP 1.1, section 6</a>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the response body.</typeparam>
|
||||
/// <author>Bruno Baia</author>
|
||||
public class HttpResponseMessage<T> : HttpEntity<T> where T : class
|
||||
{
|
||||
private HttpStatusCode statusCode;
|
||||
private string statusDescription;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HTTP status code of the response.
|
||||
/// </summary>
|
||||
public HttpStatusCode StatusCode
|
||||
{
|
||||
get { return statusCode; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the HTTP status description of the response.
|
||||
/// </summary>
|
||||
public string StatusDescription
|
||||
{
|
||||
get { return statusDescription; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpResponseMessage{T}"/> with the given status code and status description.
|
||||
/// </summary>
|
||||
/// <param name="statusCode">The HTTP status code.</param>
|
||||
/// <param name="statusDescription">The HTTP status description.</param>
|
||||
public HttpResponseMessage(HttpStatusCode statusCode, string statusDescription) :
|
||||
this(null, null, statusCode, statusDescription)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpResponseMessage{T}"/> with the given body, status code and status description.
|
||||
/// </summary>
|
||||
/// <param name="body">The response body.</param>
|
||||
/// <param name="statusCode">The HTTP status code.</param>
|
||||
/// <param name="statusDescription">The HTTP status description.</param>
|
||||
public HttpResponseMessage(T body, HttpStatusCode statusCode, string statusDescription) :
|
||||
this(body, null, statusCode, statusDescription)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpResponseMessage{T}"/> with the given headers, status code and status description.
|
||||
/// </summary>
|
||||
/// <param name="headers">The response headers.</param>
|
||||
/// <param name="statusCode">The HTTP status code.</param>
|
||||
/// <param name="statusDescription">The HTTP status description.</param>
|
||||
public HttpResponseMessage(HttpHeaders headers, HttpStatusCode statusCode, string statusDescription) :
|
||||
this(null, headers, statusCode, statusDescription)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HttpResponseMessage{T}"/> with the given body, headers, status code and status description.
|
||||
/// </summary>
|
||||
/// <param name="body">The response body.</param>
|
||||
/// <param name="headers">The response headers.</param>
|
||||
/// <param name="statusCode">The HTTP status code.</param>
|
||||
/// <param name="statusDescription">The HTTP status description.</param>
|
||||
public HttpResponseMessage(T body, HttpHeaders headers, HttpStatusCode statusCode, string statusDescription) :
|
||||
base(body, headers)
|
||||
{
|
||||
this.statusCode = statusCode;
|
||||
this.statusDescription = statusDescription;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Spring.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an HTTP message, consisting of <see cref="P:Headers">headers</see>
|
||||
/// and a readable <see cref="P:Body">body</see>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Typically implemented by an HTTP request on the server-side, or a response on the client-side.
|
||||
/// </remarks>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
public interface IHttpInputMessage
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the message headers.
|
||||
/// </summary>
|
||||
HttpHeaders Headers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the body of the message as a stream.
|
||||
/// </summary>
|
||||
Stream Body { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Spring.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an HTTP message, consisting of <see cref="P:Headers">headers</see>
|
||||
/// and a writable <see cref="P:Body">body</see>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Typically implemented by an HTTP request on the client-side, or a response on the server-side.
|
||||
/// </remarks>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
public interface IHttpOutputMessage
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the message headers.
|
||||
/// </summary>
|
||||
HttpHeaders Headers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the delegate that writes the body message as a stream.
|
||||
/// </summary>
|
||||
Action<Stream> Body { set; }
|
||||
}
|
||||
}
|
||||
@@ -1,818 +0,0 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Spring.Util;
|
||||
|
||||
namespace Spring.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an Internet Media Type, as defined in the HTTP specification.
|
||||
/// <a href="http://tools.ietf.org/html/rfc2616#section-3.7">HTTP 1.1, section 3.7</a>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Consists of a <see cref="P:Type"/> and a <see cref="P:SubType"/>.
|
||||
/// Also has functionality to parse media types from a string using <see cref="M:ParseMediaType(string)"/>,
|
||||
/// or multiple comma-separated media types using <see cref="M:ParseMediaTypes(string)"/>.
|
||||
/// </remarks>
|
||||
/// <author>Arjen Poutsma</author>
|
||||
/// <author>Juergen Hoeller</author>
|
||||
/// <author>Bruno Baia (.NET)</author>
|
||||
public class MediaType : IComparable<MediaType>
|
||||
{
|
||||
/// <summary>
|
||||
/// Public constant media type that includes all media ranges (i.e. '*/*').
|
||||
/// </summary>
|
||||
public static readonly MediaType ALL = new MediaType("*", "*");
|
||||
|
||||
/// <summary>
|
||||
/// Public constant media type for 'application/atom+xml'.
|
||||
/// </summary>
|
||||
public static readonly MediaType APPLICATION_ATOM_XML = new MediaType("application", "atom+xml");
|
||||
|
||||
/// <summary>
|
||||
/// Public constant media type for 'application/x-www-form-urlencoded'.
|
||||
/// </summary>
|
||||
public static readonly MediaType APPLICATION_FORM_URLENCODED = new MediaType("application", "x-www-form-urlencoded");
|
||||
|
||||
/// <summary>
|
||||
/// Public constant media type for 'application/json'.
|
||||
/// </summary>
|
||||
public static readonly MediaType APPLICATION_JSON = new MediaType("application", "json");
|
||||
|
||||
/// <summary>
|
||||
/// Public constant media type for 'application/octet-stream'.
|
||||
/// </summary>
|
||||
public static readonly MediaType APPLICATION_OCTET_STREAM = new MediaType("application", "octet-stream");
|
||||
|
||||
/// <summary>
|
||||
/// Public constant media type for 'application/xhtml+xml'.
|
||||
/// </summary>
|
||||
public static readonly MediaType APPLICATION_XHTML_XML = new MediaType("application", "xhtml+xml");
|
||||
|
||||
/// <summary>
|
||||
/// Public constant media type for 'image/gif'.
|
||||
/// </summary>
|
||||
public static readonly MediaType IMAGE_GIF = new MediaType("image", "gif");
|
||||
|
||||
/// <summary>
|
||||
/// Public constant media type for 'image/jpeg'.
|
||||
/// </summary>
|
||||
public static readonly MediaType IMAGE_JPEG = new MediaType("image", "jpeg");
|
||||
|
||||
/// <summary>
|
||||
/// Public constant media type for 'image/png'.
|
||||
/// </summary>
|
||||
public static readonly MediaType IMAGE_PNG = new MediaType("image", "png");
|
||||
|
||||
/// <summary>
|
||||
/// Public constant media type for 'image/xml'.
|
||||
/// </summary>
|
||||
public static readonly MediaType APPLICATION_XML = new MediaType("application", "xml");
|
||||
|
||||
/// <summary>
|
||||
/// Public constant media type for 'multipart/form-data'.
|
||||
/// </summary>
|
||||
public static readonly MediaType MULTIPART_FORM_DATA = new MediaType("multipart", "form-data");
|
||||
|
||||
/// <summary>
|
||||
/// Public constant media type for 'text/html'.
|
||||
/// </summary>
|
||||
public static readonly MediaType TEXT_HTML = new MediaType("text", "html");
|
||||
|
||||
/// <summary>
|
||||
/// Public constant media type for 'text/plain'.
|
||||
/// </summary>
|
||||
public static readonly MediaType TEXT_PLAIN = new MediaType("text", "plain");
|
||||
|
||||
/// <summary>
|
||||
/// Public constant media type for 'text/xml'.
|
||||
/// </summary>
|
||||
public static readonly MediaType TEXT_XML = new MediaType("text", "xml");
|
||||
|
||||
|
||||
private const string WILDCARD_TYPE = "*";
|
||||
|
||||
private const string PARAM_QUALITY_FACTOR = "q";
|
||||
|
||||
private const string PARAM_CHARSET = "charset";
|
||||
|
||||
private string type;
|
||||
|
||||
private string subtype;
|
||||
|
||||
private IDictionary<string, string> parameters;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the primary type.
|
||||
/// </summary>
|
||||
public string Type
|
||||
{
|
||||
get { return this.type; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the subtype.
|
||||
/// </summary>
|
||||
public string Subtype
|
||||
{
|
||||
get { return this.subtype; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicate whether the type is the wildcard character '*', or not.
|
||||
/// </summary>
|
||||
public bool IsWildcardType
|
||||
{
|
||||
get { return WILDCARD_TYPE == type; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicate whether the subtype is the wildcard character '*', or not.
|
||||
/// </summary>
|
||||
public bool IsWildcardSubtype
|
||||
{
|
||||
get { return WILDCARD_TYPE == subtype; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the character set, as indicated by a 'charset' parameter, if any.
|
||||
/// </summary>
|
||||
public string CharSet
|
||||
{
|
||||
get
|
||||
{
|
||||
string charSet = null;
|
||||
this.parameters.TryGetValue(PARAM_CHARSET, out charSet);
|
||||
return charSet;
|
||||
//string charSet = this.parameters[PARAM_CHARSET];
|
||||
//return (charSet != null ? Charset.forName(charSet) : null);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the quality value, as indicated by a 'q' parameter, if any.
|
||||
/// Defaults to '1.0'.
|
||||
/// </summary>
|
||||
public double QualityValue
|
||||
{
|
||||
get
|
||||
{
|
||||
string qualityFactory = null;
|
||||
return this.parameters.TryGetValue(PARAM_QUALITY_FACTOR, out qualityFactory)
|
||||
? Double.Parse(qualityFactory, CultureInfo.InvariantCulture)
|
||||
: 1D;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="MediaType"/> for the given primary type.
|
||||
/// The subtype is set to '*', parameters are empty.
|
||||
/// </summary>
|
||||
/// <param name="type">The primary type.</param>
|
||||
public MediaType(string type) :
|
||||
this(type, WILDCARD_TYPE)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="MediaType"/> for the given primary type and subtype.
|
||||
/// The parameters are empty.
|
||||
/// </summary>
|
||||
/// <param name="type">The primary type.</param>
|
||||
/// <param name="subtype">The subtype.</param>
|
||||
public MediaType(string type, string subtype) :
|
||||
this(type, subtype, new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="MediaType"/> for the given primary type, subtype and character set.
|
||||
/// </summary>
|
||||
/// <param name="type">The primary type.</param>
|
||||
/// <param name="subtype">The subtype.</param>
|
||||
/// <param name="charSet">The character set</param>
|
||||
public MediaType(string type, string subtype, string charSet) :
|
||||
this(type, subtype)
|
||||
{
|
||||
this.parameters.Add(PARAM_CHARSET, charSet);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="MediaType"/> for the given primary type, subtype and quality value.
|
||||
/// </summary>
|
||||
/// <param name="type">The primary type.</param>
|
||||
/// <param name="subtype">The subtype.</param>
|
||||
/// <param name="qualityValue">The quality value</param>
|
||||
public MediaType(String type, String subtype, double qualityValue) :
|
||||
this(type, subtype)
|
||||
{
|
||||
this.parameters.Add(PARAM_QUALITY_FACTOR, qualityValue.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="MediaType"/> by copying the type and subtype of the given MediaType,
|
||||
/// and allows for different parameter.
|
||||
/// </summary>
|
||||
/// <param name="otherMediaType">The other media type.</param>
|
||||
/// <param name="parameters">The parameters, may be null.</param>
|
||||
public MediaType(MediaType otherMediaType, IDictionary<string, string> parameters) :
|
||||
this(otherMediaType.Type, otherMediaType.Subtype, parameters)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="MediaType"/> for the given primary type, subtype and parameters.
|
||||
/// </summary>
|
||||
/// <param name="type">The primary type.</param>
|
||||
/// <param name="subtype">The subtype.</param>
|
||||
/// <param name="parameters">The parameters, may be null.</param>
|
||||
public MediaType(string type, string subtype, IDictionary<string, string> parameters)
|
||||
{
|
||||
AssertUtils.ArgumentHasText(type, "'type' must not be empty");
|
||||
AssertUtils.ArgumentHasText(subtype, "'subtype' must not be empty");
|
||||
//checkToken(type);
|
||||
//checkToken(subtype);
|
||||
this.type = type.ToLower(CultureInfo.InvariantCulture);
|
||||
this.subtype = subtype.ToLower(CultureInfo.InvariantCulture);
|
||||
this.parameters = new Dictionary<string, string>(parameters, StringComparer.InvariantCultureIgnoreCase);
|
||||
//if (parameters.Count > 0)
|
||||
//{
|
||||
// NameValueCollection m = new NameValueCollection(parameters.Count, null, new CaseInsensitiveComparer());
|
||||
// for (Map.Entry<String, String> entry : parameters.entrySet()) {
|
||||
// String attribute = entry.getKey();
|
||||
// String value = entry.getValue();
|
||||
// checkParameters(attribute, value);
|
||||
// m.put(attribute, unquote(value));
|
||||
// }
|
||||
// this.parameters = Collections.unmodifiableMap(m);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// this.parameters = Collections.emptyMap();
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
|
||||
/// </summary>
|
||||
/// <param name="obj">
|
||||
/// The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
|
||||
/// </returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (obj is MediaType)
|
||||
{
|
||||
MediaType otherMediaType = (MediaType)obj;
|
||||
if (this.type == otherMediaType.type &&
|
||||
this.subtype == otherMediaType.subtype)
|
||||
{
|
||||
if (otherMediaType.parameters.Count == this.parameters.Count)
|
||||
{
|
||||
foreach(string key in this.parameters.Keys)
|
||||
{
|
||||
if (!otherMediaType.parameters.ContainsKey(key) ||
|
||||
!String.Equals(otherMediaType.parameters[key], this.parameters[key]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serves as a hash function for a particular type.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see cref="M:System.Object.GetHashCode"/> is suitable for use in hashing algorithms and data structures like a hash table.
|
||||
/// </remarks>
|
||||
/// <returns>
|
||||
/// A hash code for the current <see cref="T:System.Object"/>.
|
||||
/// </returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
int result = this.type.GetHashCode();
|
||||
result = 31 * result + this.subtype.GetHashCode();
|
||||
result = 31 * result + this.parameters.GetHashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object."/>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object."/>.
|
||||
/// </returns>
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.Append(this.type);
|
||||
builder.Append('/');
|
||||
builder.Append(this.subtype);
|
||||
foreach(string key in this.parameters.Keys)
|
||||
{
|
||||
builder.Append(';');
|
||||
builder.Append(key);
|
||||
builder.Append('=');
|
||||
builder.Append(this.parameters[key]);
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
// **
|
||||
// * Checks the given token string for illegal characters, as defined in RFC 2616, section 2.2.
|
||||
// * @throws IllegalArgumentException in case of illegal characters
|
||||
// * @see <a href="http://tools.ietf.org/html/rfc2616#section-2.2">HTTP 1.1, section 2.2</a>
|
||||
// */
|
||||
//private void checkToken(String s) {
|
||||
// for (int i=0; i < s.length(); i++ ) {
|
||||
// char ch = s.charAt(i);
|
||||
// if (!TOKEN.get(ch)) {
|
||||
// throw new IllegalArgumentException("Invalid token character '" + ch + "' in token \"" + s + "\"");
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
//private void checkParameters(String attribute, String value) {
|
||||
// Assert.hasLength(attribute, "parameter attribute must not be empty");
|
||||
// Assert.hasLength(value, "parameter value must not be empty");
|
||||
// checkToken(attribute);
|
||||
// if (PARAM_QUALITY_FACTOR.equals(attribute)) {
|
||||
// value = unquote(value);
|
||||
// double d = Double.parseDouble(value);
|
||||
// Assert.isTrue(d >= 0D && d <= 1D,
|
||||
// "Invalid quality value \"" + value + "\": should be between 0.0 and 1.0");
|
||||
// }
|
||||
// else if (PARAM_CHARSET.equals(attribute)) {
|
||||
// value = unquote(value);
|
||||
// Charset.forName(value);
|
||||
// }
|
||||
// else if (!isQuotedString(value)) {
|
||||
// checkToken(value);
|
||||
// }
|
||||
//}
|
||||
|
||||
//private boolean isQuotedString(String s) {
|
||||
// return s.length() > 1 && s.startsWith("\"") && s.endsWith("\"") ;
|
||||
//}
|
||||
|
||||
//private String unquote(String s) {
|
||||
// if (s == null) {
|
||||
// return null;
|
||||
// }
|
||||
// return isQuotedString(s) ? s.substring(1, s.length() - 1) : s;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Return a generic parameter value, given a parameter name.
|
||||
/// </summary>
|
||||
/// <param name="name">The parameter name.</param>
|
||||
/// <returns>The parameter value; or null if not present.</returns>
|
||||
public string GetParameter(string name)
|
||||
{
|
||||
return this.parameters[name];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicate whether this <see cref="T:MediaType"/> includes the given media type.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For instance, 'text/*' includes 'text/plain', 'text/html', and
|
||||
/// 'application/*+xml' includes 'application/soap+xml', etc.
|
||||
/// This method is non-symmetric.
|
||||
/// </remarks>
|
||||
/// <param name="otherMediaType">The reference media type with which to compare.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true"/> if this media type includes the given media type; otherwise <see langword="false"/>.
|
||||
/// </returns>
|
||||
public bool Includes(MediaType otherMediaType)
|
||||
{
|
||||
if (otherMediaType == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.IsWildcardType)
|
||||
{
|
||||
// */* includes anything
|
||||
return true;
|
||||
}
|
||||
else if (this.type == otherMediaType.type)
|
||||
{
|
||||
if (this.subtype == otherMediaType.subtype || this.IsWildcardSubtype)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// application/*+xml includes application/soap+xml
|
||||
int thisPlusIdx = this.subtype.IndexOf('+');
|
||||
int otherPlusIdx = otherMediaType.subtype.IndexOf('+');
|
||||
if (thisPlusIdx != -1 && otherPlusIdx != -1)
|
||||
{
|
||||
string thisSubtypeNoSuffix = this.subtype.Substring(0, thisPlusIdx);
|
||||
|
||||
string thisSubtypeSuffix = this.subtype.Substring(thisPlusIdx + 1);
|
||||
string otherSubtypeSuffix = otherMediaType.subtype.Substring(otherPlusIdx + 1);
|
||||
if (thisSubtypeSuffix == otherSubtypeSuffix && WILDCARD_TYPE == thisSubtypeNoSuffix)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicate whether this <see cref="T:MediaType"/> is compatible with the given media type.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For instance, 'text/*' is compatible 'text/plain', 'text/html', and vice versa.
|
||||
/// In effect, this method is similar to <see cref="M:Includes(MediaType)"/>, except that it's symmetric.
|
||||
/// </remarks>
|
||||
/// <param name="otherMediaType">The reference media type with which to compare.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true"/> if this media type is compatible with the given media type; otherwise <see langword="false"/>.
|
||||
/// </returns>
|
||||
public bool IsCompatibleWith(MediaType otherMediaType)
|
||||
{
|
||||
if (otherMediaType == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.IsWildcardType || otherMediaType.IsWildcardType)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (this.type == otherMediaType.type)
|
||||
{
|
||||
if (this.subtype == otherMediaType.subtype || this.IsWildcardSubtype || otherMediaType.IsWildcardSubtype)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// application/*+xml is compatible with application/soap+xml, and vice-versa
|
||||
int thisPlusIdx = this.subtype.IndexOf('+');
|
||||
int otherPlusIdx = otherMediaType.subtype.IndexOf('+');
|
||||
if (thisPlusIdx != -1 && otherPlusIdx != -1)
|
||||
{
|
||||
string thisSubtypeNoSuffix = this.subtype.Substring(0, thisPlusIdx);
|
||||
string otherSubtypeNoSuffix = otherMediaType.subtype.Substring(0, otherPlusIdx);
|
||||
|
||||
string thisSubtypeSuffix = this.subtype.Substring(thisPlusIdx + 1);
|
||||
string otherSubtypeSuffix = otherMediaType.subtype.Substring(otherPlusIdx + 1);
|
||||
|
||||
if (thisSubtypeSuffix == otherSubtypeSuffix &&
|
||||
(WILDCARD_TYPE == thisSubtypeNoSuffix || WILDCARD_TYPE == otherSubtypeNoSuffix))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#region IComparable<MediaType> Membres
|
||||
|
||||
/// <summary>
|
||||
/// Compares this <see cref="MediaType"/> to another alphabetically.
|
||||
/// </summary>
|
||||
/// <param name="other">The media type to compare with this object.</param>
|
||||
/// <returns>
|
||||
/// A 32-bit signed integer that indicates the relative order of the objects
|
||||
/// being compared. The return value has the following meanings: Value Meaning
|
||||
/// Less than zero This object is less than the other parameter. Zero This object
|
||||
/// is equal to other. Greater than zero This object is greater than other.
|
||||
/// </returns>
|
||||
public int CompareTo(MediaType other)
|
||||
{
|
||||
int comp = this.type.CompareTo(other.type);
|
||||
if (comp != 0)
|
||||
{
|
||||
return comp;
|
||||
}
|
||||
comp = this.subtype.CompareTo(other.subtype);
|
||||
if (comp != 0)
|
||||
{
|
||||
return comp;
|
||||
}
|
||||
comp = this.parameters.Count - other.parameters.Count;
|
||||
if (comp != 0)
|
||||
{
|
||||
return comp;
|
||||
}
|
||||
foreach(string key in this.parameters.Keys)
|
||||
{
|
||||
if (!other.parameters.ContainsKey(key))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
comp = String.Compare(this.parameters[key], other.parameters[key]);
|
||||
if (comp != 0)
|
||||
{
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Parse the given String into a single <see cref="MediaType"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method can be used to parse a 'Content-Type' header.
|
||||
/// </remarks>
|
||||
/// <param name="mediaType">The string to parse.</param>
|
||||
/// <returns>The media type.</returns>
|
||||
public static MediaType Parse(string mediaType)
|
||||
{
|
||||
if (!StringUtils.HasText(mediaType))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string[] parts = mediaType.Split(';');
|
||||
string fullType = parts[0].Trim();
|
||||
if (fullType == WILDCARD_TYPE)
|
||||
{
|
||||
fullType = "*/*";
|
||||
}
|
||||
int subIndex = fullType.IndexOf('/');
|
||||
if (subIndex == -1)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
String.Format("'{0}' does not contain '/'", mediaType),
|
||||
"mediaType");
|
||||
}
|
||||
if (subIndex == fullType.Length - 1)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
String.Format("'{0}' does not contain subtype after '/'", mediaType),
|
||||
"mediaType");
|
||||
}
|
||||
string type = fullType.Substring(0, subIndex);
|
||||
string subtype = fullType.Substring(subIndex + 1);
|
||||
|
||||
IDictionary<string, string> parameters = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
|
||||
if (parts.Length > 1)
|
||||
{
|
||||
for (int i = 1; i < parts.Length; i++)
|
||||
{
|
||||
string parameter = parts[i].Trim();
|
||||
int eqIndex = parameter.IndexOf('=');
|
||||
if (eqIndex != -1)
|
||||
{
|
||||
string attribute = parameter.Substring(0, eqIndex);
|
||||
string value = parameter.Substring(eqIndex + 1);
|
||||
parameters.Add(attribute, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new MediaType(type, subtype, parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a string representation of the given list of <see cref="MediaType"/> objects.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method can be used to for an 'Accept' or 'Content-Type' header.
|
||||
/// </remarks>
|
||||
/// <param name="mediaTypes">The list of media types to convert.</param>
|
||||
/// <returns>The string representation of the given list.</returns>
|
||||
public static string ToString(IEnumerable<MediaType> mediaTypes)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
foreach(MediaType mediaType in mediaTypes)
|
||||
{
|
||||
if (builder.Length > 0)
|
||||
{
|
||||
builder.Append(',');
|
||||
}
|
||||
builder.Append(mediaType);
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sorts the given list of <see cref="MediaType"/> objects by specificity.
|
||||
/// <a href="http://tools.ietf.org/html/rfc2616#section-14.1">HTTP 1.1, section 14.1</a>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Given two media types:
|
||||
/// <ol>
|
||||
/// <li>if either media type has a wildcard type, then the media type without the
|
||||
/// wildcard is ordered before the other.</li>
|
||||
/// <li>if the two media types have different types, then they are considered equal and
|
||||
/// remain their current order.</li>
|
||||
/// <li>if either media type has a wildcard subtype, then the media type without
|
||||
/// the wildcard is sorted before the other.</li>
|
||||
/// <li>if the two media types have different subtypes, then they are considered equal
|
||||
/// and remain their current order.</li>
|
||||
/// <li>if the two media types have different quality value, then the media type
|
||||
/// with the highest quality value is ordered before the other.</li>
|
||||
/// <li>if the two media types have a different amount of parameters, then the
|
||||
/// media type with the most parameters is ordered before the other.</li>
|
||||
/// </ol>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// For example:
|
||||
/// <blockquote>audio/basic < audio/* < */*</blockquote>
|
||||
/// <blockquote>audio/* < audio/*;q=0.7; audio/*;q=0.3</blockquote>
|
||||
/// <blockquote>audio/basic;level=1 < audio/basic</blockquote>
|
||||
/// <blockquote>audio/basic == text/html</blockquote>
|
||||
/// <blockquote>audio/basic == audio/wave</blockquote>
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <param name="mediaTypes">The list of media types to be sorted.</param>
|
||||
public static void SortBySpecificity(List<MediaType> mediaTypes)
|
||||
{
|
||||
AssertUtils.ArgumentNotNull(mediaTypes, "mediaTypes");
|
||||
|
||||
if (mediaTypes.Count > 1)
|
||||
{
|
||||
mediaTypes.Sort(SPECIFICITY_COMPARER);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sorts the given list of <see cref="MediaType"/> objects by quality value.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Given two media types:
|
||||
/// <ol>
|
||||
/// <li>if the two media types have different quality value, then the media type
|
||||
/// with the highest quality value is ordered before the other.</li>
|
||||
/// <li>if either media type has a wildcard type, then the media type without the
|
||||
/// wildcard is ordered before the other.</li>
|
||||
/// <li>if the two media types have different types, then they are considered equal and
|
||||
/// remain their current order.</li>
|
||||
/// <li>if either media type has a wildcard subtype, then the media type without
|
||||
/// the wildcard is sorted before the other.</li>
|
||||
/// <li>if the two media types have different subtypes, then they are considered equal
|
||||
/// and remain their current order.</li>
|
||||
/// <li>if the two media types have a different amount of parameters, then the
|
||||
/// media type with the most parameters is ordered before the other.</li>
|
||||
/// </ol>
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <param name="mediaTypes">The list of media types to be sorted</param>
|
||||
public static void SortByQualityValue(List<MediaType> mediaTypes)
|
||||
{
|
||||
AssertUtils.ArgumentNotNull(mediaTypes, "mediaTypes");
|
||||
|
||||
if (mediaTypes.Count > 1)
|
||||
{
|
||||
mediaTypes.Sort(QUALITY_VALUE_COMPARER);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="IComparer<MediaType>"/> implementation by specificity value.
|
||||
/// </summary>
|
||||
public static IComparer<MediaType> SPECIFICITY_COMPARER = new SpecificityComparer();
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="IComparer<MediaType>"/> implementation by quality value.
|
||||
/// </summary>
|
||||
public static IComparer<MediaType> QUALITY_VALUE_COMPARER = new QualityValueComparer();
|
||||
|
||||
#region SpecificityComparer
|
||||
|
||||
private class SpecificityComparer : IComparer<MediaType>
|
||||
{
|
||||
public int Compare(MediaType x, MediaType y)
|
||||
{
|
||||
if (x.IsWildcardType && !y.IsWildcardType)
|
||||
{ // */* < audio/*
|
||||
return 1;
|
||||
}
|
||||
else if (y.IsWildcardType && !x.IsWildcardType)
|
||||
{ // audio/* > */*
|
||||
return -1;
|
||||
}
|
||||
else if (x.type != y.type)
|
||||
{ // audio/basic == text/html
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{ // mediaType1.type == mediaType2.type
|
||||
if (x.IsWildcardSubtype && !y.IsWildcardSubtype)
|
||||
{ // audio/* < audio/basic
|
||||
return 1;
|
||||
}
|
||||
else if (y.IsWildcardSubtype && !x.IsWildcardSubtype)
|
||||
{ // audio/basic > audio/*
|
||||
return -1;
|
||||
}
|
||||
else if (x.subtype != y.subtype)
|
||||
{ // audio/basic == audio/wave
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{ // mediaType2.subtype == mediaType2.subtype
|
||||
double quality1 = x.QualityValue;
|
||||
double quality2 = y.QualityValue;
|
||||
int qualityComparison = quality2.CompareTo(quality1);
|
||||
if (qualityComparison != 0)
|
||||
{
|
||||
return qualityComparison; // audio/*;q=0.7 < audio/*;q=0.3
|
||||
}
|
||||
else
|
||||
{
|
||||
int paramsSize1 = x.parameters.Count;
|
||||
int paramsSize2 = y.parameters.Count;
|
||||
return (paramsSize2 < paramsSize1 ? -1 : (paramsSize2 == paramsSize1 ? 0 : 1)); // audio/basic;level=1 < audio/basic
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region QualityValueComparer
|
||||
|
||||
private class QualityValueComparer : IComparer<MediaType>
|
||||
{
|
||||
public int Compare(MediaType x, MediaType y)
|
||||
{
|
||||
double quality1 = x.QualityValue;
|
||||
double quality2 = y.QualityValue;
|
||||
int qualityComparison = quality2.CompareTo(quality1);
|
||||
if (qualityComparison != 0)
|
||||
{
|
||||
return qualityComparison; // audio/*;q=0.7 < audio/*;q=0.3
|
||||
}
|
||||
else if (x.IsWildcardType && !y.IsWildcardType)
|
||||
{ // */* < audio/*
|
||||
return 1;
|
||||
}
|
||||
else if (y.IsWildcardType && !x.IsWildcardType)
|
||||
{ // audio/* > */*
|
||||
return -1;
|
||||
}
|
||||
else if (x.type != y.type)
|
||||
{ // audio/basic == text/html
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{ // mediaType1.type == mediaType2.type
|
||||
if (x.IsWildcardSubtype && !y.IsWildcardSubtype)
|
||||
{ // audio/* < audio/basic
|
||||
return 1;
|
||||
}
|
||||
else if (y.IsWildcardSubtype && !x.IsWildcardSubtype)
|
||||
{ // audio/basic > audio/*
|
||||
return -1;
|
||||
}
|
||||
else if (x.subtype != y.subtype)
|
||||
{ // audio/basic == audio/wave
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int paramsSize1 = x.parameters.Count;
|
||||
int paramsSize2 = y.parameters.Count;
|
||||
return (paramsSize2 < paramsSize1 ? -1 : (paramsSize2 == paramsSize1 ? 0 : 1)); // audio/basic;level=1 < audio/basic
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user