olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [02/50] [abbrv] git commit: [OLINGO-298] Fixed response status and removed NotAllowedException
Date Tue, 02 Sep 2014 11:49:22 GMT
[OLINGO-298] Fixed response status and removed NotAllowedException


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/7d71cee8
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/7d71cee8
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/7d71cee8

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 7d71cee8f7f8509e624db8aaa7788d3078f12a1c
Parents: d7c6824
Author: Michael Bolz <mibo@apache.org>
Authored: Mon Jun 2 11:10:34 2014 +0200
Committer: Michael Bolz <mibo@apache.org>
Committed: Mon Jun 2 11:18:51 2014 +0200

----------------------------------------------------------------------
 .../odata2/core/rest/ODataExceptionMapperImpl.java     | 13 +++++--------
 .../olingo/odata2/core/servlet/ODataServlet.java       |  7 ++++---
 .../odata2/core/rest/ODataExceptionMapperImplTest.java |  4 ++--
 .../apache/olingo/odata2/fit/basic/BasicHttpTest.java  |  4 ++--
 .../apache/olingo/odata2/fit/basic/UrlRewriteTest.java |  2 +-
 5 files changed, 14 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/7d71cee8/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataExceptionMapperImpl.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataExceptionMapperImpl.java
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataExceptionMapperImpl.java
index 5f7d059..b5dd749 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataExceptionMapperImpl.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/rest/ODataExceptionMapperImpl.java
@@ -25,7 +25,6 @@ import java.util.Set;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.NotAllowedException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Context;
@@ -93,8 +92,7 @@ public class ODataExceptionMapperImpl implements ExceptionMapper<Exception>
{
 
     ODataExceptionWrapper exceptionWrapper =
         new ODataExceptionWrapper(uriInfo, httpHeaders, getErrorHandlerCallback());
-    ODataResponse oDataResponse = exceptionWrapper.wrapInExceptionResponse(exception);
-    return oDataResponse;
+    return exceptionWrapper.wrapInExceptionResponse(exception);
   }
 
   private ODataResponse handleWebApplicationException(final Exception exception) throws ClassNotFoundException,
