Hello,

I'm having some trouble. I have a REST service returning json formatted results. The web service description is setup for the most part, it just doesn't yet describe every single result included in the results. When I run the ws_client tester, I get the following results.

TRANSACTION
REQUEST
Headers go here
Uri:http://services.jukeboxjockeyloud.com/v1/JJLoudApiXmlServices.ashx
Method:GET
Parameter:method=getcomputercheckoutrecords
format=json
user=jayshoe1
RESPONSE
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By-Plesk: PleskWin
Date: Tue, 10 Sep 2013 14:11:33 GMT
Content-Length: 2380
[{"ComputerId":"{2239CC23-BB5B-4CFC-86D6-EA8E7EFE089F}","ComputerName":"SHOEMAKERSERVER","UserId":"{A3FD398A-61C0-4D33-92C5-CACCC5B646DF}","UserName":"JayShoe1","SubscriptionId":"karaoke-cloud-pro","SubscriptionName":"Karaoke Cloud Pro","SubscriptionExpiryDate":"\/Date(1380200445000)\/","CheckOutDate":"\/Date(1378126642677)\/","ComputerExpiryDate":"\/Date(-62135575200000)\/","CheckOutDateDisplay":"2013-09-02","ComputerExpiryDateDisplay":"","SubscriptionExpiryDateDisplay":"2013-09-26"},{"ComputerId":"{A49D66E9-8249-4678-9E9C-AF2F69812D21}","ComputerName":"JAY-MONSTER-PC","UserId":"{A3FD398A-61C0-4D33-92C5-CACCC5B646DF}","UserName":"JayShoe1","SubscriptionId":"vj-pro","SubscriptionName":"VJ-Pro","SubscriptionExpiryDate":"\/Date(1380717548000)\/","CheckOutDate":"\/Date(1378775007537)\/","ComputerExpiryDate":"\/Date(1381924800000)\/","CheckOutDateDisplay":"2013-09-09","ComputerExpiryDateDisplay":"2013-10-16","SubscriptionExpiryDateDisplay":"2013-10-02"},{"ComputerId":"{A49D66E9-8249-4678-9E9C-AF2F69812D21}","ComputerName":"JAY-MONSTER-PC","UserId":"{A3FD398A-61C0-4D33-92C5-CACCC5B646DF}","UserName":"JayShoe1","SubscriptionId":"karaoke-cloud-pro","SubscriptionName":"Karaoke Cloud Pro","SubscriptionExpiryDate":"\/Date(1380200445000)\/","CheckOutDate":"\/Date(1378775011367)\/","ComputerExpiryDate":"\/Date(1381406400000)\/","CheckOutDateDisplay":"2013-09-09","ComputerExpiryDateDisplay":"2013-10-10","SubscriptionExpiryDateDisplay":"2013-09-26"},{"ComputerId":"{56786099-8EF0-4192-8B8A-519841CA4E81}","ComputerName":"JAY-MONSTER-PC","UserId":"{A3FD398A-61C0-4D33-92C5-CACCC5B646DF}","UserName":"JayShoe1","SubscriptionId":null,"SubscriptionName":null,"SubscriptionExpiryDate":"\/Date(-62135575200000)\/","CheckOutDate":"\/Date(-62135575200000)\/","ComputerExpiryDate":"\/Date(-62135575200000)\/","CheckOutDateDisplay":"","ComputerExpiryDateDisplay":"","SubscriptionExpiryDateDisplay":""},{"ComputerId":"{A6118C78-4EC9-4DDF-99A7-8AAA226FCA77}","ComputerName":"DEV4","UserId":"{A3FD398A-61C0-4D33-92C5-CACCC5B646DF}","UserName":"JayShoe1","SubscriptionId":"karaoke-cloud-pro","SubscriptionName":"Karaoke Cloud Pro","SubscriptionExpiryDate":"\/Date(1380200445000)\/","CheckOutDate":"\/Date(1378236821200)\/","ComputerExpiryDate":"\/Date(-62135575200000)\/","CheckOutDateDisplay":"2013-09-03","ComputerExpiryDateDisplay":"","SubscriptionExpiryDateDisplay":"2013-09-26"}]

The above looks OK. Then I go to the views and test the "Get Computer Checkout Records" view. But the result is not correct. It shows "array" instead of the values listed in the results.

ComputerId:
array

ComputerId:
array

ComputerId:
array

ComputerId:
array

ComputerId:
array

The strange part about it is that I also have "Get Computers" as a WS and a View, and that displays the information perfectly fine. Why would this particular display return "array" for the results?

The module is attached to make it easy to test this...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JayShoe’s picture

PS - to see the "Get Computers" Webservice Description and view work you will need to change the user to "jayshoe1" to get results rather than the "logged in user".

PatchRanger’s picture

I am pretty sure what is the root of the problem in this case: it is because Wsclient Views gets different objects as a response from Wsclient depending on format: if you choose XML format it will get SimleXML object, while choosing JSON will result in getting an array. The problem is that Wsclient Views doesn't know how to deal with all of them abstractly. Now it tries to deal with the response as with SimpleXML - and if this effort fails it just outputs "array", because it is not aware how to fetch the data from other types of responses.
So the task is to teach Wsclient Views to work with responses in unified manner.

PatchRanger’s picture

Status: Active » Closed (works as designed)
FileSize
25.14 KB

