$metadata not working with native test models
Falseclock opened this issue · 6 comments
Tried to test Person entity taken from
olingo-jpa-processor-v4/jpa/odata-jpa-test/src/main/java/com/sap/olingo/jpa/processor/core/testmodel/Person.java
root URL it works perfectly
Collection is also works perfect
But $metadata not
Getting error
OData Library: An exception without message text was thrown.
Onse deleting Persons entity and related classes, $metadata works again
I'm not able to reproduce this problem. Nevertheless there should not be an "An exception without message text was thrown" exception.
If you like you can help to find the root cause. For me the following worked best:
- set a breakpoint in method process in class ODataHandlerImpl either in line line 85 ( processInternal(request, response)) or in line 117, the last catch, as it is very likely that it is non of t he other exceptions.
- look where this exception is thrown.
Line 117 of ODataHandlerImpl gives null pointer exception because of
here is JSON debug output
{
"request": {
"method": "GET",
"uri": "http://localhost:8080/$metadata?odata-debug=json",
"protocol": "HTTP/1.1",
"headers": {
"host": "localhost:8080",
"connection": "keep-alive",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"accept-encoding": "gzip, deflate, br",
"accept-language": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7",
"cookie": "Phpstorm-46bf0b78=41ea4c49-77a8-4ddc-8cf5-fefeeac59e00; Idea-760e857b=129c3342-cb45-4e1d-8598-d9f33c1da3f3"
}
},
"response": {
"status": {
"code": "500",
"info": "Internal Server Error"
},
"headers": {
"OData-Version": "4.0",
"Content-Type": "application/xml"
},
"body": "<?xml version='1.0' encoding='UTF-8'?><error xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\"><code>null</code><message>OData Library: An exception without message text was thrown.</message></error>"
},
"server": {
"version": "odata-server-core Version 4.4.0",
"environment": {
"authType": null,
"localAddr": "0:0:0:0:0:0:0:1",
"localName": "NM-VT1",
"localPort": "8080",
"pathInfo": "/$metadata",
"pathTranslated": "D:\\git\\rest\\src\\main\\webapp\\$metadata",
"remoteAddr": "0:0:0:0:0:0:0:1",
"remoteHost": "0:0:0:0:0:0:0:1",
"remotePort": "51446",
"remoteUser": null,
"scheme": "http",
"serverName": "localhost",
"serverPort": "8080",
"servletPath": ""
},
"uri": {
"kind": "metadata",
"customQueryOptions": {
"odata-debug": "json"
}
},
"runtime": [
{
"class": "ODataHttpHandlerImpl",
"method": "process",
"duration": 1065272,
"unit": "µs",
"children": [
{
"class": "ODataHttpHandlerImpl",
"method": "fillODataRequest",
"duration": 68,
"unit": "µs",
"children": [
{
"class": "ODataHttpHandlerImpl",
"method": "copyHeaders",
"duration": 35,
"unit": "µs"
},
{
"class": "ODataHttpHandlerImpl",
"method": "fillUriInformation",
"duration": 25,
"unit": "µs"
}
]
},
{
"class": "ODataHandler",
"method": "process",
"duration": 1065199,
"unit": "µs",
"children": [
{
"class": "ODataHandler",
"method": "processInternal",
"duration": 616614,
"unit": "µs",
"children": [
{
"class": "Parser",
"method": "parseUri",
"duration": 44,
"unit": "µs"
},
{
"class": "UriValidator",
"method": "validate",
"duration": 16,
"unit": "µs"
},
{
"class": "ODataDispatcher",
"method": "dispatch",
"duration": 616546,
"unit": "µs"
}
]
},
{
"class": "ODataHandler",
"method": "handleException",
"duration": 794,
"unit": "µs",
"children": [
{
"class": "ErrorProcessor",
"method": "processError",
"duration": 613,
"unit": "µs"
}
]
}
]
}
]
}
],
"stacktrace": {
"exceptions": [
{
"class": "java.lang.NullPointerException",
"message": null,
"invocation": {
"class": "com.sap.olingo.jpa.metadata.core.edm.mapper.impl.IntermediateReferences",
"method": "getTerm",
"line": 86
}
}
],
"stacktrace": [
{
"class": "com.sap.olingo.jpa.metadata.core.edm.mapper.impl.IntermediateReferences",
"method": "getTerm",
"line": 86
},
{
"class": "com.sap.olingo.jpa.metadata.core.edm.mapper.impl.IntermediateServiceDocument",
"method": "getTerm",
"line": 220
},
{
"class": "com.sap.olingo.jpa.metadata.api.JPAEdmProvider",
"method": "getTerm",
"line": 166
},
{
"class": "org.apache.olingo.commons.core.edm.EdmProviderImpl",
"method": "createTerm",
"line": 382
},
{
"class": "org.apache.olingo.commons.core.edm.AbstractEdm",
"method": "getTerm",
"line": 289
},
{
"class": "org.apache.olingo.commons.core.edm.EdmAnnotationImpl",
"method": "getTerm",
"line": 47
},
{
"class": "org.apache.olingo.server.core.serializer.xml.MetadataDocumentXmlSerializer",
"method": "appendAnnotations",
"line": 307
},
{
"class": "org.apache.olingo.server.core.serializer.xml.MetadataDocumentXmlSerializer",
"method": "appendProperties",
"line": 900
},
{
"class": "org.apache.olingo.server.core.serializer.xml.MetadataDocumentXmlSerializer",
"method": "appendEntityTypes",
"line": 806
},
{
"class": "org.apache.olingo.server.core.serializer.xml.MetadataDocumentXmlSerializer",
"method": "appendSchema",
"line": 206
},
{
"class": "org.apache.olingo.server.core.serializer.xml.MetadataDocumentXmlSerializer",
"method": "appendDataServices",
"line": 185
},
{
"class": "org.apache.olingo.server.core.serializer.xml.MetadataDocumentXmlSerializer",
"method": "writeMetadataDocument",
"line": 176
},
{
"class": "org.apache.olingo.server.core.serializer.xml.ODataXmlSerializer",
"method": "metadataDocument",
"line": 135
},
{
"class": "org.apache.olingo.server.api.processor.DefaultProcessor",
"method": "readMetadata",
"line": 111
},
{
"class": "org.apache.olingo.server.core.ODataDispatcher",
"method": "dispatch",
"line": 95
},
{
"class": "org.apache.olingo.server.core.ODataHandlerImpl",
"method": "processInternal",
"line": 160
},
{
"class": "org.apache.olingo.server.core.ODataHandlerImpl",
"method": "process",
"line": 85
},
{
"class": "org.apache.olingo.server.core.ODataHttpHandlerImpl",
"method": "process",
"line": 74
},
{
"class": "org.apache.olingo.server.core.ODataHttpHandlerImpl",
"method": "process",
"line": 88
},
{
"class": "com.sap.olingo.jpa.processor.core.api.JPAODataGetHandler",
"method": "process",
"line": 84
},
{
"class": "com.sap.olingo.jpa.processor.core.api.JPAODataGetHandler",
"method": "process",
"line": 67
},
{
"class": "kz.mp.rest.OdataController",
"method": "service",
"line": 56
},
{
"class": "javax.servlet.http.HttpServlet",
"method": "service",
"line": 742
},
{
"class": "org.apache.catalina.core.ApplicationFilterChain",
"method": "internalDoFilter",
"line": 231
},
{
"class": "org.apache.catalina.core.ApplicationFilterChain",
"method": "doFilter",
"line": 166
},
{
"class": "org.apache.tomcat.websocket.server.WsFilter",
"method": "doFilter",
"line": 52
},
{
"class": "org.apache.catalina.core.ApplicationFilterChain",
"method": "internalDoFilter",
"line": 193
},
{
"class": "org.apache.catalina.core.ApplicationFilterChain",
"method": "doFilter",
"line": 166
},
{
"class": "kz.mp.rest.OdataComponent",
"method": "doFilter",
"line": 36
},
{
"class": "org.apache.catalina.core.ApplicationFilterChain",
"method": "internalDoFilter",
"line": 193
},
{
"class": "org.apache.catalina.core.ApplicationFilterChain",
"method": "doFilter",
"line": 166
},
{
"class": "org.springframework.web.filter.RequestContextFilter",
"method": "doFilterInternal",
"line": 99
},
{
"class": "org.springframework.web.filter.OncePerRequestFilter",
"method": "doFilter",
"line": 107
},
{
"class": "org.apache.catalina.core.ApplicationFilterChain",
"method": "internalDoFilter",
"line": 193
},
{
"class": "org.apache.catalina.core.ApplicationFilterChain",
"method": "doFilter",
"line": 166
},
{
"class": "org.springframework.web.filter.HttpPutFormContentFilter",
"method": "doFilterInternal",
"line": 109
},
{
"class": "org.springframework.web.filter.OncePerRequestFilter",
"method": "doFilter",
"line": 107
},
{
"class": "org.apache.catalina.core.ApplicationFilterChain",
"method": "internalDoFilter",
"line": 193
},
{
"class": "org.apache.catalina.core.ApplicationFilterChain",
"method": "doFilter",
"line": 166
},
{
"class": "org.springframework.web.filter.HiddenHttpMethodFilter",
"method": "doFilterInternal",
"line": 81
},
{
"class": "org.springframework.web.filter.OncePerRequestFilter",
"method": "doFilter",
"line": 107
},
{
"class": "org.apache.catalina.core.ApplicationFilterChain",
"method": "internalDoFilter",
"line": 193
},
{
"class": "org.apache.catalina.core.ApplicationFilterChain",
"method": "doFilter",
"line": 166
},
{
"class": "org.springframework.web.filter.CharacterEncodingFilter",
"method": "doFilterInternal",
"line": 200
},
{
"class": "org.springframework.web.filter.OncePerRequestFilter",
"method": "doFilter",
"line": 107
},
{
"class": "org.apache.catalina.core.ApplicationFilterChain",
"method": "internalDoFilter",
"line": 193
},
{
"class": "org.apache.catalina.core.ApplicationFilterChain",
"method": "doFilter",
"line": 166
},
{
"class": "org.apache.catalina.core.StandardWrapperValve",
"method": "invoke",
"line": 199
},
{
"class": "org.apache.catalina.core.StandardContextValve",
"method": "invoke",
"line": 96
},
{
"class": "org.apache.catalina.authenticator.AuthenticatorBase",
"method": "invoke",
"line": 496
},
{
"class": "org.apache.catalina.core.StandardHostValve",
"method": "invoke",
"line": 140
},
{
"class": "org.apache.catalina.valves.ErrorReportValve",
"method": "invoke",
"line": 81
},
{
"class": "org.apache.catalina.core.StandardEngineValve",
"method": "invoke",
"line": 87
},
{
"class": "org.apache.catalina.connector.CoyoteAdapter",
"method": "service",
"line": 342
},
{
"class": "org.apache.coyote.http11.Http11Processor",
"method": "service",
"line": 803
},
{
"class": "org.apache.coyote.AbstractProcessorLight",
"method": "process",
"line": 66
},
{
"class": "org.apache.coyote.AbstractProtocol$ConnectionHandler",
"method": "process",
"line": 790
},
{
"class": "org.apache.tomcat.util.net.NioEndpoint$SocketProcessor",
"method": "doRun",
"line": 1459
},
{
"class": "org.apache.tomcat.util.net.SocketProcessorBase",
"method": "run",
"line": 49
},
{
"class": "java.util.concurrent.ThreadPoolExecutor",
"method": "runWorker",
"line": 1149
},
{
"class": "java.util.concurrent.ThreadPoolExecutor$Worker",
"method": "run",
"line": 624
},
{
"class": "org.apache.tomcat.util.threads.TaskThread$WrappingRunnable",
"method": "run",
"line": 61
},
{
"class": "java.lang.Thread",
"method": "run",
"line": 748
}
]
}
}
}
It seems that an attribute of either Person.class
or BusinessPartner.class
has an annotation EdmAnnotation, which can be used to generate simple OData annotation, but corresponding definition of the OData annotations is missing.
This is a bug, as you do not get a meaningful error message.
To solve the issue you have two options:
- You do not need the OData annotation and remove EdmAnnotation
- You want to keep the annotation and perform the following steps:
- You download Org.OData.Core.V1.xml, store it e.g. under /src/main/resources/annotations
- You create an extension of
JPAEdmMetadataPostProcessor
and override methodprovideReferences
using the following code:
String uri = "http://docs.oasisopen.org/odata/odata/v4.0/os/vocabularies/Org.OData.Core.V1.xml";
IntermediateReferenceAccess reference = references.addReference(uri, "annotations/Org.OData.Core.V1.xml");
reference.addInclude("Org.OData.Core.V1", "Core");
@wog48 thanks, option 2 works perfectly.
I have enhanced the error processing with version 0.2.7