我有这个复杂的OData模型:
<EntityType Name="ApprovalsRequest">
<Key>
<PropertyRef Name="IdUser"/>
<PropertyRef Name="RequestId"/>
</Key>
<Property Name="ApprovalTime" Type="Edm.DateTime" Nullable="true"/>
<Property Name="IdUser" Type="Edm.Int32" Nullable="false"/>
<Property Name="RequestId" Type="Edm.Int32" Nullable="false"/>
<Property Name="Request" Type="Edm.Int32" Nullable="true"/>
<Property Name="Status" Type="Edm.String"/>
<Property Name="User" Type="Edm.Int32" Nullable="true"/>
<NavigationProperty Name="RequestDetails" Relationship="rva-persistence.ApprovalsRequest_Request_Many_ZeroToOne0" FromRole="ApprovalsRequest" ToRole="Request"/>
<NavigationProperty Name="UserDetails" Relationship="rva-persistence.ApprovalsRequest_User_Many_ZeroToOne0" FromRole="ApprovalsRequest" ToRole="User"/>
</EntityType>
此模型与其他模型有两种关系。
我正在尝试创建此模型的新条目。
我有以下XML请求:
<?xml version="1.0" encoding="UTF-8"?>
<a:entry xmlns:a="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<a:author>
<a:name />
</a:author>
<a:content type="application/xml">
<m:properties>
<d:IdUser>1</d:IdUser>
<d:RequestId>1</d:RequestId>
<d:Request>1</d:Request>
<d:User>1</d:User>
<d:ApprovalTime>19/5/2017 9:58:00</d:ApprovalTime>
<d:Status>1</d:Status>
</m:properties>
</a:content>
<a:link href="http://localhost:8080/rva_backend_ui5/incloud_backend.svc/Users(1)" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/UsersDetails" type="application/atom+xml;type=entry" />
<a:link href="http://localhost:8080/rva_backend_ui5/incloud_backend.svc/Requests(1)" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/RequestDetails" type="application/atom+xml;type=entry" />
</a:entry>
当我尝试发送此请求时,我收到一条错误消息:
The request body is malformed
我的XML请求有什么问题?
谢谢!
更新1
我已更改ApprovalTime属性的值:
<d:ApprovalTime>2015-07-14T05:00:00</d:ApprovalTime>
但是,我得到了另一个错误(我在Apache Olingo中用于将JPA实体映射为OData对象):
Internal Exception: org.postgresql.util.PSQLException: ERROR: la columna «id_user» es de tipo integer pero la expresión es de tipo character varying
Hint: Necesitará reescribir la expresión o aplicarle una conversió
Query: InsertObjectQuery(com.incloud.hcp.entity.ApprovalsRequest@243f0e32)
这是日志:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: la columna «id_user» es de tipo integer pero la expresión es de tipo character varying
Hint: Necesitará reescribir la expresión o aplicarle una conversión de tipo.
Position: 96
Error Code: 0
Call: INSERT INTO approvals_request (approval_time, STATUS, request_id, id_user) VALUES (?, ?, ?, ?)
bind => [2015-07-14 00:00:00.0, 1, 1, null]
Query: InsertObjectQuery(com.incloud.hcp.entity.ApprovalsRequest@243f0e32)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.processExceptionForCommError(DatabaseAccessor.java:1611)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:898)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:962)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:631)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:558)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1991)
at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:298)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.insertObject(DatasourceCallQueryMechanism.java:377)
at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:165)
at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:180)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:489)
at org.eclipse.persistence.queries.InsertObjectQuery.executeCommit(InsertObjectQuery.java:80)
at org.eclipse.persistence.queries.InsertObjectQuery.executeCommitWithChangeSet(InsertObjectQuery.java:90)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:301)
at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:899)
at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:798)
at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:108)
at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:85)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1793)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1775)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1726)
at org.eclipse.persistence.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:226)
at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:125)
at org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:4196)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1441)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1531)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:277)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:1169)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:132)
at org.apache.olingo.odata2.jpa.processor.core.ODataJPATransactionLocalDefault.commit(ODataJPATransactionLocalDefault.java:43)
at org.apache.olingo.odata2.jpa.processor.core.access.data.JPAProcessorImpl.processCreate(JPAProcessorImpl.java:341)
at org.apache.olingo.odata2.jpa.processor.core.access.data.JPAProcessorImpl.process(JPAProcessorImpl.java:223)
at org.apache.olingo.odata2.jpa.processor.api.ODataJPADefaultProcessor.createEntity(ODataJPADefaultProcessor.java:115)
at org.apache.olingo.odata2.core.Dispatcher.dispatch(Dispatcher.java:79)
at org.apache.olingo.odata2.core.ODataRequestHandler.handle(ODataRequestHandler.java:131)
at org.apache.olingo.odata2.core.rest.ODataSubLocator.handle(ODataSubLocator.java:164)
at org.apache.olingo.odata2.core.rest.ODataSubLocator.handlePost(ODataSubLocator.java:86)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:198)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:261)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:100)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:203)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:137)
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:158)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:243)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:163)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:219)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at com.incloud.hcp.service.factory.CORSFilter.doFilter(CORSFilter.java:33)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:614)
at com.sap.cloud.runtime.impl.bridge.security.AbstractAuthenticator.invoke(AbstractAuthenticator.java:210)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at com.sap.core.tenant.valve.TenantValidationValve.invokeNextValve(TenantValidationValve.java:168)
at com.sap.core.tenant.valve.TenantValidationValve.invoke(TenantValidationValve.java:94)
at com.sap.js.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:37)
at com.sap.core.js.monitoring.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:27)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.postgresql.util.PSQLException: ERROR: la columna «id_user» es de tipo integer pero la expresión es de tipo character varying
Hint: Necesitará reescribir la expresión o aplicarle una conversión de tipo.
Position: 96
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1836)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:334)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:890)
... 90 more
更新2
我已经解决了我的问题。我的XML请求错误,这是更正请求:
<?xml version="1.0" encoding="UTF-8"?>
<a:entry xmlns:a="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<a:author>
<a:name />
</a:author>
<a:content type="application/xml">
<m:properties>
<d:IdUser>1</d:IdUser>
<d:RequestId>1</d:RequestId>
<d:Request>1</d:Request>
<d:User>2</d:User>
<d:ApprovalTime>2015-07-14T05:00:00</d:ApprovalTime>
<d:Status>1</d:Status>
</m:properties>
</a:content>
<a:link href="http://localhost:8080/rva_backend_ui5/incloud_backend.svc/Requests(1)" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/RequestDetails" type="application/atom+xml;type=entry" />
<a:link href="http://localhost:8080/rva_backend_ui5/incloud_backend.svc/Users(1)" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/UserDetails" type="application/atom+xml;type=entry" />
</a:entry>
链接'url之一错误:
版本不正确:
<a:link href="http://localhost:8080/rva_backend_ui5/incloud_backend.svc/Users(1)" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/UsersDetails" type="application/atom+xml;type=entry" />
更正版本(UserDetails而非UsersDetails):
<a:link href="http://localhost:8080/rva_backend_ui5/incloud_backend.svc/Users(1)" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/UserDetails" type="application/atom+xml;type=entry" />
答案 0 :(得分:0)
最突出的一点是您正在使用的日期时间格式。 documentation here。
中描述了正确的格式'yyyy-mm-ddThh:mm [:ss [.fffffff]]'注意:日期时间和引用部分之间不允许有空格。 datetime不区分大小写
( datetime 部分被遗漏,如atom format中所述)
答案 1 :(得分:0)
手动编写OData XML请求的请求主体非常繁琐且容易出错。相反,我建议你使用json。 另外,为了理解预期的格式,请尝试执行“READ”,并查找各种格式。