You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by "Rainey, Riley" <ri...@sap.com> on 2014/05/14 05:59:41 UTC

Problem with JSON in line links on create

Hello all,

I've used odata4j in the past with a fair amount of success and I'm looking forward to switching to Olingo.

I have a simple JPA project where I'm creating a new object using a JSON based request; I'd expect this sort of inline syntax setting the link in the request body to work, but it appears to be silently failing:

{
   "Active": true,
   "Uuid": "E02EC59B-AA83-4AF2-8E44-9A2CE0D1E8D7",
   "Major": "0",
   "Minor": "1",
   "X":"1.0",
   "Y":"1.0",
   "Z":"1.0",
   "SiteDetails": {"__metadata":{"uri":"Sites(51)"}}
}

Where "SiteDetails" is the link I'm interested in setting.

Tracing the EclipseLink SQL messaging, I see the foreign key field remains set to "null" on the SQL insert.

Would we expect this to work with 1.2.0?  Are there special considerations to be taken into account here?

Thanks,

Riley Rainey
SAP


Re: Simple JPA Project: PUT and DELETE return "403 Forbidden" in 1.2.0

Posted by "Rainey, Riley" <ri...@sap.com>.
I found a fix for this.  The issue was in Tomcat 7's handling of PUT and DELETE.

Adding an explicit security-contraint section to the applications web.xml file resolved the problem:


