You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by Ramesh Reddy <ra...@redhat.com> on 2015/06/02 00:54:55 UTC

Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Fedric, 

You were in right path before using the code like 

private Entity getEntityFromClient(ActionRequest request ) throws DeserializerException { 

ODataDeserializer deserializer = odata .createDeserializer(ODataFormat 

. fromContentType ( request .getResponseContentType())); 

return deserializer .entity( request . getPayload (), ???? ). getEntity(); 

} 

The reason I did not provide any automatic deserialization for action is, it is POST. The payload could be arbitrary BINARY payload or JSON payload and there is no real semantics about how that load should look like unlike in create Entity scenarios (at least that is how interpreted the spec). The issue also is how will you interpret the payload when there are more than single parameter etc. So, I left that out for interpretation of the service developer. One such implementation you can see here https://github.com/teiid/teiid/blob/master/olingo/src/main/java/org/teiid/olingo/service/ProcedureSQLBuilder.java#L285 here I expect the payload to be JSON or binary data etc. My example may be little complex but in your case it could be simplified 

Ramesh.. 

----- Original Message -----

> Found the proper entry point ( actionParameters) :

> private Entity getEntityFromClient(ActionRequest request ) throws
> DeserializerException, ODataException {

> ODataDeserializer deserializer = odata .createDeserializer(ODataFormat

> . fromContentType ( request .getRequestContentType()));

> return deserializer . actionParameters ( request .getPayload(), request
> .getAction()).getEntity();

> }

> But unfortunately not yet supported at the deserializer throws:

> Entity an complex parameters currently not Implemented

> My 'customer' is indeed an entity with complex types inside.

