Error 404 in URL for encrypt with Google KMS

2019-08-17 18:08发布

问题:

I'm following the tutorial to encrypt data with google cloud kms, but when I try to encryt give me 404 error. I seach in the code and noted that it has DEFAULT_ROOT_URL = https://cloudkms.googleapis.com/. but the root of the url do not appears in the URL, then of couse give error 404. Could someone tell me why the URL was not mounted corretilly. I look in properties and there is no reference for Root_URL.

`

The requested URL /v1beta1/projects/condoease-3f3ea/locations/global/keyRings/test/cryptoKeys/quickstart:encrypt was not found on this server. That?s all we know.

at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
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:1056)
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)
at com.example.getstarted.util.CloudKeyManagementServiceHelper.wrapDataEncryptionKey(CloudKeyManagementServiceHelper.java:129)
at com.example.getstarted.util.CloudStorageHelper.getImageUrl(CloudStorageHelper.java:121)
at com.example.getstarted.basicactions.CreateBookServlet.doPost(CreateBookServlet.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:845)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1689)
at com.example.getstarted.util.DatastoreSessionFilter.doFilter(DatastoreSessionFilter.java:111)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1668)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1160)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1092)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:119)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
at org.eclipse.jetty.server.Server.handle(Server.java:518)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:244)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:246)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:156)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
at java.lang.Thread.run(Thread.java:745)

`

回答1:

API version v1beta1 is no longer supported; can you tell us where you found it documented? I'd like to get it fixed.

You'll also get this uninformative error message if you err in other part of the URLs, such as missing the fixed components like /projects/, /locations/, /keyRings/, or /cryptoKeys/. We'll look at improving it.



回答2:

https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/kms has a good sample to get you started. I don't think the getting-started-java has KMS samples (that I know of).

What version of the library are you using? Your URL is using /v1beta1/ which makes me think you're using an older version. Cloud KMS is GA and should be /v1/.

Update:

Full disclosure I'm an engineer @ Google on Cloud KMS.

https://codelabs.developers.google.com/codelabs/cloud-bookshelf-java-cloud-kms looks like it has instructions to download a legacy java client library which is constructing broken URLs to v1beta1. We've filed an issue internally to track getting this resolved ASAP, thank you for posting your issue!

In the meantime, I'd encourage the above github link to get you started using KMS. Thanks for using the product!