[Groonga-commit] groonga/gcs [master] Generate request id on handling

Back to archive index

YUKI Hiroshi null+****@clear*****
Fri Nov 9 14:04:39 JST 2012


YUKI Hiroshi	2012-11-09 14:04:39 +0900 (Fri, 09 Nov 2012)

  New Revision: ba08d7e3010bfd4a9eee0f94b1e2aa8a5b805b9d
  https://github.com/groonga/gcs/commit/ba08d7e3010bfd4a9eee0f94b1e2aa8a5b805b9d

  Log:
    Generate request id on handling

  Modified files:
    lib/api/2011-02-01/configuration.js

  Modified: lib/api/2011-02-01/configuration.js (+23 -22)
===================================================================
--- lib/api/2011-02-01/configuration.js    2012-11-09 13:10:48 +0900 (872d634)
+++ lib/api/2011-02-01/configuration.js    2012-11-09 14:04:39 +0900 (7ff1b6d)
@@ -11,7 +11,7 @@ exports.version = path.basename(__dirname);
 
 var XMLNS = 'http://cloudsearch.amazonaws.com/doc/2011-02-01';
 
-function createCommonErrorResponse(errorCode, error) {
+function createCommonErrorResponse(errorCode, error, requestId) {
   if (error.message) {
     error = error.message;
   } else {
@@ -25,11 +25,11 @@ function createCommonErrorResponse(errorCode, error) {
         .element('Message').text(error).up()
       .up()
     .up()
-    .element('RequestID').text(uuid.v4()).up();
+    .element('RequestID').text(equestId).up();
   return doc.toString();
 }
 
-function createSenderErrorResponse(errorCode, error) {
+function createSenderErrorResponse(errorCode, error, requestId) {
   if (error.message) {
     error = error.message;
   } else {
@@ -44,7 +44,7 @@ function createSenderErrorResponse(errorCode, error) {
         .element('Message').text(error).up()
       .up()
     .up()
-    .element('RequestID').text(uuid.v4()).up();
+    .element('RequestID').text(requestId).up();
   return doc.toString();
 }
 
@@ -72,7 +72,7 @@ function getBaseHostAndPort(config, request) {
     return host + ':' + port;
 }
 
-function createGenericResponse(action, result) {
+function createGenericResponse(action, result, requestId) {
   var doc = xmlbuilder.create();
   var root = doc.begin(action + 'Response', { version: '1.0' })
                 .attribute('xmlns', XMLNS);
@@ -81,7 +81,7 @@ function createGenericResponse(action, result) {
   if (result) resultContainer.importXMLBuilder(result);
 
   root.element('ResponseMetadata')
-      .element('RequestId').text(uuid.v4());
+      .element('RequestId').text(requestId);
 
   return doc.toString();
 }
@@ -126,7 +126,7 @@ handlers.CreateDomain = function(context, request, response, config) {
         created:     true
       });
   response.contentType('application/xml');
-  response.send(createGenericResponse('CreateDomain', result));
+  response.send(createGenericResponse('CreateDomain', result, request.id));
 };
 
 handlers.DeleteDomain = function(context, request, response, config) {
@@ -143,7 +143,7 @@ handlers.DeleteDomain = function(context, request, response, config) {
     result = null;
   }
   response.contentType('application/xml');
-  response.send(createGenericResponse('DeleteDomain', result));
+  response.send(createGenericResponse('DeleteDomain', result, request.id));
 };
 
 function createDomainStatusList(options) {
@@ -183,7 +183,7 @@ handlers.DescribeDomains = function(context, request, response, config) {
         hostAndPort: getBaseHostAndPort(config, request)
       });
   response.contentType('application/xml');
-  response.send(createGenericResponse('DescribeDomains', result));
+  response.send(createGenericResponse('DescribeDomains', result, request.id));
 };
 
 function createIndexFieldOptionStatus(options) {
@@ -283,7 +283,7 @@ handlers.DefineIndexField = function(context, request, response, config) {
         updatedAt: createdAt
       });
   response.contentType('application/xml');
-  response.send(createGenericResponse('DefineIndexField', result));
+  response.send(createGenericResponse('DefineIndexField', result, request.id));
 };
 
 handlers.DeleteIndexField = function(context, request, response, config) {
@@ -293,7 +293,7 @@ handlers.DeleteIndexField = function(context, request, response, config) {
   var field = domain.getIndexField(fieldName);
   field.deleteSync();
   response.contentType('application/xml');
-  response.send(createGenericResponse('DeleteIndexField'));
+  response.send(createGenericResponse('DeleteIndexField', null, request.id));
 };
 
 function createIndexFields(fields) {
@@ -327,7 +327,7 @@ handlers.DescribeIndexFields = function(context, request, response, config) {
                   domain.indexFields ;
   var result = createIndexFields(fields);
   response.contentType('application/xml');
-  response.send(createGenericResponse('DescribeIndexFields', result));
+  response.send(createGenericResponse('DescribeIndexFields', result, request.id));
 };
 
 function createFieldNames(domain) {
@@ -352,7 +352,7 @@ handlers.IndexDocuments = function(context, request, response, config) {
   domain.reindexSync();
   var result = createFieldNames(domain);
   response.contentType('application/xml');
-  response.send(createGenericResponse('IndexDocuments', result));
+  response.send(createGenericResponse('IndexDocuments', result, request.id));
 };
 
 function createSynonymOptionsStatus(options) {
@@ -385,7 +385,7 @@ handlers.UpdateSynonymOptions = function(context, request, response, config) {
         createdAt: updatedAt
       });
   response.contentType('application/xml');
-  response.send(createGenericResponse('UpdateSynonymOptions', result));
+  response.send(createGenericResponse('UpdateSynonymOptions', result, request.id));
 };
 
 handlers.DescribeSynonymOptions = function(context, request, response, config) {
@@ -397,7 +397,7 @@ handlers.DescribeSynonymOptions = function(context, request, response, config) {
         createdAt: updatedAt
       });
   response.contentType('application/xml');
-  response.send(createGenericResponse('DescribeSynonymOptions', result));
+  response.send(createGenericResponse('DescribeSynonymOptions', result, request.id));
 };
 
 function createDefaultSearchFieldStatus(options) {
@@ -426,7 +426,7 @@ handlers.UpdateDefaultSearchField = function(context, request, response, config)
         updatedAt: updatedAt
       });
   response.contentType('application/xml');
-  response.send(createGenericResponse('UpdateDefaultSearchField', result));
+  response.send(createGenericResponse('UpdateDefaultSearchField', result, request.id));
 };
 
 handlers.DescribeDefaultSearchField = function(context, request, response, config) {
@@ -439,7 +439,7 @@ handlers.DescribeDefaultSearchField = function(context, request, response, confi
         updatedAt: updatedAt
       });
   response.contentType('application/xml');
-  response.send(createGenericResponse('DescribeDefaultSearchField', result));
+  response.send(createGenericResponse('DescribeDefaultSearchField', result, request.id));
 };
 
 function getClientIp(request) {
@@ -458,6 +458,7 @@ exports.createHandler = function(context, config) {
                          config.privilegedRanges.split(/[,\| ]/);
   return function(request, response, next) {
     var message, body;
+    request.id = uuid.v4();
 
     // GCS specific behaviour: prevent to access this API from specific IP
     // range.
@@ -466,7 +467,7 @@ exports.createHandler = function(context, config) {
             return ipv4.isInRange(getClientIp(request), privilegedRange);
           })) {
         message = 'Permission denied.';
-        body = createSenderErrorResponse('InvalidClientIpRange', message);
+        body = createSenderErrorResponse('InvalidClientIpRange', message, request.id);
         response.contentType('application/xml');
         return response.send(body, 403);
       }
@@ -486,14 +487,14 @@ exports.createHandler = function(context, config) {
     if (version && version != exports.version) {
       message = 'A bad or out-of-range value "' + version + '" was supplied ' +
                 'for the "Version" input parameter.';
-      body = createSenderErrorResponse('InvalidParameterValue', message);
+      body = createSenderErrorResponse('InvalidParameterValue', message, request.id);
       response.contentType('application/xml');
       return response.send(body, 400);
     }
 
     if (!(action in handlers)) {
       message = 'The action ' + action + ' is not valid for this web service.';
-      body = createSenderErrorResponse('InvalidAction', message);
+      body = createSenderErrorResponse('InvalidAction', message, request.id);
       response.contentType('application/xml');
       return response.send(body, 400);
     }
@@ -505,10 +506,10 @@ exports.createHandler = function(context, config) {
       logger.error(error);
       var body, code;
       if (error.isValidationError) {
-        body = createSenderErrorResponse('ValidationError', error);
+        body = createSenderErrorResponse('ValidationError', error, request.id);
         code = 400;
       } else {
-        body= createCommonErrorResponse('InternalFailure', error);
+        body= createCommonErrorResponse('InternalFailure', error, request.id);
         code = 500;
       }
       response.contentType('application/xml');
-------------- next part --------------
HTML����������������������������...
다운로드 



More information about the Groonga-commit mailing list
Back to archive index