summaryrefslogtreecommitdiffstats
path: root/sca-cpp/branches/cpp-contrib/contrib/runtime/extensions/rest/service/httpd/src/tuscany/sca/rest/ModREST.cpp
blob: 4a63991515ec4744995ac53257279f4b4b1fad9a (plain)
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
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
/*
 * Copyright 2006 The Apache Software Foundation.
 *
 * 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.
 */

#include <sstream>

#include "apr_strings.h"
#include "apr_fnmatch.h"
#include "apr_lib.h"

#define APR_WANT_STRFUNC
#include "apr_want.h"
#include "ap_config.h"
#include "httpd.h"

// This section removes the windows/httpd build error "strtoul_is_not_a_portable_function_use_strtol_instead"
#if defined(WIN32)  || defined (_WINDOWS)
#ifdef strtoul
#undef strtoul
#endif
#define strtoul strtoul
#endif

#include "http_config.h"
#include "http_core.h"
#include "http_request.h"
#include "http_protocol.h"
#include "http_log.h"
#include "http_main.h"
#include "util_script.h"
#include "util_md5.h"

#include "mod_core.h"

#include "commonj/sdo/SDO.h"

#include "tuscany/sca/core/Exceptions.h"
#include "tuscany/sca/util/Logging.h"
#include "RESTServiceProxy.h"
#include "model/RESTReferenceBinding.h"
#include "tuscany/sca/rest/model/RESTInterface.h"
#include "tuscany/sca/model/Composite.h"
#include "tuscany/sca/model/CompositeService.h"
#include "tuscany/sca/model/Component.h"
#include "tuscany/sca/model/Reference.h"
#include "tuscany/sca/model/ReferenceType.h"
#include "tuscany/sca/model/WSDLDefinition.h"
#include "tuscany/sca/model/WSDLOperation.h"
#include "tuscany/sca/model/WSDLMessagePart.h"
#include "tuscany/sca/model/WSDLInterface.h" 
#include "tuscany/sca/model/Interface.h" 
#include "tuscany/sca/core/SCARuntime.h"
#include "tuscany/sca/util/Utils.h"

using namespace std;
using namespace commonj::sdo;
using namespace tuscany::sca;
using namespace tuscany::sca::model;
using namespace tuscany::sca::util;


extern "C"
{                                                                                   
    extern module AP_MODULE_DECLARE_DATA sca_rest_module;
}

namespace tuscany
{
    namespace sca
    {
        namespace rest
        {
            
            typedef struct rest_server_config_rec
            {
                char * home;
            } rest_server_config_rec_t;
            
            typedef struct rest_dir_config_rec
            {
                char * root;
                char * path;
                char * base_uri;
                char * component;
            } rest_dir_config_rec_t;
            
            CompositeService* initializeSCARuntime(const char* home, const char* root,
                const char* path, const char* baseURI, const char *component, const char* service);
            
            DataObjectPtr createPayload(DataFactoryPtr dataFactory,
                Operation& operation, const WSDLOperation& wsdlOperation);

            void addPart(XMLHelperPtr xmlHelper, string& payload, Operation& operation);
             
            int logHeaders(void* request, const char* key, const char* value);

            /**
             * Initialize the SCA runtime
             */
            CompositeService* initializeSCARuntime(const char* home, const char* root,
                const char* path, const char* baseURI, const char *component, const char* service)
            {
                logentry();
                loginfo("Home: %s", home);
                loginfo("Root: %s", root);
                loginfo("Path: %s", path);
                loginfo("Base URI: %s", baseURI);
                loginfo("Component: %s", component);
                loginfo("Service: %s", service);
                
                try
                {
                    SCARuntime* runtime = SCARuntime::initializeSharedRuntime(home, root, path, baseURI);

                    string componentName;
                    if (strlen(component))
                    {
                        componentName = component;
                    }
                    else
                    {
                        componentName = runtime->getDefaultComponentName();
                    }
                    string serviceName = service;
                    
                    loginfo("Resolving composite: %s, service: %s", componentName.c_str(), serviceName.c_str());
                    Component* compositeComponent = runtime->getSystem()->findComponent(componentName);
                    if (compositeComponent == NULL)
                    {
                        string msg = "Component not found " + componentName;
                        throwException(SystemConfigurationException, msg.c_str());
                    }
                    runtime->setDefaultComponent(compositeComponent);

                    Composite* composite = (Composite*)compositeComponent->getType();
                    CompositeService* compositeService = (CompositeService*)composite->findComponent(serviceName);
                    if (compositeService == NULL)
                    {
                        string msg = "Composite service not found " + serviceName;
                        throwException(SystemConfigurationException, msg.c_str());
                    }
                
                    return compositeService;
                }
                catch(TuscanyRuntimeException &ex)
                {
                    ostringstream msg;
                    msg << ex;
                    logerror("Failed to initialize SCA runtime: %s", msg.str().c_str());
                    throw;
                }
            }
            
            bool printRequest = false;
            
            int logHeaders(void* request, const char* key, const char* value)
            {
                loginfo("Header key: %s, value: %s", key, value);
                if (printRequest)
                {
                    ap_rprintf((request_rec*)request, "<br>Header key: %s, value: %s", key, value);
                }
                return 1;
            }
            
