GridAssetClient.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (c) Contributors, http://www.openmetaverse.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. */
  28. using System;
  29. using System.IO;
  30. using System.Xml.Serialization;
  31. using OpenSim.Framework.Console;
  32. using OpenSim.Framework.Servers;
  33. namespace OpenSim.Framework.Communications.Cache
  34. {
  35. public class GridAssetClient : AssetServerBase
  36. {
  37. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  38. private string _assetServerUrl;
  39. public GridAssetClient(string serverUrl)
  40. {
  41. _assetServerUrl = serverUrl;
  42. }
  43. #region IAssetServer Members
  44. protected override AssetBase GetAsset(AssetRequest req)
  45. {
  46. Stream s = null;
  47. try
  48. {
  49. #if DEBUG
  50. //m_log.DebugFormat("[GRID ASSET CLIENT]: Querying for {0}", req.AssetID.ToString());
  51. #endif
  52. RestClient rc = new RestClient(_assetServerUrl);
  53. rc.AddResourcePath("assets");
  54. rc.AddResourcePath(req.AssetID.ToString());
  55. if (req.IsTexture)
  56. rc.AddQueryParameter("texture");
  57. rc.RequestMethod = "GET";
  58. s = rc.Request();
  59. if (s.Length > 0)
  60. {
  61. XmlSerializer xs = new XmlSerializer(typeof (AssetBase));
  62. return (AssetBase) xs.Deserialize(s);
  63. }
  64. }
  65. catch (Exception e)
  66. {
  67. m_log.Error("[GRID ASSET CLIENT]: " + e.Message);
  68. m_log.DebugFormat("[GRID ASSET CLIENT]: Getting asset {0}", req.AssetID.ToString());
  69. m_log.Error("[GRID ASSET CLIENT]: " + e.StackTrace);
  70. }
  71. return null;
  72. }
  73. public override void UpdateAsset(AssetBase asset)
  74. {
  75. throw new Exception("The method or operation is not implemented.");
  76. }
  77. protected override void StoreAsset(AssetBase asset)
  78. {
  79. try
  80. {
  81. // MemoryStream s = new MemoryStream();
  82. // XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
  83. // xs.Serialize(s, asset);
  84. // RestClient rc = new RestClient(_assetServerUrl);
  85. m_log.Info("[GRID ASSET CLIENT]: Storing asset");
  86. //rc.AddResourcePath("assets");
  87. // rc.RequestMethod = "POST";
  88. // rc.Request(s);
  89. //m_log.InfoFormat("[ASSET]: Stored {0}", rc);
  90. m_log.Info("[GRID ASSET CLIENT]: Sending to " + _assetServerUrl + "/assets/");
  91. RestObjectPoster.BeginPostObject<AssetBase>(_assetServerUrl + "/assets/", asset);
  92. }
  93. catch (Exception e)
  94. {
  95. m_log.Error("[GRID ASSET CLIENT]: " + e.Message);
  96. }
  97. }
  98. protected override void CommitAssets()
  99. {
  100. }
  101. public override void Close()
  102. {
  103. throw new Exception("The method or operation is not implemented.");
  104. }
  105. // rex new function for "replace assets" functionality
  106. // TODO: implementation by someone
  107. public override libsecondlife.LLUUID ExistsAsset(sbyte assetType, string name)
  108. {
  109. throw new Exception("The method or operation is not implemented.");
  110. }
  111. #endregion
  112. }
  113. }