|
12 | 12 | # License for the specific language governing permissions and limitations
|
13 | 13 | # under the License.
|
14 | 14 |
|
15 |
| -import json |
16 | 15 | import logging
|
17 | 16 | import re
|
18 | 17 | import six
|
@@ -122,12 +121,13 @@ def determine_target_type_uri(self, req):
|
122 | 121 | target_type_uri = self._determine_target_type_uri_by_parts(path.split('/'))
|
123 | 122 |
|
124 | 123 | except Exception as e:
|
125 |
| - self.logger.warning("exception while determining the target type URI of '{0} {1}': {2}" |
126 |
| - .format(req.method, req.path, str(e))) |
| 124 | + self.logger.debug( |
| 125 | + "exception while determining the target type URI of '{0} {1}': {2}".format(req.method, req.path, str(e)) |
| 126 | + ) |
127 | 127 |
|
128 | 128 | finally:
|
129 | 129 | if common.is_none_or_unknown(target_type_uri):
|
130 |
| - self.logger.warning("failed to determine target type URI of '{0} {1}'".format(req.method, req.path)) |
| 130 | + self.logger.debug("failed to determine target type URI of '{0} {1}'".format(req.method, req.path)) |
131 | 131 | return
|
132 | 132 |
|
133 | 133 | return self._add_prefix_target_type_uri(target_type_uri)
|
@@ -211,16 +211,18 @@ def _cadf_action_from_body(self, json_body):
|
211 | 211 | """
|
212 | 212 | cadf_action = taxonomy.UNKNOWN
|
213 | 213 | try:
|
214 |
| - if json_body: |
215 |
| - d = json.loads(json_body) |
216 |
| - # the 1st key specifies the action type |
217 |
| - os_action = next(iter(d)) |
218 |
| - if os_action: |
219 |
| - # add prefix to os_action |
220 |
| - cadf_action = self.cadf_os_action_prefix + os_action |
221 |
| - return |
| 214 | + if isinstance(json_body, str) or isinstance(json_body, unicode): |
| 215 | + json_body = common.load_json_dict(json_body) |
| 216 | + # the 1st key specifies the action type |
| 217 | + os_action = next(iter(json_body)) |
| 218 | + # avoid empty string '""' |
| 219 | + if os_action and len(os_action) > 2: |
| 220 | + # add prefix to os_action |
| 221 | + cadf_action = self.cadf_os_action_prefix + str(os_action) |
| 222 | + return |
222 | 223 | except Exception as e:
|
223 |
| - self.logger.error("error while determining action from json body: {0}".format(str(e))) |
| 224 | + self.logger.debug("error while determining action from json body: {0}".format(str(e))) |
| 225 | + |
224 | 226 | finally:
|
225 | 227 | return cadf_action
|
226 | 228 |
|
@@ -303,7 +305,7 @@ def _determine_target_type_uri_by_regex(self, path):
|
303 | 305 | return new_path
|
304 | 306 |
|
305 | 307 | except Exception as e:
|
306 |
| - self.logger.warning('failed to apply regex {0} to path: {1}: {2}'.format(regex, path, e)) |
| 308 | + self.logger.debug('failed to apply regex {0} to path: {1}: {2}'.format(regex, path, e)) |
307 | 309 | continue
|
308 | 310 |
|
309 | 311 | # return 'None' if path is unchanged or new path
|
@@ -335,7 +337,7 @@ def _determine_target_type_uri_by_parts(self, path_parts):
|
335 | 337 | target_type_uri.append(part)
|
336 | 338 |
|
337 | 339 | except Exception as e:
|
338 |
| - self.logger.warning("failed to get target_type_uri from request path: %s" % str(e)) |
| 340 | + self.logger.debug("failed to get target_type_uri from request path: %s" % str(e)) |
339 | 341 | target_type_uri = []
|
340 | 342 | finally:
|
341 | 343 | # we need at least one part
|
@@ -485,7 +487,7 @@ def determine_target_type_uri(self, req):
|
485 | 487 | target_type_uri.append('object')
|
486 | 488 |
|
487 | 489 | except Exception as e:
|
488 |
| - self.logger.error("error while determining target type URI from request '{0} {1}': {2}" |
| 490 | + self.logger.debug("error while determining target type URI from request '{0} {1}': {2}" |
489 | 491 | .format(req.method, req.path, str(e)))
|
490 | 492 |
|
491 | 493 | finally:
|
|
0 commit comments