            int rest_handler(request_rec *request)
            {
                logentry();
                
                if (strcmp(request->handler, "sca_rest_module"))
                {
                    return DECLINED;
                }
                
                try {
                    
                    // Set up the read policy
                    int rc = ap_setup_client_block(request, REQUEST_CHUNKED_DECHUNK);
                    if (rc != OK)
                    {
                        return rc;
                    }
                    ap_should_client_block(request);
                    if (request->read_chunked == true && request->remaining == 0)
                    {
                        request->chunked = true;
                    }
                    
                    apr_table_setn(request->headers_out, "Connection", "close");
                
                    if (printRequest)
                    {
                        // Set the content type
                        ap_set_content_type(request, "text/html");
                        
                        // Send the response document
                        ap_rputs("<html><body><p>Tuscany Mod_rest works!", request);
                    }
                
                    rest_server_config_rec_t* server_conf = (rest_server_config_rec_t*)ap_get_module_config(request->server->module_config, &sca_rest_module);
                    loginfo("Tuscany home: %s", server_conf->home);
                    if (printRequest)
                    {
                        ap_rprintf(request, "<p>Tuscany home: %s", server_conf->home);
                    }
                
                    rest_dir_config_rec_t* dir_conf = (rest_dir_config_rec_t*)ap_get_module_config(request->per_dir_config, &sca_rest_module);
                    loginfo("Tuscany root: %s", dir_conf->root);
                    if (printRequest)
                    {
                        ap_rprintf(request, "<p>Tuscany root: %s", dir_conf->root);
                    }
                    loginfo("Tuscany path: %s", dir_conf->path);
                    if (printRequest)
                    {
                        ap_rprintf(request, "<p>Tuscany path: %s", dir_conf->path);
                    }
                    loginfo("SCA component: %s", dir_conf->component);
                    if (printRequest)
                    {
                        ap_rprintf(request, "<p>SCA component: %s", dir_conf->component);
                    }
                    
                    if (request->protocol)
                    {
                        loginfo("Protocol: %s", request->protocol);
                        if (printRequest)
                        {
                            ap_rprintf(request, "<p>Protocol: %s", request->protocol);
                        }
                    }
                    
                    if (request->method)
                    {
                        loginfo("HTTP method: %s", request->method);
                        if (printRequest)
                        {
                            ap_rprintf(request, "<p>HTTP method: %s", request->method);
                        }
                    }
                
                    loginfo("HTTP method number: %d", request->method_number);
                    if (printRequest)
                    {
                        ap_rprintf(request, "<p>HTTP method number: %d", request->method_number);
                    }
                    
                    const char* content_type = apr_table_get(request->headers_in, "Content-Type");
                    if (content_type)
                    {
                        loginfo("Content type: %s", content_type);
                        if (printRequest)
                        {
                            ap_rprintf(request, "<p>Content type: %s", content_type);
                        }
                    }
                    else
                    {
                        content_type = "text/plain";
                    }
                
                    if (request->content_encoding)
                    {
                        loginfo("Content encoding: %s", request->content_encoding);
                        if (printRequest)
                        {
                            ap_rprintf(request, "<p>Content encoding: %s", request->content_encoding);
                        }
                    }
                
                    if (printRequest)
                    {
                        ap_rputs("<p>", request);
                    }
                    apr_table_do(logHeaders, request, request->headers_in, NULL);
                    
                    if (request->uri)
                    {
                        loginfo("URI: %s", request->uri);
                        if (printRequest)
                        {
                            ap_rprintf(request, "<p>URI: %s", request->uri);
                        }
                    }
                    
                    if (request->path_info)
                    {
                        loginfo("Path info: %s", request->path_info);
                        if (printRequest)
                        {
                            ap_rprintf(request, "<p>Path info: %s", request->path_info);
                        }
                    }
                    
                    if (request->args)
                    {
                        loginfo("Args: %s", request->args);
                        if (printRequest)
                        {
                            ap_rprintf(request, "<p>Args: %s", request->args);
                        }
                    }
                    
                    if (printRequest)
                    {
                        ap_rputs("</body></html>", request);
                    }
                    
                    // Extract the service and component names from the HTTP URI path
                    string path;
                    if (strlen(request->path_info) != 0 && *(request->path_info) == '/')
                    {
                        path = request->path_info + 1;
                    }
                    else
                    {
                        path = request->path_info;
                    }
                    string uri;
            
                    string component;
                    string service;        
                    if (strlen(dir_conf->component))
                    {
                        // The path only specifies the service, the component name
                        // is configured in the directory/location configured
                        component = dir_conf->component;
                        Utils::tokeniseString("/", path, service, uri); 
                    }
                    else
                    {
                        // The path must be in the form component / service
                        string path2;
                        Utils::tokeniseString("/", path, component, path2);
                        Utils::tokeniseString("/", path2, service, uri);
                    }
            
                    loginfo("Component name: %s", component.c_str());
                    loginfo("Service name: %s", service.c_str());
                    
                    // Initialize the SCA runtime
                    CompositeService* compositeService = initializeSCARuntime(
                                server_conf->home, dir_conf->root, dir_conf->path, dir_conf->base_uri, component.c_str(), service.c_str());
                                
                    if(!compositeService)
                    {
                        throwException(SystemConfigurationException,
                            "Failed to initialize SCA runtime, could not initialize CompositeService");
                    }
        
                    Composite* composite = compositeService->getComposite();
                    DataFactoryPtr dataFactory = composite->getDataFactory();
                    if (dataFactory == 0)
                    {
                        throwException(SystemConfigurationException,
                            "Failed to initialize SCA runtime, could not get DataFactory");
                    }
                    XMLHelperPtr xmlHelper = composite->getXMLHelper();
        
                    // Get the REST binding
                    Reference* reference = compositeService->getReference();
                    RESTReferenceBinding* binding = (RESTReferenceBinding*)reference->getBinding();
                    
                    //  Get the REST proxy
                    RESTServiceProxy* proxy = (RESTServiceProxy*)binding->getServiceProxy();
        
                    // Get the component interface
                    Interface* iface = reference->getType()->getInterface();

                    if (request->method_number == M_GET)
                    {
                        // Handle an HTTP GET
                        
                        // Determine the operation to invoke                    
                        WSDLOperation wsdlOperation;
                        string wsdlNamespace = "";
                        string op_name = "";
                        string uriArgs = "";
                        if (iface != NULL)
                        {
                            // If we have a REST interface, the operation name is "retrieve"
                            if (iface->getInterfaceTypeQName() == RESTInterface::typeQName)
                            {
                                op_name = "retrieve";
                                uriArgs = uri;
                            }
                            else if (iface->getInterfaceTypeQName() == WSDLInterface::typeQName)
                            {
                                // we have a WSDL interface, the operation name is part of the URI
                                Utils::tokeniseString("/", uri, op_name, uriArgs);
                                
                                // look for the WSDL operation definition
                                WSDLInterface* wsdlInterface = (WSDLInterface*)iface;
                                wsdlNamespace = wsdlInterface->getNamespaceURI();
                                
                                if (wsdlNamespace != "")
                                {
                                    WSDLDefinition* wsdl = composite->findWSDLDefinition(wsdlNamespace);
                                    if (wsdl == 0)
                                    {
                                        string msg = "WSDL not found for: " + wsdlNamespace;
                                        throwException(SystemConfigurationException, msg.c_str());
                                    }
                                    try
                                    {
                                        wsdlOperation = wsdl->findOperation(wsdlInterface->getName(), op_name.c_str());
                                    }
                                    catch(SystemConfigurationException&)
                                    {   
                                        throw;
                                    }
                                    
                                    if (!wsdlOperation.isDocumentStyle() || !wsdlOperation.isWrappedStyle())
                                    {
                                        throwException(ServiceInvocationException,
                                            "Only wrapped document style WSDL operations are currentlysupported");
                                    }
                                }
                            }
                        }
                        else
                        {
                            Utils::tokeniseString("/", uri, op_name, uriArgs);
                        }
                    
                        // Create a default document literal wrapped WSDL operation
                        if (wsdlNamespace == "")
                        {
                            WSDLMessagePart inPart(op_name, "", "http://tempuri.org");
                            WSDLMessagePart outPart((op_name+"Response"), "", "http://tempuri.org");
                            wsdlNamespace = compositeService->getName();
                            wsdlOperation = WSDLOperation();
                            wsdlOperation.setOperationName(op_name.c_str());
                            wsdlOperation.setSoapAction(wsdlNamespace+ "#" +op_name);
                            wsdlOperation.setEndpoint("");
                            wsdlOperation.setSoapVersion(WSDLOperation::SOAP11);
                            wsdlOperation.setDocumentStyle(true);
                            wsdlOperation.setWrappedStyle(true);
                            wsdlOperation.setInputEncoded(false);
                            wsdlOperation.setOutputEncoded(false);
                            wsdlOperation.setInputMessagePart(op_name, inPart);
                            wsdlOperation.setOutputMessagePart((op_name+"Response"), outPart);
                        }
                        
                        // Create the input DataObject
                        Operation operation(op_name.c_str());
                        
                        // Parse the args part of the URI
                        if (uriArgs != "")
                        {
                            string args = uriArgs;
                            for (; args != ""; )
                            {
                                string param;
                                string next;
                                Utils::tokeniseString("/", args, param, next);
                                if (param != "")
                                {
                                    string* data = new string;
                                    *data = param;
                                    operation.addParameter(data);    
                                }
                                args = next;
                            }
                        }                        
                        
                        // Parse the query string
                        if (request->args)
                        {
                            string query = request->args;
                            for (; query != ""; )
                            {
                                string param;
                                string next;
                                Utils::tokeniseString("&", query, param, next);
                                if (param != "")
                                {
                                    string n;
                                    string* data = new string;
                                    Utils::tokeniseString("=", param, n, *data);
                                    operation.addParameter(data);    
                                }
                                query = next;
                            }
                        }
                        DataObjectPtr inputDataObject = createPayload(dataFactory, operation, wsdlOperation);
                        
                        // Dispatch to the REST proxy
                        DataObjectPtr outputDataObject = proxy->invoke(wsdlOperation, inputDataObject);
                        
                        // Send the output DataObject
                        if (iface!=NULL &&
                            iface->getInterfaceTypeQName() == RESTInterface::typeQName)
                        {
                            if (outputDataObject == NULL)
                            {
                                throwException(ServiceInvocationException, "Null output from REST create operation");
                            }
                            else
                            {
                                    
                                // Pure REST, send the response document
                                XMLHelperPtr xm = HelperProvider::getXMLHelper(dataFactory);
                                DataObjectList& l = outputDataObject->getList("return");
                                if (l.size() != 0)
                                {
                                    DataObjectPtr resourceDataObject = l[0];
                                    XMLDocumentPtr doc = xm->createDocument(
                                        resourceDataObject,
                                        resourceDataObject->getType().getURI(),
                                        resourceDataObject->getType().getName());
                                    char* str = xm->save(doc);
                                    
                                    // Calculate an Etag hash for the response
                                    char* etag = ap_md5(request->pool, (const unsigned char*)str);
                                    
                                    // Handle a conditional GET, if the etag matches the etag
                                    // sent by the client, we don't need to send the whole response
                                    const char* match = apr_table_get(request->headers_in, "If-None-Match");
                                    if (match != NULL && !strcmp(etag, match))
                                    {
                                        loginfo("REST resource matches ETag, sending HTTP 304 response code");
                                        request->status = HTTP_NOT_MODIFIED;
                                    }
                                    else
                                    {
                                        loginfo("Sending response: %s", str);
                                        ap_set_content_type(request, "text/xml");
                                        apr_table_setn(request->headers_out, "ETag", etag);
                                        
                                        // Send an Etag header to allow caching and
                                        // conditional gets
                                        apr_table_setn(request->headers_out, "ETag", etag);
                                        
                                        ap_rputs(str, request);
                                    }
                                }
                                else
                                {
                                    loginfo("REST resource not found, sending HTTP 404 response code");
                                    request->status = HTTP_NOT_FOUND;
                                    
                                    return OK;
                                }
                            }
                        }
                        else
                        {
                            // Command style, send the response wrapper element

                            if (outputDataObject == NULL)
                            {
                                loginfo("Sending empty response");
                                //request->status = HTTP_NO_CONTENT;
                            }
                            else
                            {
                                XMLHelperPtr xm = HelperProvider::getXMLHelper(dataFactory);
                                DataObjectList& l = outputDataObject->getList("return");
                                if (l.size() != 0)
                                {
                                    DataObjectPtr resultDataObject = l[0];
                                    XMLDocumentPtr doc = xm->createDocument(
                                        resultDataObject,
                                        resultDataObject->getType().getURI(),
                                        resultDataObject->getType().getName());
                                    char* str = xm->save(doc);
    
                                    loginfo("Sending response: %s", str);
                                    ap_set_content_type(request, "text/xml");
                                    ap_rputs(str, request);
                                }
                                else
                                {
                                    loginfo("Sending empty response");
                                    //request->status = HTTP_NO_CONTENT;
                                }
                            }
                        }
                        
                        return OK;
                    }
                    else if (request->method_number == M_POST)
                    {
                        // Handle an HTTP POST
                        
                        // Determine the operation to invoke                    
                        WSDLOperation wsdlOperation;
                        string wsdlNamespace = "";
                        string op_name = "";
                        string uriArgs = "";
                        if (iface != NULL)
                        {
                            // If we have a REST interface, the operation name is "create"
                            if (iface->getInterfaceTypeQName() == RESTInterface::typeQName)
                            {
                                op_name = "create";
                            }
                            else if (iface->getInterfaceTypeQName() == WSDLInterface::typeQName)
                            {
                                // we have a WSDL interface, the operation name is part of the URI
                                Utils::tokeniseString("/", uri, op_name, uriArgs);
                                
                                // look for the WSDL operation definition
                                WSDLInterface* wsdlInterface = (WSDLInterface*)iface;
                                wsdlNamespace = wsdlInterface->getNamespaceURI();
                                
                                if (wsdlNamespace != "")
                                {
                                    WSDLDefinition* wsdl = composite->findWSDLDefinition(wsdlNamespace);
                                    if (wsdl == 0)
                                    {
                                        string msg = "WSDL not found for: " + wsdlNamespace;
                                        throwException(SystemConfigurationException, msg.c_str());
                                    }
                                    try
                                    {
                                        wsdlOperation = wsdl->findOperation(wsdlInterface->getName(), op_name.c_str());
                                    }
                                    catch(SystemConfigurationException&)
                                    {   
                                        throw;
                                    }
                                    
                                    if (!wsdlOperation.isDocumentStyle() || !wsdlOperation.isWrappedStyle())
                                    {
                                        throwException(ServiceInvocationException,
                                            "Only wrapped document style WSDL operations are currentlysupported");
                                    }
                                }
                            }
                        }
                        else
                        {
                            Utils::tokeniseString("/", uri, op_name, uriArgs);
                        }
                    
                        // Create a default document literal wrapped WSDL operation
                        if (wsdlNamespace == "")
                        {
                            WSDLMessagePart inPart(op_name, "", "http://tempuri.org");
                            WSDLMessagePart outPart((op_name+"Response"), "", "http://tempuri.org");
                            wsdlNamespace = compositeService->getName();
                            wsdlOperation = WSDLOperation();
                            wsdlOperation.setOperationName(op_name.c_str());
                            wsdlOperation.setSoapAction(wsdlNamespace+ "#" +op_name);
                            wsdlOperation.setEndpoint("");
                            wsdlOperation.setSoapVersion(WSDLOperation::SOAP11);
                            wsdlOperation.setDocumentStyle(true);
                            wsdlOperation.setWrappedStyle(true);
                            wsdlOperation.setInputEncoded(false);
                            wsdlOperation.setOutputEncoded(false);
                            wsdlOperation.setInputMessagePart(op_name, inPart);
                            wsdlOperation.setOutputMessagePart((op_name+"Response"), outPart);
                        }
                        
                        // Create the input DataObject
                        Operation operation(op_name.c_str());
                        
                        // Parse the args part of the URI
                        if (uriArgs != "")
                        {
                            string args = uriArgs;
                            for (; args != ""; )
                            {
                                string param;
                                string next;
                                Utils::tokeniseString("/", args, param, next);
                                if (param != "")
                                {
                                    string* data = new string;
                                    *data = param;
                                    operation.addParameter(data);    
                                }
                                args = next;
                            }
                        }

                        // Parse the query string
                        if (request->args)
                        {
                            string query = request->args;
                            for (; query != ""; )
                            {
                                string param;
                                string next;
                                Utils::tokeniseString("&", query, param, next);
                                if (param != "")
                                {
                                    string n;
                                    string* data = new string;
                                    Utils::tokeniseString("=", param, n, *data);
                                    operation.addParameter(data);    
                                }
                                query = next;
                            }
                        }
                        
                        // Read the POST input
                        ostringstream sinput;
                        char buffer[2049];
                        for ( ; ; )
                        {
                            int size = ap_get_client_block(request, buffer, 2048);
                            if (size > 0)
                            {
                                buffer[size] = '\0';
                                sinput << buffer;
                            }
                            else if (size == 0)
                            {
                                break;
                            }
                            else if (size < 0)
                            {
                                throwException(ServiceInvocationException, "Error reading POST input");
                            }
                        }
                        string input = sinput.str();
                        
                        string contentType = content_type;
                        if (contentType.find("multipart/form-data") == 0)
                        {
                            // This is a multipart POST, extract each part from the
                            // POST body
                            string begin;
                            string boundary;
                            Utils::tokeniseString("boundary=", contentType, begin, boundary);
                            
                            for (;;)
                            {
                                // Read each part
                                string part;
                                string next;
                                Utils::tokeniseString(boundary, input, part, next);
                                input = next;
                                
                                // Skip first and last empty parts
                                if (part.length() == 0 || part == "--")
                                    continue;
                                
                                // Read headers
                                bool xml = false;
                                int empty = -1;
                                for (;;)
                                {
                                    string header;
                                    Utils::tokeniseString("\r\n", part, header, next);
                                    part = next;
                                    if (header == "")
                                    {
                                        // Two empty lines signal the beginning of the content
                                        empty++;
                                        if (empty == 1)
                                            break;
                                    }
                                    else
                                    {
                                        empty = 0;
                                        
                                        // Detect XML content
                                        if (header == "Content-Type: text/xml")
                                            xml = true;
                                    }
                                }

                                // Read the part content
                                if (part.length())
                                {                       
                                    // Strip the trailer         
                                    string value;
                                    Utils::tokeniseString("\r\n--", part, value, next);
                                    
                                    if (xml)
                                    {
                                        // Add an XML parameter to the operation
                                        addPart(xmlHelper, value, operation);
                                    }
                                    else
                                    {
                                        // Add a text parameter to the operation
                                        string* stringData = new string;
                                        *stringData = value;
                                        operation.addParameter(stringData); 
                                    }
                                }

                                // Read till the end of the POST body
                                if (input.length() == 0)
                                    break;
                            }                    
                        }
                        else
                        {
                            // The POST body represents a single part 
                            addPart(xmlHelper, input, operation);
                        }
                        
                        DataObjectPtr inputDataObject = createPayload(dataFactory, operation, wsdlOperation);
                        
                        // Dispatch to the REST proxy
                        DataObjectPtr outputDataObject = proxy->invoke(wsdlOperation, inputDataObject);
                        
                        // Send the response back to the client
                        if (iface!=NULL &&
                            iface->getInterfaceTypeQName() == RESTInterface::typeQName)
                        {
                            // Pure REST, send the location of the created resource

                            if (outputDataObject == NULL)
                            {
                                throwException(ServiceInvocationException, "Null output from REST create operation");
                            }
                            
                            string location = "";
                                                        
                            DataObjectList& l = outputDataObject->getList("return");
                            if (l.size())
                            {
                                location = l.getCString(0);
                            }
                            
                            if (location == "")
                            {
                                loginfo("No resource location, sending HTTP 400 response code");
                                request->status = HTTP_BAD_REQUEST;
                                
                                return OK;
                            }

                            string locuri = request->uri;
                            locuri += '/';
                            locuri += location;
                            
                            const char* loc = ap_construct_url(request->pool, locuri.c_str(), request);
                            loginfo("Sending resource location: %s", loc);
                            apr_table_setn(request->headers_out, "Location", loc);
                            apr_table_setn(request->headers_out, "Content-Location", loc);
                            request->status = HTTP_CREATED;

                            // Send the created resource entity back to the client
                            ap_set_content_type(request, "text/xml");
                            ap_rputs(input.c_str(), request);
                            
                        }
                        else
                        {
                            // Command style, send the response element
    
                            if (outputDataObject == NULL)
                            {
                                loginfo("Sending empty response");
                                //request->status = HTTP_NO_CONTENT;
                            }
                            else
                            {
                                XMLHelperPtr xm = HelperProvider::getXMLHelper(dataFactory);
                                DataObjectList& l = outputDataObject->getList("return");
                                if (l.size() != 0)
                                {
                                    DataObjectPtr resultDataObject = l[0];
                                    XMLDocumentPtr doc = xm->createDocument(
                                        resultDataObject,
                                        resultDataObject->getType().getURI(),
                                        resultDataObject->getType().getName());
                                    char* str = xm->save(doc);
    
                                    loginfo("Sending response: %s", str);
                                    ap_set_content_type(request, "text/xml");
                                    ap_rputs(str, request);
                                }
                                else
                                {
                                    loginfo("Sending empty response");
                                    //request->status = HTTP_NO_CONTENT;
                                }
                            }
                        }
                       
                        return OK;
                    }
                    else if (request->method_number == M_PUT)
                    {
    
                        // Handle an HTTP PUT
                        
                        // Determine the operation to invoke                    
                        WSDLOperation wsdlOperation;
                        string wsdlNamespace = "";
                        string op_name = "update";
                        string uriArgs = uri;
                    
                        // Create a default document literal wrapped WSDL operation
                        WSDLMessagePart inputPart(op_name, "", "http://tempuri.org");
                        WSDLMessagePart outputPart((op_name+"Response"), "", "http://tempuri.org");
                        wsdlNamespace = compositeService->getName();
                        wsdlOperation = WSDLOperation();
                        wsdlOperation.setOperationName(op_name.c_str());
                        wsdlOperation.setSoapAction(wsdlNamespace+ "#" +op_name);
                        wsdlOperation.setEndpoint("");
                        wsdlOperation.setSoapVersion(WSDLOperation::SOAP11);
                        wsdlOperation.setDocumentStyle(true);
                        wsdlOperation.setWrappedStyle(true);
                        wsdlOperation.setInputEncoded(false);
                        wsdlOperation.setOutputEncoded(false);
                        wsdlOperation.setInputMessagePart(op_name, inputPart);
                        wsdlOperation.setOutputMessagePart((op_name+"Response"), outputPart);
                        
                        // Create the input DataObject
                        Operation operation(op_name.c_str());
                        
                        // Parse the args part of the URI
                        if (uriArgs != "")
                        {
                            string args = uriArgs;
                            for (; args != ""; )
                            {
                                string param;
                                string next;
                                Utils::tokeniseString("/", args, param, next);
                                if (param != "")
                                {
                                    string* data = new string;
                                    *data = param;
                                    operation.addParameter(data);    
                                }
                                args = next;
                            }
                        }
                        
                        // Parse the query string
                        if (request->args)
                        {
                            string query = request->args;
                            for (; query != ""; )
                            {
                                string param;
                                string next;
                                Utils::tokeniseString("&", query, param, next);
                                if (param != "")
                                {
                                    string n;
                                    string* data = new string;
                                    Utils::tokeniseString("=", param, n, *data);
                                    operation.addParameter(data);    
                                }
                                query = next;
                            }
                        }
                        
                        // Read the PUT input
                        ostringstream sinput;
                        char buffer[2049];
                        for ( ; ; )
                        {
                            int size = ap_get_client_block(request, buffer, 2048);
                            if (size > 0)
                            {
                                buffer[size] = '\0';
                                sinput << buffer;
                            }
                            else if (size == 0)
                            {
                                break;
                            }
                            else if (size < 0)
                            {
                                throwException(ServiceInvocationException, "Error reading PUT input");
                            }
                        }
                        string input = sinput.str();
                        addPart(xmlHelper, input, operation);
                        
                        DataObjectPtr inputDataObject = createPayload(dataFactory, operation, wsdlOperation);
                        
                        // Dispatch to the REST proxy
                        DataObjectPtr outputDataObject = proxy->invoke(wsdlOperation, inputDataObject);

                        // Empty response                        
                        //request->status = HTTP_NO_CONTENT;
                        return OK;
                    }
                    else if (request->method_number == M_DELETE)
                    {
                        
                        // Determine the operation to invoke                    
                        WSDLOperation wsdlOperation;
                        string wsdlNamespace = "";
                        string op_name = "delete";
                        string uriArgs = uri;
                    
                        // Create a default document literal wrapped WSDL operation
                        WSDLMessagePart inPart(op_name, "", "http://tempuri.org");
                        WSDLMessagePart outPart((op_name+"Response"), "", "http://tempuri.org");
                        wsdlNamespace = compositeService->getName();
                        wsdlOperation = WSDLOperation();
                        wsdlOperation.setOperationName(op_name.c_str());
                        wsdlOperation.setSoapAction(wsdlNamespace+ "#" +op_name);
                        wsdlOperation.setEndpoint("");
                        wsdlOperation.setSoapVersion(WSDLOperation::SOAP11);
                        wsdlOperation.setDocumentStyle(true);
                        wsdlOperation.setWrappedStyle(true);
                        wsdlOperation.setInputEncoded(false);
                        wsdlOperation.setOutputEncoded(false);
                        wsdlOperation.setInputMessagePart(op_name, inPart);
                        wsdlOperation.setOutputMessagePart((op_name+"Response"), outPart);
                        
                        // Create the input DataObject
                        Operation operation(op_name.c_str());
                        
                        // Parse the args part of the URI
                        if (uriArgs != "")
                        {
                            string args = uriArgs;
                            for (; args != ""; )
                            {
                                string param;
                                string next;
                                Utils::tokeniseString("/", args, param, next);
                                if (param != "")
                                {
                                    string* data = new string;
                                    *data = param;
                                    operation.addParameter(data);    
                                }
                                args = next;
                            }
                        }
                        
                        // Parse the query string
                        if (request->args)
                        {
                            string query = request->args;
                            for (; query != ""; )
                            {
                                string param;
                                string next;
                                Utils::tokeniseString("&", query, param, next);
                                if (param != "")
                                {
                                    string n;
                                    string* data = new string;
                                    Utils::tokeniseString("=", param, n, *data);
                                    operation.addParameter(data);    
                                }
                                query = next;
                            }
                        }
                        
                        DataObjectPtr inputDataObject = createPayload(dataFactory, operation, wsdlOperation);
                        
                        // Dispatch to the REST proxy
                        DataObjectPtr outputDataObject = proxy->invoke(wsdlOperation, inputDataObject);

                        // Empty response
                        //request->status = HTTP_NO_CONTENT;                        
                        return OK;
                    }
                    else
                    {
                        if (request->method)
                        {
                            logerror("Unsupported HTTP method: %s", request->method);
                        }
                        else
                        {
                            logerror("Unsupported HTTP method: %d", request->method_number);
                        }
                        return HTTP_NOT_IMPLEMENTED;
                    }
                }
                catch(TuscanyRuntimeException& ex)
                {
                    ostringstream msg;
                    msg << ex;
                    logerror("Failed to process REST request: %s", msg.str().c_str());
                    return HTTP_INTERNAL_SERVER_ERROR;
                }        
            }
            
