Fixes to URLs for SOAP and ActiveSync requests; additional logging in case of error

This commit is contained in:
Patrick Simpson 2018-02-07 15:34:01 +02:00
parent 073f883ba6
commit 126bfff3be
4 changed files with 23 additions and 7 deletions

View File

@ -84,11 +84,23 @@ namespace Acacia.ZPush.Connect.Soap
#region Decoding
public override object ParseResponse(Stream result)
public override object ParseResponse(string url, Stream result)
{
// Parse xml
XmlDocument xml = new XmlDocument();
xml.Load(result);
using (StreamReader reader = new StreamReader(result))
{
string text = reader.ReadToEnd();
try
{
xml.LoadXml(text);
}
catch (Exception e)
{
Logger.Instance.Error(this, "Error in SOAP response:\nurl={0}\nresponse={1}", url, text);
throw e;
}
}
// Check if it's an error message
CheckFaultResponse(xml);

View File

@ -136,7 +136,7 @@ namespace Acacia.ZPush.Connect
using (HttpContent responseContent = response.Content)
{
Logger.Instance.Trace(this, "Response: {0}", responseContent.ReadAsStringAsync().Result);
return request.ParseResponse(responseContent.ReadAsStreamAsync().Result);
return request.ParseResponse(url, responseContent.ReadAsStreamAsync().Result);
}
}
}
@ -288,8 +288,12 @@ namespace Acacia.ZPush.Connect
public Response Execute(ActiveSync.RequestBase request)
{
string url = string.Format(ACTIVESYNC_URL, _account.Account.ServerURL, _account.Account.DeviceId,
request.Command, _account.Account.UserName, "WindowsOutlook");
string url = string.Format(ACTIVESYNC_URL,
_account.Account.ServerURL,
Uri.EscapeDataString(_account.Account.DeviceId),
request.Command,
Uri.EscapeDataString(_account.Account.UserName),
"WindowsOutlook");
// Construct the body
WBXMLDocument doc = new WBXMLDocument();

View File

@ -28,6 +28,6 @@ namespace Acacia.ZPush.Connect
{
public abstract HttpContent GetContent();
public abstract object ParseResponse(Stream result);
public abstract object ParseResponse(string url, Stream result);
}
}

View File

@ -49,7 +49,7 @@ namespace Acacia.ZPush.Connect
string url = string.Format(ACTIVESYNC_URL, _connection.Account.Account.ServerURL, "webservice",
ServiceName,
// TODO: this username is a bit of a quick hack.
request.UserName ?? _connection.Account.Account.UserName,
Uri.EscapeDataString(request.UserName ?? _connection.Account.Account.UserName),
"webservice");
// Set up the encoding