Unable to update GCP deployment using Java deployment manager SDK - java

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.

Related

Sending templates through Mailgun Java API returns 400 despite following spec

I am trying to use the mailgun Java API for my kotlin project and want to send emails using templates. I believe I have followed the docs but I am getting a 400 Bad Request response.
My kotlin code looks like:
val client = MailgunClient.config("https://api.eu.mailgun.net/", "<raw-api-key>")
.logLevel(Logger.Level.HEADERS)
.createApi<MailgunMessagesApi>(MailgunMessagesApi::class.java)
val message = Message.builder()
.from("Sender name <sender#domain1.com>")
.to("receiver#domain2.com")
.template("template_name")
.subject("Hello")
.mailgunVariables(
mapOf(Pair("param1": "Hello"), Pair("param2": "world"), Pair("param3": "2020-01-01"))
.build()
client.sendMessageFeignResponse(domain, message)
The response logging I get says:
HTTP/1.1 400 Bad Request
access-control-allow-credentials: true
access-control-allow-origin: *
cache-control: no-store
content-length: 78
content-type: application/json;
date: Thu, 22 Dec 2022 00:54:29 GMT
strict-transport-security:
x-xss-protection: 1; mode=block
{}
feign.Response$ByteArrayBody#1744d3cb
I have tried the following and it works in the command line:
curl -s --user 'api:<raw-api-key>' \
https://api.eu.mailgun.net/v3/<user-domain>/messages \
-F from='Sender name <sender#domain1.com>' \
-F to=receiver#domain2.com \
-F template='template_name' \
-F subject='Hello' \
-F t:variables='{"param1": "Hello", "param2": "world", "param3": "2020-01-01"}'

bmsubmit is not working due to Bad Request 400. Why?

I am using byteman 4.0.17. Installing byteman succeeded. Using bmsubmit.sh tool is throwing an error.
$ byteman-download-4.0.17/bin/bmsubmit.sh -y
Failed to process request: java.lang.Exception: Invalid name/value pair in line [HTTP/1.1 400 Bad Request]. Full response below:
HTTP/1.1 400 Bad Request
Content-Type: text/plain; charset=utf-8
Connection: close
400 Bad Request
java.lang.Exception: Invalid name/value pair in line [HTTP/1.1 400 Bad Request]. Full response below:
HTTP/1.1 400 Bad Request
Content-Type: text/plain; charset=utf-8
Connection: close
400 Bad Request
at [org.jboss.byteman.agent.submit.Submit.listSystemProperties][1](Submit.java:767)
at org.jboss.byteman.agent.submit.Submit.main(Submit.java:1113)
$
Also when I try to submit a rule I get an error.
$ byteman-download-4.0.17/bin/bmsubmit.sh -l /mnt/jenkins/FileDescriptorLeak.btm
HTTP/1.1 400 Bad Request
Content-Type: text/plain; charset=utf-8
Connection: close
400 Bad Request
$
Am I doing something wrong here ?
########################################################################
#
# Rule to trace opening files
#
RULE FileOutputStream open trace
CLASS java.io.FileOutputStream
METHOD <init>
AT EXIT
IF TRUE
DO traceStack("*** Called init in thread " + Thread.currentThread().getName() + "\n", 30)
ENDRULE
The solution to the issue is to define an unused port when using the bminstall command. With the -p flag.

QAF: '401 Unauthorized: Access is denied' when running script with NTLM request

I already implemented the NTLMAuthClient class
rest.client.impl=com.qmetry.qaf.automation.ws.client.NTLMAuthClient
into the project properties but still getting the aforementioned error.
Here is the JSON request template I am using and I am not sure whether the structure is what causes the error:
{
    "headers":
    {
        "Authorization":
        [
            {
                "username": "${ntlm.user}",
                "password": "${ntlm.password}"
            },
            {
                "domain": "${ntlm.domain}"
            }
        ],
        "Content-Type":"application/json"
    },
    
    "endPoint": "",
    "baseUrl": "${base_url}/api/data/v4/contacts(integrationkey='${clientNumber}')",
    "method": "PATCH",
    
    "body":
    {
    "userid": ""
    }
}
And here's the response from the QMetry report:
Request
Client out-bound request PATCH
https://xxxx.com/CRMDEV2/api/data/v4/contacts(integrationkey='xxxx')
Authorization: [{username=xxxx, password=xxxx},
{domain=xxxx}] Content-Type: application/json
{"userid":""}
Reponse
Client in-bound response 401 REQ_ID:
3d391170-40d7-4ea6-80ca-2531a7fe73ff Server: WWW-Authenticate: NTLM
WWW-Authenticate: Negotiate Set-Cookie:
ReqClientId=21490c2c-bdfe-4c00-9330-401ca0bb5811; expires=Thu,
22-Oct-2071 11:59:11 GMT; path=/; secure; HttpOnly Content-Length: 49
Date: Fri, 22 Oct 2021 11:59:11 GMT Content-Type: text/plain HTTP
Error 401 - Unauthorized: Access is denied
Appreciate the help.
QAF and Selenium version I am using:
QAF version: 2.1.14
Selenium: 3.141.59
Refer NTLMAuthClient java-doc. Instead of Authorization in request call header, you should try providing properties used by NTLMAuthClient.
NTLMAuthClient class uses following properties:
ntlm.user - The user name. This should not include the domain to authenticate with. For example: "user" is correct whereas "DOMAIN\\user" is not.
ntlm.password - The password
ntlm.workstation - workstation (default is blank) The workstation the authentication request is originating from. Essentially, the computer name for this machine.
ntlm.domain- domain The domain to authenticate within (default is blank).
#register NTLMAuthClient
rest.client.impl=com.qmetry.qaf.automation.ws.client.NTLMAuthClient
set above properties in your property file and then try without authorization in request call header.

OAuth2 authorization code flow: spring-security does not accept the issued access_token

I am learning the OAuth2 authorization code flow.
I have my own Authorization Server (AS) which is OpenAM 7.1.
The Client is a simple Spring-Boot web application with a static HTML page, I use Spring-Security to protect the HTML page and control the Oauth2 flow.
I think that my Authorization Server configuration is correct because AS produces the access_token at the end when I simulate the communication with CURL.
But somehow Spring-Security does not want to accept the issued and validated access token. So I think that my Spring-Security configuration is not correct.
I tried to configure Spring-Security in many different ways, but unfortunately, none of them was working.
Maybe I need to implement the steps that I execute with CURL with Spring-Security, but maybe I just missed a configuration line.
This is the last step of my CURL chain where AS gives me the access token (exchange the authorization code for an access token):
url="$authServerHost/openam/oauth2/realms/root/access_token"
curl \
--silent \
--dump-header - \
--insecur \
--request POST \
--data "grant_type=authorization_code" \
--data "code=$authorizationCode" \
--data "client_id=$clientId" \
--data "client_secret=$clientSecret" \
--data "redirect_uri=$redirectUri" \
"$url"
-------- response ---------
HTTP/1.1 200
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Cache-Control: no-store
Pragma: no-cache
Content-Type: application/json;charset=UTF-8
Content-Length: 157
Date: Wed, 29 Sep 2021 17:57:30 GMT
{
"access_token":"2SiD3moh2iql5j3ocdPOR-W4QRE",
"refresh_token":"zWSG-fi1J9hUrY0Tw6GHeXnndgM",
"scope":"public_profile",
"token_type":"Bearer",
"expires_in":3599
}
This is the probe of the token (validate and retrieve information about the token):
url="$authServerHost/openam/oauth2/tokeninfo"
curl \
--silent \
--dump-header - \
--insecur \
--request GET \
--header "Authorization: Bearer $accessToken" \
"$url"
-------- response ---------
HTTP/1.1 200
X-Frame-Options: SAMEORIGIN
X-Content-Type-Options: nosniff
Cache-Control: no-store
Pragma: no-cache
Content-Type: application/json;charset=UTF-8
Content-Length: 326
Date: Wed, 29 Sep 2021 17:57:30 GMT
{
"access_token":"2SiD3moh2iql5j3ocdPOR-W4QRE",
"grant_type":"authorization_code",
"auth_level":0,
"auditTrackingId":"45f24ab1-f9a4-43df-bb17-4b4d6c0ffee4-112239",
"scope":["public_profile"],
"public_profile":"",
"realm":"/",
"token_type":"Bearer",
"expires_in":3599,
"authGrantId":"2tg__erKRo_utv4Py_TOt1NOtDo",
"client_id":"hello-web"
}
Then I try to fetch the protected content with this CURL but Spring-Security redirects me again to the Spring Security's provider selection page:
url="https://web.example.com:8444/user.html"
curl \
--silent \
--insecur \
--dump-header - \
--request GET \
--header "Authorization: Bearer $accessToken" \
"$url"
-------- response ---------
HTTP/1.1 302
Cache-Control: private
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Frame-Options: DENY
Location: https://web.example.com:8444/oauth2/authorization/openam
Content-Length: 0
Date: Wed, 29 Sep 2021 18:18:40 GMT
As you can see my web-app with Spring-Security does not accept the valid bearer token and redirects the request to the Authorization Server despite I provided the token.
This is my Spring-Security configuration:
spring:
security:
oauth2:
client:
registration:
openam:
client-id: hello-web
client-secret: client-secret
authorization-grant-type: authorization_code
redirect-uri: https://web.example.com:8444/user.html
scope: public_profile
provider:
openam:
token-uri: https://openam.example.com:8443/openam/oauth2/access_token
authorization-uri: https://openam.example.com:8443/openam/oauth2/authorize
And the Spring-Security config I use:
#EnableWebSecurity
public class OAuth2SecurityConfig extends WebSecurityConfigurerAdapter {
#Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests(authorizeRequests -> authorizeRequests
.antMatchers("/").permitAll()
.anyRequest().authenticated()
)
.oauth2Login(withDefaults());
}
}
What did I miss?
Could you please guide me in the right direction?
----> ADDITIONAL INFO <----
When I open the protected page https://web.example.com:8444/user.html in the web browser, then
I am redirected properly to the Authorization Server login page.
Then I log in.
Then the consent approval form appears where I give access to the "public_profile" scope
Then Spring redirects me again to the login page (step 2).
I think that happens because Spring just does not want to accept the issued access token.
Spring log:
open http://web.example.com:8081/user.html
o.s.security.web.FilterChainProxy : Securing GET /user.html
s.s.w.c.SecurityContextPersistenceFilter : Set SecurityContextHolder to empty SecurityContext
o.s.s.w.a.AnonymousAuthenticationFilter : Set SecurityContextHolder to anonymous SecurityContext
o.s.s.w.a.i.FilterSecurityInterceptor : Failed to authorize filter invocation [GET /user.html] with attributes [authenticated]
o.s.s.w.s.HttpSessionRequestCache : Saved request https://web.example.com:8444/user.html to session
s.w.a.DelegatingAuthenticationEntryPoint : Trying to match using And [Not [RequestHeaderRequestMatcher [expectedHeaderName=X-Requested-With, expectedHeaderValue=XMLHttpRequest]], Not [And [Or [Ant [pattern='/login'], Ant [pattern='/favicon.ico']], And [Not [RequestHeaderRequestMatcher [expectedHeaderName=X-Requested-With, expectedHeaderValue=XMLHttpRequest]], MediaTypeRequestMatcher [contentNegotiationStrategy=org.springframework.web.accept.ContentNegotiationManager#6f2273f8, matchingMediaTypes=[application/xhtml+xml, image/*, text/html, text/plain], useEquals=false, ignoredMediaTypes=[*/*]]]]]]
s.w.a.DelegatingAuthenticationEntryPoint : Match found! Executing org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint#23fec83b
o.s.s.web.DefaultRedirectStrategy : Redirecting to https://web.example.com:8444/oauth2/authorization/openam
w.c.HttpSessionSecurityContextRepository : Did not store empty SecurityContext
w.c.HttpSessionSecurityContextRepository : Did not store empty SecurityContext
s.s.w.c.SecurityContextPersistenceFilter : Cleared SecurityContextHolder to complete request
o.s.security.web.FilterChainProxy : Securing GET /oauth2/authorization/openam
s.s.w.c.SecurityContextPersistenceFilter : Set SecurityContextHolder to empty SecurityContext
o.s.s.web.DefaultRedirectStrategy : Redirecting to https://openam.example.com:8443/openam/oauth2/authorize?response_type=code&client_id=example-web&scope=public_profile&state=HYbQUtdrCuQ5dKUtGI6bBoBbLvScCoELGcundKpNGoI%3D&redirect_uri=https://web.example.com:8444/user.html
w.c.HttpSessionSecurityContextRepository : Did not store empty SecurityContext
w.c.HttpSessionSecurityContextRepository : Did not store empty SecurityContext
s.s.w.c.SecurityContextPersistenceFilter : Cleared SecurityContextHolder to complete request
then the Authorization Server's login page appears
then I allow access to the "public_profile" scope
then this happens on the Spring side:
o.s.security.web.FilterChainProxy : Securing GET /user.html?code=1aC6OC44B03k37pACmmD8n-Ol38&iss=https%3A%2F%2Fopenam.example.com%3A8443%2Fopenam%2Foauth2&state=HYbQUtdrCuQ5dKUtGI6bBoBbLvScCoELGcundKpNGoI%3D&client_id=example-web
s.s.w.c.SecurityContextPersistenceFilter : Set SecurityContextHolder to empty SecurityContext
o.s.s.w.a.AnonymousAuthenticationFilter : Set SecurityContextHolder to anonymous SecurityContext
o.s.s.w.a.i.FilterSecurityInterceptor : Failed to authorize filter invocation [GET /user.html?code=1aC6OC44B03k37pACmmD8n-Ol38&iss=https%3A%2F%2Fopenam.example.com%3A8443%2Fopenam%2Foauth2&state=HYbQUtdrCuQ5dKUtGI6bBoBbLvScCoELGcundKpNGoI%3D&client_id=example-web] with attributes [authenticated]
o.s.s.w.s.HttpSessionRequestCache : Saved request https://web.example.com:8444/user.html?code=1aC6OC44B03k37pACmmD8n-Ol38&iss=https%3A%2F%2Fopenam.example.com%3A8443%2Fopenam%2Foauth2&state=HYbQUtdrCuQ5dKUtGI6bBoBbLvScCoELGcundKpNGoI%3D&client_id=example-web to session
s.w.a.DelegatingAuthenticationEntryPoint : Trying to match using And [Not [RequestHeaderRequestMatcher [expectedHeaderName=X-Requested-With, expectedHeaderValue=XMLHttpRequest]], Not [And [Or [Ant [pattern='/login'], Ant [pattern='/favicon.ico']], And [Not [RequestHeaderRequestMatcher [expectedHeaderName=X-Requested-With, expectedHeaderValue=XMLHttpRequest]], MediaTypeRequestMatcher [contentNegotiationStrategy=org.springframework.web.accept.ContentNegotiationManager#6f2273f8, matchingMediaTypes=[application/xhtml+xml, image/*, text/html, text/plain], useEquals=false, ignoredMediaTypes=[*/*]]]]]]
s.w.a.DelegatingAuthenticationEntryPoint : Match found! Executing org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint#23fec83b
o.s.s.web.DefaultRedirectStrategy : Redirecting to https://web.example.com:8444/oauth2/authorization/openam
w.c.HttpSessionSecurityContextRepository : Did not store empty SecurityContext
w.c.HttpSessionSecurityContextRepository : Did not store empty SecurityContext
s.s.w.c.SecurityContextPersistenceFilter : Cleared SecurityContextHolder to complete request
o.s.security.web.FilterChainProxy : Securing GET /oauth2/authorization/openam
s.s.w.c.SecurityContextPersistenceFilter : Set SecurityContextHolder to empty SecurityContext
o.s.s.web.DefaultRedirectStrategy : Redirecting to https://openam.example.com:8443/openam/oauth2/authorize?response_type=code&client_id=example-web&scope=public_profile&state=SRHzhN7krlfUhJ50m9lsvaWgLUHglgMOA0wMZHrAmYo%3D&redirect_uri=https://web.example.com:8444/user.html
w.c.HttpSessionSecurityContextRepository : Did not store empty SecurityContext
w.c.HttpSessionSecurityContextRepository : Did not store empty SecurityContext
s.s.w.c.SecurityContextPersistenceFilter : Cleared SecurityContextHolder to complete request
I notice two issues in the code you have shared.
The first is that you may be confusing an OAuth 2.0 resource server and an OAuth 2.0 client.
The application running on web.example.com:8444 is configured as an OAuth 2.0 client.
However, you are making a request to web.example.com:8444, providing a bearer token and asking for a resource.
The client will not validate the bearer token. In this scenario it seems like you are treating the application as if it were a resource server.
If you are looking to create a resource server application, you can see the full documentation in the Spring Security reference.
The second issue is the behaviour you described when accessing the client in the browser.
The problem here is customising redirect-uri: https://web.example.com:8444/user.html.
When doing this you override the default redirect URI, which is /login/oauth2/callback/{registrationId}.
This URI is special because it prompts the OAuth2LoginAuthenticationFilter to process the request, attempt to authenticate the user and create the OAuth2AuthenticationToken.
When you customise redirect URI, the OAuth2LoginAuthenticationFilter is not invoked and the application does not know if the user is authenticated.

google drive sdk error uploading presentations

I'm trying to upload a presentation, using the google api drive, but the presentation goes incomplete some slides are blank, watching the logs this is what shows
com.google.api.client.http.HttpRequest execute: -------------- REQUEST --------------
PUT https://www.googleapis.com/upload/drive/v2/files? uploadType=resumable&upload_id=AEnB2UrDPJgLIehcqH--aWgwl- R_atDhqdvbXnJiWMXKE0V0euJGOvULbM4y5YmvUePWaHSrYyFdOgsmTASJGe-Dtvg09NCkzQ
Accept-Encoding: gzip
Authorization: Bearer ya29.AHES6ZTfSaK77NGCcZO1bK_aTbT8zVX3eslOAb8BkrvpeXARK94XsXY
Content-Range: bytes 0-1048575/6774302
User-Agent: Google-HTTP-Java-Client/1.11.0-beta (gzip)
Content-Type: application/vnd.openxmlformats-officedocument.presentationml.presentation
Content-Length: 1048576
com.google.api.client.http.HttpRequest execute: curl -v --compressed -X PUT -H 'Accept- Encoding: gzip' -H 'Authorization: Bearer ya29.AHES6ZTfSaK77NGCcZO1bK_aTbT8zVX3eslOAb8BkrvpeXARK94XsXY' -H 'Content-Range: bytes 0- 1048575/6774302' -H 'User-Agent: Google-HTTP-Java-Client/1.11.0-beta (gzip)' -H 'Content-Type: application/vnd.openxmlformats-officedocument.presentationml.presentation' -d '#-' -- https://www.googleapis.com/upload/drive/v2/files? uploadType=resumable&upload_id=AEnB2UrDPJgLIehcqH--aWgwl- R_atDhqdvbXnJiWMXKE0V0euJGOvULbM4y5YmvUePWaHSrYyFdOgsmTASJGe-Dtvg09NCkzQ << $$$
com.google.api.client.http.HttpResponse <init>: -------------- RESPONSE --------------
308 OK
server: HTTP Upload Server Built on Oct 3 2012 16:52:30 (1349308350)
range: bytes=0-1048575
x-range-md5: 19230c1c1a0fc493f3431f46cf30c14c
date: Mon, 05 Nov 2012 22:00:33 GMT
pragma: no-cache
expires: Fri, 01 Jan 1990 00:00:00 GMT
cache-control: no-cache, no-store, must-revalidate
content-length: 0
content-type: text/html; charset=UTF-8
x-google-cache-control: remote-fetch
via: HTTP/1.1 GWA
and this is the code that am using:
byte[] myFile = readImageData(blobKey,size);
ByteArrayContent mediaContent = new ByteArrayContent(mimeType, myFile);
Drive.Files.Insert insert = service.files().insert(body, mediaContent);
insert.getMediaHttpUploader().setChunkSize(1024 * 1024);
File file = insert.execute();
UPDATE
doing some testing, it seems the error only occurs when upload presentations with extension .pptx
is there any problem with the mimeType of that extension?
I hope someone can help me, thx in advance.
It seems like the resumable upload protocol is not being implemented correctly. The 308 response code indicates that only a chunk of the request has been uploaded and you should proceed with the next chunk.
Does it work correctly if you remove the following line from your code?
insert.getMediaHttpUploader().setChunkSize(1024 * 1024);

Categories

Resources