oobx00
Contributor
Contributor

Invalid Accept Header With PHP SDK 5.1 against 1.5.1 vCloud Director

Jump to solution

Do the samples in PHP SDK 5.1 not work against 1.5.1 vCloud Director?  Will any code that I endeavor to write with the PHP SDK 5.1 really work agains my vCD 1.5.1?  Or, will it fail like the samples?  Is there something that I can do to make the samples and everything work?

My issue seems very similar to http://communities.vmware.com/message/2142668#2142668.  I was having some success with the 1.5 SDK samples against my 1.5.1 vCloud Director.  But, when I upgraded to the PHP 5.1 SDK, all I could get was "invalid accept header" messages, like this:

PHP Fatal error:  Uncaught exception 'VMware_VCloud_SDK_Exception' with message 'POST https://vcloud.mydomain.edu/api/login failed, return code: 400, error: <?xml version="1.0" encoding="UTF-8"?>

<Error xmlns="http://www.vmware.com/vcloud/v1.5" stackTrace="com.vmware.vcloud.api.rest.handlers.exceptions.BadRequestRestApiException: The request has invalid accept header

        at com.vmware.vcloud.api.rest.common.handlers.ErrorHandler.getBadRequestApiException(ErrorHandler.java:71)

        at com.vmware.vcloud.api.rest.common.handlers.ErrorHandler.errorBadRequest(ErrorHandler.java:44)

        at sun.reflect.GeneratedMethodAccessor11639.invoke(Unknown Source)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:173)

        at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:89)

        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:133)

        at org.ap in /home/bob/lib/vcloudPHP-5.1.0/library/VMware/VCloud/ServiceAbstract.php on line 178

After changing VCLOUD_API_VERSION in library/VMware/VCloud/Constants.php from 5.1 to 1.5, I get this:

PHP Fatal error:  Uncaught exception 'VMware_VCloud_SDK_Exception' with message 'POST https://vcloud.mydomain.edu/api/login failed, return code: 401, error: , request data:
' in /home/bob/lib/vcloudPHP-5.1.0/library/VMware/VCloud/ServiceAbstract.php:178
Stack trace:
#0 /home/bob/lib/vcloudPHP-5.1.0/library/VMware/VCloud/Service.php(114): VMware_VCloud_SDK_Service_Abstract->post('https://vcloud....', 200)
#1 /home/bob/lib/vcloudPHP-5.1.0/samples/login.php(78): VMware_VCloud_SDK_Service->login('vcloud.mydomain....', Array, Array)
#2 {main}
  thrown in /home/bob/lib/vcloudPHP-5.1.0/library/VMware/VCloud/ServiceAbstract.php on line 178

A standard API call seems to work:

curl -id testing=true -u scripty@system -H "Accept: application/*+xml;version=1.5" https://vcloud.mydomain.edu/api/sessions

Enter host password for user 'scripty@system':


HTTP/1.1 200 OK

Date: Wed, 28 Nov 2012 17:43:56 GMT

x-vcloud-authorization: rxpTQIswdd15HNz+hZku6BCutGljF5VLUrt0M8x+IGI=

Set-Cookie: vcloud-token=rxpTQIswdd15HNz+hZku6BCutGljF5VLUrt0M8x+IGI=; Secure; Path=/

Content-Type: application/vnd.vmware.vcloud.session+xml;version=1.5

Date: Wed, 28 Nov 2012 17:43:56 GMT

Content-Length: 1009


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

<Session xmlns="http://www.vmware.com/vcloud/v1.5" user="scripty" org="System" type="application/vnd.vmware.vcloud.session+xml" href="https://vcloud.mydomain.edu/api/session/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcloud.the.usg.edu/api/v1.5/schema/master.xsd">

    <Link rel="down" type="application/vnd.vmware.vcloud.orgList+xml" href="https://vcloud.mydomain.edu/api/org/"/>

    <Link rel="down" type="application/vnd.vmware.admin.vcloud+xml" href="https://vcloud.mydomain.edu/api/admin/"/>

    <Link rel="down" type="application/vnd.vmware.admin.vmwExtension+xml" href="https://vcloud.mydomain.edu/api/admin/extension"/>

    <Link rel="down" type="application/vnd.vmware.vcloud.query.queryList+xml" href="https://vcloud.mydomain.edu/api/query"/>

    <Link rel="entityResolver" type="application/vnd.vmware.vcloud.entity+xml" href="https://vcloud.mydomain.edu/api/entity/"/>

</Session>

Switching the version in the raw API call from 1.5 to 5.1 results in the invalid accept header message, which is not surprising, now that I've become familar with the accept header requirement and format.
So, can samples/code from the 5.1 SDK really work against 1.5.1 API?
Thanks!!!

0 Kudos
1 Solution

Accepted Solutions
rkamal
VMware Employee
VMware Employee

Hi,

PHP Fatal error:  Uncaught exception 'VMware_VCloud_SDK_Exception' with message 'POST https://vcloud.mydomain.edu/api/login failed, return code: 401, error: , request data:

    [Rajesh] This looks to me as a username password issue. As it clearly says 401.

