Actions and empty values

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Actions and empty values

Pete Gould
Hi,

I've had a bit more time to look at Cling now, but I seem to have come across a small issue. Whilst I was attempting to test the browse action of my media server, I received the following error:

"Current state of service prevents invoking that action"

Using the Cling workbench I recreated this using the same arguments that the media renderer I was using had passed to the service, it turns out that the issue occurs if one or more of the arguments is empty (and I believe this is a valid case - for example, the sortCriteria of the Browse action for the ContentDirectoryService can be an empty string).

Looking at the code, this exception is thrown in the createInputArugmentValues method of the MethodActionExecutor class, as a NullPointerException is thrown on the following line, as getValue() returns null:

    Object o = ctor.newInstance(inputCallValue.getValue().toString());

For now, I've just added a null check and incremented the array index in this case, but was wondering if you do consider this to be a valid issue or not.

So my the mediaserver is now returning a correct response to browse action requests (unfortunately the PS3 still doesn't like them - I imagine that's because I'm missing the required DLNA headers, but I'll look at that tonight)

Cheers,

Pete
Reply | Threaded
Open this post in threaded view
|

Re: Actions and empty values

Christian Bauer
Administrator
You found a bug there, this line has to be guarded with a null check. I've committed a fix into trunk, it will be in beta3.

I'd love to get some feedback on null/emptystring handling in Cling though. The UPnP spec is silent about this issue so I had to come up with my own solution and I'm not sure if it's the right one.

Here is a new test I've committed. It shows how Cling handles null/emptystring in action invocations (eventing is the same).

The UPnP specifications don't constrain null or empty string when you transmit a call. As far as I understand, the SOAP message body must contain <SomeVar></SomeVar> for all input arguments of an action. So my conclusion is that if you provide an empty string or a null value when preparing a call, it will always be a null on the receiving end because we can only transmit one thing, an empty XML element. Everything else is based on that assumption.

The question is: what happens if we use <SomeVar></SomeVar> if an empty string is provided, and simply omit the whole XML element if null is provided. If this would work with other services, we can distinguish between null and empty string and preserve the semantics. What I've seen so far from other UPnP stacks, I wouldn't bet on that.

Another open question is whether we should simply fill up the ActionInvocation.input with nulls/emptystring if you do not provide all input arguments to an action call. Right now that will fail validation before execution, and you are forced to call addValue(null) until all input arguments are set. I guess it all depends how often you will see actions with optional input argument values.
Reply | Threaded
Open this post in threaded view
|

Re: Actions and empty values

Pete Gould
Hi,

I agree - the Action Invocation section (3.2.1) of the Device Architecture spec does state that - "Every “in” argument in the definition of the action in the service description MUST be included", so I guess that means that a solution to distinguish between null and empty strings can't be provided?

Not sure that I can comment on the final question as I'm not familiar with many of the UPnP services, and haven't implemented any Control Points yet. It seems sensible to have to explicitly call addValue(null). If values were to be set to null implicitly for any input arguments that aren't set, then would some facility to set input arguments based on their index be required? Suppose that could get messy?
Reply | Threaded
Open this post in threaded view
|

Re: Actions and empty values

Christian Bauer
Administrator

On Jul 10, 2010, at 0:12 , Pete Gould [via Cling users and developers] wrote:

> I agree - the Action Invocation section (3.2.1) of the Device Architecture spec does state that - "Every “in” argument in the definition of the action in the service description MUST be included", so I guess that means that a solution to distinguish between null and empty strings can't be provided?

Exactly, not within the specifications. For example a special magic "NULL" string could be used but only Cling clients/servers would understand it. I think the best solution right now is good documentation for the empty-string-is-null behavior.

> It seems sensible to have to explicitly call addValue(null). If values were to be set to null implicitly for any input arguments that aren't set, then would some facility to set input arguments based on their index be required? Suppose that could get messy?

There is addValue(o) and setValue(index, o) and also a fillValuesWithNull() method which can be called when you are done and do not care about the remaining (optional) arguments.

Reply | Threaded
Open this post in threaded view
|

Re: Actions and empty values

Pete Gould
Christian Bauer wrote
There is addValue(o) and setValue(index, o) and also a fillValuesWithNull() method which can be called when you are done and do not care about the remaining (optional) arguments.
Oh yes, so there is - should have looked at the Javadocs. Can't remember if I mentioned that I'd checked out the latest after your fix, and it all works as expected (which was proved by your test anyway, but hey).