            DataObjectPtr createPayload(DataFactoryPtr dataFactory, Operation& operation, const WSDLOperation& wsdlOperation)
            {   
                logentry();
            
                DataObjectPtr inputDataObject;
                string inputTypeUri;
                string inputTypeName;
                try
                {
                    // Since its Document wrapped, there will only be one part
                    std::list<std::string> partList = wsdlOperation.getInputMessagePartNames();
                    const WSDLMessagePart &inputMessage =
                      wsdlOperation.getInputMessagePart(partList.front());
                    inputTypeName = inputMessage.getPartType();
                    inputTypeUri = inputMessage.getPartUri();
                    
                    // Create the input wrapper
                    const Type& rootType = dataFactory->getType(inputTypeUri.c_str(), "RootType");
                    const Property& prop = rootType.getProperty(inputTypeName.c_str());
                    const Type& inputType = prop.getType();
                    inputDataObject = dataFactory->create(inputType);
                }
                catch (SDORuntimeException&)
                {
                    try
                    {
                        // Create the input wrapper
                        const Type& inputType =
                          dataFactory->getType(inputTypeUri.c_str(), inputTypeName.c_str());
                        inputDataObject = dataFactory->create(inputType);
                    }
                    catch (SDORuntimeException&)
                    {
                        
                        // The input wrapper type is not known, create an open DataObject 
                        inputDataObject = dataFactory->create("http://tempuri.org", "Wrapper");
                    }
                }
                        
                // Go through data object to set the input parameters
                PropertyList pl = inputDataObject->getType().getProperties();
            
                if(pl.size() == 0)
                {
                    if(inputDataObject->getType().isOpenType() && inputDataObject->getType().isDataObjectType())
                    {
                        /*
                         * This code deals with sending xsd:any elements
                         */
                        for (int i=0; i<operation.getNParms(); i++)
                        {
                            ostringstream pname;
                            pname << "param" << (i+1);
                            DataObjectList& l = inputDataObject->getList(pname.str());
                            
                            const Operation::Parameter& parm = operation.getParameter(i);
                            switch(parm.getType())
                            {
                            case Operation::STRING: 
                                {
                                    l.append((*(string*)parm.getValue()).c_str());
                                    break;
                                }
                            case Operation::DATAOBJECT: 
                                {
                                    l.append(*(DataObjectPtr*)parm.getValue());
                                    break;
                                }
                            default:
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                else {
                    
                    // Each parameter in the operation should be a property on the request dataobject
                    for (unsigned int i=0; i<operation.getNParms(); i++)
                    {
                        const Operation::Parameter& parm = operation.getParameter(i);
                        switch(parm.getType())
                        {
                        case Operation::STRING: 
                            {
                                inputDataObject->setCString(i, (*(string*)parm.getValue()).c_str());
                                break;
                            }
                        case Operation::DATAOBJECT: 
                            {
                                inputDataObject->setDataObject(i, *(DataObjectPtr*)parm.getValue());
                                break;
                            }
                        default:
                            {
                                break;
                            }
                        }
                    }
                }
                
                return inputDataObject;
             }

             void addPart(XMLHelperPtr xmlHelper, string& payload, Operation& operation)
             {  
                logentry();
                
                
                //TODO Remove this workaround once SDO supports loading of open top level content
                // The workaround is to wrap the open content in a wrapper element
                string xmldecl;
                string xml;
                Utils::rTokeniseString("?>", payload, xmldecl, xml);
                string body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
                body += "<Wrapper xmlns=\"http://tempuri.org\" xmlns:tns=\"http://tempuri.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n";
                body += xml;
                body +=  "\n</Wrapper>";
                
                // Convert the body to an SDO DataObject
                DataObjectPtr inputWrapperDataObject = NULL;
                XMLDocumentPtr theXMLDocument = xmlHelper->load(body.c_str(), NULL);
                if (theXMLDocument != 0)
                {
                    inputWrapperDataObject = theXMLDocument->getRootDataObject();
                }
                if(!inputWrapperDataObject)
                {
                    ostringstream msg;
                    msg << "Could not convert received document to SDO: " << body;                     
                    throwException(ServiceDataException, msg.str().c_str());
                }                    

                // Get the body part
                DataObjectPtr inputDataObject = NULL; 
                PropertyList bpl = inputWrapperDataObject->getInstanceProperties();
                if (bpl.size()!=0)
                {
                    if (bpl[0].isMany())
                    {
                        DataObjectList& parts = inputWrapperDataObject->getList((unsigned int)0);
                        inputDataObject = parts[0];
                    }
                    else
                    {
                        inputDataObject = inputWrapperDataObject->getDataObject(bpl[0]);
                    }
                }
                if (inputDataObject == NULL)
                {
                    ostringstream msg;
                    msg << "Could not convert received document to SDO: " << body;                     
                    throwException(ServiceDataException, msg.str().c_str());
                }
                
                DataObjectPtr* dataObjectData = new DataObjectPtr;
                *dataObjectData = inputDataObject;
                (*dataObjectData)->detach();
                operation.addParameter(dataObjectData);
             }

            const char *rest_set_home(cmd_parms *cmd, void *dummy, 
                                    const char *arg)
            {
                rest_server_config_rec_t *conf = (rest_server_config_rec_t*)ap_get_module_config(
                                    cmd->server->module_config, &sca_rest_module);
                conf->home = apr_pstrdup(cmd->pool, arg);
                return NULL;
            }
            
            const char *rest_set_path(cmd_parms *cmd, void *c, 
                                    const char *arg)
            {
                rest_dir_config_rec_t *conf = (rest_dir_config_rec_t*)c;
                conf->path = apr_pstrdup(cmd->pool, arg);
                return NULL;
            }
            
            const char *rest_set_root(cmd_parms *cmd, void *c, 
                                    const char *arg)
            {
                rest_dir_config_rec_t *conf = (rest_dir_config_rec_t*)c;
                conf->root = apr_pstrdup(cmd->pool, arg);
                return NULL;
            }
            
            const char *rest_set_base_uri(cmd_parms *cmd, void *c, 
                                    const char *arg)
            {
                rest_dir_config_rec_t *conf = (rest_dir_config_rec_t*)c;
                conf->base_uri = apr_pstrdup(cmd->pool, arg);
                return NULL;
            }
            
            const char *rest_set_component(cmd_parms *cmd, void *c, 
                                    const char *arg)
            {
                rest_dir_config_rec_t *conf = (rest_dir_config_rec_t*)c;
                conf->component = apr_pstrdup(cmd->pool, arg);
                return NULL;
            }
            
            const command_rec rest_module_cmds[] = 
            {
                AP_INIT_TAKE1("TuscanyHome", (const char*(*)())tuscany::sca::rest::rest_set_home, NULL, RSRC_CONF,
                              "Tuscany home directory"),
                AP_INIT_TAKE1("TuscanyPath", (const char*(*)())tuscany::sca::rest::rest_set_path, NULL, ACCESS_CONF,
                              "Tuscany SCA composite search path"),
                AP_INIT_TAKE1("TuscanyRoot", (const char*(*)())tuscany::sca::rest::rest_set_root, NULL, ACCESS_CONF,
                              "Tuscany root SCA configuration path"),
                AP_INIT_TAKE1("TuscanyBaseURI", (const char*(*)())tuscany::sca::rest::rest_set_base_uri, NULL, ACCESS_CONF,
                              "Tuscany SCA system base URI"),
                AP_INIT_TAKE1("TuscanyComponent", (const char*(*)())tuscany::sca::rest::rest_set_component, NULL, ACCESS_CONF,
                              "SCA component name"),
                {NULL}
            };
            
            int rest_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
                                   server_rec *s)
            {
                return OK;
            }
            
            void rest_child_init(apr_pool_t* p, server_rec* svr_rec)
            {
                rest_server_config_rec_t *conf = (rest_server_config_rec_t*)ap_get_module_config(
                                    svr_rec->module_config, &sca_rest_module); 
            
                if(false)
                {
                    fprintf(stderr, "[Tuscany] Due to one or more errors mod_rest loading"
                                    " failed. Causing apache2 to stop loading\n");
                    exit(APEXIT_CHILDFATAL);
                }
            }
            
            void register_hooks(apr_pool_t *p)
            {
                ap_hook_handler(rest_handler, NULL, NULL, APR_HOOK_MIDDLE);
                ap_hook_post_config(rest_init, NULL, NULL, APR_HOOK_MIDDLE);
                ap_hook_child_init(rest_child_init, NULL, NULL, APR_HOOK_MIDDLE);
            }
            
            void *rest_create_dir_config(apr_pool_t *p, char *dirspec)
            {
                rest_dir_config_rec_t* conf = (rest_dir_config_rec_t* )apr_palloc(p, sizeof(*conf));
                conf->path = "";
                conf->root = "";
                conf->base_uri = "";
                conf->component = "";
                return conf;
            }
            
            void* rest_create_server_config(apr_pool_t *p, server_rec *s)
            {
                rest_server_config_rec_t* conf = (rest_server_config_rec_t* )apr_palloc(p, sizeof(*conf));
                conf->home = "";
                return conf;
            }
            
        } // End namespace rest        
    } // End namespace sca
} // End namespace tuscany

extern "C"
{

    module AP_MODULE_DECLARE_DATA sca_rest_module =
    {
        STANDARD20_MODULE_STUFF,
        tuscany::sca::rest::rest_create_dir_config,         /* dir config */
        NULL,                       /* dir merger --- default is to override */
        tuscany::sca::rest::rest_create_server_config,        /* server config */
        NULL,                       /* merge server config */
        tuscany::sca::rest::rest_module_cmds,         /* command table */
        tuscany::sca::rest::register_hooks              /* register_hooks */
    };
    
}