After changing VCLOUD_API_VERSION in library/VMware/VCloud/Constants.php from 5.1 to 1.5, I get this:

    [Rajesh] SDK users should not change the code in the library. This is a bug with the SDK for not allowing the users to change API versions via the library(login method accepting the version as well) rather than changing it in the library.
Regards,
Rajesh Kamal.

View solution in original post

0 Kudos
9 Replies
rkamal
VMware Employee
VMware Employee

Hi,

PHP Fatal error:  Uncaught exception 'VMware_VCloud_SDK_Exception' with message 'POST https://vcloud.mydomain.edu/api/login failed, return code: 401, error: , request data:

    [Rajesh] This looks to me as a username password issue. As it clearly says 401.

After changing VCLOUD_API_VERSION in library/VMware/VCloud/Constants.php from 5.1 to 1.5, I get this:

    [Rajesh] SDK users should not change the code in the library. This is a bug with the SDK for not allowing the users to change API versions via the library(login method accepting the version as well) rather than changing it in the library.
Regards,
Rajesh Kamal.

View solution in original post

0 Kudos
oobx00
Contributor
Contributor

Rajesh was right on the money.  I was so distracted by the VCLOUD_API_VERSION constant, I failed to review my config file, even though I saw the 401.  I thought I had tried giving the username/pass on the command line.  Turns out, I had not put @organization in my username in the config.php file.  The $org variable tricked me into thinking that I should put the simple username in $user and my organization in $org.

So, I had this in config.php:

$user = 'scripty';

$org = 'System';

I needed this:

$user = 'scripty@System';

I'm not really sure what $org is for, other than to serve as a default organization to operate on.  Seems to me that if I'm the sysadmin, I would *not* want a default org.  And, if I'm a regular user, my default org would certainly be the organization in my username.

I expect a patch to the SDK to allow for a configurable $vcloud_api_version.  Until then, changing the VCLOUD_API_VERSION to "1.5" allows me to run the PHP 5.1 SDK against my vCloud Director 1.5.1 API.  Thanks for the good work on the SDKs!

I sure wish I had posted sooner.  Thanks for the quick resolution.

0 Kudos
vmir
Contributor
Contributor

Hi,

We run into the same problem, tried to find the solution, and found out that a new version of PHP SDK (5.1.1) was released.

But to our regret the problem is still presented in SDK. The released SDK solves half of the problem with login method, but there is still no way to set version for SetVcloudToken method.

Without setting API version in this method we get the following error:

"GET https://vcloud/api/org/ failed, return code: 406, error: No valid API version can be selected"

The issue can be easily solved by providing an additional parameter apiVersion to SetVcloudToken method (the same way as in login), and invoking $this->setAPIVersion($apiVersion), but according to the license agreement we are not allowed to modify SDK.

Could we expect that this problem will be resolved soon?

Thanks in advance!

--

Vladimir

0 Kudos
rkamal
VMware Employee
VMware Employee

Hi,

For using PHP SDK 5.1.1 against 1.5.X, just override the login method's version from 5.1 to 1.5. This should work.

Just curious, if you have a vCD 1.5.X endpoint. What was the need to use PHP SDK 5.1.1 instead of PHP SDK 1.5.X.

Regards,

Rajesh Kamal.

0 Kudos
oobx00
Contributor
Contributor

Just curious, if you have a vCD 1.5.X endpoint. What was the need to use PHP SDK 5.1.1 instead of PHP SDK 1.5.X.

For me, I just thought I should be trying to use the latest stuff available, where possible. I'm new to the SDK. We hope to be moving to vCloud 5.1 API soon. So, why not learn and write against the new stuff instead of history.

Thanks

0 Kudos
rkamal
VMware Employee
VMware Employee

Hi,

Sounds good.

Did your problem get resolved when using the PHP SDK 5.1.1 against vCD 1.5.X.

Sending the 1.5 version in the login method should solve your issue. The login method in the PHP SDK 5.1.1 sends version 5.1 by default. This needs to be overridden to 1.5 to talk to vCD 1.5.X.

Regards,

Rajesh Kamal.

0 Kudos
oobx00
Contributor
Contributor

I'll get 5.1.1 and try it out. Thanks!

0 Kudos
vmir
Contributor
Contributor

Hi,

Could you clarify what do you mean under "just override the login method's version from 5.1 to 1.5."?

We found a way to work around the issue with SetVcloudToken method without breaking the license agreement:

$service = VMware_VCloud_SDK_Service::getService();
$service->SetVcloudToken($url, $token, $httpConfig);

$httpClient = $service->getHttpClient();
$httpClient->setAPIVersion($apiVersion);
$service->setHttpClient($httpClient);

But this is just a workaround. I think there should be a way to specify version of API in SetVcloudToken method.

Thank you!

--

Vladimir

0 Kudos
oobx00
Contributor
Contributor

We just moved to vCloud 5.1.1 using a wholesale replacement migration due to a vCenter database crash (caused by a power outage).  I think I did connect back to our 1.5 environment at some point.  Thanks for the fix and all the work on the SDK.

Boy, 5.1.1 API sure has some tricks to figure out.  Not that I had done a ton of API work in the old version.  But, the storage profiles and networking architecture changes have given my brain a workout.

Again, thanks for the SDK work!

0 Kudos