[OLINGO-1201] Enhancements to run better with Netty
This commit is contained in:
parent
1ce51fd4ec
commit
5e21bb2ba5
|
@ -50,6 +50,11 @@
|
|||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.1.16.Final</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -79,6 +79,11 @@
|
|||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.1.16.Final</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -230,41 +230,42 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
|
|||
}
|
||||
|
||||
static HttpMethod extractMethod(final HttpServletRequest httpRequest) throws ODataLibraryException {
|
||||
final HttpMethod httpRequestMethod;
|
||||
try {
|
||||
httpRequestMethod = HttpMethod.valueOf(httpRequest.getMethod());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new ODataHandlerException("HTTP method not allowed" + httpRequest.getMethod(), e,
|
||||
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpRequest.getMethod());
|
||||
}
|
||||
try {
|
||||
if (httpRequestMethod == HttpMethod.POST) {
|
||||
String xHttpMethod = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD);
|
||||
String xHttpMethodOverride = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD_OVERRIDE);
|
||||
final HttpMethod httpRequestMethod;
|
||||
try {
|
||||
httpRequestMethod = HttpMethod.valueOf(httpRequest.getMethod());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new ODataHandlerException("HTTP method not allowed" + httpRequest.getMethod(), e,
|
||||
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpRequest.getMethod());
|
||||
}
|
||||
try {
|
||||
if (httpRequestMethod == HttpMethod.POST) {
|
||||
String xHttpMethod = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD);
|
||||
String xHttpMethodOverride = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD_OVERRIDE);
|
||||
|
||||
if (xHttpMethod == null && xHttpMethodOverride == null) {
|
||||
return httpRequestMethod;
|
||||
} else if (xHttpMethod == null) {
|
||||
return HttpMethod.valueOf(xHttpMethodOverride);
|
||||
} else if (xHttpMethodOverride == null) {
|
||||
return HttpMethod.valueOf(xHttpMethod);
|
||||
} else {
|
||||
if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) {
|
||||
throw new ODataHandlerException("Ambiguous X-HTTP-Methods",
|
||||
ODataHandlerException.MessageKeys.AMBIGUOUS_XHTTP_METHOD, xHttpMethod, xHttpMethodOverride);
|
||||
}
|
||||
return HttpMethod.valueOf(xHttpMethod);
|
||||
}
|
||||
} else {
|
||||
return httpRequestMethod;
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new ODataHandlerException("Invalid HTTP method" + httpRequest.getMethod(), e,
|
||||
ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD, httpRequest.getMethod());
|
||||
}
|
||||
}
|
||||
if (xHttpMethod == null && xHttpMethodOverride == null) {
|
||||
return httpRequestMethod;
|
||||
} else if (xHttpMethod == null) {
|
||||
return HttpMethod.valueOf(xHttpMethodOverride);
|
||||
} else if (xHttpMethodOverride == null) {
|
||||
return HttpMethod.valueOf(xHttpMethod);
|
||||
} else {
|
||||
if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) {
|
||||
throw new ODataHandlerException("Ambiguous X-HTTP-Methods",
|
||||
ODataHandlerException.MessageKeys.AMBIGUOUS_XHTTP_METHOD, xHttpMethod, xHttpMethodOverride);
|
||||
}
|
||||
return HttpMethod.valueOf(xHttpMethod);
|
||||
}
|
||||
} else {
|
||||
return httpRequestMethod;
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new ODataHandlerException("Invalid HTTP method" + httpRequest.getMethod(), e,
|
||||
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 rawODataPath;
|
||||
|
@ -274,10 +275,12 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
|
|||
int beginIndex = rawRequestUri.indexOf(requestMapping) + requestMapping.length();
|
||||
rawODataPath = rawRequestUri.substring(beginIndex);
|
||||
}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);
|
||||
} 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);
|
||||
} else {
|
||||
rawODataPath = httpRequest.getRequestURI();
|
||||
|
@ -310,13 +313,13 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
|
|||
}
|
||||
|
||||
static void copyHeaders(ODataRequest odRequest, final HttpServletRequest req) {
|
||||
for (final Enumeration<?> headerNames = req.getHeaderNames(); headerNames.hasMoreElements();) {
|
||||
final String headerName = (String) headerNames.nextElement();
|
||||
@SuppressWarnings("unchecked")
|
||||
// getHeaders() says it returns an Enumeration of String.
|
||||
final List<String> headerValues = Collections.list(req.getHeaders(headerName));
|
||||
odRequest.addHeader(headerName, headerValues);
|
||||
}
|
||||
for (final Enumeration<?> headerNames = req.getHeaderNames(); headerNames.hasMoreElements();) {
|
||||
final String headerName = (String) headerNames.nextElement();
|
||||
@SuppressWarnings("unchecked")
|
||||
// getHeaders() says it returns an Enumeration of String.
|
||||
final List<String> headerValues = Collections.list(req.getHeaders(headerName));
|
||||
odRequest.addHeader(headerName, headerValues);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue