Skip to content
This repository has been archived by the owner on Jan 7, 2021. It is now read-only.

Unable to get Sonar Viewer From Stash: Received response with type text/plain instead of JSON #156

Closed
shaunlee0 opened this issue Oct 6, 2017 · 7 comments

Comments

@shaunlee0
Copy link

Hi all,

I have followed the installation instructions, set up my user details in sonar/sonar-scanner arguments and executed the sonar-scanner to get the following exception:

ERROR: Unable to get SonarQube reviewer from Stash org.sonar.plugins.stash.exceptions.StashClientException: Received response with type text/plain instead of JSON at org.sonar.plugins.stash.client.StashClient.extractResponse(StashClient.java:371)

Can you please tell me if this is an issue extracting the response or the response itself from bitbucket for the user. If it is the latter can you please provide the URL that is used when getting a user?

Also, does your sonar instance have to be publically accessible by the URL you provide in order to allow bitbucket to communicate with it? Or is it all handled by the user auth within the plugin/arguments.

Thanks,
Shaun

@t-8ch
Copy link
Contributor

t-8ch commented Oct 9, 2017

Hi @shaunlee0 ,

The only communication that has to be possible is from the system running the sonar scanner to both BitBucket and SonarQube.
Can you make sure you have the correct url for BitBucket configured? (Also including redirects)

@shaunlee0
Copy link
Author

I have the correct sonar.stash.url set, what are the redirect urls? and how do I set these, they are not mentioned in the documentation.

It would help if you supplied the endpoint you use to authenticate reviewers along with how you create these requests so I can test this communication.

If I do a wget from the system running sonar scanner to the bitbucket url used and I get a 200 along with a permission denied when it tries to output the index.html. How do you authenticate these requests? I have supplied a valid bitbucket user and password, would have thought I would receive an authentication failed message rather than this "Received response with type text/plain instead of JSON" error message.

@shaunlee0
Copy link
Author

I can get my user using: https://api.bitbucket.org/1.0/users/shaunlee0 But I cannot using the url structure specified in your stash client class which gives a url of: https://bitbucket.org/ridebooker/rest/1.0/users/shaunlee0 that results in a 404.

@shaunlee0
Copy link
Author

shaunlee0 commented Oct 13, 2017

In the debug console log I see the following request fails right before the job fails.

Request DefaultFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: EmptyByteBufBE)
GET /1.0/users/shaunlee0 HTTP/1.1
Content-Type: application/json
Accept: application/json
Accept-Encoding: gzip,deflate
Host: api.bitbucket.org
Authorization: Basic XXX
User-Agent: SonarQube/6.5.0.27846 Stash/1.3.0-SNAPSHOT AHC/2.0

Response DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
HTTP/1.1 403 Forbidden
Server: nginx
Content-Type: text/plain
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Date: Fri, 13 Oct 2017 18:59:43 GMT
X-Served-By: app-142
X-Static-Version: 38c40bdeb954
ETag: "13102fd01f7456de2d6501b5185325a9"
X-Render-Time: 0.615251064301
Connection: keep-alive
X-Version: 38c40bdeb954
X-Request-Count: 221
X-Frame-Options: SAMEORIGIN
Content-Length: 91

I changed the host to api.bitbucket.org due to having issues using the current url structure (see previous comment).

@shaunlee0
Copy link
Author

Acording to the documentation, a 403 from bibucket cloud API signifies the following:

403 FORBIDDEN : Returned if the caller attempts to make a call or modify a resource for which the caller is not authorized. The request was a valid request, the caller's authentication credentials succeeded but those credentials do not grant the caller permission to access the resource.

@shaunlee0
Copy link
Author

I am using bitbucket cloud if this effects how any of this works and how the API is used (if it even can be).

@t-8ch
Copy link
Contributor

t-8ch commented Oct 16, 2017

@shaunlee0 Unfortunately this plugin only support bitbucket server (so far).
Patches to also support Bitbucket cloud are welcome though, also see #66

Note: you leaked your password in your debug log. I removed it, but you should regard this password as compromised.

@t-8ch t-8ch closed this as completed Oct 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants