Google cloud endpoints wrong response - google-app-engine

I was working with Google cloud endpoints and everything was fine.
But when I updated my Android key and web key to production mode every request returns
200 null or 400 null.
I have rebuilt the project and nothing worked I am trying in both Android and api explorer and both return : status code then null
Despite that the full result is contained in the response in JSON format .
I get the response but the status message always null
You can try it at this URL and see the result :
https://apis-explorer.appspot.com/apis-explorer/?base=https%3A%2F%2Fcutter-1215.appspot.com%2F_ah%2Fapi#p/userRegistrationApi/v1/userRegistrationApi.signUser
UPDATE:
After some experiments the status message returned by Google chrome or android device is null , but on Firefox it's not null and working.
I don't know what is the reason for that

The latest chrome version have an issue with this thing. Hope to get it fixed soon in next release or update of chrome.
Even i am facing the same issue. A simple workaround would be testing endpoints in other browsers(IE/Firefox/Safari).
Hope this helps.

I have found that the problem is Google Chrome new Algorithm maybe it removes some headers to make it's browser faster.
The solution is on chrome just don't use it and use any other browser and it should work correctly.
But, on Android especially Lollipop (5.0) it's based on Chromenum which is based on Chrome ... the same problem that I faced with google chrome I faced with android and null response was the response.
I have changed the user agent for my Google cloud endpoints to Firefox and everything worked correctly.
private static final String firexFox_userAgent = "Mozilla/5.0 (Windows NT 6.1; rv:40.0) Gecko/20100101 Firefox/40.0";
private static final HttpRequestInitializer intializer = new HttpRequestInitializer() {
#Override
public void initialize(HttpRequest request) throws IOException {
final HttpHeaders headers = request.getHeaders();
List<String> agents = new ArrayList<>();
agents.add(firexFox_userAgent);
headers.put("User-Agent", agents);
}
};
and added it to the api builder
private static UserRegistrationApi mUserRegApi mUserRegBuilder = new UserRegistrationApi.Builder(EnpointConsts.sAndroidHttp, EnpointConsts.sGsonFactory, CredentialHolder.getCredential()).setApplicationName(Consts.APP_ID).setHttpRequestInitializer(intializer);

Related

RESTfulWebServiceClient find returning 404 error in Codenameone

I've setup a basic java json api for testing. I can access it through a web browser, or with Rest.get("https://guarded-thicket-52527.herokuapp.com/users").jsonContent(). However when I try the following code:
RESTfulWebServiceClient client = new RESTfulWebServiceClient("https://fatidique-croissant-89302.herokuapp.com/users");
client.find(
new Query(), rowset -> {
});
It gives me a 404 error. I haven't started trying to deal with the data, since I get the 404 before I can get to it.
The network monitor shows going to the url fatidique-croissant-89302.herokuapp.com/users/0/29. I've fixed it by adding doing new Query().id("") instead of just new Query() to go directly to the address provided.

Post xhr blob request (300kb) failed with Firefox and App engine flexible environnement

When I test my website in SSL context with load balancer. Impossible to post a big GZIPed content (300kB) . The request freeze in firebug. If the request lighter, it works.
It works perflecty with Chrome or others browsers.
I don't see log request on the app engine instance. Don't see log in the nginx. Don't see log on load balancer during the request. When the request fail, I see logs and the logs say it take 60seconds (timeout)
I see the same problem here :
Ajax post being aborted by firefox (not seen in Chrome or IE)
(Using fiddler proxy also worked)
Tried with "async: false" does not worked.
Tried to use "setTimeout" around the ajax call does not worked.
Note that when I use the app directly to the instance without load balancer, opening the ports, it work perflectly.
It work perfectly in localhost with SSL configured. (self signed certificate)
Note that when I use the app without SSL and with the load balancer it work perflectly.
The request appear in firebug with empty information (the last request) and stay like this and without return code.
Following here, it could be relative to the load balancer configuration.
Firefox AJAX POST w/ FormData Never Completes
But it's the Google App engine load balancer. I don't have the hand on it and don't know the stack.
Equivalent problem here :
ajax request not work in Firefox
Also, when I use Fiddler proxy to intercept the request and decrypt it, it works !
I used formData to send the GZIP data and it works now.
var formData = new FormData();
var blob = new Blob([binary]);
formData.append("file", blob);
that.postDataBody = formData;
instead of
that.postDataBody = new Blob([binary]);

Migrating to firebase from channel api

