You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ranger.apache.org by Ramachandran Krishnan <ra...@gmail.com> on 2022/09/21 16:26:36 UTC

Review Request 74135: RANGER-3847:Http status & Error message is not correct for the invalid json request body

-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/74135/
-----------------------------------------------------------

Review request for ranger, Abhay Kulkarni, Madhan Neethiraj, Nikhil P, Pradeep Agrawal, Ramesh Mani, Selvamohan Neethiraj, Sailaja Polavarapu, and Velmurugan Periasamy.


Bugs: RANGER-3847
    https://issues.apache.org/jira/browse/RANGER-3847


Repository: ranger


Description
-------

In Ranger rest API if you pass an Invalid attribute type in the JSON request body,  it throws a 404 error instead of 400 (Bad Request). It seems a bug where we need to handle the JsonMappingException by adding Exception Mapper globally to handle incorrect JSON format or Invalid attribute type in the JSON request body otherwise our Rest API will throw a 404 error instead of 400 error


Diffs
-----

  security-admin/src/main/java/org/apache/ranger/common/GenericRangerJsonMappingExceptionMapper.java PRE-CREATION 
  security-admin/src/main/java/org/apache/ranger/common/GenericRangerJsonParserExceptionMapper.java PRE-CREATION 


Diff: https://reviews.apache.org/r/74135/diff/1/


Testing
-------

Request with proper request : Passing int values

curl --location --request POST 'https://----------------/service/xaudit/trx_log' \
--header 'Authorization: Basic XXXX=' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
  "objectClassType" : "123456",
  "objectId" : "1234567"
}' 

Response : ok 


Request with bad request : Passing String values

curl --location --request POST 'https://---------/service/xaudit/trx_log' \
--header 'Authorization: Basic XXXXX==' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
  "objectClassType" : "abcdef",
  "objectId" : "abcdef"
}' 

Response : 
{
  "errorCode": "Bad Request",
  "error": "Can not construct instance of int from String value 'abcdef': not a valid Integer value\n at [Source: org.apache.catalina.connector.CoyoteInputStream@2c444edc; line: 1, column: 2] (through reference chain: org.apache.ranger.view.VXTrxLog[\"objectClassType\"])"
}


Thanks,

Ramachandran Krishnan


Re: Review Request 74135: RANGER-3847:Http status & Error message is not correct for the invalid json request body

Posted by Ramachandran Krishnan <ra...@gmail.com>.

> On Sept. 21, 2022, 4:38 p.m., Madhan Neethiraj wrote:
> > The patch looks good. One suggestion: instead of multiple exception mappers (GenericRangerJsonMappingExceptionMapper and GenericRangerJsonParserExceptionMapper), how about using a single mapper - similar to https://github.com/apache/ranger/blob/master/kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSExceptionsProvider.java?
> 
> Ramachandran Krishnan wrote:
>     KMSExceptionsProvider looks very generic.But we need to handle only invalid jsonformat,invalid attribute in valid json body.Inside generic exception anyway we need to cast the generic exception into JsonParseException or JsonMappingException ,etc.To make it clean i created mapper for specific exception which we are looking into it.
> 
> Madhan Neethiraj wrote:
>     Within a generic mapper, it is still possible to handle specific exceptions like JsonParseException/JsonMappingException - similar to KMSExceptionsProvider. It will help keep all exception handling in one place.

Sure .We will do it .I will make necessary changes for this .


- Ramachandran


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/74135/#review224695
-----------------------------------------------------------


On Sept. 21, 2022, 4:26 p.m., Ramachandran Krishnan wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/74135/
> -----------------------------------------------------------
> 
> (Updated Sept. 21, 2022, 4:26 p.m.)
> 
> 
> Review request for ranger, Abhay Kulkarni, Madhan Neethiraj, Nikhil P, Pradeep Agrawal, Ramesh Mani, Selvamohan Neethiraj, Sailaja Polavarapu, and Velmurugan Periasamy.
> 
> 
> Bugs: RANGER-3847
>     https://issues.apache.org/jira/browse/RANGER-3847
> 
> 
> Repository: ranger
> 
> 
> Description
> -------
> 
> In Ranger rest API if you pass an Invalid attribute type in the JSON request body,  it throws a 404 error instead of 400 (Bad Request). It seems a bug where we need to handle the JsonMappingException by adding Exception Mapper globally to handle incorrect JSON format or Invalid attribute type in the JSON request body otherwise our Rest API will throw a 404 error instead of 400 error
> 
> 
> Diffs
> -----
> 
>   security-admin/src/main/java/org/apache/ranger/common/GenericRangerJsonMappingExceptionMapper.java PRE-CREATION 
>   security-admin/src/main/java/org/apache/ranger/common/GenericRangerJsonParserExceptionMapper.java PRE-CREATION 
> 
> 
> Diff: https://reviews.apache.org/r/74135/diff/1/
> 
> 
> Testing
> -------
> 
> Request with proper request : Passing int values
> 
> curl --location --request POST 'https://----------------/service/xaudit/trx_log' \
> --header 'Authorization: Basic XXXX=' \
> --header 'Accept: application/json' \
> --header 'Content-Type: application/json' \
> --data-raw '{
>   "objectClassType" : "123456",
>   "objectId" : "1234567"
> }' 
> 
> Response : ok 
> 
> 
> Request with bad request : Passing String values
> 
> curl --location --request POST 'https://---------/service/xaudit/trx_log' \
> --header 'Authorization: Basic XXXXX==' \
> --header 'Accept: application/json' \
> --header 'Content-Type: application/json' \
> --data-raw '{
>   "objectClassType" : "abcdef",
>   "objectId" : "abcdef"
> }' 
> 
> Response : 
> {
>   "errorCode": "Bad Request",
>   "error": "Can not construct instance of int from String value 'abcdef': not a valid Integer value\n at [Source: org.apache.catalina.connector.CoyoteInputStream@2c444edc; line: 1, column: 2] (through reference chain: org.apache.ranger.view.VXTrxLog[\"objectClassType\"])"
> }
> 
> 
> Thanks,
> 
> Ramachandran Krishnan
> 
>


Re: Review Request 74135: RANGER-3847:Http status & Error message is not correct for the invalid json request body

Posted by Ramachandran Krishnan <ra...@gmail.com>.

> On Sept. 21, 2022, 4:38 p.m., Madhan Neethiraj wrote:
> > The patch looks good. One suggestion: instead of multiple exception mappers (GenericRangerJsonMappingExceptionMapper and GenericRangerJsonParserExceptionMapper), how about using a single mapper - similar to https://github.com/apache/ranger/blob/master/kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSExceptionsProvider.java?

KMSExceptionsProvider looks very generic.But we need to handle only invalid jsonformat,invalid attribute in valid json body.Inside generic exception anyway we need to cast the generic exception into JsonParseException or JsonMappingException ,etc.To make it clean i created mapper for specific exception which we are looking into it.


- Ramachandran


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/74135/#review224695
-----------------------------------------------------------


On Sept. 21, 2022, 4:26 p.m., Ramachandran Krishnan wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/74135/
> -----------------------------------------------------------
> 
> (Updated Sept. 21, 2022, 4:26 p.m.)
> 
> 
> Review request for ranger, Abhay Kulkarni, Madhan Neethiraj, Nikhil P, Pradeep Agrawal, Ramesh Mani, Selvamohan Neethiraj, Sailaja Polavarapu, and Velmurugan Periasamy.
> 
> 
> Bugs: RANGER-3847
>     https://issues.apache.org/jira/browse/RANGER-3847
> 
> 
> Repository: ranger
> 
> 
> Description
> -------
> 
> In Ranger rest API if you pass an Invalid attribute type in the JSON request body,  it throws a 404 error instead of 400 (Bad Request). It seems a bug where we need to handle the JsonMappingException by adding Exception Mapper globally to handle incorrect JSON format or Invalid attribute type in the JSON request body otherwise our Rest API will throw a 404 error instead of 400 error
> 
> 
> Diffs
> -----
> 
>   security-admin/src/main/java/org/apache/ranger/common/GenericRangerJsonMappingExceptionMapper.java PRE-CREATION 
>   security-admin/src/main/java/org/apache/ranger/common/GenericRangerJsonParserExceptionMapper.java PRE-CREATION 
> 
> 
> Diff: https://reviews.apache.org/r/74135/diff/1/
> 
> 
> Testing
> -------
> 
> Request with proper request : Passing int values
> 
> curl --location --request POST 'https://----------------/service/xaudit/trx_log' \
> --header 'Authorization: Basic XXXX=' \
> --header 'Accept: application/json' \
> --header 'Content-Type: application/json' \
> --data-raw '{
>   "objectClassType" : "123456",
>   "objectId" : "1234567"
> }' 
> 
> Response : ok 
> 
> 
> Request with bad request : Passing String values
> 
> curl --location --request POST 'https://---------/service/xaudit/trx_log' \
> --header 'Authorization: Basic XXXXX==' \
> --header 'Accept: application/json' \
> --header 'Content-Type: application/json' \
> --data-raw '{
>   "objectClassType" : "abcdef",
>   "objectId" : "abcdef"
> }' 
> 
> Response : 
> {
>   "errorCode": "Bad Request",
>   "error": "Can not construct instance of int from String value 'abcdef': not a valid Integer value\n at [Source: org.apache.catalina.connector.CoyoteInputStream@2c444edc; line: 1, column: 2] (through reference chain: org.apache.ranger.view.VXTrxLog[\"objectClassType\"])"
> }
> 
> 
> Thanks,
> 
> Ramachandran Krishnan
> 
>


Re: Review Request 74135: RANGER-3847:Http status & Error message is not correct for the invalid json request body

Posted by Ramachandran Krishnan <ra...@gmail.com>.

> On Sept. 21, 2022, 4:38 p.m., Madhan Neethiraj wrote:
> > The patch looks good. One suggestion: instead of multiple exception mappers (GenericRangerJsonMappingExceptionMapper and GenericRangerJsonParserExceptionMapper), how about using a single mapper - similar to https://github.com/apache/ranger/blob/master/kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSExceptionsProvider.java?
> 
> Ramachandran Krishnan wrote:
>     KMSExceptionsProvider looks very generic.But we need to handle only invalid jsonformat,invalid attribute in valid json body.Inside generic exception anyway we need to cast the generic exception into JsonParseException or JsonMappingException ,etc.To make it clean i created mapper for specific exception which we are looking into it.
> 
> Madhan Neethiraj wrote:
>     Within a generic mapper, it is still possible to handle specific exceptions like JsonParseException/JsonMappingException - similar to KMSExceptionsProvider. It will help keep all exception handling in one place.
> 
> Ramachandran Krishnan wrote:
>     Sure .We will do it .I will make necessary changes for this .

Added a generic Exception mapper .This class can be leveraged if we want to add any specific exception also in the future .


- Ramachandran


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/74135/#review224695
-----------------------------------------------------------