<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

  <display-name>WHERE</display-name>

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

  </welcome-file-list>

  <servlet>

    <servlet-name>ODataServlet</servlet-name>

    <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>

    <init-param>

      <param-name>javax.ws.rs.Application</param-name>

      <param-value>org.apache.olingo.odata2.core.rest.app.ODataApplication</param-value>

    </init-param>

    <init-param>

      <param-name>org.apache.olingo.odata2.service.factory</param-name>

      <param-value>com.sap.mic.where.services.Where1ServiceFactory</param-value>

    </init-param>

    <load-on-startup>1</load-on-startup>

  </servlet>

  <!--

  <filter>

    <filter-name>CorsFilter</filter-name>

    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>

  </filter>

  <filter-mapping>

    <filter-name>CorsFilter</filter-name>

    <url-pattern>/*</url-pattern>

  </filter-mapping>

  -->

  <servlet-mapping>

    <servlet-name>ODataServlet</servlet-name>

    <url-pattern>/V1/*</url-pattern>

  </servlet-mapping>

  <security-constraint>

   <web-resource-collection>

     <web-resource-name>ODataServlet</web-resource-name>

     <url-pattern>/V1/*</url-pattern>

     <http-method>DELETE</http-method>

     <http-method>PUT</http-method>

     <http-method>GET</http-method>

     <http-method>POST</http-method>

   </web-resource-collection>

   <user-data-constraint>

     <transport-guarantee>NONE</transport-guarantee>

   </user-data-constraint>

  </security-constraint>

</web-app>



From: <Rainey>, Riley Rainey <ri...@sap.com>>
Date: Wednesday, May 14, 2014 8:23 AM
To: "user@olingo.apache.org<ma...@olingo.apache.org>" <us...@olingo.apache.org>>
Cc: "Reyes, Ivan" <iv...@sap.com>>
Subject: Simple JPA Project: PUT and DELETE return "403 Forbidden" in 1.2.0

All,

I was just wondering if anyone has run into this before — GET and POST are operating as expected in a simple JPA-based Olingo project I created.  PUT and DELETE are returning 403 errors, though.

I am running this in Tomcat 7.0.47 and I believe my web.xml is set up per the Olingo recommendations:


<?xmlversion="1.0"encoding="UTF-8"?>

<web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version="3.0">

  <display-name>WHERE</display-name>

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

  </welcome-file-list>

  <servlet>

    <servlet-name>ODataServlet</servlet-name>

    <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>

    <init-param>

      <param-name>javax.ws.rs.Application</param-name>

      <param-value>org.apache.olingo.odata2.core.rest.app.ODataApplication</param-value>

    </init-param>

    <init-param>

      <param-name>org.apache.olingo.odata2.service.factory</param-name>

      <param-value>com.sap.mic.where.services.Where1ServiceFactory</param-value>

    </init-param>

    <load-on-startup>1</load-on-startup>

  </servlet>

  <filter>

    <filter-name>CorsFilter</filter-name>

    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>

  </filter>

  <filter-mapping>

    <filter-name>CorsFilter</filter-name>

    <url-pattern>/*</url-pattern>

  </filter-mapping>

  <servlet-mapping>

    <servlet-name>ODataServlet</servlet-name>

    <url-pattern>/V1/*</url-pattern>

  </servlet-mapping>

</web-app>


Has anyone run into this before?


Riley

Simple JPA Project: PUT and DELETE return "403 Forbidden" in 1.2.0

Posted by "Rainey, Riley" <ri...@sap.com>.
All,

I was just wondering if anyone has run into this before — GET and POST are operating as expected in a simple JPA-based Olingo project I created.  PUT and DELETE are returning 403 errors, though.

I am running this in Tomcat 7.0.47 and I believe my web.xml is set up per the Olingo recommendations:


<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

  <display-name>WHERE</display-name>

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

  </welcome-file-list>

  <servlet>

    <servlet-name>ODataServlet</servlet-name>

    <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>

    <init-param>

      <param-name>javax.ws.rs.Application</param-name>

      <param-value>org.apache.olingo.odata2.core.rest.app.ODataApplication</param-value>

    </init-param>

    <init-param>

      <param-name>org.apache.olingo.odata2.service.factory</param-name>

      <param-value>com.sap.mic.where.services.Where1ServiceFactory</param-value>

    </init-param>

    <load-on-startup>1</load-on-startup>

  </servlet>

  <filter>

    <filter-name>CorsFilter</filter-name>

    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>

  </filter>

  <filter-mapping>

    <filter-name>CorsFilter</filter-name>

    <url-pattern>/*</url-pattern>

  </filter-mapping>

  <servlet-mapping>

    <servlet-name>ODataServlet</servlet-name>

    <url-pattern>/V1/*</url-pattern>

  </servlet-mapping>

</web-app>


Has anyone run into this before?


Riley

Re: Problem with JSON in line links on create

Posted by "Rainey, Riley" <ri...@sap.com>.
Chandan,

Thanks, I'll do that as soon as the dust settles on this current project.  After some experimentation, I discovered that sending the POST as XML content creates the entity with the correct relationship:

POST to URL http://localhost:8180/WHERE/V1/Beacons
Content-Type: application/atom+xml

<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="http://localhost:8180/WHERE/V1/">
<category term="where1.Beacon" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"></category>
<link href="Sites(51)" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/SiteDetails" title="SiteDetails" type="application/atom+xml;type=feed"></link>
<content type="application/xml">
<m:properties>
<d:Active>true</d:Active>
<d:InstalledTimestamp m:null="true"></d:InstalledTimestamp>
<d:Major>0</d:Major>
<d:Minor>23</d:Minor>
<d:RemovedTimestamp m:null="true"></d:RemovedTimestamp>
<d:Uuid>E02EC59B-AA83-4AF2-8E44-9A2CE0D1E8D7</d:Uuid>
<d:X>1.0</d:X>
<d:Y>1.0</d:Y>
<d:Z>1.0</d:Z>
</m:properties>
</content>
</entry>

So there does appear to be a JSON-specific issue here.

Regards,

Riley

From: <V.A>, Chandan <ch...@sap.com>>
Reply-To: "user@olingo.apache.org<ma...@olingo.apache.org>" <us...@olingo.apache.org>>
Date: Wednesday, May 14, 2014 2:15 AM
To: "user@olingo.apache.org<ma...@olingo.apache.org>" <us...@olingo.apache.org>>
Subject: RE: Problem with JSON in line links on create

Hello Riley,
Linking two entities via inline link/uri is supported in Olingo 1.2.0. However JPQL statements are not used for linking two entities. The OData JPA Processor library, instantiates a JPA Entity and sets the associated entity in its relationship property and commits the newly created entity. This feature is supported.

Can you please explain in detail what error are you facing. You could open a JIRA issue at - https://issues.apache.org/jira/browse/OLINGO

Thanks,
Kind Regards
Chandan VA

From: Rainey, Riley [mailto:riley.rainey@sap.com]
Sent: Wednesday, May 14, 2014 9:30 AM
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: Problem with JSON in line links on create

Hello all,

I've used odata4j in the past with a fair amount of success and I'm looking forward to switching to Olingo.

I have a simple JPA project where I'm creating a new object using a JSON based request; I'd expect this sort of inline syntax setting the link in the request body to work, but it appears to be silently failing:

{
   "Active": true,
   "Uuid": "E02EC59B-AA83-4AF2-8E44-9A2CE0D1E8D7",
   "Major": "0",
   "Minor": "1",
   "X":"1.0",
   "Y":"1.0",
   "Z":"1.0",
   "SiteDetails": {"__metadata":{"uri":"Sites(51)"}}
}

Where "SiteDetails" is the link I'm interested in setting.

Tracing the EclipseLink SQL messaging, I see the foreign key field remains set to "null" on the SQL insert.

Would we expect this to work with 1.2.0?  Are there special considerations to be taken into account here?

Thanks,

Riley Rainey
SAP


RE: Problem with JSON in line links on create

Posted by "V.A, Chandan" <ch...@sap.com>.
Hello Riley,
Linking two entities via inline link/uri is supported in Olingo 1.2.0. However JPQL statements are not used for linking two entities. The OData JPA Processor library, instantiates a JPA Entity and sets the associated entity in its relationship property and commits the newly created entity. This feature is supported.

Can you please explain in detail what error are you facing. You could open a JIRA issue at - https://issues.apache.org/jira/browse/OLINGO

Thanks,
Kind Regards
Chandan VA

From: Rainey, Riley [mailto:riley.rainey@sap.com]
Sent: Wednesday, May 14, 2014 9:30 AM
To: user@olingo.apache.org
Subject: Problem with JSON in line links on create

Hello all,

I've used odata4j in the past with a fair amount of success and I'm looking forward to switching to Olingo.

I have a simple JPA project where I'm creating a new object using a JSON based request; I'd expect this sort of inline syntax setting the link in the request body to work, but it appears to be silently failing:

{
   "Active": true,
   "Uuid": "E02EC59B-AA83-4AF2-8E44-9A2CE0D1E8D7",
   "Major": "0",
   "Minor": "1",
   "X":"1.0",
   "Y":"1.0",
   "Z":"1.0",
   "SiteDetails": {"__metadata":{"uri":"Sites(51)"}}
}

Where "SiteDetails" is the link I'm interested in setting.

Tracing the EclipseLink SQL messaging, I see the foreign key field remains set to "null" on the SQL insert.

Would we expect this to work with 1.2.0?  Are there special considerations to be taken into account here?

Thanks,

Riley Rainey
SAP