Wanted to access files there in Bitbucket from java code. Is there any way to access bitbucket from code.
Yes, there is, checkout the documentation link, Bellow just a preview
You can list files
https://api.bitbucket.org/1.0/repositories/{accountname}/{repo_slug}/src/{revision}/{path}
Or get a file raw content
https://api.bitbucket.org/1.0/repositories/{accountname}/{repo_slug}/raw/{revision}/{path}
Update - 2018-01-04
Based in this article you can use Basic Authentication or oAuth (recommended by Atlassian), as the Basic Authentication is more simple to do then here a full Basic Authentication sample:
$ curl -i https://ElvisDeFreitas:myVerySecretPassword#api.bitbucket.org/1.0/repositories/ElvisDeFreitas/jna-examples/src/4bd1a0f584af/src/main/java/nativeapi/jna/syscall
HTTP/1.1 200 OK
Server: nginx
Vary: Authorization
Content-Type: application/json; charset=utf-8
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Date: Thu, 04 Jan 2018 09:38:27 GMT
X-Served-By: app-142
ETag: "3414c377599e4dc02df7b370ffc557b5"
X-Static-Version: 2cd31fe906e9
X-Content-Type-Options: nosniff
X-Accepted-OAuth-Scopes: repository
X-Credential-Type: password
X-Render-Time: 0.156632900238
Connection: keep-alive
X-Request-Count: 300
X-Version: 2cd31fe906e9
X-Frame-Options: SAMEORIGIN
Content-Length: 668
{
"node": "4bd1a0f584af",
"path": "src/main/java/nativeapi/jna/syscall/",
"directories": [],
"files": [
{
"size": 19248,
"path": "src/main/java/nativeapi/jna/syscall/BytesUtils.java",
"timestamp": "2016-10-18T19:09:06Z",
"utctimestamp": "2016-10-18 19:09:06+00:00",
"revision": "4bd1a0f584af"
},
{
"size": 723,
"path": "src/main/java/nativeapi/jna/syscall/HelloWorldJNA.java",
"timestamp": "2016-10-17T19:45:10Z",
"utctimestamp": "2016-10-17 19:45:10+00:00",
"revision": "40cd9622d67c"
},
{
"size": 611,
"path": "src/main/java/nativeapi/jna/syscall/TestJNA.java",
"timestamp": "2016-10-17T19:45:10Z",
"utctimestamp": "2016-10-17 19:45:10+00:00",
"revision": "40cd9622d67c"
}
]
}
Related
I have searched to send the data as a batch to rest end points. But didn't got a correct solution. Could you please help me on this.
PFB the sample body of the data.
--batch
Content-Type: multipart/mixed; boundary=changeset
--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary
POST CorporateAccountCollection HTTP/1.1
Content-Type: application/json
Content-ID: 2
Content-Length: 10000
{
"Name":"Testing Batch Operation MB",
"RoleCode":"XXXXX",
"CountryCode":"US",
"CorporateAccountIdentification" : [
{
"IDTypeCode":"XXXXXX",
"IDNumber":"9999999999"
}
]
}
--changeset--
--batch--
I'm trying to post several files, the API endpoint accept a file and json File, but I Receive a 415 Response Code
#Test(enabled = true)
public void testResp(){
RestAssured.given()
.baseUri("http://localhost")
.port(8082)
.basePath("/documents/")
.header(new Header("content-type", "multipart+/form-data"))
.multiPart(new MultiPartSpecBuilder(directoryFiles)
.fileName("file.txt")
.controlName("file")
.mimeType("text/plain")
.build())
.multiPart(new MultiPartSpecBuilder(directoryFiles)
.fileName("metadata-txt.json")
.controlName("metadata")
.mimeType("application/json")
.build())
.when()
.post("documents/")
.then()
.log()
.all();
}
Log
HTTP/1.1 405
Allow: GET
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 31 Jul 2020 16:11:55 GMT
Keep-Alive: timeout=60
Connection: keep-alive
{
"timestamp": "2020-07-31T16:11:55.657+00:00",
"status": 405,
"error": "Method Not Allowed",
"message": "",
"path": "/docmgmt/documents/documents/"
}
Now I have a Different Error,
I'm trying to write an application to manage GCP deployments using the Deployment Manager SDK for Java. I'm able to list deployments successfully but unable to update a deployment as the SDK throws an exception shown below.
com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
{
"code" : 404,
"errors" : [ {
"domain" : "global",
"message" : "The object 'projects/--redacted-project--/global/deployments' is not found.",
"reason" : "notFound"
} ],
"message" : "The object 'projects/--redacted-project--/global/deployments' is not found."
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:150)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1067)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
My calling code is:
val content = new Deployment().setTarget(target)
val updateResult = client.deployments().update(project, name, content)
.setCreatePolicy("CREATE_OR_ACQUIRE")
.setDeletePolicy("DELETE")
.setPreview(false)
.execute()
When I switch on debug for the SDK I see the following exchange:
2020-04-13 17:52:36,353 [deploy-akka.deploy-dispatcher-10] INFO c.g.a.c.h.HttpTransport - -------------- REQUEST --------------
PUT https://www.googleapis.com/deploymentmanager/v2/projects/--redacted-project--/global/deployments/--redacted-deployment--
Accept-Encoding: gzip
Authorization: <Not Logged>
User-Agent: Google-API-Java-Client Google-HTTP-Java-Client/1.25.0 (gzip)
Content-Type: application/json; charset=UTF-8
Content-Encoding: gzip
Content-Length: 565
2020-04-13 17:52:36,353 [deploy-akka.deploy-dispatcher-10] INFO c.g.a.c.h.HttpTransport - curl -v --compressed -X PUT -H 'Accept-Encoding: gzip' -H 'Authorization: <Not Logged>' -H 'User-Agent: Google-API-Java-Client Google-HTTP-Java-Client/1.25.0 (gzip)' -H 'Content-Type: application/json; charset=UTF-8' -H 'Content-Encoding: gzip' -d '#-' -- 'https://www.googleapis.com/deploymentmanager/v2/projects/--redacted-project--/global/deployments/--redacted-deployment--' << $$$
2020-04-13 17:52:36,354 [deploy-akka.deploy-dispatcher-10] INFO c.g.a.c.h.HttpTransport - Total: 1,449 bytes
2020-04-13 17:52:36,354 [deploy-akka.deploy-dispatcher-10] INFO c.g.a.c.h.HttpTransport - {"target":{"config":{"content":"imports:\n - path: dep.jinja\n\nresources:\n - name: testing\n type: dep.jinja\n properties:\n env: prod\n banana: yes\n retentionInDays: 5"},"imports":[{"content":"resources:\n- name: riffraff-dataset\n type: bigquery.v2.dataset\n properties:\n location: europe-west2\n datasetReference:\n datasetId: riffraff_test\n- name: test-table\n type: bigquery.v2.table\n metadata:\n dependsOn:\n - riffraff-dataset\n properties:\n datasetId: riffraff_test\n tableReference:\n tableId: banana\n schema:\n fields:\n - name: species\n type: string\n - name: plantation\n type: string\n - name: harvested\n type: date\n - name: quantity\n type: numeric\n - name: edible\n type: boolean\n{% if properties['banana'] == \"yes\" %}\n- name: test-topic\n type: gcp-types/pubsub-v1:projects.topics\n properties:\n topic: riffraff-topic\n{% endif %}\n- name: riffraff-bucket\n type: storage.v1.bucket\n properties:\n location: europe-west2\n storageClass: STANDARD\n iamConfiguration:\n uniformBucketLevelAccess:\n enabled: True\n {% if properties['retentionInDays'] %}\n lifecycle:\n rule:\n - action:\n type: Delete\n condition:\n age: {{ properties['retentionInDays'] }}\n {% endif %}","name":"dep.jinja"}]}}
2020-04-13 17:52:37,174 [deploy-akka.deploy-dispatcher-10] INFO c.g.a.c.h.HttpTransport - -------------- RESPONSE --------------
HTTP/1.1 404 Not Found
Content-Type: application/json; charset=UTF-8
Vary: Origin
Vary: X-Origin
Vary: Referer
Content-Encoding: gzip
Date: Mon, 13 Apr 2020 16:52:37 GMT
Server: ESF
Cache-Control: private
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Alt-Svc: quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,h3-T050=":443"; ma=2592000
Transfer-Encoding: chunked
So it looks like an invalid URL or object.
However if I use the gcloud CLI tool to do the same thing with --log-http I see that it is hitting exactly the same endpoint but not getting a 404:
==== request start ====
uri: https://www.googleapis.com/deploymentmanager/v2/projects/--redacted-project--/global/deployments/--redacted-deployment--?alt=json&preview=False&createPolicy=CREATE_OR_ACQUIRE&deletePolicy=DELETE
method: PUT
Not sure where to go from here.
After further digging I noticed that the fields in the body JSON in the PUT request were different. The gcloud CLI was sending fingerprint, name and target whilst the Java SDK was only sending target.
Tucked away in the documentation for the request body it says that you need to set fingerprint for update and a handful of other methods.
I modified my code to GET the deployment first and include the fingerprint in the request and it began to work.
val content = new Deployment().setName(name).setFingerprint(fingerprint).setTarget(target)
val updateResult = client.deployments().update(project, name, content)
.setCreatePolicy("CREATE_OR_ACQUIRE")
.setDeletePolicy("DELETE")
.setPreview(false)
.execute()
In my view 404 is the wrong error for this. Google should be returning a 400 as the client is not including a required field in the request.
In addition the SDK does a large number of precondition checks to catch invalid requests but does not include this one. I've opened an issue with Google to suggest this.
I'm using Spring Boot v2.1.1.RELEASE together with Spring Security and am trying to log into the application via REST.
I have a configuration file which implements WebMvcConfigurer so I can override the addCorsMappings method:
#Override
public void addCorsMappings(final CorsRegistry registry) {
registry.addMapping("/**");
}
This works fine; I can send my login data to http://localhost:8080/login and get a normal Response back, with session cookie and all:
Access-Control-Allow-Origin: *
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Length: 0
Date: Sun, 20 Jan 2019 13:14:46 GMT
Expires: 0
Pragma: no-cache
Set-Cookie: JSESSIONID=66B74AE4F547BA77604AE199E0A48D7E; Path=/; HttpOnly
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
Mind the Access-Control-Allow-Origin header.
However, if I specify the allowed origins as follows, the Response does not include the formerly mentioned header:
#Override
public void addCorsMappings(final CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("localhost");
}
Will result in the Response:
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Length: 20
Date: Sun, 20 Jan 2019 13:15:15 GMT
Expires: 0
Pragma: no-cache
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
It doesn't matter which origin I am allowing; "http://localhost", "http://example.com" and "example.com" all lead to the same result.
While debugging, I noticed that the authentication process stops at the CorsFilter when I include the allowedOrigins bit in the code.
This is all about the login process! I can't use the #CrossOrigin annotation (as far as I'm aware) because I have no method to put it on.
I am testing the REST login with this script: https://pastebin.com/YezC3wWr
Is this a bug in Spring or by design? Am I missing something here?
EDIT: The "Access-Control-Allow-Origin" header in the response is only sent if the request is sent from an allowed origin, and that was NOT the case. I was hosting the HTML test file on http://localhost:8000, so I had to add this exact URL to the allowed origins on the server. Not localhost, not localhost:8000 but http://localhost:8000. The authentication then succeeds and the header is also included in the response.
If you're running the HTML page on the same domain as the login request, there will be no Origin header in request, thus no Access-Control-Allow-Origin.
Is this the case with your code? do you run the HTML file under http://localhost:8080/ ?
If no, please post the error from the browser's console.
Also, would be great if you can post both request and response headers
Try using "http://localhost:8080".
Do you test it via web browser or POST directly for example with Postman?
I've been using App-Engine as the backend for an Android and iOS application. It's been working without problem with both the local development server (over http) and actual app-engine (over https).
Then I noticed that, while renaming endpoints, I accidentally duplicated a word in the class name of an endpoint: RegionRegionIconsEndpoint instead of simply RegionIconsEndpoint. It was a 1-line fix.
public class RegionRegionIconsEndpoint {
#ApiMethod(name = "getRegionIcons", path="regionIcons", httpMethod = HttpMethod.POST)
public RegionInfoVersion.RegionIcons getRegionIcons(User user, #Named("id") String id)
throws OAuthRequestException {
...
}
}
became
public class RegionIconsEndpoint {
#ApiMethod(name = "getRegionIcons", path="regionIcons", httpMethod = HttpMethod.POST)
public RegionInfoVersion.RegionIcons getRegionIcons(User user, #Named("id") String id)
throws OAuthRequestException {
...
}
}
I generated new cloud-endpoint libraries and continued development using the local development server. All good.
When I deployed it to the real App-Engine service, however, a problem arose. When my app starts, there are a series of calls to other endpoints defined just as the one shown above; these always work fine. Then there are calls to this endpoint. A typical call looks like this:
POST https://my-app.appspot.com/_ah/api/client/v1/regionIcons?id=foo
Authorization is also provided and the expected result comes back most of the time... say 80%. The AE logs look like this:
2014-05-02 21:36:30.551 /_ah/spi/com.example.app.endpoints.RegionIconsEndpoint.getRegionIcons 200 48ms 0kb Google-HTTP-Java-Client/1.16.0-rc (gzip) module=default version=1
70.80.59.221 - - [02/May/2014:18:36:30 -0700] "POST /_ah/spi/com.example.app.endpoints.RegionIconsEndpoint.getRegionIcons HTTP/1.1" 200 149 - "Google-HTTP-Java-Client/1.16.0-rc (gzip)" "my-app.appspot.com" ms=49 cpu_ms=41 cpm_usd=0.000017 app_engine_release=1.9.4 instance=006c1b117c1b2d35341e0f407ae5785a825b65e5
The remaining times, I get a 404 Not Found response and the AE logs have this:
2014-05-02 21:36:30.852 /_ah/spi/BackendService.logMessages 204 16ms 0kb module=default version=1
10.1.0.41 - - [02/May/2014:18:36:30 -0700] "POST /_ah/spi/BackendService.logMessages HTTP/1.1" 204 0 - - "my-app.appspot.com" ms=16 cpu_ms=0 app_engine_release=1.9.4 instance=006c1b117c1b2d35341e0f407ae5785a825b65e5
E 2014-05-02 21:36:30.851
Request URL: https://my-app.appspot.com/_ah/api/client/v1/regionIcons?id=foo
Method: client.getRegionIcons
Error Code: 404
Reason: notFound
Message: service 'com.example.app.endpoints.RegionRegionIconsEndpoint' not found
2014-05-02 21:36:30.802 /_ah/spi/com.example.app.endpoints.RegionRegionIconsEndpoint.getRegionIcons 404 16ms 0kb Google-HTTP-Java-Client/1.16.0-rc (gzip) module=default version=1
70.80.59.221 - - [02/May/2014:18:36:30 -0700] "POST /_ah/spi/com.example.app.endpoints.RegionRegionIconsEndpoint.getRegionIcons HTTP/1.1" 404 166 - "Google-HTTP-Java-Client/1.16.0-rc (gzip)" "my-app.appspot.com" ms=16 cpu_ms=0 cpm_usd=0.000019 app_engine_release=1.9.4 instance=006c1b117c1b2d35341e0f407ae5785a825b65e5
You can see on the Message line that, sometimes, AE is still trying to process the call using the old class name with the duplicated word! I've done searches over my entire code-base and the generated files and I cannot find the string "RegionRegion" anywhere. I've checked the web.xml file a dozen times and it has only the new "RegionIconsEndpoint" class name.
Wondering if somehow Google's servers were keeping old information around, I deployed the new version of my app as 2-dot-my-app.appspot.com. The behavior remains exactly the same except that there are no AE log messages for the requests that fail with 404 on this version. Successful request logs are as before.
Both my Android and iPad apps are experiencing this. In addition, I've managed to reproduce it using the web and Google's API explorer on my-app.appspot.com. In this last case, a successful request shows this:
200 OK
cache-control: no-cache, no-store, max-age=0, must-revalidate
content-encoding: gzip
content-length: 171
content-type: application/json; charset=UTF-8
date: Sat, 03 May 2014 03:07:05 GMT
etag: "G170GGjYGsLnxTffzUEJmTttHzU/LUWzmydK3mjH7IeRbEc_n9J6cDQ"
expires: Fri, 01 Jan 1990 00:00:00 GMT
pragma: no-cache
server: GSE
{
"iconsVid": "foo",
"iconsVersion": 3,
"kind": "client#resourcesItem",
"etag": "\"G170GGjYGsLnxTffzUEJmTttHzU/LUWzmydK3mjH7IeRbEc_n9J6cDQ\""
}
and a failed request shows this:
404 Not Found
cache-control: private, max-age=0
content-encoding: gzip
content-length: 169
content-type: application/json; charset=UTF-8
date: Sat, 03 May 2014 03:08:34 GMT
expires: Sat, 03 May 2014 03:08:34 GMT
server: GSE
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "service 'com.example.app.endpoints.RegionRegionIconsEndpoint' not found"
}
],
"code": 404,
"message": "service 'com.example.app.endpoints.RegionRegionIconsEndpoint' not found"
}
}
again clearly showing an access to the old class name. When trying to do the same to the v2 version that I deployed (2-dot-my-app.appspot.com), it's different. A success request ends like this:
200 OK
cache-control: no-cache, no-store, max-age=0, must-revalidate
content-encoding: gzip
content-length: 171
content-type: application/json; charset=UTF-8
date: Sat, 03 May 2014 03:12:08 GMT
etag: "EP5CWx59se1v4KdDnkfEx7cTkis/LUWzmydK3mjH7IeRbEc_n9J6cDQ"
expires: Fri, 01 Jan 1990 00:00:00 GMT
pragma: no-cache
server: GSE
{
"iconsVid": "foo",
"iconsVersion": 3,
"kind": "client#resourcesItem",
"etag": "\"EP5CWx59se1v4KdDnkfEx7cTkis/LUWzmydK3mjH7IeRbEc_n9J6cDQ\""
}
and a failed request ends like this:
404 Not Found
cache-control: no-cache, no-store, max-age=0, must-revalidate
content-encoding: gzip
content-length: 29
content-type: text/html; charset=UTF-8
date: Sat, 03 May 2014 03:06:10 GMT
expires: Fri, 01 Jan 1990 00:00:00 GMT
pragma: no-cache
server: GSE
Not Found
I don't know what else to try. To me, it looks like a bug in App-Engine.
So... any ideas what is going on here and how to fix or work around it?
2014-05-04: I tried changing the method from POST to GET: exact same behavior. I tried changing the path from regionIcons to regionIconsFoo: exact same behavior. I tried changing the #API version from v1 to v2: exact same behavior.
Finally, I tried changing the name of the class back to the previous (with the duplicated word): I get fewer failures (maybe 5% instead of 20%) but they still occur with the failing requests trying to access the now non-existent class name without the duplicated word.
Restoring the correct name resumes the originally described behavior with the original failure rate.
I've been struggling with similar problem. Check logs on appengine.com project site. You should see log about updating, if it has additional info about error - check it.
Sometimes AE works on local machine well but deployment process reveals some bugs.
Edit:
1. Rename the class back to old "double" name, upload it to AE and check if all requests are working without a bug, if yes, rename the class again. (if it's appengine bug it should fix it).
2. Create as simple as possible api and substitute it with your project. Update it to AE and check with api explorer is everything ok, without methods from your main project. If it's ok, once again swap "test" project with your true one and upload to AE.
This isn't an answer because it doesn't address the cause, but it is my solution.
I duplicated the working class back into the old class name.
public class RegionRegionIconsEndpoint {
#ApiMethod(name = "getRegionIconsOld", path="regionIconsOld", httpMethod = HttpMethod.POST)
public RegionInfoVersion.RegionIcons getRegionIcons(User user, #Named("id") String id)
throws OAuthRequestException {
...
}
}
Now in the log, even though I'm only ever calling getRegionIcons, I see indications that both classes are being called with the "old" version handling about 20% of the requests. It's a hack and I don't like it, but it works and the clients are happy with it.
If you can't beat 'em, join 'em.