try {
// -> first make sure that the policy is valid by parsing it
PolicyParser parser = new PolicyParser();
S3BucketPolicy sbp = parser.parse( policy, bucketName );
policyDao.deletePolicy( bucketName );
if (null != policy && !policy.isEmpty()) policyDao.addPolicy( bucketName, client, policy );
if (null != sbp) ServiceProvider.getInstance().setBucketPolicy( bucketName, sbp );
response.setStatus(200);
}