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

dmitriusan 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 ab11712  AMBARI-25204. Ambari returns stack trace in HTML doc when an 
error occurs retrieving details for an Ambari View resource that does not exist 
- backport for 2.6 (dlysnichenko) (#2959)
ab11712 is described below

commit ab11712f3b47658083976be2ecadaa773dc02e55
Author: Lisnichenko Dmitro <dlysniche...@hortonworks.com>
AuthorDate: Mon May 6 12:39:23 2019 +0300

    AMBARI-25204. Ambari returns stack trace in HTML doc when an error occurs 
retrieving details for an Ambari View resource that does not exist - backport 
for 2.6 (dlysnichenko) (#2959)
---
 .../server/api/services/ViewInstanceService.java   | 131 ++++++++++++++++++++-
 1 file changed, 127 insertions(+), 4 deletions(-)

diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewInstanceService.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewInstanceService.java
index fa0850e..4f894f4 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewInstanceService.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ViewInstanceService.java
@@ -19,6 +19,7 @@
 package org.apache.ambari.server.api.services;
 
 import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.services.serializers.JsonSerializer;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.orm.entities.ViewInstanceEntity;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
@@ -34,6 +35,7 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import java.util.HashMap;
@@ -215,20 +217,141 @@ public class ViewInstanceService extends BaseService {
         ViewRegistry.getInstance().getInstanceDefinition(viewName, version, 
instanceName);
 
     if (instanceDefinition == null) {
-      throw new IllegalArgumentException("A view instance " +
-          viewName + "/" + instanceName + " can not be found.");
+      String msg = "A view instance " +
+          viewName + "/" + instanceName + " can not be found.";
+
+      return new NotFoundResponse(msg);
     }
 
     Object service = instanceDefinition.getService(resources);
 
     if (service == null) {
-      throw new IllegalArgumentException("A resource type " + resources + " 
for view instance " +
-          viewName + "/" + instanceName + " can not be found.");
+      String msg = "A resource type " + resources + " for view instance " +
+          viewName + "/" + instanceName + " can not be found.";
+      return new NotFoundResponse(msg);
     }
     return service;
   }
 
   /**
+   * Stub class for 404 error response
+   *
+   */
+  @Path("/")
+  public class NotFoundResponse {
+
+    String msg;
+
+    NotFoundResponse(String msg){
+      this.msg=msg;
+    }
+
+    /**
+     * Handles: GET /{resourceName}
+     * Handle GET resource with 404 response
+     * @return 404 response with msg
+     */
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response get() {
+      return getResponse();
+    }
+
+    /**
+     * Handles: POST /{resourceName}
+     * Handle POST resource with 404 response
+     * @return 404 response with msg
+     */
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response post() {
+      return getResponse();
+    }
+
+    /**
+     * Handles: PUT /{resourceName}
+     * Handle PUT resource with 404 response
+     * @return 404 response with msg
+     */
+    @PUT
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response put() {
+      return getResponse();
+    }
+
+    /**
+     * Handles: DELETE /{resourceName}
+     * Handle DELETE resource with 404 response
+     * @return 404 response with msg
+     */
+    @DELETE
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response delete() {
+      return getResponse();
+    }
+
+    /**
+     * Handles: GET /{resourceName}/{.*}
+     * Handle GET sub-resource with 404 response
+     * @return 404 response with msg
+     */
+    @GET
+    @Path("{path: .*}")
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response getSub() {
+      return getResponse();
+    }
+
+    /**
+     * Handles: POST /{resourceName}/{.*}
+     * Handle POST sub-resource with 404 response
+     * @return 404 response with msg
+     */
+    @POST
+    @Path("{path: .*}")
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response postSub() {
+      return getResponse();
+    }
+
+    /**
+     * Handles: PUT /{resourceName}/{.*}
+     * Handle PUT sub-resource with 404 response
+     * @return 404 response with msg
+     */
+    @PUT
+    @Path("{path: .*}")
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response putSub() {
+      return getResponse();
+    }
+
+    /**
+     * Handles: DELETE /{resourceName}/{.*}
+     * Handle DELETE sub-resource with 404 response
+     * @return 404 response with msg
+     */
+    @DELETE
+    @Path("{path: .*}")
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response deleteSub() {
+      return getResponse();
+    }
+
+    /**
+     * Build 404 response with msg
+     * @return 404 response with msg
+     */
+    public Response getResponse() {
+      Result result = new ResultImpl(new 
ResultStatus(ResultStatus.STATUS.NOT_FOUND, msg));
+      Response.ResponseBuilder builder = 
Response.status(result.getStatus().getStatusCode()).entity(new 
JsonSerializer().serialize(result));
+      return builder.build();
+    }
+
+  }
+
+
+  /**
    * Gets the admin privilege service
    */
   @Path("{instanceName}/privileges")

Reply via email to