[OLINGO-1201] Enhancements to run better with Netty
This commit is contained in:
parent
1ce51fd4ec
commit
5e21bb2ba5
|
@ -50,6 +50,11 @@
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-all</artifactId>
|
||||||
|
<version>4.1.16.Final</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -39,7 +39,7 @@ public interface ODataHttpHandler extends ODataHandler {
|
||||||
* @param response - HTTP OData response
|
* @param response - HTTP OData response
|
||||||
*/
|
*/
|
||||||
void process(HttpServletRequest request, HttpServletResponse response);
|
void process(HttpServletRequest request, HttpServletResponse response);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the split parameter which is used for service resolution.
|
* Sets the split parameter which is used for service resolution.
|
||||||
* @param split the number of path segments reserved for service resolution; default is 0
|
* @param split the number of path segments reserved for service resolution; default is 0
|
||||||
|
|
|
@ -79,6 +79,11 @@
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-all</artifactId>
|
<artifactId>mockito-all</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-all</artifactId>
|
||||||
|
<version>4.1.16.Final</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -125,7 +125,7 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
|
||||||
environment.put("servletPath", request.getServletPath());
|
environment.put("servletPath", request.getServletPath());
|
||||||
return environment;
|
return environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getIntAsString(final int number) {
|
private String getIntAsString(final int number) {
|
||||||
return number == 0 ? "unknown" : Integer.toString(number);
|
return number == 0 ? "unknown" : Integer.toString(number);
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
|
||||||
writeContent(odResponse, response);
|
writeContent(odResponse, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeContent(final ODataResponse odataResponse, final HttpServletResponse servletResponse) {
|
static void writeContent(final ODataResponse odataResponse, final HttpServletResponse servletResponse) {
|
||||||
try {
|
try {
|
||||||
ODataContent res = odataResponse.getODataContent();
|
ODataContent res = odataResponse.getODataContent();
|
||||||
|
@ -195,7 +195,7 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
|
||||||
closeStream(output);
|
closeStream(output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void closeStream(final Channel closeable) {
|
private static void closeStream(final Channel closeable) {
|
||||||
if (closeable != null) {
|
if (closeable != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -205,7 +205,7 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ODataRequest fillODataRequest(final ODataRequest odRequest, final HttpServletRequest httpRequest,
|
private ODataRequest fillODataRequest(final ODataRequest odRequest, final HttpServletRequest httpRequest,
|
||||||
final int split) throws ODataLibraryException {
|
final int split) throws ODataLibraryException {
|
||||||
final int requestHandle = debugger.startRuntimeMeasurement("ODataHttpHandlerImpl", "fillODataRequest");
|
final int requestHandle = debugger.startRuntimeMeasurement("ODataHttpHandlerImpl", "fillODataRequest");
|
||||||
|
@ -228,43 +228,44 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
|
||||||
debugger.stopRuntimeMeasurement(requestHandle);
|
debugger.stopRuntimeMeasurement(requestHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static HttpMethod extractMethod(final HttpServletRequest httpRequest) throws ODataLibraryException {
|
static HttpMethod extractMethod(final HttpServletRequest httpRequest) throws ODataLibraryException {
|
||||||
final HttpMethod httpRequestMethod;
|
final HttpMethod httpRequestMethod;
|
||||||
try {
|
try {
|
||||||
httpRequestMethod = HttpMethod.valueOf(httpRequest.getMethod());
|
httpRequestMethod = HttpMethod.valueOf(httpRequest.getMethod());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new ODataHandlerException("HTTP method not allowed" + httpRequest.getMethod(), e,
|
throw new ODataHandlerException("HTTP method not allowed" + httpRequest.getMethod(), e,
|
||||||
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpRequest.getMethod());
|
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpRequest.getMethod());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (httpRequestMethod == HttpMethod.POST) {
|
if (httpRequestMethod == HttpMethod.POST) {
|
||||||
String xHttpMethod = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD);
|
String xHttpMethod = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD);
|
||||||
String xHttpMethodOverride = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD_OVERRIDE);
|
String xHttpMethodOverride = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD_OVERRIDE);
|
||||||
|
|
||||||
if (xHttpMethod == null && xHttpMethodOverride == null) {
|
if (xHttpMethod == null && xHttpMethodOverride == null) {
|
||||||
return httpRequestMethod;
|
return httpRequestMethod;
|
||||||
} else if (xHttpMethod == null) {
|
} else if (xHttpMethod == null) {
|
||||||
return HttpMethod.valueOf(xHttpMethodOverride);
|
return HttpMethod.valueOf(xHttpMethodOverride);
|
||||||
} else if (xHttpMethodOverride == null) {
|
} else if (xHttpMethodOverride == null) {
|
||||||
return HttpMethod.valueOf(xHttpMethod);
|
return HttpMethod.valueOf(xHttpMethod);
|
||||||
} else {
|
} else {
|
||||||
if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) {
|
if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) {
|
||||||
throw new ODataHandlerException("Ambiguous X-HTTP-Methods",
|
throw new ODataHandlerException("Ambiguous X-HTTP-Methods",
|
||||||
ODataHandlerException.MessageKeys.AMBIGUOUS_XHTTP_METHOD, xHttpMethod, xHttpMethodOverride);
|
ODataHandlerException.MessageKeys.AMBIGUOUS_XHTTP_METHOD, xHttpMethod, xHttpMethodOverride);
|
||||||
}
|
}
|
||||||
return HttpMethod.valueOf(xHttpMethod);
|
return HttpMethod.valueOf(xHttpMethod);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return httpRequestMethod;
|
return httpRequestMethod;
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new ODataHandlerException("Invalid HTTP method" + httpRequest.getMethod(), e,
|
throw new ODataHandlerException("Invalid HTTP method" + httpRequest.getMethod(), e,
|
||||||
ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD, httpRequest.getMethod());
|
ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD, httpRequest.getMethod());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fillUriInformation(final ODataRequest odRequest, final HttpServletRequest httpRequest, final int split) {
|
static void fillUriInformation(final ODataRequest odRequest,
|
||||||
|
final HttpServletRequest httpRequest, final int split) {
|
||||||
String rawRequestUri = httpRequest.getRequestURL().toString();
|
String rawRequestUri = httpRequest.getRequestURL().toString();
|
||||||
|
|
||||||
String rawODataPath;
|
String rawODataPath;
|
||||||
|
@ -274,10 +275,12 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
|
||||||
int beginIndex = rawRequestUri.indexOf(requestMapping) + requestMapping.length();
|
int beginIndex = rawRequestUri.indexOf(requestMapping) + requestMapping.length();
|
||||||
rawODataPath = rawRequestUri.substring(beginIndex);
|
rawODataPath = rawRequestUri.substring(beginIndex);
|
||||||
}else if(!"".equals(httpRequest.getServletPath())) {
|
}else if(!"".equals(httpRequest.getServletPath())) {
|
||||||
int beginIndex = rawRequestUri.indexOf(httpRequest.getServletPath()) + httpRequest.getServletPath().length();
|
int beginIndex = rawRequestUri.indexOf(httpRequest.getServletPath()) +
|
||||||
|
httpRequest.getServletPath().length();
|
||||||
rawODataPath = rawRequestUri.substring(beginIndex);
|
rawODataPath = rawRequestUri.substring(beginIndex);
|
||||||
} else if (!"".equals(httpRequest.getContextPath())) {
|
} else if (!"".equals(httpRequest.getContextPath())) {
|
||||||
int beginIndex = rawRequestUri.indexOf(httpRequest.getContextPath()) + httpRequest.getContextPath().length();
|
int beginIndex = rawRequestUri.indexOf(httpRequest.getContextPath()) +
|
||||||
|
httpRequest.getContextPath().length();
|
||||||
rawODataPath = rawRequestUri.substring(beginIndex);
|
rawODataPath = rawRequestUri.substring(beginIndex);
|
||||||
} else {
|
} else {
|
||||||
rawODataPath = httpRequest.getRequestURI();
|
rawODataPath = httpRequest.getRequestURI();
|
||||||
|
@ -310,13 +313,13 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void copyHeaders(ODataRequest odRequest, final HttpServletRequest req) {
|
static void copyHeaders(ODataRequest odRequest, final HttpServletRequest req) {
|
||||||
for (final Enumeration<?> headerNames = req.getHeaderNames(); headerNames.hasMoreElements();) {
|
for (final Enumeration<?> headerNames = req.getHeaderNames(); headerNames.hasMoreElements();) {
|
||||||
final String headerName = (String) headerNames.nextElement();
|
final String headerName = (String) headerNames.nextElement();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
// getHeaders() says it returns an Enumeration of String.
|
// getHeaders() says it returns an Enumeration of String.
|
||||||
final List<String> headerValues = Collections.list(req.getHeaders(headerName));
|
final List<String> headerValues = Collections.list(req.getHeaders(headerName));
|
||||||
odRequest.addHeader(headerName, headerValues);
|
odRequest.addHeader(headerName, headerValues);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class ServerCoreDebugger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ODataResponse createDebugResponse(final ODataRequest request, final ODataResponse response,
|
public ODataResponse createDebugResponse(final ODataRequest request, final ODataResponse response,
|
||||||
final Exception exception, final UriInfo uriInfo, final Map<String, String> serverEnvironmentVariables) {
|
final Exception exception, final UriInfo uriInfo, final Map<String, String> serverEnvironmentVariables) {
|
||||||
// Failsafe so we do not generate unauthorized debug messages
|
// Failsafe so we do not generate unauthorized debug messages
|
||||||
|
|
Loading…
Reference in New Issue