You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2013/12/05 14:15:27 UTC
git commit: Introduced ODataDebugResponseWrapperCallback
Updated Branches:
refs/heads/master 12ea18aed -> 37fa6deb9
Introduced ODataDebugResponseWrapperCallback
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/37fa6deb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/37fa6deb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/37fa6deb
Branch: refs/heads/master
Commit: 37fa6deb9241c164d2925bc3a03e72cec4b088a5
Parents: 12ea18a
Author: Michael Bolz <mi...@apache.org>
Authored: Thu Dec 5 14:15:14 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Thu Dec 5 14:15:14 2013 +0100
----------------------------------------------------------------------
.../api/ODataDebugResponseWrapperCallback.java | 42 ++++++++++++++++++++
.../olingo/odata2/core/ODataContextImpl.java | 8 +---
.../olingo/odata2/core/ODataRequestHandler.java | 24 ++++++-----
.../core/debug/ODataDebugResponseWrapper.java | 9 ++---
.../debug/ODataDebugResponseWrapperTest.java | 31 +++++----------
5 files changed, 70 insertions(+), 44 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/37fa6deb/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ODataDebugResponseWrapperCallback.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ODataDebugResponseWrapperCallback.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ODataDebugResponseWrapperCallback.java
new file mode 100644
index 0000000..8d19990
--- /dev/null
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ODataDebugResponseWrapperCallback.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.
+ ******************************************************************************/
+package org.apache.olingo.odata2.api;
+
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataRequest;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.uri.UriInfo;
+
+/**
+ * Debug handler.
+ */
+public interface ODataDebugResponseWrapperCallback extends ODataCallback {
+
+ /**
+ * Handles the output of a response helpful in case of debugging.
+ * @param context generic context information
+ * @param request the original request
+ * @param response the original response
+ * @param uriInfo structured parts of the request URI
+ * @param exception the exception in case of an error
+ * @return the debug response
+ */
+ ODataResponse handle(ODataContext context, ODataRequest request, ODataResponse response, UriInfo uriInfo,
+ Exception exception);
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/37fa6deb/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataContextImpl.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataContextImpl.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataContextImpl.java
index aba98ee..92ddd35 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataContextImpl.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataContextImpl.java
@@ -284,12 +284,8 @@ public class ODataContextImpl implements ODataContext {
}
private boolean checkDebugMode(final Map<String, String> queryParameters) {
- if (getQueryDebugValue(queryParameters) == null) {
- return false;
- } else {
- final ODataDebugCallback callback = getServiceFactory().getCallback(ODataDebugCallback.class);
- return callback != null && callback.isDebugEnabled();
- }
+ final ODataDebugCallback callback = getServiceFactory().getCallback(ODataDebugCallback.class);
+ return callback == null ? getQueryDebugValue(queryParameters) != null : callback.isDebugEnabled();
}
private static String getQueryDebugValue(final Map<String, String> queryParameters) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/37fa6deb/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
index 014a771..47554d4 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
@@ -22,6 +22,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import org.apache.olingo.odata2.api.ODataDebugResponseWrapperCallback;
import org.apache.olingo.odata2.api.ODataService;
import org.apache.olingo.odata2.api.ODataServiceFactory;
import org.apache.olingo.odata2.api.ODataServiceVersion;
@@ -148,15 +149,22 @@ public class ODataRequestHandler {
odataResponse = extendedResponse.build();
} catch (final Exception e) {
exception = e;
- odataResponse =
- new ODataExceptionWrapper(context, request.getQueryParameters(), request.getAcceptHeaders())
- .wrapInExceptionResponse(e);
+ odataResponse = new ODataExceptionWrapper(context, request.getQueryParameters(), request.getAcceptHeaders())
+ .wrapInExceptionResponse(e);
}
context.stopRuntimeMeasurement(timingHandle);
- final String debugValue = getDebugValue(context, request.getQueryParameters());
- return debugValue == null ? odataResponse : new ODataDebugResponseWrapper(context, odataResponse, uriInfo,
- exception, debugValue).wrapResponse();
+ if (context.isInDebugMode()) {
+ if (getQueryDebugValue(request.getQueryParameters()) == null) {
+ ODataDebugResponseWrapperCallback callback =
+ context.getServiceFactory().getCallback(ODataDebugResponseWrapperCallback.class);
+ return callback == null ? odataResponse : callback.handle(context, request, odataResponse, uriInfo, exception);
+ } else {
+ return new ODataDebugResponseWrapper(context, odataResponse, uriInfo, exception).wrapResponse();
+ }
+ } else {
+ return odataResponse;
+ }
}
private HttpStatusCodes getStatusCode(final ODataResponse odataResponse, final ODataHttpMethod method,
@@ -516,10 +524,6 @@ public class ODataRequestHandler {
return concurrency;
}
- private static String getDebugValue(final ODataContext context, final Map<String, String> queryParameters) {
- return context.isInDebugMode() ? getQueryDebugValue(queryParameters) : null;
- }
-
private static String getQueryDebugValue(final Map<String, String> queryParameters) {
final String debugValue = queryParameters.get(ODataDebugResponseWrapper.ODATA_DEBUG_QUERY_PARAMETER);
return ODataDebugResponseWrapper.ODATA_DEBUG_JSON.equals(debugValue) ? debugValue : null;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/37fa6deb/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapper.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapper.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapper.java
index e32973e..f4d9482 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapper.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapper.java
@@ -42,7 +42,6 @@ import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
/**
* Wraps an OData response into an OData response containing additional
* information useful for support purposes.
- *
*/
public class ODataDebugResponseWrapper {
@@ -53,22 +52,20 @@ public class ODataDebugResponseWrapper {
private final ODataResponse response;
private final UriInfo uriInfo;
private final Exception exception;
- private final boolean isJson;
public ODataDebugResponseWrapper(final ODataContext context, final ODataResponse response, final UriInfo uriInfo,
- final Exception exception, final String debugValue) {
+ final Exception exception) {
this.context = context;
this.response = response;
this.uriInfo = uriInfo;
this.exception = exception;
- isJson = ODATA_DEBUG_JSON.equals(debugValue);
}
public ODataResponse wrapResponse() {
try {
return ODataResponse.status(HttpStatusCodes.OK)
- .entity(isJson ? wrapInJson(createParts()) : null)
- .contentHeader(isJson ? HttpContentType.APPLICATION_JSON : null)
+ .entity(wrapInJson(createParts()))
+ .contentHeader(HttpContentType.APPLICATION_JSON)
.build();
} catch (final ODataException e) {
throw new ODataRuntimeException("Should not happen", e);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/37fa6deb/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapperTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapperTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapperTest.java
index f13d8a4..8a8184c 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapperTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/debug/ODataDebugResponseWrapperTest.java
@@ -110,8 +110,7 @@ public class ODataDebugResponseWrapperTest extends BaseTest {
final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.NO_CONTENT, null, null);
final ODataResponse response =
- new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
+ new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null)
.wrapResponse();
String actualJson = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertEquals(EXPECTED.replace(ODataHttpMethod.GET.name(), ODataHttpMethod.PUT.name())
@@ -126,9 +125,7 @@ public class ODataDebugResponseWrapperTest extends BaseTest {
final ODataContext context = mockContext(ODataHttpMethod.GET);
ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.OK, "\"test\"", HttpContentType.APPLICATION_JSON);
- ODataResponse response =
- new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
+ ODataResponse response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null)
.wrapResponse();
String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertEquals(EXPECTED.replace("{\"request", "{\"body\":\"test\",\"request")
@@ -137,9 +134,7 @@ public class ODataDebugResponseWrapperTest extends BaseTest {
entity);
wrappedResponse = mockResponse(HttpStatusCodes.OK, "test", HttpContentType.TEXT_PLAIN);
- response =
- new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
+ response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null)
.wrapResponse();
entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertEquals(
@@ -150,9 +145,7 @@ public class ODataDebugResponseWrapperTest extends BaseTest {
wrappedResponse = mockResponse(HttpStatusCodes.OK, null, "image/png");
when(wrappedResponse.getEntity()).thenReturn(new ByteArrayInputStream("test".getBytes()));
- response =
- new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
+ response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null)
.wrapResponse();
entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertEquals(EXPECTED.replace("{\"request", "{\"body\":\"dGVzdA==\",\"request")
@@ -170,8 +163,7 @@ public class ODataDebugResponseWrapperTest extends BaseTest {
final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.OK, null, HttpContentType.APPLICATION_JSON);
final ODataResponse response =
- new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
+ new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null)
.wrapResponse();
String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertEquals(EXPECTED.replace("},\"response",
@@ -210,9 +202,7 @@ public class ODataDebugResponseWrapperTest extends BaseTest {
when(uriInfo.getSelect()).thenReturn(Arrays.asList(select1, select2));
final ODataResponse response =
- new ODataDebugResponseWrapper(context, wrappedResponse, uriInfo, null,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
- .wrapResponse();
+ new ODataDebugResponseWrapper(context, wrappedResponse, uriInfo, null).wrapResponse();
String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertEquals(EXPECTED.replace("}}}",
"}},\"uri\":{\"filter\":{\"nodeType\":\"LITERAL\",\"type\":\"Edm.Boolean\",\"value\":\"true\"},"
@@ -242,8 +232,7 @@ public class ODataDebugResponseWrapperTest extends BaseTest {
when(exception.getFilterTree()).thenReturn(filterTree);
final ODataResponse response =
- new ODataDebugResponseWrapper(context, wrappedResponse, uriInfo, exception,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
+ new ODataDebugResponseWrapper(context, wrappedResponse, uriInfo, exception)
.wrapResponse();
String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertEquals(EXPECTED.replace("}}}",
@@ -271,8 +260,7 @@ public class ODataDebugResponseWrapperTest extends BaseTest {
final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.OK, null, null);
ODataResponse response =
- new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
+ new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null)
.wrapResponse();
String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertEquals(EXPECTED.replace("}}}",
@@ -303,8 +291,7 @@ public class ODataDebugResponseWrapperTest extends BaseTest {
when(exception.getStackTrace()).thenReturn(Arrays.copyOfRange(stackTrace, 1, 3));
final ODataResponse response =
- new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), exception,
- ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
+ new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), exception)
.wrapResponse();
String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertEquals(EXPECTED