> :[

> Any alternatives?

> Cheers,

> Frederic

> From: Frédéric SOUCHU
> Sent: 27 May 2015 10:57
> To: user@olingo.apache.org
> Subject: [OData 4 Java] invoke Action - how to deserialize parameters?

> I have an action defined as such:

> <Action Name="Refresh">

> <Parameter Name="batchID" Type="Emd.Guid" Nullable ="false" />

> <Parameter Name="customers" Type="Collection(ws.company.com.Customer)"
> Nullable ="false" />

> </Action>

> Using the new ServiceHandler base class, my custom code is correctly called
> (POST http://myservice/Refresh with a JSON body):

> public <T extends ServiceResponse> void invoke(ActionRequest request , String
> eTag , T response ) throws ODataTranslatedException,
> ODataApplicationException {

> EdmAction action = request .getAction();

> if ( action .getName().equals( "Refresh" )) {

> // for debug purposes only – works well

> System. out .println( "Action: Refresh" );

> for (String it : action .getParameterNames()) {

> EdmParameter p = action .getParameter( it );

> System. out .println( "param: " + it + " = " + p
> .getType().getFullQualifiedName().getFullQualifiedNameAsString());

> }

> // now how to get the JSON body??

> ??? body = getEntityFromClient(request);

> }

> I did not a find an example in the source using action (or function)
> parameters.

> Looking at code to create an entity (very similar to what I want to do), I
> would write something like:

> private Entity getEntityFromClient(ActionRequest request ) throws
> DeserializerException {

> ODataDeserializer deserializer = odata .createDeserializer(ODataFormat

> . fromContentType ( request .getResponseContentType()));

> return deserializer .entity( request . getPayload (), ???? ). getEntity();

> }

> Thing is, I don't understand what 'entitytype' should be passed to the
> deserializer for an action…

> Regards,

> Frederic

RE: [OData 4 Java] invoke Action - how to deserialize parameters?

Posted by "Handl, Ralf" <ra...@sap.com>.
An action definition matching the example request payload

{
  "param1": 42,
  "param2": {
    "Street": "One Microsoft Way",
    "Zip": 98052
  },
  "param3": [ 1, 42, 99 ],
  "param4": null
}

would be

      <Action Name="Example">
        <Parameter Name="param1" Type="Edm.Int32" />
        <Parameter Name="param2" Type="My.Address" />
        <Parameter Name="param3" Type="Collection(Edm.Decimal)" />
        <Parameter Name="param4" Type="Edm.String" />
      </Action>

      <ComplexType Name="Address">
        <Property Type="Edm.String" Name="Street" />
        <Property Type="Edm.Decimal" Name="Zip" />
      </ComplexType>

It could also be a bound action with an additional first (binding) parameter (e.g. “param0”) whose “value” would then be provided via the action request URL


To your other question regarding streams: Edm.Stream can only be the binding parameter of an action or function, and it can be the returning parameter of a function, so you could do things like

GET ~/Products(42)/LargePhoto/ImageProcessing.SepiaFilter(saturation=50)/ImageProcessing.RoundedCorners(radius=20)

Your metadata would contain/reference a schema that defines

    <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="ImageProcessing">

      <Function Name="SepiaFilter" IsBound="true">
        <Parameter Name="in" Type="Edm.Stream" />
        <Parameter Name="saturation" Type="Edm.Byte" />
        <ReturnType Type="Edm.Stream" />
      </Function>

      <Function Name="RoundedCorners" IsBound="true">
        <Parameter Name="in" Type="Edm.Stream" />
        <Parameter Name="radius" Type="Edm.Int32" />
        <ReturnType Type="Edm.Stream" />
      </Function>

    </Schema>


From: Frédéric SOUCHU [mailto:Frederic.SOUCHU@ingenico.com]
Sent: Montag, 15. Juni 2015 18:44
To: user@olingo.apache.org
Subject: RE: [OData 4 Java] invoke Action - how to deserialize parameters?

Story created here:
https://issues.apache.org/jira/browse/OLINGO-700


From: Ramesh Reddy [mailto:rareddy@redhat.com]
Sent: 15 June 2015 15:32
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Ralf, Frederic,

Sorry for mis-interpretation. As I remember, the issue(s) I was facing to implement automatic parsing in the Olingo library are

- Since this payload is does not have set edm-type, it was not possible to represent in concrete object after parsing. I think that can be handled with Map type. The issue is with parameters like "param2", the type of that input is complex? then is that need to be defined in $matadata? As long as they are scalars it will be easy, once they are complex I was not sure.
- Handling a Stream type was important. That is missing from spec IMO. For example in Teiid, we have many procedures, that can take XML/Clob/Blob as input and produce similar kind of output.

Ralf, any guidance on above is very much appreciated.

Thank you.

Ramesh..

________________________________
Hi Frédéric,

Please create a story in JIRA.

Thanks in advance!
--Ralf

From: Frédéric SOUCHU [mailto:Frederic.SOUCHU@ingenico.com]
Sent: Montag, 15. Juni 2015 13:21
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: RE: [OData 4 Java] invoke Action - how to deserialize parameters?

Thanks – I was a bit puzzled by Ramesh's answer ;)
Should I go ahead and create a story in JIRA?

From: Handl, Ralf [mailto:ralf.handl@sap.com]
Sent: 15 June 2015 13:10
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: RE: [OData 4 Java] invoke Action - how to deserialize parameters?

The JSON Format specification defines the how action parameters are represented as a JSON request body in chapter “17 Action Invocation”,
http://docs.oasis-open.org/odata/odata-json-format/v4.0/errata02/os/odata-json-format-v4.0-errata02-os-complete.html#_Toc403940651:

Action parameter values are encoded in a single JSON object in the request body.
Each non-binding parameter value is encoded as a separate name/value pair in this JSON object. The name is the name of the parameter. The value is the parameter value in the JSON representation appropriate for its type.
Any parameter values not specified in the JSON object are assumed to have the null value.
Example 37:
{
  "param1": 42,
  "param2": {
    "Street": "One Microsoft Way",
    "Zip": 98052
  },
  "param3": [ 1, 42, 99 ],
  "param4": null
}


The corresponding chapter “17 Action Invocation” in the Atom Format specification defines how action parameters are represented as an XML request body, http://docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html#_Toc372792808:

Action parameter values in the request body MUST be encoded as an individual complex scalar value<http://docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html#_Single_Scalar_Value> with the name parameters and no metadata:type attribute for the parameters element.
Each non-binding parameter value specified MUST be encoded as an individual primitive or complex scalar value. The name of the scalar value is the name of the parameter. The value is the parameter value in the XML representation appropriate for its type.
Any parameter values not specified in the request body MUST be assumed to have the null value.
Example 43:
<parameters>
  <param1>42</param1>
  <param2 metadata:type="#Model.Address">
    <Street>One Microsoft Way</Street>
    <Zip>98052</Zip>
  </param2>
  <param3>
    <element>1</element>
    <element>42</element>
    <element>99</element>
  </param3>
  <param4 metadata:null="true"/>
  <!-- <param5/> not specified, has null value -->
<parameters>


From: Ramesh Reddy [mailto:rareddy@redhat.com]
Sent: Dienstag, 2. Juni 2015 14:21
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Action metadata does define the parameters, it does not define how it packs the data. Every one's natural thinking will be a JSON array, or XML fragment. What I am saying spec does not say that. It also falls out if want to send more than one stream payloads. So, there is some confusion, otherwise it would easy to parse them out as they come in. If any one can clarify the spec, then I will fix the code.

________________________________
Thanks - I've used Teiid as a good provider example before Beta 03.

That said, the <action> type does declare a number of parameters with known types, not arbitrary data.
The EDM parser should be able to create a type out of these?

Frederic

From: Ramesh Reddy [mailto:rareddy@redhat.com]
Sent: 02 June 2015 00:55
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Fedric,

You were in right path before using the code like


  private Entity getEntityFromClient(ActionRequest request) throws DeserializerException {

        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat

            .fromContentType(request.getResponseContentType()));

        return deserializer.entity(request.getPayload(), ????).getEntity();

      }



The reason I did not provide any automatic deserialization for action is, it is POST. The payload could be arbitrary BINARY payload or JSON payload and there is no real semantics about how that load should look like unlike in create Entity scenarios (at least that is how interpreted the spec). The issue also is how will you interpret the payload when there are more than single parameter etc. So, I left that out for interpretation of the service developer. One such implementation  you can see here https://github.com/teiid/teiid/blob/master/olingo/src/main/java/org/teiid/olingo/service/ProcedureSQLBuilder.java#L285 here I expect the payload to be JSON or binary data etc. My example may be little complex but in your case it could be simplified



Ramesh..

________________________________
Found the proper entry point (actionParameters):

    private Entity getEntityFromClient(ActionRequest request) throws DeserializerException, ODataException {
        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
            .fromContentType(request.getRequestContentType()));
        return deserializer.actionParameters(request.getPayload(), request.getAction()).getEntity();
      }

But unfortunately not yet supported at the deserializer throws:
Entity an complex parameters currently not Implemented
My 'customer' is indeed an entity with complex types inside.
:[

Any alternatives?

Cheers,
Frederic

From: Frédéric SOUCHU
Sent: 27 May 2015 10:57
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: [OData 4 Java] invoke Action - how to deserialize parameters?

I have an action defined as such:

<Action Name="Refresh">
<Parameter Name="batchID" Type="Emd.Guid" Nullable="false" />
<Parameter Name="customers" Type="Collection(ws.company.com.Customer)" Nullable="false" />
</Action>

Using the new ServiceHandler base class, my custom code is correctly called (POST http://myservice/Refresh with a JSON body):

public <T extends ServiceResponse> void invoke(ActionRequest request, String eTag, T response) throws ODataTranslatedException, ODataApplicationException {
EdmAction action = request.getAction();

if (action.getName().equals("Refresh")) {
// for debug purposes only – works well
System.out.println("Action: Refresh");
for(String it : action.getParameterNames()) {
                     EdmParameter p =  action.getParameter(it);
                     System.out.println("param: " + it + " = " + p.getType().getFullQualifiedName().getFullQualifiedNameAsString());
              }
// now how to get the JSON body??
                                ??? body =  getEntityFromClient(request);
       }
I did not a find an example in the source using action (or function) parameters.
Looking at code to create an entity (very similar to what I want to do), I would write something like:

    private Entity getEntityFromClient(ActionRequest request) throws DeserializerException {
        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
            .fromContentType(request.getResponseContentType()));
        return deserializer.entity(request.getPayload(), ????).getEntity();
      }

Thing is, I don't understand what 'entitytype' should be passed to the deserializer for an action…

Regards,
Frederic





RE: [OData 4 Java] invoke Action - how to deserialize parameters?

Posted by Frédéric SOUCHU <Fr...@ingenico.com>.
Story created here:
https://issues.apache.org/jira/browse/OLINGO-700


From: Ramesh Reddy [mailto:rareddy@redhat.com]
Sent: 15 June 2015 15:32
To: user@olingo.apache.org
Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Ralf, Frederic,

Sorry for mis-interpretation. As I remember, the issue(s) I was facing to implement automatic parsing in the Olingo library are

- Since this payload is does not have set edm-type, it was not possible to represent in concrete object after parsing. I think that can be handled with Map type. The issue is with parameters like "param2", the type of that input is complex? then is that need to be defined in $matadata? As long as they are scalars it will be easy, once they are complex I was not sure.
- Handling a Stream type was important. That is missing from spec IMO. For example in Teiid, we have many procedures, that can take XML/Clob/Blob as input and produce similar kind of output.

Ralf, any guidance on above is very much appreciated.

Thank you.

Ramesh..

________________________________
Hi Frédéric,

Please create a story in JIRA.

Thanks in advance!
--Ralf

From: Frédéric SOUCHU [mailto:Frederic.SOUCHU@ingenico.com]
Sent: Montag, 15. Juni 2015 13:21
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: RE: [OData 4 Java] invoke Action - how to deserialize parameters?

Thanks – I was a bit puzzled by Ramesh's answer ;)
Should I go ahead and create a story in JIRA?

From: Handl, Ralf [mailto:ralf.handl@sap.com]
Sent: 15 June 2015 13:10
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: RE: [OData 4 Java] invoke Action - how to deserialize parameters?

The JSON Format specification defines the how action parameters are represented as a JSON request body in chapter “17 Action Invocation”,
http://docs.oasis-open.org/odata/odata-json-format/v4.0/errata02/os/odata-json-format-v4.0-errata02-os-complete.html#_Toc403940651:

Action parameter values are encoded in a single JSON object in the request body.
Each non-binding parameter value is encoded as a separate name/value pair in this JSON object. The name is the name of the parameter. The value is the parameter value in the JSON representation appropriate for its type.
Any parameter values not specified in the JSON object are assumed to have the null value.
Example 37:
{
  "param1": 42,
  "param2": {
    "Street": "One Microsoft Way",
    "Zip": 98052
  },
  "param3": [ 1, 42, 99 ],
  "param4": null
}


The corresponding chapter “17 Action Invocation” in the Atom Format specification defines how action parameters are represented as an XML request body, http://docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html#_Toc372792808:

Action parameter values in the request body MUST be encoded as an individual complex scalar value<http://docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html#_Single_Scalar_Value> with the name parameters and no metadata:type attribute for the parameters element.
Each non-binding parameter value specified MUST be encoded as an individual primitive or complex scalar value. The name of the scalar value is the name of the parameter. The value is the parameter value in the XML representation appropriate for its type.
Any parameter values not specified in the request body MUST be assumed to have the null value.
Example 43:
<parameters>
  <param1>42</param1>
  <param2 metadata:type="#Model.Address">
    <Street>One Microsoft Way</Street>
    <Zip>98052</Zip>
  </param2>
  <param3>
    <element>1</element>
    <element>42</element>
    <element>99</element>
  </param3>
  <param4 metadata:null="true"/>
  <!-- <param5/> not specified, has null value -->
<parameters>


From: Ramesh Reddy [mailto:rareddy@redhat.com]
Sent: Dienstag, 2. Juni 2015 14:21
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Action metadata does define the parameters, it does not define how it packs the data. Every one's natural thinking will be a JSON array, or XML fragment. What I am saying spec does not say that. It also falls out if want to send more than one stream payloads. So, there is some confusion, otherwise it would easy to parse them out as they come in. If any one can clarify the spec, then I will fix the code.

________________________________
Thanks - I've used Teiid as a good provider example before Beta 03.

That said, the <action> type does declare a number of parameters with known types, not arbitrary data.
The EDM parser should be able to create a type out of these?

Frederic

From: Ramesh Reddy [mailto:rareddy@redhat.com]
Sent: 02 June 2015 00:55
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Fedric,

You were in right path before using the code like


  private Entity getEntityFromClient(ActionRequest request) throws DeserializerException {

        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat

            .fromContentType(request.getResponseContentType()));

        return deserializer.entity(request.getPayload(), ????).getEntity();

      }



The reason I did not provide any automatic deserialization for action is, it is POST. The payload could be arbitrary BINARY payload or JSON payload and there is no real semantics about how that load should look like unlike in create Entity scenarios (at least that is how interpreted the spec). The issue also is how will you interpret the payload when there are more than single parameter etc. So, I left that out for interpretation of the service developer. One such implementation  you can see here https://github.com/teiid/teiid/blob/master/olingo/src/main/java/org/teiid/olingo/service/ProcedureSQLBuilder.java#L285 here I expect the payload to be JSON or binary data etc. My example may be little complex but in your case it could be simplified



Ramesh..

________________________________
Found the proper entry point (actionParameters):

    private Entity getEntityFromClient(ActionRequest request) throws DeserializerException, ODataException {
        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
            .fromContentType(request.getRequestContentType()));
        return deserializer.actionParameters(request.getPayload(), request.getAction()).getEntity();
      }

But unfortunately not yet supported at the deserializer throws:
Entity an complex parameters currently not Implemented
My 'customer' is indeed an entity with complex types inside.
:[

Any alternatives?

Cheers,
Frederic

From: Frédéric SOUCHU
Sent: 27 May 2015 10:57
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: [OData 4 Java] invoke Action - how to deserialize parameters?

I have an action defined as such:

<Action Name="Refresh">
<Parameter Name="batchID" Type="Emd.Guid" Nullable="false" />
<Parameter Name="customers" Type="Collection(ws.company.com.Customer)" Nullable="false" />
</Action>

Using the new ServiceHandler base class, my custom code is correctly called (POST http://myservice/Refresh with a JSON body):

public <T extends ServiceResponse> void invoke(ActionRequest request, String eTag, T response) throws ODataTranslatedException, ODataApplicationException {
EdmAction action = request.getAction();

if (action.getName().equals("Refresh")) {
// for debug purposes only – works well
System.out.println("Action: Refresh");
for(String it : action.getParameterNames()) {
                     EdmParameter p =  action.getParameter(it);
                     System.out.println("param: " + it + " = " + p.getType().getFullQualifiedName().getFullQualifiedNameAsString());
              }
// now how to get the JSON body??
                                ??? body =  getEntityFromClient(request);
       }
I did not a find an example in the source using action (or function) parameters.
Looking at code to create an entity (very similar to what I want to do), I would write something like:

    private Entity getEntityFromClient(ActionRequest request) throws DeserializerException {
        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
            .fromContentType(request.getResponseContentType()));
        return deserializer.entity(request.getPayload(), ????).getEntity();
      }

Thing is, I don't understand what 'entitytype' should be passed to the deserializer for an action…

Regards,
Frederic





Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Posted by Ramesh Reddy <ra...@redhat.com>.
Ralf, Frederic, 

Sorry for mis-interpretation. As I remember, the issue(s) I was facing to implement automatic parsing in the Olingo library are 

- Since this payload is does not have set edm-type, it was not possible to represent in concrete object after parsing. I think that can be handled with Map type. The issue is with parameters like "param2", the type of that input is complex? then is that need to be defined in $matadata? As long as they are scalars it will be easy, once they are complex I was not sure. 
- Handling a Stream type was important. That is missing from spec IMO. For example in Teiid, we have many procedures, that can take XML/Clob/Blob as input and produce similar kind of output. 

Ralf, any guidance on above is very much appreciated. 

Thank you. 

Ramesh.. 

----- Original Message -----

> Hi Frédéric,

> Please create a story in JIRA.

> Thanks in advance!
> --Ralf

> From: Frédéric SOUCHU [mailto:Frederic.SOUCHU@ingenico.com]
> Sent: Montag, 15. Juni 2015 13:21
> To: user@olingo.apache.org
> Subject: RE: [OData 4 Java] invoke Action - how to deserialize parameters?

> Thanks – I was a bit puzzled by Ramesh's answer ;)

> Should I go ahead and create a story in JIRA?

> From: Handl, Ralf [ mailto:ralf.handl@sap.com ]
> Sent: 15 June 2015 13:10
> To: user@olingo.apache.org
> Subject: RE: [OData 4 Java] invoke Action - how to deserialize parameters?

> The JSON Format specification defines the how action parameters are
> represented as a JSON request body in chapter “17 Action Invocation”,

> http://docs.oasis-open.org/odata/odata-json-format/v4.0/errata02/os/odata-json-format-v4.0-errata02-os-complete.html#_Toc403940651
> :

> Action parameter values are encoded in a single JSON object in the request
> body.

> Each non-binding parameter value is encoded as a separate name/value pair in
> this JSON object. The name is the name of the parameter. The value is the
> parameter value in the JSON representation appropriate for its type.

> Any parameter values not specified in the JSON object are assumed to have the
> null value.

> Example 37:

> {

> "param1": 42,

> "param2": {

> "Street": "One Microsoft Way",

> "Zip": 98052

> },

> "param3": [ 1, 42, 99 ],

> "param4": null

> }

> The corresponding chapter “17 Action Invocation” in the Atom Format
> specification defines how action parameters are represented as an XML
> request body,
> http://docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html#_Toc372792808
> :

> Action parameter values in the request body MUST be encoded as an individual
> complex scalar value with the name parameters and no metadata:type attribute
> for the parameters element.

> Each non-binding parameter value specified MUST be encoded as an individual
> primitive or complex scalar value. The name of the scalar value is the name
> of the parameter. The value is the parameter value in the XML representation
> appropriate for its type.

> Any parameter values not specified in the request body MUST be assumed to
> have the null value.

> Example 43:

> <parameters>

> <param1>42</param1>

> <param2 metadata:type="#Model.Address">

> <Street>One Microsoft Way</Street>

> <Zip>98052</Zip>

> </param2>

> <param3>

> <element>1</element>

> <element>42</element>

> <element>99</element>

> </param3>

> <param4 metadata:null="true"/>

> <!-- <param5/> not specified, has null value -->

> <parameters>

> From: Ramesh Reddy [ mailto:rareddy@redhat.com ]
> Sent: Dienstag, 2. Juni 2015 14:21
> To: user@olingo.apache.org
> Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

> Action metadata does define the parameters, it does not define how it packs
> the data. Every one's natural thinking will be a JSON array, or XML
> fragment. What I am saying spec does not say that. It also falls out if want
> to send more than one stream payloads. So, there is some confusion,
> otherwise it would easy to parse them out as they come in. If any one can
> clarify the spec, then I will fix the code.

> > Thanks - I've used Teiid as a good provider example before Beta 03.
> 

> > That said, the <action> type does declare a number of parameters with known
> > types, not arbitrary data.
> 

> > The EDM parser should be able to create a type out of these?
> 

> > Frederic
> 

> > From: Ramesh Reddy [ mailto:rareddy@redhat.com ]
> 
> > Sent: 02 June 2015 00:55
> 
> > To: user@olingo.apache.org
> 
> > Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?
> 

> > Fedric,
> 

> > You were in right path before using the code like
> 

> > private Entity getEntityFromClient(ActionRequest request ) throws
> > DeserializerException {
> 

> > ODataDeserializer deserializer = odata .createDeserializer(ODataFormat
> 

> > . fromContentType ( request .getResponseContentType()));
> 

> > return deserializer .entity( request . getPayload (), ???? ). getEntity();
> 

> > }
> 

> > The reason I did not provide any automatic deserialization for action is,
> > it
> > is POST. The payload could be arbitrary BINARY payload or JSON payload and
> > there is no real semantics about how that load should look like unlike in
> > create Entity scenarios (at least that is how interpreted the spec). The
> > issue also is how will you interpret the payload when there are more than
> > single parameter etc. So, I left that out for interpretation of the service
> > developer. One such implementation you can see here
> > https://github.com/teiid/teiid/blob/master/olingo/src/main/java/org/teiid/olingo/service/ProcedureSQLBuilder.java#L285
> > here I expect the payload to be JSON or binary data etc. My example may be
> > little complex but in your case it could be simplified
> 

> > Ramesh..
> 

> > > Found the proper entry point ( actionParameters) :
> > 
> 

> > > private Entity getEntityFromClient(ActionRequest request ) throws
> > > DeserializerException, ODataException {
> > 
> 

> > > ODataDeserializer deserializer = odata .createDeserializer(ODataFormat
> > 
> 

> > > . fromContentType ( request .getRequestContentType()));
> > 
> 

> > > return deserializer . actionParameters ( request .getPayload(), request
> > > .getAction()).getEntity();
> > 
> 

> > > }
> > 
> 

> > > But unfortunately not yet supported at the deserializer throws:
> > 
> 

> > > Entity an complex parameters currently not Implemented
> > 
> 

> > > My 'customer' is indeed an entity with complex types inside.
> > 
> 

> > > :[
> > 
> 

> > > Any alternatives?
> > 
> 

> > > Cheers,
> > 
> 

> > > Frederic
> > 
> 

> > > From: Frédéric SOUCHU
> > 
> 
> > > Sent: 27 May 2015 10:57
> > 
> 
> > > To: user@olingo.apache.org
> > 
> 
> > > Subject: [OData 4 Java] invoke Action - how to deserialize parameters?
> > 
> 

> > > I have an action defined as such:
> > 
> 

> > > <Action Name="Refresh">
> > 
> 

> > > <Parameter Name="batchID" Type="Emd.Guid" Nullable ="false" />
> > 
> 

> > > <Parameter Name="customers" Type="Collection(ws.company.com.Customer)"
> > > Nullable ="false" />
> > 
> 

> > > </Action>
> > 
> 

> > > Using the new ServiceHandler base class, my custom code is correctly
> > > called
> > > (POST http://myservice/Refresh with a JSON body):
> > 
> 

> > > public <T extends ServiceResponse> void invoke(ActionRequest request ,
> > > String
> > > eTag , T response ) throws ODataTranslatedException,
> > > ODataApplicationException {
> > 
> 

> > > EdmAction action = request .getAction();
> > 
> 

> > > if ( action .getName().equals( "Refresh" )) {
> > 
> 

> > > // for debug purposes only – works well
> > 
> 

> > > System. out .println( "Action: Refresh" );
> > 
> 

> > > for (String it : action .getParameterNames()) {
> > 
> 

> > > EdmParameter p = action .getParameter( it );
> > 
> 

> > > System. out .println( "param: " + it + " = " + p
> > > .getType().getFullQualifiedName().getFullQualifiedNameAsString());
> > 
> 

> > > }
> > 
> 

> > > // now how to get the JSON body??
> > 
> 

> > > ??? body = getEntityFromClient(request);
> > 
> 

> > > }
> > 
> 

> > > I did not a find an example in the source using action (or function)
> > > parameters.
> > 
> 

> > > Looking at code to create an entity (very similar to what I want to do),
> > > I
> > > would write something like:
> > 
> 

> > > private Entity getEntityFromClient(ActionRequest request ) throws
> > > DeserializerException {
> > 
> 

> > > ODataDeserializer deserializer = odata .createDeserializer(ODataFormat
> > 
> 

> > > . fromContentType ( request .getResponseContentType()));
> > 
> 

> > > return deserializer .entity( request . getPayload (), ???? ).
> > > getEntity();
> > 
> 

> > > }
> > 
> 

> > > Thing is, I don't understand what 'entitytype' should be passed to the
> > > deserializer for an action…
> > 
> 

> > > Regards,
> > 
> 

> > > Frederic
> > 
> 

RE: [OData 4 Java] invoke Action - how to deserialize parameters?

Posted by "Handl, Ralf" <ra...@sap.com>.
Hi Frédéric,

Please create a story in JIRA.

Thanks in advance!
--Ralf

From: Frédéric SOUCHU [mailto:Frederic.SOUCHU@ingenico.com]
Sent: Montag, 15. Juni 2015 13:21
To: user@olingo.apache.org
Subject: RE: [OData 4 Java] invoke Action - how to deserialize parameters?

Thanks – I was a bit puzzled by Ramesh's answer ;)
Should I go ahead and create a story in JIRA?

From: Handl, Ralf [mailto:ralf.handl@sap.com]
Sent: 15 June 2015 13:10
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: RE: [OData 4 Java] invoke Action - how to deserialize parameters?

The JSON Format specification defines the how action parameters are represented as a JSON request body in chapter “17 Action Invocation”,
http://docs.oasis-open.org/odata/odata-json-format/v4.0/errata02/os/odata-json-format-v4.0-errata02-os-complete.html#_Toc403940651:

Action parameter values are encoded in a single JSON object in the request body.
Each non-binding parameter value is encoded as a separate name/value pair in this JSON object. The name is the name of the parameter. The value is the parameter value in the JSON representation appropriate for its type.
Any parameter values not specified in the JSON object are assumed to have the null value.
Example 37:
{
  "param1": 42,
  "param2": {
    "Street": "One Microsoft Way",
    "Zip": 98052
  },
  "param3": [ 1, 42, 99 ],
  "param4": null
}


The corresponding chapter “17 Action Invocation” in the Atom Format specification defines how action parameters are represented as an XML request body, http://docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html#_Toc372792808:

Action parameter values in the request body MUST be encoded as an individual complex scalar value<http://docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html#_Single_Scalar_Value> with the name parameters and no metadata:type attribute for the parameters element.
Each non-binding parameter value specified MUST be encoded as an individual primitive or complex scalar value. The name of the scalar value is the name of the parameter. The value is the parameter value in the XML representation appropriate for its type.
Any parameter values not specified in the request body MUST be assumed to have the null value.
Example 43:
<parameters>
  <param1>42</param1>
  <param2 metadata:type="#Model.Address">
    <Street>One Microsoft Way</Street>
    <Zip>98052</Zip>
  </param2>
  <param3>
    <element>1</element>
    <element>42</element>
    <element>99</element>
  </param3>
  <param4 metadata:null="true"/>
  <!-- <param5/> not specified, has null value -->
<parameters>


From: Ramesh Reddy [mailto:rareddy@redhat.com]
Sent: Dienstag, 2. Juni 2015 14:21
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Action metadata does define the parameters, it does not define how it packs the data. Every one's natural thinking will be a JSON array, or XML fragment. What I am saying spec does not say that. It also falls out if want to send more than one stream payloads. So, there is some confusion, otherwise it would easy to parse them out as they come in. If any one can clarify the spec, then I will fix the code.

________________________________
Thanks - I've used Teiid as a good provider example before Beta 03.

That said, the <action> type does declare a number of parameters with known types, not arbitrary data.
The EDM parser should be able to create a type out of these?

Frederic

From: Ramesh Reddy [mailto:rareddy@redhat.com]
Sent: 02 June 2015 00:55
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Fedric,

You were in right path before using the code like


  private Entity getEntityFromClient(ActionRequest request) throws DeserializerException {

        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat

            .fromContentType(request.getResponseContentType()));

        return deserializer.entity(request.getPayload(), ????).getEntity();

      }



The reason I did not provide any automatic deserialization for action is, it is POST. The payload could be arbitrary BINARY payload or JSON payload and there is no real semantics about how that load should look like unlike in create Entity scenarios (at least that is how interpreted the spec). The issue also is how will you interpret the payload when there are more than single parameter etc. So, I left that out for interpretation of the service developer. One such implementation  you can see here https://github.com/teiid/teiid/blob/master/olingo/src/main/java/org/teiid/olingo/service/ProcedureSQLBuilder.java#L285 here I expect the payload to be JSON or binary data etc. My example may be little complex but in your case it could be simplified



Ramesh..

________________________________
Found the proper entry point (actionParameters):

    private Entity getEntityFromClient(ActionRequest request) throws DeserializerException, ODataException {
        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
            .fromContentType(request.getRequestContentType()));
        return deserializer.actionParameters(request.getPayload(), request.getAction()).getEntity();
      }

But unfortunately not yet supported at the deserializer throws:
Entity an complex parameters currently not Implemented
My 'customer' is indeed an entity with complex types inside.
:[

Any alternatives?

Cheers,
Frederic

From: Frédéric SOUCHU
Sent: 27 May 2015 10:57
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: [OData 4 Java] invoke Action - how to deserialize parameters?

I have an action defined as such:

<Action Name="Refresh">
<Parameter Name="batchID" Type="Emd.Guid" Nullable="false" />
<Parameter Name="customers" Type="Collection(ws.company.com.Customer)" Nullable="false" />
</Action>

Using the new ServiceHandler base class, my custom code is correctly called (POST http://myservice/Refresh with a JSON body):

public <T extends ServiceResponse> void invoke(ActionRequest request, String eTag, T response) throws ODataTranslatedException, ODataApplicationException {
EdmAction action = request.getAction();

if (action.getName().equals("Refresh")) {
// for debug purposes only – works well
System.out.println("Action: Refresh");
for(String it : action.getParameterNames()) {
                     EdmParameter p =  action.getParameter(it);
                     System.out.println("param: " + it + " = " + p.getType().getFullQualifiedName().getFullQualifiedNameAsString());
              }
// now how to get the JSON body??
                                ??? body =  getEntityFromClient(request);
       }
I did not a find an example in the source using action (or function) parameters.
Looking at code to create an entity (very similar to what I want to do), I would write something like:

    private Entity getEntityFromClient(ActionRequest request) throws DeserializerException {
        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
            .fromContentType(request.getResponseContentType()));
        return deserializer.entity(request.getPayload(), ????).getEntity();
      }

Thing is, I don't understand what 'entitytype' should be passed to the deserializer for an action…

Regards,
Frederic




RE: [OData 4 Java] invoke Action - how to deserialize parameters?

Posted by Frédéric SOUCHU <Fr...@ingenico.com>.
Thanks – I was a bit puzzled by Ramesh's answer ;)
Should I go ahead and create a story in JIRA?

From: Handl, Ralf [mailto:ralf.handl@sap.com]
Sent: 15 June 2015 13:10
To: user@olingo.apache.org
Subject: RE: [OData 4 Java] invoke Action - how to deserialize parameters?

The JSON Format specification defines the how action parameters are represented as a JSON request body in chapter “17 Action Invocation”,
http://docs.oasis-open.org/odata/odata-json-format/v4.0/errata02/os/odata-json-format-v4.0-errata02-os-complete.html#_Toc403940651:

Action parameter values are encoded in a single JSON object in the request body.
Each non-binding parameter value is encoded as a separate name/value pair in this JSON object. The name is the name of the parameter. The value is the parameter value in the JSON representation appropriate for its type.
Any parameter values not specified in the JSON object are assumed to have the null value.
Example 37:
{
  "param1": 42,
  "param2": {
    "Street": "One Microsoft Way",
    "Zip": 98052
  },
  "param3": [ 1, 42, 99 ],
  "param4": null
}


The corresponding chapter “17 Action Invocation” in the Atom Format specification defines how action parameters are represented as an XML request body, http://docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html#_Toc372792808:

Action parameter values in the request body MUST be encoded as an individual complex scalar value<http://docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html#_Single_Scalar_Value> with the name parameters and no metadata:type attribute for the parameters element.
Each non-binding parameter value specified MUST be encoded as an individual primitive or complex scalar value. The name of the scalar value is the name of the parameter. The value is the parameter value in the XML representation appropriate for its type.
Any parameter values not specified in the request body MUST be assumed to have the null value.
Example 43:
<parameters>
  <param1>42</param1>
  <param2 metadata:type="#Model.Address">
    <Street>One Microsoft Way</Street>
    <Zip>98052</Zip>
  </param2>
  <param3>
    <element>1</element>
    <element>42</element>
    <element>99</element>
  </param3>
  <param4 metadata:null="true"/>
  <!-- <param5/> not specified, has null value -->
<parameters>


From: Ramesh Reddy [mailto:rareddy@redhat.com]
Sent: Dienstag, 2. Juni 2015 14:21
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Action metadata does define the parameters, it does not define how it packs the data. Every one's natural thinking will be a JSON array, or XML fragment. What I am saying spec does not say that. It also falls out if want to send more than one stream payloads. So, there is some confusion, otherwise it would easy to parse them out as they come in. If any one can clarify the spec, then I will fix the code.

________________________________
Thanks - I've used Teiid as a good provider example before Beta 03.

That said, the <action> type does declare a number of parameters with known types, not arbitrary data.
The EDM parser should be able to create a type out of these?

Frederic

From: Ramesh Reddy [mailto:rareddy@redhat.com]
Sent: 02 June 2015 00:55
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Fedric,

You were in right path before using the code like


  private Entity getEntityFromClient(ActionRequest request) throws DeserializerException {

        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat

            .fromContentType(request.getResponseContentType()));

        return deserializer.entity(request.getPayload(), ????).getEntity();

      }



The reason I did not provide any automatic deserialization for action is, it is POST. The payload could be arbitrary BINARY payload or JSON payload and there is no real semantics about how that load should look like unlike in create Entity scenarios (at least that is how interpreted the spec). The issue also is how will you interpret the payload when there are more than single parameter etc. So, I left that out for interpretation of the service developer. One such implementation  you can see here https://github.com/teiid/teiid/blob/master/olingo/src/main/java/org/teiid/olingo/service/ProcedureSQLBuilder.java#L285 here I expect the payload to be JSON or binary data etc. My example may be little complex but in your case it could be simplified



Ramesh..

________________________________
Found the proper entry point (actionParameters):

    private Entity getEntityFromClient(ActionRequest request) throws DeserializerException, ODataException {
        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
            .fromContentType(request.getRequestContentType()));
        return deserializer.actionParameters(request.getPayload(), request.getAction()).getEntity();
      }

But unfortunately not yet supported at the deserializer throws:
Entity an complex parameters currently not Implemented
My 'customer' is indeed an entity with complex types inside.
:[

Any alternatives?

Cheers,
Frederic

From: Frédéric SOUCHU
Sent: 27 May 2015 10:57
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: [OData 4 Java] invoke Action - how to deserialize parameters?

I have an action defined as such:

<Action Name="Refresh">
<Parameter Name="batchID" Type="Emd.Guid" Nullable="false" />
<Parameter Name="customers" Type="Collection(ws.company.com.Customer)" Nullable="false" />
</Action>

Using the new ServiceHandler base class, my custom code is correctly called (POST http://myservice/Refresh with a JSON body):

public <T extends ServiceResponse> void invoke(ActionRequest request, String eTag, T response) throws ODataTranslatedException, ODataApplicationException {
EdmAction action = request.getAction();

if (action.getName().equals("Refresh")) {
// for debug purposes only – works well
System.out.println("Action: Refresh");
for(String it : action.getParameterNames()) {
                     EdmParameter p =  action.getParameter(it);
                     System.out.println("param: " + it + " = " + p.getType().getFullQualifiedName().getFullQualifiedNameAsString());
              }
// now how to get the JSON body??
                                ??? body =  getEntityFromClient(request);
       }
I did not a find an example in the source using action (or function) parameters.
Looking at code to create an entity (very similar to what I want to do), I would write something like:

    private Entity getEntityFromClient(ActionRequest request) throws DeserializerException {
        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
            .fromContentType(request.getResponseContentType()));
        return deserializer.entity(request.getPayload(), ????).getEntity();
      }

Thing is, I don't understand what 'entitytype' should be passed to the deserializer for an action…

Regards,
Frederic




RE: [OData 4 Java] invoke Action - how to deserialize parameters?

Posted by "Handl, Ralf" <ra...@sap.com>.
The JSON Format specification defines the how action parameters are represented as a JSON request body in chapter “17 Action Invocation”,
http://docs.oasis-open.org/odata/odata-json-format/v4.0/errata02/os/odata-json-format-v4.0-errata02-os-complete.html#_Toc403940651:

Action parameter values are encoded in a single JSON object in the request body.
Each non-binding parameter value is encoded as a separate name/value pair in this JSON object. The name is the name of the parameter. The value is the parameter value in the JSON representation appropriate for its type.
Any parameter values not specified in the JSON object are assumed to have the null value.
Example 37:
{
  "param1": 42,
  "param2": {
    "Street": "One Microsoft Way",
    "Zip": 98052
  },
  "param3": [ 1, 42, 99 ],
  "param4": null
}


The corresponding chapter “17 Action Invocation” in the Atom Format specification defines how action parameters are represented as an XML request body, http://docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html#_Toc372792808:

Action parameter values in the request body MUST be encoded as an individual complex scalar value<http://docs.oasis-open.org/odata/odata-atom-format/v4.0/cs02/odata-atom-format-v4.0-cs02.html#_Single_Scalar_Value> with the name parameters and no metadata:type attribute for the parameters element.
Each non-binding parameter value specified MUST be encoded as an individual primitive or complex scalar value. The name of the scalar value is the name of the parameter. The value is the parameter value in the XML representation appropriate for its type.
Any parameter values not specified in the request body MUST be assumed to have the null value.
Example 43:
<parameters>
  <param1>42</param1>
  <param2 metadata:type="#Model.Address">
    <Street>One Microsoft Way</Street>
    <Zip>98052</Zip>
  </param2>
  <param3>
    <element>1</element>
    <element>42</element>
    <element>99</element>
  </param3>
  <param4 metadata:null="true"/>
  <!-- <param5/> not specified, has null value -->
<parameters>


From: Ramesh Reddy [mailto:rareddy@redhat.com]
Sent: Dienstag, 2. Juni 2015 14:21
To: user@olingo.apache.org
Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Action metadata does define the parameters, it does not define how it packs the data. Every one's natural thinking will be a JSON array, or XML fragment. What I am saying spec does not say that. It also falls out if want to send more than one stream payloads. So, there is some confusion, otherwise it would easy to parse them out as they come in. If any one can clarify the spec, then I will fix the code.

________________________________
Thanks - I've used Teiid as a good provider example before Beta 03.

That said, the <action> type does declare a number of parameters with known types, not arbitrary data.
The EDM parser should be able to create a type out of these?

Frederic

From: Ramesh Reddy [mailto:rareddy@redhat.com]
Sent: 02 June 2015 00:55
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Fedric,

You were in right path before using the code like


  private Entity getEntityFromClient(ActionRequest request) throws DeserializerException {

        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat

            .fromContentType(request.getResponseContentType()));

        return deserializer.entity(request.getPayload(), ????).getEntity();

      }



The reason I did not provide any automatic deserialization for action is, it is POST. The payload could be arbitrary BINARY payload or JSON payload and there is no real semantics about how that load should look like unlike in create Entity scenarios (at least that is how interpreted the spec). The issue also is how will you interpret the payload when there are more than single parameter etc. So, I left that out for interpretation of the service developer. One such implementation  you can see here https://github.com/teiid/teiid/blob/master/olingo/src/main/java/org/teiid/olingo/service/ProcedureSQLBuilder.java#L285 here I expect the payload to be JSON or binary data etc. My example may be little complex but in your case it could be simplified



Ramesh..

________________________________
Found the proper entry point (actionParameters):

    private Entity getEntityFromClient(ActionRequest request) throws DeserializerException, ODataException {
        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
            .fromContentType(request.getRequestContentType()));
        return deserializer.actionParameters(request.getPayload(), request.getAction()).getEntity();
      }

But unfortunately not yet supported at the deserializer throws:
Entity an complex parameters currently not Implemented
My 'customer' is indeed an entity with complex types inside.
:[

Any alternatives?

Cheers,
Frederic

From: Frédéric SOUCHU
Sent: 27 May 2015 10:57
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: [OData 4 Java] invoke Action - how to deserialize parameters?

I have an action defined as such:

<Action Name="Refresh">
<Parameter Name="batchID" Type="Emd.Guid" Nullable="false" />
<Parameter Name="customers" Type="Collection(ws.company.com.Customer)" Nullable="false" />
</Action>

Using the new ServiceHandler base class, my custom code is correctly called (POST http://myservice/Refresh with a JSON body):

public <T extends ServiceResponse> void invoke(ActionRequest request, String eTag, T response) throws ODataTranslatedException, ODataApplicationException {
EdmAction action = request.getAction();

if (action.getName().equals("Refresh")) {
// for debug purposes only – works well
System.out.println("Action: Refresh");
for(String it : action.getParameterNames()) {
                     EdmParameter p =  action.getParameter(it);
                     System.out.println("param: " + it + " = " + p.getType().getFullQualifiedName().getFullQualifiedNameAsString());
              }
// now how to get the JSON body??
                                ??? body =  getEntityFromClient(request);
       }
I did not a find an example in the source using action (or function) parameters.
Looking at code to create an entity (very similar to what I want to do), I would write something like:

    private Entity getEntityFromClient(ActionRequest request) throws DeserializerException {
        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
            .fromContentType(request.getResponseContentType()));
        return deserializer.entity(request.getPayload(), ????).getEntity();
      }

Thing is, I don't understand what 'entitytype' should be passed to the deserializer for an action…

Regards,
Frederic




RE: [OData 4 Java] invoke Action - how to deserialize parameters?

Posted by Frédéric SOUCHU <Fr...@ingenico.com>.
Ok – got it.

From: Ramesh Reddy [mailto:rareddy@redhat.com]
Sent: 02 June 2015 14:21
To: user@olingo.apache.org
Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Action metadata does define the parameters, it does not define how it packs the data. Every one's natural thinking will be a JSON array, or XML fragment. What I am saying spec does not say that. It also falls out if want to send more than one stream payloads. So, there is some confusion, otherwise it would easy to parse them out as they come in. If any one can clarify the spec, then I will fix the code.

________________________________
Thanks - I've used Teiid as a good provider example before Beta 03.

That said, the <action> type does declare a number of parameters with known types, not arbitrary data.
The EDM parser should be able to create a type out of these?

Frederic

From: Ramesh Reddy [mailto:rareddy@redhat.com]
Sent: 02 June 2015 00:55
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Fedric,

You were in right path before using the code like


  private Entity getEntityFromClient(ActionRequest request) throws DeserializerException {

        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat

            .fromContentType(request.getResponseContentType()));

        return deserializer.entity(request.getPayload(), ????).getEntity();

      }



The reason I did not provide any automatic deserialization for action is, it is POST. The payload could be arbitrary BINARY payload or JSON payload and there is no real semantics about how that load should look like unlike in create Entity scenarios (at least that is how interpreted the spec). The issue also is how will you interpret the payload when there are more than single parameter etc. So, I left that out for interpretation of the service developer. One such implementation  you can see here https://github.com/teiid/teiid/blob/master/olingo/src/main/java/org/teiid/olingo/service/ProcedureSQLBuilder.java#L285 here I expect the payload to be JSON or binary data etc. My example may be little complex but in your case it could be simplified



Ramesh..

________________________________
Found the proper entry point (actionParameters):

    private Entity getEntityFromClient(ActionRequest request) throws DeserializerException, ODataException {
        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
            .fromContentType(request.getRequestContentType()));
        return deserializer.actionParameters(request.getPayload(), request.getAction()).getEntity();
      }

But unfortunately not yet supported at the deserializer throws:
Entity an complex parameters currently not Implemented
My 'customer' is indeed an entity with complex types inside.
:[

Any alternatives?

Cheers,
Frederic

From: Frédéric SOUCHU
Sent: 27 May 2015 10:57
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: [OData 4 Java] invoke Action - how to deserialize parameters?

I have an action defined as such:

<Action Name="Refresh">
<Parameter Name="batchID" Type="Emd.Guid" Nullable="false" />
<Parameter Name="customers" Type="Collection(ws.company.com.Customer)" Nullable="false" />
</Action>

Using the new ServiceHandler base class, my custom code is correctly called (POST http://myservice/Refresh with a JSON body):

public <T extends ServiceResponse> void invoke(ActionRequest request, String eTag, T response) throws ODataTranslatedException, ODataApplicationException {
EdmAction action = request.getAction();

if (action.getName().equals("Refresh")) {
// for debug purposes only – works well
System.out.println("Action: Refresh");
for(String it : action.getParameterNames()) {
                     EdmParameter p =  action.getParameter(it);
                     System.out.println("param: " + it + " = " + p.getType().getFullQualifiedName().getFullQualifiedNameAsString());
              }
// now how to get the JSON body??
                                ??? body =  getEntityFromClient(request);
       }
I did not a find an example in the source using action (or function) parameters.
Looking at code to create an entity (very similar to what I want to do), I would write something like:

    private Entity getEntityFromClient(ActionRequest request) throws DeserializerException {
        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
            .fromContentType(request.getResponseContentType()));
        return deserializer.entity(request.getPayload(), ????).getEntity();
      }

Thing is, I don't understand what 'entitytype' should be passed to the deserializer for an action…

Regards,
Frederic




Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Posted by Ramesh Reddy <ra...@redhat.com>.
Action metadata does define the parameters, it does not define how it packs the data. Every one's natural thinking will be a JSON array, or XML fragment. What I am saying spec does not say that. It also falls out if want to send more than one stream payloads. So, there is some confusion, otherwise it would easy to parse them out as they come in. If any one can clarify the spec, then I will fix the code. 

----- Original Message -----

> Thanks - I've used Teiid as a good provider example before Beta 03.

> That said, the <action> type does declare a number of parameters with known
> types, not arbitrary data.

> The EDM parser should be able to create a type out of these?

> Frederic

> From: Ramesh Reddy [mailto:rareddy@redhat.com]
> Sent: 02 June 2015 00:55
> To: user@olingo.apache.org
> Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

> Fedric,

> You were in right path before using the code like

> private Entity getEntityFromClient(ActionRequest request ) throws
> DeserializerException {

> ODataDeserializer deserializer = odata .createDeserializer(ODataFormat

> . fromContentType ( request .getResponseContentType()));

> return deserializer .entity( request . getPayload (), ???? ). getEntity();

> }

> The reason I did not provide any automatic deserialization for action is, it
> is POST. The payload could be arbitrary BINARY payload or JSON payload and
> there is no real semantics about how that load should look like unlike in
> create Entity scenarios (at least that is how interpreted the spec). The
> issue also is how will you interpret the payload when there are more than
> single parameter etc. So, I left that out for interpretation of the service
> developer. One such implementation you can see here
> https://github.com/teiid/teiid/blob/master/olingo/src/main/java/org/teiid/olingo/service/ProcedureSQLBuilder.java#L285
> here I expect the payload to be JSON or binary data etc. My example may be
> little complex but in your case it could be simplified

> Ramesh..

> ----- Original Message -----

> > Found the proper entry point ( actionParameters) :
> 

> > private Entity getEntityFromClient(ActionRequest request ) throws
> > DeserializerException, ODataException {
> 

> > ODataDeserializer deserializer = odata .createDeserializer(ODataFormat
> 

> > . fromContentType ( request .getRequestContentType()));
> 

> > return deserializer . actionParameters ( request .getPayload(), request
> > .getAction()).getEntity();
> 

> > }
> 

> > But unfortunately not yet supported at the deserializer throws:
> 

> > Entity an complex parameters currently not Implemented
> 

> > My 'customer' is indeed an entity with complex types inside.
> 

> > :[
> 

> > Any alternatives?
> 

> > Cheers,
> 

> > Frederic
> 

> > From: Frédéric SOUCHU
> 
> > Sent: 27 May 2015 10:57
> 
> > To: user@olingo.apache.org
> 
> > Subject: [OData 4 Java] invoke Action - how to deserialize parameters?
> 

> > I have an action defined as such:
> 

> > <Action Name="Refresh">
> 

> > <Parameter Name="batchID" Type="Emd.Guid" Nullable ="false" />
> 

> > <Parameter Name="customers" Type="Collection(ws.company.com.Customer)"
> > Nullable ="false" />
> 

> > </Action>
> 

> > Using the new ServiceHandler base class, my custom code is correctly called
> > (POST http://myservice/Refresh with a JSON body):
> 

> > public <T extends ServiceResponse> void invoke(ActionRequest request ,
> > String
> > eTag , T response ) throws ODataTranslatedException,
> > ODataApplicationException {
> 

> > EdmAction action = request .getAction();
> 

> > if ( action .getName().equals( "Refresh" )) {
> 

> > // for debug purposes only – works well
> 

> > System. out .println( "Action: Refresh" );
> 

> > for (String it : action .getParameterNames()) {
> 

> > EdmParameter p = action .getParameter( it );
> 

> > System. out .println( "param: " + it + " = " + p
> > .getType().getFullQualifiedName().getFullQualifiedNameAsString());
> 

> > }
> 

> > // now how to get the JSON body??
> 

> > ??? body = getEntityFromClient(request);
> 

> > }
> 

> > I did not a find an example in the source using action (or function)
> > parameters.
> 

> > Looking at code to create an entity (very similar to what I want to do), I
> > would write something like:
> 

> > private Entity getEntityFromClient(ActionRequest request ) throws
> > DeserializerException {
> 

> > ODataDeserializer deserializer = odata .createDeserializer(ODataFormat
> 

> > . fromContentType ( request .getResponseContentType()));
> 

> > return deserializer .entity( request . getPayload (), ???? ). getEntity();
> 

> > }
> 

> > Thing is, I don't understand what 'entitytype' should be passed to the
> > deserializer for an action…
> 

> > Regards,
> 

> > Frederic
> 

RE: [OData 4 Java] invoke Action - how to deserialize parameters?

Posted by Frédéric SOUCHU <Fr...@ingenico.com>.
Thanks - I've used Teiid as a good provider example before Beta 03.

That said, the <action> type does declare a number of parameters with known types, not arbitrary data.
The EDM parser should be able to create a type out of these?

Frederic

From: Ramesh Reddy [mailto:rareddy@redhat.com]
Sent: 02 June 2015 00:55
To: user@olingo.apache.org
Subject: Re: [OData 4 Java] invoke Action - how to deserialize parameters?

Fedric,

You were in right path before using the code like


  private Entity getEntityFromClient(ActionRequest request) throws DeserializerException {

        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat

            .fromContentType(request.getResponseContentType()));

        return deserializer.entity(request.getPayload(), ????).getEntity();

      }



The reason I did not provide any automatic deserialization for action is, it is POST. The payload could be arbitrary BINARY payload or JSON payload and there is no real semantics about how that load should look like unlike in create Entity scenarios (at least that is how interpreted the spec). The issue also is how will you interpret the payload when there are more than single parameter etc. So, I left that out for interpretation of the service developer. One such implementation  you can see here https://github.com/teiid/teiid/blob/master/olingo/src/main/java/org/teiid/olingo/service/ProcedureSQLBuilder.java#L285 here I expect the payload to be JSON or binary data etc. My example may be little complex but in your case it could be simplified



Ramesh..

________________________________
Found the proper entry point (actionParameters):

    private Entity getEntityFromClient(ActionRequest request) throws DeserializerException, ODataException {
        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
            .fromContentType(request.getRequestContentType()));
        return deserializer.actionParameters(request.getPayload(), request.getAction()).getEntity();
      }

But unfortunately not yet supported at the deserializer throws:
Entity an complex parameters currently not Implemented
My 'customer' is indeed an entity with complex types inside.
:[

Any alternatives?

Cheers,
Frederic

From: Frédéric SOUCHU
Sent: 27 May 2015 10:57
To: user@olingo.apache.org<ma...@olingo.apache.org>
Subject: [OData 4 Java] invoke Action - how to deserialize parameters?

I have an action defined as such:

<Action Name="Refresh">
<Parameter Name="batchID" Type="Emd.Guid" Nullable="false" />
<Parameter Name="customers" Type="Collection(ws.company.com.Customer)" Nullable="false" />
</Action>

Using the new ServiceHandler base class, my custom code is correctly called (POST http://myservice/Refresh with a JSON body):

public <T extends ServiceResponse> void invoke(ActionRequest request, String eTag, T response) throws ODataTranslatedException, ODataApplicationException {
EdmAction action = request.getAction();

if (action.getName().equals("Refresh")) {
// for debug purposes only – works well
System.out.println("Action: Refresh");
for(String it : action.getParameterNames()) {
                     EdmParameter p =  action.getParameter(it);
                     System.out.println("param: " + it + " = " + p.getType().getFullQualifiedName().getFullQualifiedNameAsString());
              }
// now how to get the JSON body??
                                ??? body =  getEntityFromClient(request);
       }
I did not a find an example in the source using action (or function) parameters.
Looking at code to create an entity (very similar to what I want to do), I would write something like:

    private Entity getEntityFromClient(ActionRequest request) throws DeserializerException {
        ODataDeserializer deserializer = odata.createDeserializer(ODataFormat
            .fromContentType(request.getResponseContentType()));
        return deserializer.entity(request.getPayload(), ????).getEntity();
      }

Thing is, I don't understand what 'entitytype' should be passed to the deserializer for an action…

Regards,
Frederic