This is an automated email from the ASF dual-hosted git repository.

amagyar pushed a commit to branch branch-2.6
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/branch-2.6 by this push:
     new 0b1df74  AMBARI-25175. Start, Stop, Service Check and other request 
actions using PUT/POST from Ambari UI do not respond when tried via Knox TP 
(amagyar) (#2842)
0b1df74 is described below

commit 0b1df74280d413ee0950001b6dae5cad6d6a011e
Author: Attila Magyar <m.magy...@gmail.com>
AuthorDate: Mon Mar 4 08:44:01 2019 +0100

    AMBARI-25175. Start, Stop, Service Check and other request actions using 
PUT/POST from Ambari UI do not respond when tried via Knox TP (amagyar) (#2842)
---
 .../java/org/apache/ambari/server/api/services/RequestFactory.java    | 3 ++-
 ambari-web/app/utils/ajax/ajax.js                                     | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/RequestFactory.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/RequestFactory.java
index 2f71776..7795b7a 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/RequestFactory.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/RequestFactory.java
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.api.services;
 
+import org.apache.ambari.server.api.predicate.QueryLexer;
 import org.apache.ambari.server.api.resources.ResourceDefinition;
 import org.apache.ambari.server.api.resources.ResourceInstance;
 
@@ -84,7 +85,6 @@ public class RequestFactory {
    */
   private Request createPostRequest(HttpHeaders headers, RequestBody body, 
UriInfo uriInfo, ResourceInstance resource) {
     boolean batchCreate = !applyDirectives(Request.Type.POST, body, uriInfo, 
resource);;
-
     return (batchCreate) ?
         new QueryPostRequest(headers, body, uriInfo, resource) :
         new PostRequest(headers, body, uriInfo, resource);
@@ -153,6 +153,7 @@ public class RequestFactory {
    */
   private boolean applyDirectives(Request.Type requestType, RequestBody body, 
UriInfo uriInfo, ResourceInstance resource) {
     Map<String, String> queryParameters = getQueryParameters(uriInfo, body);
+    queryParameters.remove(QueryLexer.QUERY_DOAS); // KNOX appends a doAs 
parameter to every request. Ignore this as it's neither a query predicate nor a 
directive.
     Map<String, String> requestInfoProperties;
     boolean allDirectivesApplicable = true;
     if (!queryParameters.isEmpty()) {
diff --git a/ambari-web/app/utils/ajax/ajax.js 
b/ambari-web/app/utils/ajax/ajax.js
index 0747658..96a934d 100644
--- a/ambari-web/app/utils/ajax/ajax.js
+++ b/ambari-web/app/utils/ajax/ajax.js
@@ -3141,6 +3141,10 @@ var formatRequest = function (data) {
   if (this.format) {
     jQuery.extend(opt, this.format(data, opt));
   }
+  if (!('headers' in opt && 'Content-Type' in opt.headers)) {
+    // With the default www-url-form-encoded Content-Type KNOX would corrupt 
the json content.
+    opt.headers['Content-Type'] = 'text/plain';
+  }
   var statusCode = jQuery.extend({}, require('data/statusCodes'));
   statusCode['404'] = function () {
     console.log("Error code 404: URI not found. -> " + opt.url);

Reply via email to