On Sept. 22, 2022, 4:45 a.m., Ramachandran Krishnan wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/74135/
> -----------------------------------------------------------
> 
> (Updated Sept. 22, 2022, 4:45 a.m.)
> 
> 
> Review request for ranger, Abhay Kulkarni, Madhan Neethiraj, Nikhil P, Pradeep Agrawal, Ramesh Mani, Selvamohan Neethiraj, Sailaja Polavarapu, and Velmurugan Periasamy.
> 
> 
> Bugs: RANGER-3847
>     https://issues.apache.org/jira/browse/RANGER-3847
> 
> 
> Repository: ranger
> 
> 
> Description
> -------
> 
> In Ranger rest API if you pass an Invalid attribute type in the JSON request body,  it throws a 404 error instead of 400 (Bad Request). It seems a bug where we need to handle the JsonMappingException by adding Exception Mapper globally to handle incorrect JSON format or Invalid attribute type in the JSON request body otherwise our Rest API will throw a 404 error instead of 400 error
> 
> 
> Diffs
> -----
> 
>   security-admin/src/main/java/org/apache/ranger/common/RangerExceptionProvider.java PRE-CREATION 
> 
> 
> Diff: https://reviews.apache.org/r/74135/diff/2/
> 
> 
> Testing
> -------
> 
> Request with proper request : Passing int values
> 
> curl --location --request POST 'https://----------------/service/xaudit/trx_log' \
> --header 'Authorization: Basic XXXX=' \
> --header 'Accept: application/json' \
> --header 'Content-Type: application/json' \
> --data-raw '{
>   "objectClassType" : "123456",
>   "objectId" : "1234567"
> }' 
> 
> Response : ok 
> 
> 
> Request with bad request : Passing String values
> 
> curl --location --request POST 'https://---------/service/xaudit/trx_log' \
> --header 'Authorization: Basic XXXXX==' \
> --header 'Accept: application/json' \
> --header 'Content-Type: application/json' \
> --data-raw '{
>   "objectClassType" : "abcdef",
>   "objectId" : "abcdef"
> }' 
> 
> Response : 
> {
>   "errorCode": "Bad Request",
>   "error": "Can not construct instance of int from String value 'abcdef': not a valid Integer value\n at [Source: org.apache.catalina.connector.CoyoteInputStream@2c444edc; line: 1, column: 2] (through reference chain: org.apache.ranger.view.VXTrxLog[\"objectClassType\"])"
> }
> 
> 
> Thanks,
> 
> Ramachandran Krishnan
> 
>


Re: Review Request 74135: RANGER-3847:Http status & Error message is not correct for the invalid json request body

Posted by Madhan Neethiraj <ma...@apache.org>.

> On Sept. 21, 2022, 4:38 p.m., Madhan Neethiraj wrote:
> > The patch looks good. One suggestion: instead of multiple exception mappers (GenericRangerJsonMappingExceptionMapper and GenericRangerJsonParserExceptionMapper), how about using a single mapper - similar to https://github.com/apache/ranger/blob/master/kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSExceptionsProvider.java?
> 
> Ramachandran Krishnan wrote:
>     KMSExceptionsProvider looks very generic.But we need to handle only invalid jsonformat,invalid attribute in valid json body.Inside generic exception anyway we need to cast the generic exception into JsonParseException or JsonMappingException ,etc.To make it clean i created mapper for specific exception which we are looking into it.

Within a generic mapper, it is still possible to handle specific exceptions like JsonParseException/JsonMappingException - similar to KMSExceptionsProvider. It will help keep all exception handling in one place.


- Madhan


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/74135/#review224695
-----------------------------------------------------------


