My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
using System;
using System.Web;
using System.Xml;
using System.Net;
using System.IO;
using Microsoft.Data.SqlXml;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Specialized;

using Exyus.Xml;
using Exyus.Caching;
using Exyus.Security;

namespace Exyus.Web
{
[MediaTypes("text/xml")]
public class XmlSqlResource: HTTPResource
{
// public properties
public string ConnectionString = string.Empty;
public string PostLocationUri = string.Empty;
public string DocumentsFolder = string.Empty;
public string[] XHtmlNodes = null;
public bool RedirectOnPost = false;
public bool RedirectOnPut = false;
public string PostIdXPath = "//@id";

// internal vars
private Utility util = new Utility();
private string rex_sqex = "Description=\"(.*)\"";
private string rex_notfound = "not found";
private Cache ch = new Cache();

public XmlSqlResource()
{
if (this.ContentType == null || this.ContentType == string.Empty)
{
this.ContentType = Constants.cType_Xml;
}
}

public override void Delete()
{
XmlDocument xmlout = new XmlDocument();
XmlDocument xmlin = new XmlDocument();
string out_text = string.Empty;
string xsd_file = string.Empty;
string xsl_file = string.Empty;

string XslArgs = this.Context.Server.MapPath(this.DocumentsFolder + "args.xsl");
string XslDeleteArgs = this.Context.Server.MapPath(this.DocumentsFolder + "delete_args.xsl");

string xslDeleteRequest = this.Context.Server.MapPath(this.DocumentsFolder + "delete_request.xsl");
string xslDeleteRequestContentType = this.Context.Server.MapPath(this.DocumentsFolder + (CurrentMediaType == string.Empty ? "delete_request.xsl" : string.Format("delete_request_{0}.xsl", CurrentFileType)));

string XsdFile = this.Context.Server.MapPath(this.DocumentsFolder + "delete.xsd");
string XsdFileMtype = this.Context.Server.MapPath(this.DocumentsFolder + (CurrentMediaType == string.Empty ? "delete.xsd" : string.Format("delete_{0}.xsd", CurrentFileType)));


try
{
// transform arglist into xml document
xsl_file = string.Empty;
xsl_file = (File.Exists(XslDeleteArgs) ? XslDeleteArgs : XslArgs);
if (File.Exists(xsl_file))
{
XslTransformer xslt = new XslTransformer();
out_text = xslt.ExecuteText(xmlin, xsl_file, ArgumentList);

if (out_text == string.Empty)
throw new HttpException(400, "bad request");
else
xmlin.LoadXml(out_text);

out_text = string.Empty;
}
else
{
xmlin.LoadXml("<args />");
}

// validate args before continuing
xsd_file = string.Empty;
xsd_file = (File.Exists(XsdFileMtype) ? XsdFileMtype : XsdFile);
if (File.Exists(xsd_file))
{
SchemaValidator sv = new SchemaValidator();
string sch_error = sv.Execute(xmlin, xsd_file);
if (sch_error != string.Empty)
throw new HttpException(400, sch_error);
}

// transform xmldoc into sql
xsl_file = string.Empty;
xsl_file = (File.Exists(xslDeleteRequestContentType) ? xslDeleteRequestContentType : xslDeleteRequest);
if (File.Exists(xsl_file))
{
XslTransformer xslt = new XslTransformer();
string cmdtext = xslt.ExecuteText(xmlin, xsl_file, ArgumentList);

// execute sql and return empty
SqlXmlCommand cmd = new SqlXmlCommand(util.GetConfigSectionItem(Constants.cfg_exyusSettings, this.ConnectionString));
cmd.CommandText = cmdtext;
cmd.ExecuteNonQuery();
this.StatusCode = HttpStatusCode.NoContent;

// cache invalidation
ch.ClearCache(this.ImmediateCacheUriTemplates, this.BackgroundCacheUriTemplates, "", ArgumentList, util.LoadUriCache());

}
else
{
throw new HttpException(500, "missing transform");
}

xmlout = null;
}
catch (HttpException hex)
{
this.StatusCode = (HttpStatusCode)hex.GetHttpCode();
this.StatusDescription = hex.Message;
out_text = util.RenderError("http error", hex.Message, CurrentMediaType);
}
catch (SqlXmlException sqex)
{
string msg = string.Format("{0}", Regex.Match(sqex.Message, rex_sqex).Groups[1].Value);
if (msg==string.Empty)
{
msg = sqex.Message;
}
msg += " (db)";

if (Regex.IsMatch(msg, rex_notfound))
{
this.StatusCode = HttpStatusCode.NotFound;
this.StatusDescription = msg;
}
else
{
this.StatusCode = HttpStatusCode.BadRequest;
this.StatusDescription = msg;
}
out_text = util.RenderError("db error", msg, CurrentMediaType);
}
catch (Exception ex)
{
this.StatusCode = HttpStatusCode.InternalServerError;
this.StatusDescription = ex.Message;
out_text = util.RenderError("unknown error", ex.Message, CurrentMediaType);
}

if (CurrentMediaType == Constants.cType_FormUrlEncoded)
{
CurrentMediaType = Constants.cType_Html;
}
this.Response = out_text;

xmlin = null;
xmlout = null;
}

public override void Head()
{
this.Get();
this.Response = null;
}

public override void Get()
{
XmlDocument xmlout = new XmlDocument();
XmlDocument xmlin = new XmlDocument();
XslTransformer xslt = new XslTransformer();
string xsd_file = string.Empty;
string xsl_file = string.Empty;
string out_text = string.Empty;

// possible control documents
string XslArgs = this.Context.Server.MapPath(this.DocumentsFolder + "args.xsl");
string XslGetArgs = this.Context.Server.MapPath(this.DocumentsFolder + "get_args.xsl");

string xslGetRequest = this.Context.Server.MapPath(this.DocumentsFolder + "get_request.xsl");
string xslGetRequestContentType = this.Context.Server.MapPath(this.DocumentsFolder + (CurrentMediaType == string.Empty ? "get_request.xsl" : string.Format("get_request_{0}.xsl", CurrentFileType)));

string xslGetResponse = this.Context.Server.MapPath(this.DocumentsFolder + "get_response.xsl");
string xslGetResponseContentType = this.Context.Server.MapPath(this.DocumentsFolder + (CurrentMediaType == string.Empty ? "get_response.xsl" : string.Format("get_response_{0}.xsl", CurrentFileType)));

string XsdFile = this.Context.Server.MapPath(this.DocumentsFolder + "get.xsd");
string XsdFileMtype = this.Context.Server.MapPath(this.DocumentsFolder + (CurrentMediaType == string.Empty ? "get.xsd" : string.Format("get_{0}.xsd", CurrentFileType)));

try
{
if (ch.CachedResourceIsValid((HTTPResource)this))
return;

// transform into proper argument list
xsl_file = string.Empty;
xsl_file = (File.Exists(XslGetArgs) ? XslGetArgs : XslArgs);
if (File.Exists(xsl_file))
{
xslt = new XslTransformer();
out_text = xslt.ExecuteText(xmlin, xsl_file, ArgumentList);
xmlin.LoadXml(out_text);
}
else
{
xmlin.LoadXml("<args />");
}

// validate args before continuing
xsd_file = string.Empty;
xsd_file = (XsdFileMtype != string.Empty ? XsdFileMtype : XsdFile);
if (File.Exists(xsd_file))
{
SchemaValidator sv = new SchemaValidator();
string sch_error = sv.Execute(xmlin, xsd_file);
if (sch_error != string.Empty)
throw new HttpException(400, sch_error);
}

// transform args into sql and execute
xsl_file = string.Empty;
xsl_file = (File.Exists(xslGetRequestContentType) ? xslGetRequestContentType : xslGetRequest);
if (File.Exists(xsl_file))
{
xslt = new XslTransformer();
string cmdtext = xslt.ExecuteText(xmlin, xsl_file, ArgumentList);

// execute sql and return results
SqlXmlCommand cmd = new SqlXmlCommand(util.GetConfigSectionItem(Constants.cfg_exyusSettings, this.ConnectionString));
cmd.CommandText = cmdtext;

using (XmlReader rdr = cmd.ExecuteXmlReader())
{
xmlout.Load(rdr);
rdr.Close();
}

// transform outputs into representation
xsl_file = (File.Exists(xslGetResponseContentType) ? xslGetResponseContentType : xslGetResponse);
if (File.Exists(xsl_file))
{
xslt = new XslTransformer();

out_text = util.FixEncoding(xslt.ExecuteText(xmlout, xsl_file, ArgumentList));
}
else
{
out_text = util.FixEncoding(xmlout.OuterXml);
}

// handle caching of this resource
ch.CacheResource((HTTPResource)this,util.FixEncoding(out_text));
}
else
throw new HttpException(500, "missing transform");
}
catch (HttpException hex)
{
this.StatusCode = (HttpStatusCode)hex.GetHttpCode();
this.StatusDescription = hex.Message;
out_text = util.RenderError("http error", hex.Message, CurrentMediaType);
}
catch (SqlXmlException sqex)
{
string msg = string.Format("{0}", Regex.Match(sqex.Message, rex_sqex).Groups[1].Value);
if (msg == string.Empty)
{
msg = sqex.Message;
}
msg += " (db)";

if (Regex.IsMatch(msg, rex_notfound))
{
this.StatusCode = HttpStatusCode.NotFound;
this.StatusDescription = msg;
}
else
{
this.StatusCode = HttpStatusCode.BadRequest;
this.StatusDescription = msg;
}
out_text = util.RenderError("db error", msg, CurrentMediaType);
}
catch (Exception ex)
{
this.StatusCode = HttpStatusCode.InternalServerError;
this.StatusDescription = ex.Message;
out_text = util.RenderError("unknown error", ex.Message, CurrentMediaType);
}

// return the results
this.Response = out_text;

xmlin = null;
xmlout = null;
}

public override void Post()
{
XmlDocument xmlout = new XmlDocument();
XmlDocument xmlin = new XmlDocument();
XmlDocument xmlargs = new XmlDocument();
XslTransformer xslt = new XslTransformer();
string xsl_file = string.Empty;
string xsd_file = string.Empty;
string id = string.Empty;
string original_contentType = this.ContentType;
string out_text = string.Empty;

// possible control documents
string XslArgs = this.Context.Server.MapPath(this.DocumentsFolder + "args.xsl");
string XslGetArgs = this.Context.Server.MapPath(this.DocumentsFolder + "post_args.xsl");

string xslGetRequest = this.Context.Server.MapPath(this.DocumentsFolder + "post_request.xsl");
string xslGetRequestContentType = this.Context.Server.MapPath(this.DocumentsFolder + (CurrentMediaType == string.Empty ? "post_request.xsl" : string.Format("post_request_{0}.xsl", CurrentFileType)));

string xslGetResponse = this.Context.Server.MapPath(this.DocumentsFolder + "post_response.xsl");
string xslGetResponseContentType = this.Context.Server.MapPath(this.DocumentsFolder + (CurrentMediaType == string.Empty ? "post_response.xsl" : string.Format("post_response_{0}.xsl", CurrentFileType)));

string XsdFile = this.Context.Server.MapPath(this.DocumentsFolder + "post.xsd");
string XsdFileMtype = this.Context.Server.MapPath(this.DocumentsFolder + (CurrentMediaType == string.Empty ? "post.xsd" : string.Format("post_{0}.xsd", CurrentFileType)));

try
{
// since GET has no body, build 'stub xmldocument'
xmlin.LoadXml("<root />");

// transform into proper argument list
xsl_file = string.Empty;
xsl_file = (File.Exists(XslGetArgs) ? XslGetArgs : XslArgs);
if (File.Exists(xsl_file))
{
xslt = new XslTransformer();
out_text = xslt.ExecuteText(xmlin, xsl_file, ArgumentList);
xmlargs.LoadXml(out_text);
}

// get the xmldoc from the entity
this.Context.Request.InputStream.Position = 0;
switch (CurrentMediaType.ToLower())
{
case Constants.cType_FormUrlEncoded:
xmlin = util.ProcessFormVars(this.Context.Request.Form);
break;
case Constants.cType_Json:
xmlin = util.ProcessJSON(this.Context.Request.InputStream);
break;
default:
xmlin.Load(this.Context.Request.InputStream);
break;
}

// validate the doc
xsd_file = string.Empty;
xsd_file = (XsdFileMtype != string.Empty ? XsdFileMtype : XsdFile);
if (File.Exists(xsd_file))
{
SchemaValidator sv = new SchemaValidator();
string sch_error = sv.Execute(xmlin, xsd_file);
if (sch_error != string.Empty)
throw new HttpException(400, sch_error);
}

// validate html
util.ValidateXHtmlNodes(ref xmlin, this.XHtmlNodes);

// transform xmldoc into sql command
xsl_file = string.Empty;
xsl_file = (File.Exists(xslGetRequestContentType) ? xslGetRequestContentType : xslGetRequest);
if (File.Exists(xsl_file))
{
xslt = new XslTransformer();
string cmdtext = xslt.ExecuteText(xmlin, xsl_file, ArgumentList);

// execute sql and return results
SqlXmlCommand cmd = new SqlXmlCommand(util.GetConfigSectionItem(Constants.cfg_exyusSettings, ConnectionString));
cmd.CommandText = cmdtext;

using (XmlReader rdr = cmd.ExecuteXmlReader())
{
xmlout.Load(rdr);
rdr.Close();
}

// udpate arg list with new id
util.SafeAdd(ref ArgumentList, "id", xmlout.SelectSingleNode(this.PostIdXPath).InnerText);

// transform outputs into representation
xsl_file = string.Empty;
xsl_file = (File.Exists(xslGetResponseContentType) ? xslGetResponseContentType : xslGetResponse);
if (File.Exists(xsl_file))
{
xslt = new XslTransformer();
out_text = util.FixEncoding(xslt.ExecuteText(xmlout, xsl_file, ArgumentList));
}
else
{
out_text = util.FixEncoding(xmlout.OuterXml);
}

// check for redirect to created item
this.StatusCode = (this.RedirectOnPost ? HttpStatusCode.Redirect : HttpStatusCode.Created);
this.Location = util.ReplaceArgs(util.GetConfigSectionItem(Constants.cfg_exyusSettings, Constants.cfg_rootfolder) + this.PostLocationUri, ArgumentList);

// cache invalidation
ch.ClearCache(this.ImmediateCacheUriTemplates, this.BackgroundCacheUriTemplates, "", ArgumentList, util.LoadUriCache());
}
else
{
throw new HttpException(500, "missing transform");
}
}
catch (HttpException hex)
{
this.StatusCode = (HttpStatusCode)hex.GetHttpCode();
this.StatusDescription = hex.Message;
out_text = util.RenderError("http error", hex.Message, CurrentMediaType);
}
catch (SqlXmlException sqex)
{
string msg = string.Format("{0}", Regex.Match(sqex.Message, rex_sqex).Groups[1].Value);
if (msg == string.Empty)
{
msg = sqex.Message;
}
msg += " (db)";

if (Regex.IsMatch(msg, rex_notfound))
{
this.StatusCode = HttpStatusCode.NotFound;
this.StatusDescription = msg;
}
else
{
this.StatusCode = HttpStatusCode.BadRequest;
this.StatusDescription = msg;
}
out_text = util.RenderError("db error", msg, CurrentMediaType);
}
catch (Exception ex)
{
this.StatusCode = HttpStatusCode.InternalServerError;
this.StatusDescription = ex.Message;
out_text = util.RenderError("unknown error", ex.Message, CurrentMediaType);
}

// if we were using form-posting, reset to preferred content type (text/html, most likely)
if (this.ContentType == Constants.cType_FormUrlEncoded)
{
this.ContentType = (original_contentType == Constants.cType_FormUrlEncoded ? Constants.cType_Html : original_contentType);
}
this.Response = out_text;

xmlin = null;
xmlout = null;
}

public override void Put()
{
XmlDocument xmlout = new XmlDocument();
XmlDocument xmlin = new XmlDocument();
XmlDocument xmlargs = new XmlDocument();
XslTransformer xslt = new XslTransformer();
string out_text = string.Empty;
string xsl_file = string.Empty;
string xsd_file = string.Empty;
string original_contentType = this.ContentType;

// possible control documents
string XslArgs = this.Context.Server.MapPath(this.DocumentsFolder + "args.xsl");
string XslPutArgs = this.Context.Server.MapPath(this.DocumentsFolder + "put_args.xsl");

string XsdArgs = this.Context.Server.MapPath(this.DocumentsFolder + "args.xsd");
string XsdPutArgs = this.Context.Server.MapPath(this.DocumentsFolder + "put_args.xsd");

string xslPutRequest = this.Context.Server.MapPath(this.DocumentsFolder + "put_request.xsl");
string xslPutRequestContentType = this.Context.Server.MapPath(this.DocumentsFolder + (CurrentMediaType == string.Empty ? "put_request.xsl" : string.Format("put_request_{0}.xsl", CurrentFileType)));

string xslPutResponse = this.Context.Server.MapPath(this.DocumentsFolder + "put_response.xsl");
string xslPutResponseContentType = this.Context.Server.MapPath(this.DocumentsFolder + (CurrentMediaType == string.Empty ? "put_response.xsl" : string.Format("put_response_{0}.xsl", CurrentFileType)));

string XsdFile = this.Context.Server.MapPath(this.DocumentsFolder + "put.xsd");
string XsdFileMtype = this.Context.Server.MapPath(this.DocumentsFolder + (CurrentMediaType == string.Empty ? "put.xsd" : string.Format("put_{0}.xsd", CurrentFileType)));

try
{
// transform into proper argument list
xmlargs.LoadXml("<root />");

xsl_file = string.Empty;
xsl_file = (File.Exists(XslPutArgs) ? XslPutArgs : XslArgs);
if (File.Exists(xsl_file))
{
xslt = new XslTransformer();
out_text = xslt.ExecuteText(xmlargs, xsl_file, ArgumentList);
xmlargs.LoadXml(out_text);
}

// validate the args
xsd_file = string.Empty;
xsd_file = (File.Exists(XsdPutArgs) ? XsdPutArgs : XsdArgs);
if (File.Exists(xsd_file))
{
SchemaValidator sv = new SchemaValidator();
string sch_error = sv.Execute(xmlargs, xsd_file);
if (sch_error != string.Empty)
throw new HttpException(400, sch_error);
}

// get the xmldoc from the entity
this.Context.Request.InputStream.Position = 0;
switch (CurrentMediaType.ToLower())
{
case Constants.cType_FormUrlEncoded:
xmlin = util.ProcessFormVars(this.Context.Request.Form);
break;
case Constants.cType_Json:
xmlin = util.ProcessJSON(this.Context.Request.InputStream);
break;
default:
xmlin.Load(this.Context.Request.InputStream);
break;
}

// validate the doc
xsd_file = string.Empty;
xsd_file = (File.Exists(XsdFileMtype) ? XsdFileMtype : XsdFile);
if (File.Exists(xsd_file))
{
SchemaValidator sv = new SchemaValidator();
string sch_error = sv.Execute(xmlin, xsd_file);
if (sch_error != string.Empty)
throw new HttpException(400, sch_error);
}

// validate html nodes
util.ValidateXHtmlNodes(ref xmlin, this.XHtmlNodes);

// prepare for update/create
bool save_item = false;
string etag = string.Empty;
string last_mod = string.Empty;
string put_error = "Unable to complete PUT."; // generic message

// next, do a head request for this resource
HTTPClient cl = new HTTPClient();
ExyusPrincipal ep = (ExyusPrincipal)this.Context.User;
cl.Credentials = new NetworkCredential(((ExyusIdentity)ep.Identity).Name, ((ExyusIdentity)ep.Identity).Password);

// load headers for request
PutHeaders ph = new PutHeaders(this.Context);
if (ph.IfMatch != string.Empty)
cl.RequestHeaders.Set(Constants.hdr_if_none_match, ph.IfMatch);
if (ph.IfUnmodifiedSince != string.Empty)
cl.RequestHeaders.Set(Constants.hdr_if_modified_since, ph.IfUnmodifiedSince);
if (ph.IfUnmodifiedSince == string.Empty && ph.LastModified != string.Empty)
cl.RequestHeaders.Set(Constants.hdr_if_modified_since, ph.LastModified);
// make request for existing resource
try
{
out_text = cl.Execute(
string.Format("{0}://{1}{2}",
this.Context.Request.Url.Scheme,
this.Context.Request.Url.DnsSafeHost,
this.Context.Request.RawUrl),
"head", (CurrentMediaType==Constants.cType_FormUrlEncoded?"text/html":CurrentMediaType));

// record exists, this must be an update
etag = util.GetHttpHeader(Constants.hdr_etag, (NameValueCollection)cl.ResponseHeaders);
last_mod = util.GetHttpHeader(Constants.hdr_last_modified, (NameValueCollection)cl.ResponseHeaders);

// sort out update conditions
util.CheckPutUpdateCondition(ph, etag, last_mod, ref put_error, ref save_item);
}
catch (HttpException hex2)
{
// record not there or some other error
int code = hex2.GetHttpCode();

switch (code)
{
// record exists w/o changes, we can update!
case (int)HttpStatusCode.NotModified:
save_item = true;
break;
// see if it's ok to save
case (int)HttpStatusCode.NotFound:
// sort out create conditions
util.CheckPutCreateCondition(ph, this.AllowCreateOnPut, etag, ref put_error, ref save_item);
break;
// some other error, omgz!
default:
put_error = hex2.Message + " Unable to PUT.";
save_item = false;
break;
}
}

if (save_item == true)
{
// transform xmldoc into sql command
xsl_file = string.Empty;
xsl_file = (File.Exists(xslPutRequestContentType) ? xslPutRequestContentType : xslPutRequest);
if (File.Exists(xsl_file))
{
xslt = new XslTransformer();
string cmdtext = xslt.ExecuteText(xmlin, xsl_file, ArgumentList);

// execute sql and return results
SqlXmlCommand cmd = new SqlXmlCommand(util.GetConfigSectionItem(Constants.cfg_exyusSettings, this.ConnectionString));
cmd.CommandText = cmdtext;

using (XmlReader rdr = cmd.ExecuteXmlReader())
{
xmlout.Load(rdr);
rdr.Close();
}

// transform outputs into representation
xsl_file = string.Empty;
xsl_file = (File.Exists(xslPutResponseContentType) ? xslPutResponseContentType : xslPutResponse);
if (File.Exists(xsl_file))
{
xslt = new XslTransformer();
out_text = util.FixEncoding(xslt.ExecuteText(xmlout, xsl_file, ArgumentList));
}
else
{
out_text = util.FixEncoding(xmlout.OuterXml);
}

// cache invalidation
ch.ClearCache(this.ImmediateCacheUriTemplates, this.BackgroundCacheUriTemplates, "", ArgumentList, util.LoadUriCache());
}
else
{
throw new HttpException(500, "missing transform");
}
}
else
{
throw new HttpException((int)HttpStatusCode.PreconditionFailed, put_error);
}
}
catch (HttpException hex)
{
this.StatusCode = (HttpStatusCode)hex.GetHttpCode();
this.StatusDescription = hex.Message;
out_text = util.RenderError("http error", hex.Message, CurrentMediaType);
}
catch (SqlXmlException sqex)
{
string msg = string.Format("{0}", Regex.Match(sqex.Message, rex_sqex).Groups[1].Value);
if (msg == string.Empty)
{
msg = sqex.Message;
}
msg += " (db)";

if (Regex.IsMatch(msg, rex_notfound))
{
this.StatusCode = HttpStatusCode.NotFound;
this.StatusDescription = msg;
}
else
{
this.StatusCode = HttpStatusCode.BadRequest;
this.StatusDescription = msg;
}
out_text = util.RenderError("db error", msg, CurrentMediaType);
}
catch (Exception ex)
{
this.StatusCode = HttpStatusCode.InternalServerError;
this.StatusDescription = ex.Message;
out_text = util.RenderError("unknown error", ex.Message, CurrentMediaType);
}
this.Response = out_text;

xmlargs = null;
xmlin = null;
xmlout = null;
}
}
}

Change log

r174 by m...@amundsen.com on Jun 16, 2008   Diff
CodeBreaker.cs
  * modified to support text/xml as well
as text/html
XmlSqlResource.cs
  * fixed XSD file reference bug
Program.cs
  * added start of codebreaker console
client
Go to: 
Project members, sign in to write a code review

Older revisions

r172 by m...@amundsen.com on Apr 12, 2008   Diff
Caching/Cache.cs
  * Return304 - fixed bug that mis-
handled Last-Modified Date
Other/Utility.cs
  * added support for adding Xslt
...
r166 by m...@amundsen.com on Mar 30, 2008   Diff
Other/Utility.cs
  * added GetAllowedMediaTypes
  * add setting X-Acceptable header
  * added signature for
ParseUrlPattern
...
r163 by m...@amundsen.com on Mar 27, 2008   Diff
SMTPResource.cs
  * added use of shared_args
  * updated error rendering
StaticResource.cs
  * added use of arg_list
...
All revisions of this file

File info

Size: 30546 bytes, 686 lines

File properties

svn:mime-type
text/plain
svn:eol-style
native
svn:keywords
Id Rev Date Author
Powered by Google Project Hosting