@@ -132,8 +130,9 @@ public class ODataExceptionMapperImpl implements ExceptionMapper<Exception>
{
     context.setErrorCode(null);
     context.setMessage(exception.getMessage());
     context.setLocale(DEFAULT_RESPONSE_LOCALE);
-    context.setHttpStatus(HttpStatusCodes.fromStatusCode(exception.getResponse().getStatus()));
-    if (exception instanceof NotAllowedException) {
+    HttpStatusCodes statusCode = HttpStatusCodes.fromStatusCode(exception.getResponse().getStatus());
+    context.setHttpStatus(statusCode);
+    if (statusCode == HttpStatusCodes.METHOD_NOT_ALLOWED) {
       // RFC 2616, 5.1.1: " An origin server SHOULD return the status code
       // 405 (Method Not Allowed) if the method is known by the origin server
       // but not allowed for the requested resource, and 501 (Not Implemented)
@@ -194,10 +193,8 @@ public class ODataExceptionMapperImpl implements ExceptionMapper<Exception>
{
   }
 
   private ODataErrorCallback getErrorHandlerCallback() {
-    ODataErrorCallback callback = null;
     final ODataServiceFactory serviceFactory =
         ODataRootLocator.createServiceFactoryFromContext(app, servletRequest, servletConfig);
-    callback = serviceFactory.getCallback(ODataErrorCallback.class);
-    return callback;
+    return serviceFactory.getCallback(ODataErrorCallback.class);
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/7d71cee8/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
index dbe2935..ef5be4f 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
@@ -128,7 +128,7 @@ public class ODataServlet extends HttpServlet {
     } else if (HTTP_METHOD_HEAD.equals(method) || HTTP_METHOD_OPTIONS.equals(method)) {
       createNotImplementedResponse(req, ODataNotImplementedException.COMMON, resp);
     } else {
-      createMethodNotAllowedResponse(req, ODataHttpException.COMMON, resp);
+      createNotImplementedResponse(req, ODataHttpException.COMMON, resp);
     }
   }
 
@@ -149,7 +149,7 @@ public class ODataServlet extends HttpServlet {
     } else if (HTTP_METHOD_HEAD.equals(xHttpMethod) || HTTP_METHOD_OPTIONS.equals(xHttpMethod))
{
       createNotImplementedResponse(req, ODataNotImplementedException.COMMON, resp);
     } else {
-      return false;
+      createNotImplementedResponse(req, ODataNotImplementedException.COMMON, resp);
     }
     return true;
   }
@@ -201,7 +201,7 @@ public class ODataServlet extends HttpServlet {
           .build();
       createResponse(resp, odataResponse);
     } else {
-      createMethodNotAllowedResponse(req, ODataHttpException.COMMON, resp);
+      createNotImplementedResponse(req, ODataHttpException.COMMON, resp);
     }
 
   }
@@ -239,6 +239,7 @@ public class ODataServlet extends HttpServlet {
     ODataExceptionWrapper exceptionWrapper = new ODataExceptionWrapper(req);
     ODataResponse response =
         exceptionWrapper.wrapInExceptionResponse(new ODataNotImplementedException(messageReference));
+//    resp.setStatus(HttpStatusCodes.NOT_IMPLEMENTED.getStatusCode());
     createResponse(resp, response);
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/7d71cee8/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/rest/ODataExceptionMapperImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/rest/ODataExceptionMapperImplTest.java
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/rest/ODataExceptionMapperImplTest.java
index 64e8cb2..74da93c 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/rest/ODataExceptionMapperImplTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/rest/ODataExceptionMapperImplTest.java
@@ -36,7 +36,7 @@ import java.util.Map;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.NotAllowedException;
+import javax.ws.rs.ClientErrorException;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MultivaluedHashMap;
 import javax.ws.rs.core.MultivaluedMap;
@@ -370,7 +370,7 @@ public class ODataExceptionMapperImplTest extends BaseTest {
     // prepare
     String message = "The request dispatcher does not allow the HTTP method used for the
request.";
     Exception exception =
-        new NotAllowedException(Response.status(Response.Status.METHOD_NOT_ALLOWED).header(HttpHeaders.ALLOW,
"GET")
+        new ClientErrorException(Response.status(Response.Status.METHOD_NOT_ALLOWED).header(HttpHeaders.ALLOW,
"GET")
             .build());
 
     // execute

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/7d71cee8/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicHttpTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicHttpTest.java
b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicHttpTest.java
index b8d5939..408373c 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicHttpTest.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicHttpTest.java
@@ -207,7 +207,7 @@ public class BasicHttpTest extends AbstractBasicTest {
   public void unknownMethod() throws Exception {
     HttpSomethingUnsupported request = new HttpSomethingUnsupported(getEndpoint() + "aaa/bbb/ccc");
     final HttpResponse response = getHttpClient().execute(request);
-    assertEquals(HttpStatusCodes.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatusLine().getStatusCode());
+    assertEquals(HttpStatusCodes.NOT_IMPLEMENTED.getStatusCode(), response.getStatusLine().getStatusCode());
   }
 
   @Test
@@ -269,6 +269,6 @@ public class BasicHttpTest extends AbstractBasicTest {
 
   @Test
   public void tunneledUnknownMethodOverride() throws Exception {
-    tunnelPost("X-HTTP-Method-Override", "xxx", HttpStatusCodes.METHOD_NOT_ALLOWED);
+    tunnelPost("X-HTTP-Method-Override", "xxx", HttpStatusCodes.NOT_IMPLEMENTED);
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/7d71cee8/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/UrlRewriteTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/UrlRewriteTest.java
b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/UrlRewriteTest.java
index 348e715..37d8ba7 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/UrlRewriteTest.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/UrlRewriteTest.java
@@ -130,7 +130,7 @@ public class UrlRewriteTest extends AbstractBasicTest {
   public void testSomethingUnsupportedServiceDocumentRedirect() throws Exception {
     final HttpRequestBase httpMethod = createRedirectRequest(HttpSomethingUnsupported.class);
     final HttpResponse response = getHttpClient().execute(httpMethod);
-    assertEquals(HttpStatusCodes.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatusLine().getStatusCode());
+    assertEquals(HttpStatusCodes.NOT_IMPLEMENTED.getStatusCode(), response.getStatusLine().getStatusCode());
   }
 
   private HttpRequestBase createRedirectRequest(final Class<? extends HttpRequestBase>
clazz) throws Exception {


Mime
View raw message