I am trying to migrate from Channel API in GAE to firebase. To do this, first, I am trying to setup a local development environment. I cloned the sample app from GAE samples. (Link to sample)
When I ran this, I get the following error, when the web client is trying to authenticate with the firebase DB.The error is in the console.
Screenshot of the error
i.e token authentication failed.Clearly, this points to the fact that generated JWT is not correct.
To be sure, I have done the following:
Created a service account in Google cloud console.
Downloaded the JSON and pointed to this JSON in the environment variable "GOOGLE_APPLICATION_CREDENTIALS"
Put the code snipped from the firebase into WEB-INF/view/firebase_config.jspf file
The code to generate the token is as follows ( from FirebaseChannel.java )
public String createFirebaseToken(Game game, String userId) {
final AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService();
final BaseEncoding base64 = BaseEncoding.base64();
String header = base64.encode("{\"typ\":\"JWT\",\"alg\":\"RS256\"}".getBytes());
// Construct the claim
String channelKey = game.getChannelKey(userId);
String clientEmail = appIdentity.getServiceAccountName();
System.out.println(clientEmail);
long epochTime = System.currentTimeMillis() / 1000;
long expire = epochTime + 60 * 60; // an hour from now
Map<String, Object> claims = new HashMap<String, Object>();
claims.put("iss", clientEmail);
claims.put("sub", clientEmail);
claims.put("aud", IDENTITY_ENDPOINT);
claims.put("uid", channelKey);
claims.put("iat", epochTime);
claims.put("exp", expire);
System.out.println(claims);
String payload = base64.encode(new Gson().toJson(claims).getBytes());
String toSign = String.format("%s.%s", header, payload);
AppIdentityService.SigningResult result =
appIdentity.signForApp(toSign.getBytes());
return String.format("%s.%s", toSign,
base64.encode(result.getSignature()));
}
Instead of Step #2, have also tried 'gcloud auth application-default login' and then running after unsetting the environment variable - resulting in the same issue
Appreciate any help in this regard.
After further research, I found out additional info which may help others facing the same issue. I did the following to be able to run the sample locally.
Its important to ensure that the service account in appengine has the permissions to access resources. Chose "Editor" as the role for permissions (other levels may also work, but I chose this) for the default appengine service account. This will ensure that you do not run into "Unauthorized" error.
My application was enabled for domain authentication and did not use Google authentication. The sample however has been created for Google authentication. I had to make changes to the sample code to send the userId as part of the URL and removed the code that referred to UserServiceFactory.
The console error did show up even now, but the application worked fine. This error probably can be ignored. In the deployed environment, however, this error does not show up.
I would appreciate if Google/Firebase engineers update this answer with official responses, or update the sample documentation appropriately as currently this information does not seem to be mentioned anywhere.

Google App Engine connection request timeout error

I am working on a GAE web app which shows movie related data.To get the movie data I am using API from OMDB (http://www.omdbapi.com/) .Below is the code snippet I use to connect to the API.
When i run it locally it works perfectly fine, but doesn't work when deployed on GAE. It throws connection timeout exception, i tried increasing connection timeout period but that didn't work.
String URLstr = "http://www.omdbapi.com/?t="+URLEncoder.encode(Request,"utf-8");
URL url=null;
URLConnection uc = null;
BufferedReader bf = null;
try {
url= new URL(URLstr);
uc = url.openConnection();
uc.setConnectTimeout(15* 1000);
bf = new BufferedReader(new InputStreamReader(uc.getInputStream()));
} catch (IOException e) {
throw new IllegalArgumentException(e.getMessage());
}
Is my code incorrect? are there some restrictions with GAE that i missed?
Your code looks correct. I am having the exact same issue with OMDB API and Google App Engine as of a few weeks ago. I reached out to Brian who runs OMDB API regarding this and I think it had to do with the App Engine IP range being blocked because of abuse a few weeks ago.
I created the following webapp to figure out what external IP address the url fetch from my app was showing up as to the OMDB servers. I deployed the following to GAE to get the public IP.
import webapp2
import logging
from google.appengine.api import urlfetch
class ifconfig(webapp2.RequestHandler):
def get(self):
url="http://ipecho.net/plain"
urlfetch.set_default_fetch_deadline(60)
result = urlfetch.fetch(url)
logging.debug("I think my external IP is %s " % result.content)
self.response.write(result.content)
app = webapp2.WSGIApplication([
('/ifconfig', ifconfig)
])
In Google App Engine, I went to the instances tab and shutdown the instance, and checked what external IP the new instance had. I did this several times, and in my case it seemed like the external IPs were all coming from 107.178.195.0/24, so I provided this information to OMDB API.
I guess this was in the banned IP block, and Brian was able to unblock that range. This fixed my issue and requests to the API started working again.
This possibly might have resolved the issue for you as well, but if it didn't, you might want to figure out what your public IP is and reach out to Brian to see if it's in an IP range that's being blocked

Selenium Webdriver : How to get All cookies in the Current page

Trying to get all cookies in the current page using Chrome driver with java .
Please help me to retrieve all cookies in the page once after close browser and trying to open new browser with old cookies.
Using the WebDriver API available at:
http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebDriver.Options.html
Get all cookies for current page and parse to Collection of cookie Objects:
driver.manage().getCookies();
//TODO Parse results to Cookie Objects and Do what you want
Getting cookies from all domains
In automated tests there might be instances where we have to validate cookies of a website.
Webdriver has simple and powerful API to retrieve cookies of current page domain. Here is the sample code to read cookies:
public Dictionary<string, string> GetAllPageCookies()
{
return _driver.Manage().Cookies.AllCookies.ToDictionary(cookie => cookie.Name, cookie => cookie.Value);
}

Resources