I've just done as you described: downloaded & installed the module, checked that it works in Tester, then replaced default value with "jayshoe1" - and - voila! - it works without any changes.
Screenshot proving that it works.
Please make sure to use the latest development release. The only commit introduces all necessary changes - so no patch this time.

PatchRanger’s picture

Status: Closed (works as designed) » Active

Sorry, I read it wrong, you told exactly the same thing in your exactly the first post.
Re-open to investigate the situation with "Get Computer Checkout Records".

PatchRanger’s picture

It works now for "Get Computer Checkout Records" as well.
(I've changed the style to "Table" for better visibility.)
The problem was caused by case-sensitive comparison. As you could see your getcomputers wsclient views configuration is lowercased: id, name, userid - while the response is given CamelCased: Id, Name, UserId.
Before the patch Wsclient Views was lowercasing the result - so it works for getcomputers. Now, with getcomputercheckoutrecords where CamelCased parameter was introduced (ComputerId), Wsclient Views failed to match computerid with ComputerId.
After the patch Wsclient Views turns both parameter name and field name lowercased before matching, making it completely case-insensitive, which fixes the issue.
Tester works and worked nevertheless because it doesn't need to match defined parameters with the properties of response it got: it just outputs the result and that's it.
Please review.

PatchRanger’s picture

Status: Fixed » Needs review

Oh, I guess the appropriate status is 'needs review'.

JayShoe’s picture

Hello Dmitry,

Can you confirm a fresh install of the module from git works? I go to sites/all/modules and

git clone http://git.drupal.org/sandbox/wesnick/1437134.git web_services_client_views

However, the module won't show in the module list. Its probably a newbie problem but I can't seem to get it to work.

Jay

PatchRanger’s picture

@JayShoe It is great, that you showed your command, in fact it should look like this:
git clone --branch 7.x-1.x http://git.drupal.org/sandbox/wesnick/1437134.git web_services_client_views
as described here: https://drupal.org/node/1437134/git-instructions . Your command works fine in case if the project follows the "coding standards": one of them tells that code should be stored at version-specific branch and default 'master' branch should be deleted. I suggest always specify branch with git clone to avoid such troubles with projects that don't follow this recommendation: in that case your command fetches the default branch, which is 'master' - and that leads to confusion.
I have deleted 'master' branch completely as described here: https://drupal.org/empty-git-master - so now you wouldn't have any troubles.

JayShoe’s picture

FileSize
4.49 KB

@JayShoe It is great, that you showed your command, in fact it should look like this:
git clone --branch 7.x-1.x http://git.drupal.org/sandbox/wesnick/1437134.git web_services_client_views
as described here: https://drupal.org/node/1437134/git-instructions .

When going to the sandbox home page there is a bar that contains a git command... It's a bit misleading I suppose. But I guess this isn't an issue with this module - rather one for drupal.org!

CamelCased parameter was introduced (ComputerId), Wsclient Views failed to match computerid with ComputerId.
After the patch Wsclient Views turns both parameter name and field name lowercased before matching, making it completely case-insensitive, which fixes the issue.

I can confirm that this has resolved the issue!

Tester works and worked nevertheless because it doesn't need to match defined parameters with the properties of response it got: it just outputs the result and that's it.

I wonder if THIS module could be an "advanced tester" for the wsclient. The benefit being that you can also confirm that the results have been parsed properly. You could keep the raw data in the tester and add the parsed results in a new section.

Related issue... Array for Empty Values
This patch has fixed the CamelCase issue. But values that have no value in the data, still show "array".

Raw Data:

<CheckOutRecord>
<ComputerId>{56786099-8EF0-4192-8B8A-519841CA4E81}</ComputerId>
<ComputerName>JAY-MONSTER-PC</ComputerName>
<UserId>{A3FD398A-61C0-4D33-92C5-CACCC5B646DF}</UserId>
<UserName>JayShoe1</UserName>
<SubscriptionExpiryDate>0001-01-01T00:00:00</SubscriptionExpiryDate>
<CheckOutDate>0001-01-01T00:00:00</CheckOutDate>
<ComputerExpiryDate>0001-01-01T00:00:00</ComputerExpiryDate>
<CheckOutDateDisplay/>
<ComputerExpiryDateDisplay/>
<SubscriptionExpiryDateDisplay/>
</CheckOutRecord>

Result:
array

I'm hoping to be able to specify the "No Results" behavior in the views UI for each field. To specify what the text should read if no value is present.

JayShoe’s picture

JayShoe’s picture

FileSize
15.44 KB

Attached.

PatchRanger’s picture

Status: Needs review » Needs work

When going to the sandbox home page there is a bar that contains a git command... It's a bit misleading I suppose. But I guess this isn't an issue with this module - rather one for drupal.org!

I guess it was the module fault - it had 'master' branch as a default, so drupal.org provided you with wrong command. Now the default branch is set to '7.x-1.x' and 'master' branch is removed - so you can continue to use the "Version control" tab.

I can confirm that this has resolved the issue!

Great!

This patch has fixed the CamelCase issue. But values that have no value in the data, still show "array".
...
I'm hoping to be able to specify the "No Results" behavior in the views UI for each field. To specify what the text should read if no value is present.

I guess you are right, that is the way to go. I am going to re-roll the patch to include suggested proposal.

PatchRanger’s picture

I've fixed it locally and dared to commit it: http://drupalcode.org/sandbox/wesnick/1437134.git/commit/a32380d .
So wait until the latest development snapshot built to download it.
How it works: just use "No results behavior" setting in View UI for field.
UI
Result

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.