On Sept. 21, 2022, 4:26 p.m., Ramachandran Krishnan wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/74135/
> -----------------------------------------------------------
> 
> (Updated Sept. 21, 2022, 4:26 p.m.)
> 
> 
> Review request for ranger, Abhay Kulkarni, Madhan Neethiraj, Nikhil P, Pradeep Agrawal, Ramesh Mani, Selvamohan Neethiraj, Sailaja Polavarapu, and Velmurugan Periasamy.
> 
> 
> Bugs: RANGER-3847
>     https://issues.apache.org/jira/browse/RANGER-3847
> 
> 
> Repository: ranger
> 
> 
> Description
> -------
> 
> In Ranger rest API if you pass an Invalid attribute type in the JSON request body,  it throws a 404 error instead of 400 (Bad Request). It seems a bug where we need to handle the JsonMappingException by adding Exception Mapper globally to handle incorrect JSON format or Invalid attribute type in the JSON request body otherwise our Rest API will throw a 404 error instead of 400 error
> 
> 
> Diffs
> -----
> 
>   security-admin/src/main/java/org/apache/ranger/common/GenericRangerJsonMappingExceptionMapper.java PRE-CREATION 
>   security-admin/src/main/java/org/apache/ranger/common/GenericRangerJsonParserExceptionMapper.java PRE-CREATION 
> 
> 
> Diff: https://reviews.apache.org/r/74135/diff/1/
> 
> 
> Testing
> -------
> 
> Request with proper request : Passing int values
> 
> curl --location --request POST 'https://----------------/service/xaudit/trx_log' \
> --header 'Authorization: Basic XXXX=' \
> --header 'Accept: application/json' \
> --header 'Content-Type: application/json' \
> --data-raw '{
>   "objectClassType" : "123456",
>   "objectId" : "1234567"
> }' 
> 
> Response : ok 
> 
> 
> Request with bad request : Passing String values
> 
> curl --location --request POST 'https://---------/service/xaudit/trx_log' \
> --header 'Authorization: Basic XXXXX==' \
> --header 'Accept: application/json' \
> --header 'Content-Type: application/json' \
> --data-raw '{
>   "objectClassType" : "abcdef",
>   "objectId" : "abcdef"
> }' 
> 
> Response : 
> {
>   "errorCode": "Bad Request",
>   "error": "Can not construct instance of int from String value 'abcdef': not a valid Integer value\n at [Source: org.apache.catalina.connector.CoyoteInputStream@2c444edc; line: 1, column: 2] (through reference chain: org.apache.ranger.view.VXTrxLog[\"objectClassType\"])"
> }
> 
> 
> Thanks,
> 
> Ramachandran Krishnan
> 
>


Re: Review Request 74135: RANGER-3847:Http status & Error message is not correct for the invalid json request body

Posted by Madhan Neethiraj <ma...@apache.org>.
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/74135/#review224695
-----------------------------------------------------------



The patch looks good. One suggestion: instead of multiple exception mappers (GenericRangerJsonMappingExceptionMapper and GenericRangerJsonParserExceptionMapper), how about using a single mapper - similar to https://github.com/apache/ranger/blob/master/kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSExceptionsProvider.java?

- Madhan Neethiraj


On Sept. 21, 2022, 4:26 p.m., Ramachandran Krishnan wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/74135/
> -----------------------------------------------------------
> 
> (Updated Sept. 21, 2022, 4:26 p.m.)
> 
> 
> Review request for ranger, Abhay Kulkarni, Madhan Neethiraj, Nikhil P, Pradeep Agrawal, Ramesh Mani, Selvamohan Neethiraj, Sailaja Polavarapu, and Velmurugan Periasamy.
> 
> 
> Bugs: RANGER-3847
>     https://issues.apache.org/jira/browse/RANGER-3847
> 
> 
> Repository: ranger
> 
> 
> Description
> -------
> 
> In Ranger rest API if you pass an Invalid attribute type in the JSON request body,  it throws a 404 error instead of 400 (Bad Request). It seems a bug where we need to handle the JsonMappingException by adding Exception Mapper globally to handle incorrect JSON format or Invalid attribute type in the JSON request body otherwise our Rest API will throw a 404 error instead of 400 error
> 
> 
> Diffs
> -----
> 
>   security-admin/src/main/java/org/apache/ranger/common/GenericRangerJsonMappingExceptionMapper.java PRE-CREATION 
>   security-admin/src/main/java/org/apache/ranger/common/GenericRangerJsonParserExceptionMapper.java PRE-CREATION 
> 
> 
> Diff: https://reviews.apache.org/r/74135/diff/1/
> 
> 
> Testing
> -------
> 
> Request with proper request : Passing int values
> 
> curl --location --request POST 'https://----------------/service/xaudit/trx_log' \
> --header 'Authorization: Basic XXXX=' \
> --header 'Accept: application/json' \
> --header 'Content-Type: application/json' \
> --data-raw '{
>   "objectClassType" : "123456",
>   "objectId" : "1234567"
> }' 
> 
> Response : ok 
> 
> 
> Request with bad request : Passing String values
> 
> curl --location --request POST 'https://---------/service/xaudit/trx_log' \
> --header 'Authorization: Basic XXXXX==' \
> --header 'Accept: application/json' \
> --header 'Content-Type: application/json' \
> --data-raw '{
>   "objectClassType" : "abcdef",
>   "objectId" : "abcdef"
> }' 
> 
> Response : 
> {
>   "errorCode": "Bad Request",
>   "error": "Can not construct instance of int from String value 'abcdef': not a valid Integer value\n at [Source: org.apache.catalina.connector.CoyoteInputStream@2c444edc; line: 1, column: 2] (through reference chain: org.apache.ranger.view.VXTrxLog[\"objectClassType\"])"
> }
> 
> 
> Thanks,
> 
> Ramachandran Krishnan
> 
>


