HTTP code 302 encountered when deploying on Google App Engine Endpoints - google-app-engine

When developing for App Engine Endpoints in Java using the official documentation, after running endpoints.cmd with the appropriate parameters and deploying in GAE, the dev server shows the proper endpoints at http://localhost:8888/_ah/api/discovery/v1/apis, but accessing the explorer for the production version on GAE shows old endpoints at https://<my-app>.appspot.com/_ah/api/discovery/v1/apis.
The error was traced to the HTTP 302 (moved temporarily) code found in the Logs of the production app for access to /_ah/spi/BackendService.getApiConfigs. Until that clears (i.e., gives HTTP 200), Google's servers won't be able to serve the endpoint (See this comment).

This error stems in part due to inconsistent documentation. While the official documentation's sample web.xml uses a <security-constraint> block, that of the sample tictactoe app does not.
If you are getting a HTTP 302 status code, check the following two things (from this post):
in your .api file in WEB-INF, change http to https in the bns declaration,
remove the <security-constraint> block from your web.xml.
The above worked for me; not sure what the security constraint bit was about. Maybe a GAE admin can improve this answer?

Related

Java 11 app running on Google Cloud App Engine fails with 401 error for registering debuggee

I deployed Java 11 app on Google Cloud App Engine, and app is running fine, I can see the home page in the browser, but when the app tries to call Microsoft Graph API (the HTTP call is executed by using Microsoft Graph SDK), I am getting runtime failure.
The failure relates to Google debugger, but I didn't even enable debugger. I found information that debugger is enabled by default when Google builds the container image. I have two options - either to figure out why I am getting 401 error for the debugger, and configure debugger properly, or disable debugger completely.
I tried to find information how to disable Google debugger for container image generation, but didn't find anything helpful. I also tried to find information how to configure debugger properly for app engine, and also was not able to find complete working instructions. Does someone know what I need to configure on App Engine to bypass this error:
java.io.IOException: Server returned HTTP response code: 401 for URL: https://clouddebugger.googleapis.com/v2/controller/debuggees/register
at com.google.devtools.cdbg.debuglets.java.GcpHubClient.registerDebuggee
Assuming your Java app is in an App Engine Standard environment and using the bundled services, then you are still using appengine-web.xml file for app configuration. As stated in GAE standard Issuing HTTP(S) Request documentation:
URL Fetch will handle all outbound requests and cause requests that you send to your VPC network or the client libraries to fail. If any of these scenarios apply to you, make sure that the url-stream-handler field in your configuration is not set to urlfetch.
This scenario includes Google Cloud Debugger Client for Java hence the HTTP error. As a workaround, you can omit the following line in the appengine-web.xml file:
<url-stream-handler>urlfetch</url-stream-handler>

Google App Engine 302 Found response

We have a micro service running on GCloud and to our surprise today a very important callback we expect from a vendor service receives a 302 Found response. Which is not an issue, problem is that vendor is not prepared to adjust their code to follow redirects.
Is their any solution around such cases, some configuration in GCloud we can activate. Funny we don't get 302 when we make calls from local machine and testing environments.
Figured out the issue: In our case vendor was using HTTP protocol instead of HTTPS since we have a secure:always configuration in app.yaml they where getting 302 which makes sense, since app engine was redirecting to HTTPS.

Google App Engine - Does not redirect HTTP traffic to HTTPS

I have recently installed a GoDaddy certificate on my Google App Engine Java App.
All went well and HTTPS links are working when directly accessed.
When I tried to configure all the links which needs to be secured in Web.xml I encountered a redirection issue. From some reason GAE acknowledges the links should be secured but it fails to redirect them to HTTPS (as it should).
I used the following definition in Web.xml:
<security-constraint>
<display-name>SecurityConstraint</display-name>
<web-resource-collection>
<url-pattern>/Login.html</url-pattern>
<url-pattern>/Register.html</url-pattern>
<url-pattern>/Billing.html</url-pattern>
<url-pattern>/PurchaseCredit.html</url-pattern>
<url-pattern>/PastPurchases.html</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
Example: when I try to reach
http://MyDomain/Login.html
I get:HTTP Error 403 (Forbidden): The server refused to fulfill the request.
Instead of:
https://MyDomain/Login.html
It seems that when I turned off Google PageSpeed the problem is solved.
I just read that Google published special notification regarding PageSpeed and HTTPS
https://developers.google.com/speed/docs/pss/faq
It seems that to integrate these two you have to email them for further instructions.
Either way, I am happy I found this, and hope it will save you guys a lot of time.

GAE: API serving not allowed for this application

I am attempting to follow the tutorial at: http://www.youtube.com/watch?v=v9TG7OzsZqQ
My Cloud Endpoint REST API works well on my local development machine, but when I deploy to App Engine, I receive errors in my Admin Log that "API serving not allowed for this application".
Is this a paid feature that I must enable billing to receive? If not, is there documentation that explains this issue and how to fix this error?
To use Endpoints in production you need to be accepted into the trusted tester program. You can apply here. Mention this Stack Overflow post in your request and I'll see if I can expedite approval.

urlfetch.fetch() from Google App Engine not showing up in Fiddler2

I'm testing a Google App Engine app on my Windows machine, running locally on localhost:8084. Fiddler2 shows all my activity when I navigate around my app, but when requesting an external url with urlfetch.fetch() it doesn't show up in Fiddler at all, even when using an http, not an https address, and with a successful status code 200 in the response.
What do I need to do to get the urlfetch.fetch() request from Google App Engine to show up in Fiddler2?
My understanding is that Fiddler2 runs as an HTTP proxy; browser requests go through this proxy instead of directly to the internet resource. This allows Fiddler2 to capture information about the request and the response.
According to the Fiddler2 docs, "You can configure any application which accepts a HTTP Proxy to run through Fiddler so you can debug its traffic". So I think you would need to change the URLFetch API call to use a proxy, supplying the Fiddler URL and port. However, the URLFetch documentation doesn't specify exactly how to do this. You might be able to use urllib2 as specified in this question.
Irussell is generally right, but I'd like to make the answer more specific.
As proxies aren’t supported within Google AppEngine production environment, it’s not directly supported by development engine either. It seems that the only way to overcome this limitation is to modify the code of AppEngine development server.
You'll have to modify the urlfetch_stub.py file, by adding the following lines:
connection = connection_class('127.0.0.1', 8888)
and
full_path = protocol + "://" + host + full_path
You may find the detailed explanation in my blog post Use Fiddler to debug urlfetch requests in Google AppEngine

Resources