Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I'm just trying a simple integration of webservice client. I try to get the value in
http://utopiemetal.fr/test.xml
- I create a webservice named xml Test.
- An operation test_xml calling http://utopiemetal.fr/test.xml with no parameter
- This operation returns a Xml Test : Résultat de la requête data type
- Xml Test : Résultat de la requête is a data type that contains one data type : named "message" (the xml markup) and typed "text"
- I create a Rule that calls this webservice operation, and it returns me 45.844 ms Error invoking the REST service xml Test, operation test_xml: Failed to unserialize response
I couldn't find an easier example of xml webservice call... Could someone tell me what I'm doing wrong ?
Thank you all.
Comment | File | Size | Author |
---|---|---|---|
#37 | WS-test-result.png | 333.61 KB | RAWDESK |
#37 | ws-operation.png | 176.47 KB | RAWDESK |
#37 | ws-description.png | 253.87 KB | RAWDESK |
#37 | WS-fulfillment.JPG | 60.28 KB | RAWDESK |
#30 | wsclient-advanced-rest-service-1280332-31.patch | 28.34 KB | dman |
Comments
Comment #1
Beulette CreditAttribution: Beulette commentedI changed the example, to ease the help.
I tryed to show the simplest example I could, and it still didn't work :(
Comment #2
Beulette CreditAttribution: Beulette commentedAnd here is the export of the webservice :
Comment #3
Beulette CreditAttribution: Beulette commentedI solved the problem !!
Actually... no, I didn't...
The module seemed to use only JSON format, and I changed that in my version to make it use only XML... What would be am besten is to use both. Or maybe the module does, and I just didn't find how...
So, I changed this line (lines 43-45 in wsclient_rest.module) :
Actually, only adding a setting "Choose between XML and JSON", just like it's done for "REST/SOAP" could solve this kind of problem ??
If it's a solution, if I'm not wrong, I could develop a little patch (not really hard to do, this change) ...
Comment #4
klausiYes, at the moment you can only define JSON formatted REST services in the UI. If you define a REST service in code you can pass the formatter class in the settings ($service->settings['formatter']). See also #1087538: Support custom formatter to be exportable.
So we need a UI addition in wsclient_rest.module. Implement wsclient_rest_form_wsclient_service_form_alter() and add an option list to select either from JSON or XML. Add a submit handler that saves the corresponding formatter class to $service->settings['formatter'].
Comment #5
alerivrod CreditAttribution: alerivrod commentedI tried to make this change in order to call a webservice which result is in XML format instead of JSON.
I did the same than Belette.
However I got an error because i dont have the constant HttpClientXMLFormatter.
Notice: Use of undefined constant HttpClientXMLFormatter - assumed 'HttpClientXMLFormatter' in WSClientRESTEndpoint->client() (line 45 of sites/all/modules/wsclient/wsclient_rest/wsclient_rest.module).
Do u know how I can solve it? Thank you in advance.
Comment #6
krlucas CreditAttribution: krlucas commentedAttached is a patch that does what @klausi said in #4.
Comment #7
krlucas CreditAttribution: krlucas commentedComment #8
klausiThis has nothing to do with Rules directly, this an Entity property API callback.
param/return documentation is missing? See http://drupal.org/node/1354#functions . But since this a Entity property API callback I think it is enough to add the appropriate @see reference that points to the callback docs.
use entity_load_single() instead.
This will not work when the module is upgraded and the formatter does not exist. Please add an isset() call and a default fallback to JSON. Or you can add hook_update_N() and write a default formatter to all existing service definitions.
why is this json encode/decode necessary? Please add a comment.
?: is only available in PHP 5.3, right? So that will break 5.2 installations.
@param docs are not necessary on form handling functions, see http://drupal.org/node/1354#forms
You are not changing the test cases here, have you checked that they still work? I have not run them myself for a long time, so be prepared for failures ...
Comment #9
klausiAh, I just realized that there is already an isset() check around the formatter setting, so never mind that :)
Comment #10
klausiActually I don't think this is a stable release blocker right now.
Also, supporting configurable formatters seems a bit more work. They can have constructor variables, like the HttpClientXMLFormatter can use a $default_root variable to specify the XML root element. Should we invoke a wsclient_rest_formatter_info hook to collect formatter classes? Should service settings or even operation settings have entries for the constructor arguments of the formatter? And should we expose that in the UI as well?
Also a public example for wsclient_examples testing would be nice, so that we know XML works as we expect.
Comment #11
PatchRanger CreditAttribution: PatchRanger commentedComment #12
PatchRanger CreditAttribution: PatchRanger commentedLooking at the screenshot, I've noticed the typo: the description of 'Adaptive root' is misspelled.
Here is the new patch, fixed.
Interdiff is also attached.
Please note: the patch is git-aware (i.e., was made using
git format-patch
), so it should be applied usinggit am
. See https://drupal.org/node/1146430 for more details.Comment #13
tito.brasolin CreditAttribution: tito.brasolin commentedHello PatchRanger, I just realized that my patch for $request_alter:
https://drupal.org/node/1934274#comment-7667253
... conflicts with yours. According to you, what is the best way to solve the problem? Should I post a new patch? Or maybe you can merge mine into yours, adding support for $request_alter too?
Comment #14
PatchRanger CreditAttribution: PatchRanger commented@tito.brasolin I am glad that you've posted your comment, because I am using both patches too and do have the same trouble. I've handled the conflicts manually, believing that patches will be committed soon. In general I wouldn't prefer to merge patches in order not to harden the reviewing process. But in this particular case it could be the option.
Here is the new re-rolled patch, which introduces merging with yours and some other changes (see interdiff).
Please review.
Comment #15
PatchRanger CreditAttribution: PatchRanger commentedFixing the warnings.
Comment #16
tito.brasolin CreditAttribution: tito.brasolin commentedThank you @PatchRanger, I just did a quick test and everything worked almost fine. My web service is defined in hook_default_wsclient_service() and it worked without any setting... till now.
The fatal error is: "Class name must be a valid object or a string in [...]wsclient_rest.inc on line 40"
Such a beviour may break existing installations, I had to explicitly add a few lines to my module to make it work again:
Comment #17
PatchRanger CreditAttribution: PatchRanger commentedThanks for feedback.
Fixed patch is attached: I had to add update hook - so the patch doesn't have "No migration" advantage anymore :)
Should work for everyone out-of-the-box after running update.
Comment #18
klausiShould be "HTTP".
Comments should start upper case and end with punctuation.
Missing function description. I think you can just use {@inheritdoc} here, see https://drupal.org/coding-standards/docs#inheritdoc
errr, what? This has nothing to do with this issue, so this should not be introduced here. Let's stay focused on the REST UI formatter setting. Otherwise this patch becomes too complicated to review/commit. Other issues can depend on this patch, I think it is not far from being committed.
Doc block is missing. Please check all introduced methods and all classes.
So this breaks existing service descriptions that have defined some other formatter? It will just overwrite it with WsclientRestJSONFormatter. I think we should not alter existing service definitions, we have the extra function anyway? Just mark it as "custom"?
Each @ annotation should also have a description, see https://drupal.org/coding-standards/docs#param . Also elsewhere.
Should be "bool", see https://drupal.org/coding-standards/docs#types
Why do you have to instantiate the formatter? Just use class_implements()? Also elsewhere.
serializer and parser? Why parser? That are bad names. Let's use "send_formatter" and "receive_formatter". We can also make the backward compatible check then, if "formatter" is set we just use that, otherwise the two send/receive formatters.
I find it annoying that we have to provide all that custom formatter classes that just overwrite their parent with one line. Is that really necessary? Why does http_client not provide us with that classes?
Other than that this looks great, good work!
Comment #19
freddura CreditAttribution: freddura commentedCurrently there is no option to exclude empty elements from the request body. I added modified this code to support this functionality. Not sure where this code should belong, so I created an issue for it: #2109963: Option to exclude empty elements from request body
Comment #19.0
freddura CreditAttribution: freddura commentedI totally changed the example to go to the easiest use case I could. And so ease any helper's work :)
Comment #20
smokrisUpdated patch from #17 to apply to latest head.
Comment #21
dman CreditAttribution: dman commentedDarn.
I just came in from looking at a small fix to allow 'optional' arguments to truly be optional, similar to #2045847: The provided argument for parameter is empty and #2109963: Option to exclude empty elements from request body but now I see this behemoth looming here.
This rewrite is ... huge. Though all good I'm sure, and looks well-reviewed by everyone.
Klausi, apart from the important things in the docblocks like http vs HTTP - (which is obviously a release blocker) do I understand that you endorse this whole thing? Should I try to get it in?
If this is to happen at all (and the theory looks good to me), then it's sorta blocking any other further work on REST services at all until it goes in. ... and what seemed to be an easy, the short-and-sweet authentication support fix over in #2138617: OAuth2 authentication for http_client now looks like a terrible conflict I've created etc.
:-(
Comment #22
dman CreditAttribution: dman commented1,2,3 docblock punctuation : done
4 removed the noted lines, I guess someone else should put it in later?
5. docblock added.
6. I'm not sure, but as there is no UI for it currently, any existing code that uses a custom formatter already is probably calling it from code? As this checks update checks empty() before making any change to any remembered settings, I think it's probably OK. But I'm not sure of the use-case you are describing, so I can't see how to create a test case where this would fail. Leaving it as is.
7. If
is unacceptable (it helps my IDE enough), and the choice is therefore between
or to have no annotation at all - then we can can follow the examples set in wsclient.module instead.
So, fixed.
8. fixed.
9. I can't answer that. unchanged.
10 - renamed serializer and parser as requested.
Re-Rolled on top of the current dev
(needed re-merge over a minor authentication issue that doesn't impact this one ... once the merge conflict (function jumped to a different file) was sorted #2138617: OAuth2 authentication for http_client )
So - all of Klausis requests apart from #9 that I can't do and doesn;t seem to stop it working are here now...
So far it still holds together OK (is not broken) but I don't have services to test all the new functionality on.
Comment #23
dman CreditAttribution: dman commentednote, for testing this to update an existing system you need to run update.php, and (it seems) clear cache.
The problem with incorrect undefined (optional) parameters being sent is still a fatal flaw for the APIs (Google services) I'm trying to plug in to, and I need this stable before I can re-roll the fixes for that.
Comment #24
dman CreditAttribution: dman commentedGolly. I find myself back at this issue again, on a different project this time after struggling through the conversion of a GET service to a POST service, and discovering that I needed to switch from the default JSONFormatter to the nice HTTPClientCompositeFormatter that lets me POST a query and get JSON back. goody.
But still, this can only be done in code, and lacks this UI exposure. Even if I *want* to set the formatter in code today, It still needs to be on the service description screen for diagnostics.
Re-running this all today, on a different task, I can re-confirm that
* the patch works great, the UI is there and the choices made do take effect.
* It fixes another issue I had with POST data not being transferred to the REQUEST body(and had my own patch to fix, but this one makes it redundant!)
* The 'upgrade' path/legacy support transition here works exactly as needed - it did not break an old-style WSClient service definition, and just improved it.
It's pretty awesome, and certain bits of what we would expect from the REST client (like being able to use POST method at all are not working without it.
I'm really keen to push this in.
Comment #25
arm75 CreditAttribution: arm75 commentedHello, I am having a hard time applying this patch to 7.x-1.x-dev. Is that the correct version?
The error I am getting is:
Patching file 'wsclient_rest.api.php'
Assertion failed, hunk, file patch.c line 321
I have applyed other patched in the past without issue. Is there something special about this?
BTW, that file wsclient_rest.api.php doesn't exist in my copy of 7.x-1.x-dev.
Any thoughts would be greatly appreciated.
Thanks
Comment #26
dman CreditAttribution: dman commentedNot sure.
I tried a re-run, seems OK.
ran clean for me.
Yes, it's a big patch and adds some re-architecturing - including the creation of the wsclient_rest.api.php file to hold the now-more-structured code.
Comment #27
arm75 CreditAttribution: arm75 commentedThanks for your response.
Ok, I noticed that you get the module from git before you apply the patch, whereas I was simply downloading the module from the modules homepage then applying the patch via unixtools in windows.
Is there a difference in the module when retrieved from git rather then downloaded via the webpage?
Thanks.
Aaron
Comment #28
dman CreditAttribution: dman commented@arm75
Depends on timing, but usually they are the same within an hour (or a day for sandboxes IIRC)
today, the 7.x-1.x-dev tarball says 2014-Jan-10
which matches with the repository history, also with the last change at 2014-01-10 http://drupalcode.org/project/wsclient.git
So no, they *should* not be different.
However, as a matter of course, if you are testing a patch, the much more common workflow would be to be using git primarily. It's not required, no, but generally common.
Comment #29
dman CreditAttribution: dman commentedI'm now on my third independent project where this patch is needed on a *totally different web service* provided from another direction.
The above patch - that allows selection of JSON or XML as supported response formats for HTTP REST queries - is necessary, and amazingly still applies clean! (though does need a cache clear when upgrading)
Still searching for an OPEN web service that will work for testing though... I just need someone to confirm that it doesn't seem to break existing functions. I have found that it still works with all my wsclient_tester examples, though know that's not complete. Please test it out against your existing REST service to see it's not messing up anything unexpected.
Can I get a RTBC on this?
Comment #30
dman CreditAttribution: dman commentedstill applies clean
Comment #31
dieuweThank you! This patch saved my life.
Comment #32
dman CreditAttribution: dman at Sparks Interactive commented@Klausi - I'm happy to put this in, it's working in real world sites for me with no regression.
But due to the size of it, can I get a thumbs-up from you?
It's backwards-compatible with old behaviours, and (though it requires a cache-clear) doesn't seem to break anything I can test for.
Comment #33
klausiI don't have a project where I use wsclient right now, so no real world scenario to test this.
Patch looks good otherwise.
Comment #35
dman CreditAttribution: dman at Sparks Interactive commentedPut that in then, to clear the decks and start looking seriously at some of the smaller issues that have been straggling.
NOTE: YOU WILL NEED TO CLEAR CACHE AFTER UPGRADING.
Comment #37
RAWDESK CreditAttribution: RAWDESK commentedHi,
I am on my first project with ws_client and using latest dev versions of both this module and http_client.
My webservice specification are briefly explained by example in attached WS-fulfillment.jpg illustration.
So i gets to basic HTTP authentication using XML formatting for both request as response.
I would like to trigger my webservices as much as posible by rules.
In attached WS-test-result.png, you can witness the webservice replied with a 400 Bad Request - The XML is not valid according to the XSD.
In the last dpm'nd variable $this->formatter (inside HttpClient.inc) it is clear the HttpCleintCompositeFormatter has been used instead of the by wsclient_rest.module instantiated WsclientRestXMLFormatter. (see dpm: settings-formatter)
Looking into wsclient_rest.inc, i believe to understand that on line 51 the evaluation on wsclient_rest_has_old_formatter should have returned true :
In other words, how can i fully enable HttpClient's XML formatter without understanding the logic behind this legacy supporting has_old _formatter build in deviation ?
PS. I've also attached my WS description as my applied WS operation settings.
PS2. For the basic authentication, i wrote a custom module on hook_wsclient_service_load(), which seem to work.