Re: Review Request 74135: RANGER-3847:Http status & Error message is not correct for the invalid json request body

Posted by Madhan Neethiraj <ma...@apache.org>.
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/74135/#review224726
-----------------------------------------------------------


Ship it!




Ramachandran - one looking into this further, I think your first patch to use multipe exception mappers - one for each exception type, is safer. Thanks!

- Madhan Neethiraj


On Sept. 22, 2022, 4:48 a.m., Ramachandran Krishnan wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/74135/
> -----------------------------------------------------------
> 
> (Updated Sept. 22, 2022, 4:48 a.m.)
> 
> 
> Review request for ranger, Abhay Kulkarni, Madhan Neethiraj, Nikhil P, Pradeep Agrawal, Ramesh Mani, Selvamohan Neethiraj, Sailaja Polavarapu, and Velmurugan Periasamy.
> 
> 
> Bugs: RANGER-3847
>     https://issues.apache.org/jira/browse/RANGER-3847
> 
> 
> Repository: ranger
> 
> 
> Description
> -------
> 
> In Ranger rest API if you pass an Invalid attribute type in the JSON request body,  it throws a 404 error instead of 400 (Bad Request). It seems a bug where we need to handle the JsonMappingException by adding Exception Mapper globally to handle incorrect JSON format or Invalid attribute type in the JSON request body otherwise our Rest API will throw a 404 error instead of 400 error
> 
> 
> Diffs
> -----
> 
>   security-admin/src/main/java/org/apache/ranger/common/RangerExceptionProvider.java PRE-CREATION 
> 
> 
> Diff: https://reviews.apache.org/r/74135/diff/3/
> 
> 
> Testing
> -------
> 
> Request with proper request : Passing int values
> 
> curl --location --request POST 'https://----------------/service/xaudit/trx_log' \
> --header 'Authorization: Basic XXXX=' \
> --header 'Accept: application/json' \
> --header 'Content-Type: application/json' \
> --data-raw '{
>   "objectClassType" : "123456",
>   "objectId" : "1234567"
> }' 
> 
> Response : ok 
> 
> 
> Request with bad request : Passing String values
> 
> curl --location --request POST 'https://---------/service/xaudit/trx_log' \
> --header 'Authorization: Basic XXXXX==' \
> --header 'Accept: application/json' \
> --header 'Content-Type: application/json' \
> --data-raw '{
>   "objectClassType" : "abcdef",
>   "objectId" : "abcdef"
> }' 
> 
> Response : 
> {
>   "errorCode": "Bad Request",
>   "error": "Can not construct instance of int from String value 'abcdef': not a valid Integer value\n at [Source: org.apache.catalina.connector.CoyoteInputStream@2c444edc; line: 1, column: 2] (through reference chain: org.apache.ranger.view.VXTrxLog[\"objectClassType\"])"
> }
> 
> 
> Thanks,
> 
> Ramachandran Krishnan
> 
>


Re: Review Request 74135: RANGER-3847:Http status & Error message is not correct for the invalid json request body

Posted by Ramachandran Krishnan <ra...@gmail.com>.
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/74135/
-----------------------------------------------------------

(Updated Sept. 22, 2022, 4:48 a.m.)


