activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1222971 - in /activemq/activemq-apollo/trunk: apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/ apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/
Date Sat, 24 Dec 2011 13:32:43 GMT
Author: chirino
Date: Sat Dec 24 13:32:43 2011
New Revision: 1222971

URL: http://svn.apache.org/viewvc?rev=1222971&view=rev
Log:
Fixes web console HTML view regression add more details to the ErrorDTO.

Bug introduced when the fix for APLO-122 was committed.

Added:
    activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/ErrorDTO.jade
Modified:
    activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ErrorDTO.java
    activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/JaxrsExceptionMapper.scala
    activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala

Modified: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ErrorDTO.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ErrorDTO.java?rev=1222971&r1=1222970&r2=1222971&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ErrorDTO.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ErrorDTO.java
Sat Dec 24 13:32:43 2011
@@ -31,44 +31,28 @@ import java.util.List;
 public class ErrorDTO {
 
     /**
+     * The error code.
+     */
+    @XmlAttribute(name="code")
+    public String code;
+
+    /**
      * The message associated with the error.
      */
     @XmlAttribute(name="message")
     public String message;
 
-    public ErrorDTO(){}
+    /**
+     * The resource being access which caused the error
+     */
+    @XmlAttribute(name="resource")
+    public String resource;
 
-    public ErrorDTO(String message) {
-        this.message = message;
-    }
+    public ErrorDTO(){}
 
     /**
      * To hold any other non-matching XML elements
      */
     @XmlAnyElement(lax=true)
     public List<Object> other = new ArrayList<Object>();
-
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) return true;
-        if (!(o instanceof ErrorDTO)) return false;
-
-        ErrorDTO errorDTO = (ErrorDTO) o;
-
-        if (message != null ? !message.equals(errorDTO.message) : errorDTO.message != null)
return false;
-
-        return true;
-    }
-
-    @Override
-    public int hashCode() {
-        return message != null ? message.hashCode() : 0;
-    }
-
-    @Override
-    public String toString() {
-        return "ErrorDTO{" +
-                "message='" + message + '\'' +
-                '}';
-    }
 }

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/JaxrsExceptionMapper.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/JaxrsExceptionMapper.scala?rev=1222971&r1=1222970&r2=1222971&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/JaxrsExceptionMapper.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/JaxrsExceptionMapper.scala
Sat Dec 24 13:32:43 2011
@@ -19,6 +19,8 @@ package org.apache.activemq.apollo.web.r
 import javax.ws.rs.core._
 import javax.ws.rs.ext._
 import javax.ws.rs._
+import core.MediaType._
+import core.Response.Status
 import core.Response.Status._
 import org.apache.activemq.apollo.dto.ErrorDTO
 import javax.servlet.http.HttpServletRequest
@@ -40,21 +42,34 @@ class JaxrsExceptionMapper extends Excep
     http_request.getRequestURI + Option(query).map("?"+_).getOrElse("")
   }
 
+  @Produces(Array(APPLICATION_JSON, APPLICATION_XML, TEXT_XML))
   def toResponse(error: Throwable): Response = {
-    
-    def response(status: Response.Status, msg: String) = {
+
+    def response(status: Response.Status, msg: String=null) = {
       val response = Response.status(status)
-      response.entity(new ErrorDTO(msg))
+      var dto = new ErrorDTO()
+      dto.code = "%d: %s".format(status.getStatusCode, status.getReasonPhrase)
+      dto.message = msg;
+      dto.resource = requested_uri;
+      response.entity(dto)
       response.build
     }
 
     error match {
       case ex:WebApplicationException =>
-        ex.getResponse.getStatus match {
-          case 404 =>
-            response(NOT_FOUND, "Resource not found: "+requested_uri)
-          case _ =>
-            ex.getResponse
+        var code = ex.getResponse.getStatus
+        if(code >= 400 && code != 401) {
+          if(ex.getResponse.getStatus >= 500) {
+            Resource.warn(ex, "HTTP request from '%s' for %s '%s' caused internal server
error: %s", http_request.getRemoteAddr, http_request.getMethod, requested_uri, ex.toString);
+          }
+          var status = Status.fromStatusCode(ex.getResponse.getStatus)
+          ex.getResponse.getEntity match {
+            case null => response(status)
+            case x:String => response(status, x)
+            case _ => ex.getResponse
+          }
+        } else {
+          ex.getResponse
         }
       case ex:Throwable =>
         Resource.warn(ex, "HTTP request from '%s' for %s '%s' caused internal server error:
%s", http_request.getRemoteAddr, http_request.getMethod, requested_uri, ex.toString);

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala?rev=1222971&r1=1222970&r2=1222971&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala
Sat Dec 24 13:32:43 2011
@@ -33,6 +33,7 @@ import util.continuations._
 import org.apache.activemq.apollo.util._
 import java.net.{InetSocketAddress, URI}
 import java.security.cert.X509Certificate
+import org.apache.activemq.apollo.dto.ErrorDTO
 
 object Resource extends Log {
 
@@ -108,10 +109,10 @@ abstract class Resource(parent:Resource=
             if (authorizer.can(security_context, action, resource)) {
               block.onComplete(rc)
             } else {
-              unauthroized
+              unauthorized
             }
           } else {
-            unauthroized
+            unauthorized
           }
         } catch {
           case e:Throwable =>
@@ -217,13 +218,18 @@ abstract class Resource(parent:Resource=
     }
   }
 
-  protected def unauthroized = {
+  protected def unauthorized = {
     val response = Response.status(HttpServletResponse.SC_UNAUTHORIZED)
     if( http_request.getHeader("AuthPrompt")!="false" && http_request.getSession(false)==null
) {
       // TODO: perhaps get the realm from the authenticator
       var http_realm = "Apollo"
       response.header(HEADER_WWW_AUTHENTICATE, AUTHENTICATION_SCHEME_BASIC + " realm=\""
+ http_realm + "\"")
     }
+
+    var dto = new ErrorDTO()
+    dto.code = "%d: %s".format(UNAUTHORIZED.getStatusCode, UNAUTHORIZED.getReasonPhrase)
+    dto.message = "You do not have access to access the resource.";
+    response.entity(dto)
     throw new WebApplicationException(response.build())
   }
 

Added: activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/ErrorDTO.jade
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/ErrorDTO.jade?rev=1222971&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/ErrorDTO.jade
(added)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/ErrorDTO.jade
Sat Dec 24 13:32:43 2011
@@ -0,0 +1,31 @@
+-# Licensed to the Apache Software Foundation (ASF) under one or more
+-# contributor license agreements.  See the NOTICE file distributed with
+-# this work for additional information regarding copyright ownership.
+-# The ASF licenses this file to You under the Apache License, Version 2.0
+-# (the "License"); you may not use this file except in compliance with
+-# the License.  You may obtain a copy of the License at
+-# 
+-# http://www.apache.org/licenses/LICENSE-2.0
+-# 
+-# Unless required by applicable law or agreed to in writing, software
+-# distributed under the License is distributed on an "AS IS" BASIS,
+-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-# See the License for the specific language governing permissions and
+-# limitations under the License.
+
+- import it._
+- val helper = new org.apache.activemq.apollo.web.resources.ViewHelper
+- import helper._
+
+div(style="padding:2em;font-size:150%")
+  - if(code!=null)
+    h1(style="font-size:150%") #{code}
+  - else
+    h1 Error
+  div(style="padding-left:1em")
+    - if(message !=null)
+      p #{message}
+    - if(it.resource !=null)
+      p
+        while trying to access
+        code #{it.resource}
\ No newline at end of file



Mime
View raw message