For those who want to service the local GCS files that were created in the GAE GCS library, one solution is to expose the Java servlet as follows:
package my.applicaion.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.google.appengine.api.blobstore.BlobKey; import com.google.appengine.api.blobstore.BlobstoreService; import com.google.appengine.api.blobstore.BlobstoreServiceFactory; public final class GoogleCloudStorageServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { final BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService(); final String fileName = "/gs" + request.getPathInfo(); final BlobKey blobKey = blobstoreService.createGsBlobKey(fileName); blobstoreService.serve(blobKey, response); } }
and in your web.xml:
<servlet> <servlet-name>GoogleCloudStorage</servlet-name> <servlet-class>my.applicaion.servlet.GoogleCloudStorageServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>GoogleCloudStorage</servlet-name> <url-pattern>/gcs/*</url-pattern> </servlet-mapping>
If you host this servlet in your GAE application, the URL to access the GCS file with bucket-name and fileName is http://localhost:8181:/gcs/bucket-name/fileName , then the serverβs local port number GAE's development is 8181 .
It works, at least from GAE v1.9.50.
And if you intend to use the local GCS server in unit test with Jetty, here is the work, hopefully with the right comments:
final int localGcsPortNumber = 8081; final Server localGcsServer = new Server(localGcsPortNumber); final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); final String allPathSpec = "/*"; context.addServlet(new ServletHolder(new HttpServlet() { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService(); final String fileName = "/gs" + request.getRequestURI(); final BlobKey blobKey = blobstoreService.createGsBlobKey(fileName); if (blobKey != null) {
source share