Review request for ranger, Abhay Kulkarni, Madhan Neethiraj, Nikhil P, Pradeep Agrawal, Ramesh Mani, Selvamohan Neethiraj, Sailaja Polavarapu, and Velmurugan Periasamy.


Bugs: RANGER-3847
    https://issues.apache.org/jira/browse/RANGER-3847


Repository: ranger


Description
-------

In Ranger rest API if you pass an Invalid attribute type in the JSON request body,  it throws a 404 error instead of 400 (Bad Request). It seems a bug where we need to handle the JsonMappingException by adding Exception Mapper globally to handle incorrect JSON format or Invalid attribute type in the JSON request body otherwise our Rest API will throw a 404 error instead of 400 error


Diffs (updated)
-----

  security-admin/src/main/java/org/apache/ranger/common/RangerExceptionProvider.java PRE-CREATION 


Diff: https://reviews.apache.org/r/74135/diff/3/

Changes: https://reviews.apache.org/r/74135/diff/2-3/


Testing
-------

Request with proper request : Passing int values

curl --location --request POST 'https://----------------/service/xaudit/trx_log' \
--header 'Authorization: Basic XXXX=' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
  "objectClassType" : "123456",
  "objectId" : "1234567"
}' 

Response : ok 


Request with bad request : Passing String values

curl --location --request POST 'https://---------/service/xaudit/trx_log' \
--header 'Authorization: Basic XXXXX==' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
  "objectClassType" : "abcdef",
  "objectId" : "abcdef"
}' 

Response : 
{
  "errorCode": "Bad Request",
  "error": "Can not construct instance of int from String value 'abcdef': not a valid Integer value\n at [Source: org.apache.catalina.connector.CoyoteInputStream@2c444edc; line: 1, column: 2] (through reference chain: org.apache.ranger.view.VXTrxLog[\"objectClassType\"])"
}


Thanks,

Ramachandran Krishnan


Re: Review Request 74135: RANGER-3847:Http status & Error message is not correct for the invalid json request body

Posted by Ramachandran Krishnan <ra...@gmail.com>.
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/74135/
-----------------------------------------------------------

(Updated Sept. 22, 2022, 4:45 a.m.)


Review request for ranger, Abhay Kulkarni, Madhan Neethiraj, Nikhil P, Pradeep Agrawal, Ramesh Mani, Selvamohan Neethiraj, Sailaja Polavarapu, and Velmurugan Periasamy.


Bugs: RANGER-3847
    https://issues.apache.org/jira/browse/RANGER-3847


Repository: ranger


Description
-------

In Ranger rest API if you pass an Invalid attribute type in the JSON request body,  it throws a 404 error instead of 400 (Bad Request). It seems a bug where we need to handle the JsonMappingException by adding Exception Mapper globally to handle incorrect JSON format or Invalid attribute type in the JSON request body otherwise our Rest API will throw a 404 error instead of 400 error


Diffs (updated)
-----

  security-admin/src/main/java/org/apache/ranger/common/RangerExceptionProvider.java PRE-CREATION 


Diff: https://reviews.apache.org/r/74135/diff/2/

Changes: https://reviews.apache.org/r/74135/diff/1-2/


Testing
-------

Request with proper request : Passing int values

curl --location --request POST 'https://----------------/service/xaudit/trx_log' \
--header 'Authorization: Basic XXXX=' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
  "objectClassType" : "123456",
  "objectId" : "1234567"
}' 

Response : ok 


Request with bad request : Passing String values

curl --location --request POST 'https://---------/service/xaudit/trx_log' \
--header 'Authorization: Basic XXXXX==' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
  "objectClassType" : "abcdef",
  "objectId" : "abcdef"
}' 

Response : 
{
  "errorCode": "Bad Request",
  "error": "Can not construct instance of int from String value 'abcdef': not a valid Integer value\n at [Source: org.apache.catalina.connector.CoyoteInputStream@2c444edc; line: 1, column: 2] (through reference chain: org.apache.ranger.view.VXTrxLog[\"objectClassType\"])"
}


Thanks,

Ramachandran Krishnan