[Olingo-731] finalize debug supprt
This commit is contained in:
parent
4a81409246
commit
179c46396e
|
@ -21,14 +21,14 @@ package org.apache.olingo.commons.api.http;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HttpHeader container
|
* HttpHeader container
|
||||||
*/
|
*/
|
||||||
public class HttpHeaders {
|
public class HttpHeaders {
|
||||||
private final Map<String, HttpHeader> headers = new TreeMap<String, HttpHeader>();
|
private final Map<String, HttpHeader> headers = new LinkedHashMap<String, HttpHeader>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a header with given name and value.
|
* Add a header with given name and value.
|
||||||
|
|
|
@ -75,6 +75,7 @@ public interface UriInfoResource {
|
||||||
OrderByOption getOrderByOption();
|
OrderByOption getOrderByOption();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* <b>CURRENTLY NOT SUPPORTED. WILL ALWAYS RETURN NULL</b>
|
||||||
* @return Object containing information of the $search option
|
* @return Object containing information of the $search option
|
||||||
*/
|
*/
|
||||||
SearchOption getSearchOption();
|
SearchOption getSearchOption();
|
||||||
|
|
|
@ -38,6 +38,7 @@ public interface ExpandItem {
|
||||||
FilterOption getFilterOption();
|
FilterOption getFilterOption();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* <b>CURRENTLY NOT SUPPORTED. WILL ALWAYS RETURN NULL</b>
|
||||||
* @return Information of the option $search when used within $expand
|
* @return Information of the option $search when used within $expand
|
||||||
*/
|
*/
|
||||||
SearchOption getSearchOption();
|
SearchOption getSearchOption();
|
||||||
|
|
|
@ -138,7 +138,6 @@ public class DebugResponseHelperImpl implements DebugResponseHelper {
|
||||||
|
|
||||||
gen.writeStartObject();
|
gen.writeStartObject();
|
||||||
DebugTab requestInfo = parts.get(0);
|
DebugTab requestInfo = parts.get(0);
|
||||||
// TODO: Should we really translate to lower case here?
|
|
||||||
gen.writeFieldName(requestInfo.getName().toLowerCase(Locale.ROOT));
|
gen.writeFieldName(requestInfo.getName().toLowerCase(Locale.ROOT));
|
||||||
requestInfo.appendJson(gen);
|
requestInfo.appendJson(gen);
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||||
import org.apache.olingo.server.api.ODataResponse;
|
import org.apache.olingo.server.api.ODataResponse;
|
||||||
|
@ -43,31 +44,27 @@ public class DebugTabBody implements DebugTab {
|
||||||
|
|
||||||
private final String serviceRoot;
|
private final String serviceRoot;
|
||||||
|
|
||||||
// private final boolean isXml;
|
|
||||||
// private final boolean isJson;
|
|
||||||
// private final boolean isText;
|
|
||||||
// private final boolean isImage;
|
|
||||||
|
|
||||||
public DebugTabBody(final ODataResponse response, final String serviceRoot) {
|
public DebugTabBody(final ODataResponse response, final String serviceRoot) {
|
||||||
this.response = response;
|
this.response = response;
|
||||||
this.serviceRoot = serviceRoot == null ? "/" : serviceRoot;
|
this.serviceRoot = serviceRoot == null ? "/" : serviceRoot;
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
final String contentType = response.getHeader(HttpHeader.CONTENT_TYPE);
|
final String contentTypeString = response.getHeader(HttpHeader.CONTENT_TYPE);
|
||||||
// TODO: Differentiate better
|
if (contentTypeString != null) {
|
||||||
if (contentType != null) {
|
if (contentTypeString.startsWith("application/json")) {
|
||||||
responseContent = ResponseContent.JSON;
|
responseContent = ResponseContent.JSON;
|
||||||
|
} else if (contentTypeString.startsWith("image/")) {
|
||||||
|
responseContent = ResponseContent.IMAGE;
|
||||||
|
} else if (contentTypeString.contains("xml")) {
|
||||||
|
responseContent = ResponseContent.XML;
|
||||||
|
} else {
|
||||||
|
responseContent = ResponseContent.TEXT;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
responseContent = ResponseContent.TEXT;
|
responseContent = ResponseContent.TEXT;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
responseContent = ResponseContent.TEXT;
|
responseContent = ResponseContent.TEXT;
|
||||||
}
|
}
|
||||||
// isXml = contentType.contains("xml");
|
|
||||||
// isJson = !isXml && contentType.startsWith(HttpContentType.APPLICATION_JSON);
|
|
||||||
// isText = isXml || isJson || contentType.startsWith("text/")
|
|
||||||
// || contentType.startsWith(HttpContentType.APPLICATION_HTTP)
|
|
||||||
// || contentType.startsWith(HttpContentType.MULTIPART_MIXED);
|
|
||||||
// isImage = !isText && contentType.startsWith("image/");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -90,14 +87,12 @@ public class DebugTabBody implements DebugTab {
|
||||||
String contentString;
|
String contentString;
|
||||||
switch (responseContent) {
|
switch (responseContent) {
|
||||||
case IMAGE:
|
case IMAGE:
|
||||||
// TODO: DecodeString as base 64
|
contentString = Base64.encodeBase64String(IOUtils.toString(response.getContent()).getBytes());
|
||||||
contentString = "Currently not supported";
|
|
||||||
break;
|
break;
|
||||||
case JSON:
|
case JSON:
|
||||||
case XML:
|
case XML:
|
||||||
case TEXT:
|
case TEXT:
|
||||||
default:
|
default:
|
||||||
// TODO: Remove IOUtils from core dependency
|
|
||||||
contentString = IOUtils.toString(response.getContent(), "UTF-8");
|
contentString = IOUtils.toString(response.getContent(), "UTF-8");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +119,6 @@ public class DebugTabBody implements DebugTab {
|
||||||
writer.append("</pre>\n");
|
writer.append("</pre>\n");
|
||||||
break;
|
break;
|
||||||
case IMAGE:
|
case IMAGE:
|
||||||
// Make header query case insensitive
|
|
||||||
writer.append("<img src=\"data:").append(response.getHeader(HttpHeader.CONTENT_TYPE)).append(";base64,")
|
writer.append("<img src=\"data:").append(response.getHeader(HttpHeader.CONTENT_TYPE)).append(";base64,")
|
||||||
.append(body)
|
.append(body)
|
||||||
.append("\" />\n");
|
.append("\" />\n");
|
||||||
|
|
Loading…
Reference in New Issue