Google Cloud Endpoints EOFException - java

I have the method below in AppEngine:
#ApiMethod(name = "authed", path = "greeting/authed")
public HelloGreeting authedGreeting(User user) {
...
}
My doInBackground method in Android AsyncTask:
HelloGreeting hg = null;
try {
hg = service.authed().execute();
} catch (IOException e) {
Log.d("error", e.getMessage(), e);
}
return hg;
I encountered the ff error:
/_ah/api/.../v1/greeting/authed: java.io.EOFException
In logcat:
Problem accessing /_ah/api/.../v1/greeting/authed. Reason: INTERNAL_SERVER_ERROR
at java.util.zip.GZIPInputStream.readUByte
at java.util.zip.GZIPInputStream.readUShort
at java.util.zip.GZIPInputStream.readUShort
It only work when calling non-auth method. How to fix it?
Im using the local server.

I was running into a similar problem with when making a call for inserting values. Mine differs slightly because I am not using authentication, however I was getting the same exception. I am using appengine-java-sdk-1.8.8. I was able to make other endpoint calls having this error. I looked at the generated code and the difference that I saw with the working calls versus the non-working calls, was the HttpMethod. The failing call was defined as "POST". I was able to change this using the annotation attribute httpMethod=ApiMethod.HttpMethod.GET in the #ApiMethod annotation.
#ApiMethod(httpMethod = ApiMethod.HttpMethod.GET, name = "insertUserArtist", path = "insertUserArtist")
I then regenerated the client code and I was able to make the call without getting the dreaded EOFException. I am not sure why POST doesn't work properly but changing it to GET worked. This does possibly present some questions on how much data can be sent across and should be addressed (possibly a library issue). I am going to look into creating a demonstration app to submit to Google.

If you passed an "entity" object, then the POST will work. If you are passing primitive data type, you'll be stuck with using HttpMethod.GET.

If you are running on the local dev server,
then add the following snippet in MyApi.Builder to set it up properly after setting root url.
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
#Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
abstractGoogleClientRequest.setDisableGZipContent(true);
}
})
Source: https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloEndpoints

Related

Facebook Java SDK | Marketing API Error #803

I am currently trying to use the Facebook Java SDK to publish ads automatically.
I am just attempting to test my API Authentication using the basic facebook demo code they have provided: https://developers.facebook.com/docs/business-sdk/getting-started/
Here is where I define my APIContext so that I can instantiate my AdAccount:
public static final APIContext context = new APIContext(
"{App Auth Token}",
"{App Secret}"
);
When I execute System.out.println(context.getAppID()); I am returned the ID of the App I have set up within developers.facebook. At this point I think everything is working as intended...?
I then attempt to execute the following code:
AdAccount account = new AdAccount("act_{10405322}", context);
try {
APINodeList<Campaign> campaigns = account.getCampaigns().requestAllFields().execute();
for(Campaign campaign : campaigns) {
System.out.println(campaign.getFieldName());
}
} catch (Exception e) {
e.printStackTrace();
}
}
My application keeps failing with this response:
com.facebook.ads.sdk.APIException$FailedRequestException: {"error":{"message":"(#803) Some of the
aliases you requested do not exist:
act_{10405322}","type":"OAuthException","code":803,"fbtrace_id":"A3uiRKVWUVQyMqZO9GIfWAY"}}
Could someone explain to me why this is the case? act_{10405322} is the ad account I am attempting to reach, so I am not sure why the "alias does not exist"
Thanks!
After rigorous testing, I found two issues that solved my error.
I was using a App Token rather than a Page Access Token
I changed act_{10405322} to act_10405322 and I finally got a successful response.

Unable to retrieve slot information for clusters with admission failover level control policy enabled

I'm experiencing some problems when trying to retrieve the slot information for VMware clusters with admission failover level control policy enabled. I use the VI Java API.
When calling the following method:
clusterComputeResource.retrieveDasAdvancedRuntimeInfo()
I either get the following Exception:
java.rmi.RemoteException: VI SDK invoke exception:java.rmi.RemoteException: Exception in
WSClient.invoke:; nested exception is:
java.lang.NoSuchFieldException: slotInfo
at com.vmware.vim25.ws.WSClient.invoke(WSClient.java:122)
at com.vmware.vim25.ws.VimStub.retrieveDasAdvancedRuntimeInfo(VimStub.java:269)
or I get the result which is of type ClusterDasAdvancedRuntimeInfo
but I need the subclass ClusterDasFailoverLevelAdvancedRuntimeInfo in order to get the SlotInfo field (casting to the required sublcass doesn't work either).
I tried to access the web service of a vcenter directly via Soap UI and it worked without any problems, but with the vijava API it just doesn't.
Thanks in advance for any help!!!
After a lot of of debugging to see what the VI Java API does internally, I found out that if the web service client (wsc) is invoked with the name of the sublcass instead of the name of the superclass (as last parameter), the response will be converted correctly. This way the slot information can be retrieved without any problems. Here is the solution for those experiencing the same problems:
ClusterDasFailoverLevelAdvancedRuntimeInfo clusterDasFailoverLevelAdvancedRuntimeInfo = null;
try {
final Argument[] paras = new Argument[1];
paras[0] = new Argument("_this", "ManagedObjectReference", clusterComputeResource.getMOR());
clusterDasFailoverLevelAdvancedRuntimeInfo = (ClusterDasFailoverLevelAdvancedRuntimeInfo) serviceInstance.getServerConnection().getVimService().getWsc().invoke("RetrieveDasAdvancedRuntimeInfo", paras, "ClusterDasFailoverLevelAdvancedRuntimeInfo");
} catch (final Exception e) {
//error handling
}
(Note that this only works if admission control failover level policy is enabled!!!)

Locally working web-app throws VerifyError on GAE

my web-app based on GWT uses scala-compiler.jar (2.10.3) on its server-side to provide on the fly compiling and executing of Scala code which a user inputs in his/her browser.
It's working fine locally uder GAE SDK 1.8.4 -- when I call service method and pass some trivial script it compiles, executes and logs the resulting string "Hello, Adeal!":
final Object o = AdalModuleEval.eval("class C { override def toString = \"Hello, Adeal!\" }; new C()");
log.warning(o.toString());
But after deploying to Google App Engine server the same code throws me:
exception: java.lang.VerifyError: Bad type on operand stack in method sun.reflect.generics.repository.ClassRepository.getSuperclass()Ljava/lang/reflect/Type; at offset 1
Full stack trace you can see here
It's really disappointing and I'd very appreciate any suggestions about how to resolve this issue.
Thanks in advance,
Alex
You probably solved that or this below is not your case, but for me it was a method catching exceptions like this:
try {
...
} catch (ServiceException | IOException e) {
e.printStackTrace();
}
Once I put a single Exception in every catch everything worked properly

why does documentUrl return null

I'm making a web application for blackberry and I really need the current URL
In the description of documentUrl, it says
This method will return the URL of the currently loaded page of this BrowserField Instance
My code is:
_bf2.requestContent("google.com";);
add(_bf2);
Global.c = _bf2.getDocumentUrl();
Global.be=new BasicEditField("URL: "+Global.c,Global.c);
add(Global.be);
and the weird thing is that www.google.com gets loaded in the BrowserField and the documentUrl returns null.
This is my current code:
BrowserField _bf2 = new BrowserField();
MYBrowserFieldListener _listener = new MYBrowserFieldListener();
_bf2.requestContent("google.com";);
_bf2.addListener(_listener);
String url=_bf2.getDocumentUrl();
Global.be=new BasicEditField("URL: "+url,url);
add(Global.be);
add(_bf2);
I changed it to
final BrowserField _bf2 = new BrowserField();
_bf2.requestContent("google.com";);
//_bf2.addListener(listener);
Global.be=new BasicEditField("URL: "+Global.c,Global.c);
add(Global.be);
add(_bf2);
_bf2.addListener(new BrowserFieldListener(){
public void documentLoaded(BrowserField _bf2, Document document) throws Exception {
Global.c=_bf2.getDocumentUrl();
}
});
But it still returns null. Can someone please tell me how to fix this? Thanks in advance!
I would say that Arhimed has answered your question. An HTTP request is a very time consuming process (from a CPU perspective) and will block until the server responds. I suspect that RIM programmers have coded the requestContent() method as per their own recommendations and are fetching the web content on a separate thread. So, requestContent() will return immediately, when you call getDocumentUrl() it is still null since the fetch thread has probably not even connected to the server at this point.
You will need to implement a BrowserFieldListener and listen for documentLoaded().

Java: Oauth 2.0 How can I use Google API RefreshTokens to avoid requesting access every time my app launches?

There is a lot of sample code for the google API showing how to Get an authorization token and use it, but I cannot find any sample code that shows you how to use the Oauth 2.0 GoogleAccessProtectedResource.refreshToken() method in the java client to get a new authorization token in in Java. Google search turns up nothing, and I can only find a C# example on Stackoverflow. If you could point me to a bit of sample code in Java showing how this is done that would be great. The platform I am working on in Android. An example of the model of OAuth 2.0 I would like to use is here: http://blog.doityourselfandroid.com/2011/08/06/oauth-2-0-flow-android/
Thanks a lot
Answering my own question here. It turned out to be quite straight forward, by calling GoogleAccessProtectedResource.refreshToken() the accesstoken is refreshed inside the class, it can be read and reused as needed through its getter.
You would have to catch 401(unauthorized) errors. After this do something like this.
accountManager.invalidateAuthToken(accessProtectedResource.getAccessToken());
accessProtectedResource.setAccessToken(null);
After this simply get back the token. This time user will not have to authorize access again.
accountManager.manager.getAuthToken(account, AUTH_TOKEN_TYPE, true,
new AccountManagerCallback<Bundle>() {
#Override
public void run(AccountManagerFuture<Bundle> future) {
try {
Bundle bundle = future.getResult();
if (bundle.containsKey(AccountManager.KEY_INTENT)) {
Intent intent = bundle.getParcelable(AccountManager.KEY_INTENT);
intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(intent, REQUEST_AUTHENTICATE);
} else if (bundle.containsKey(AccountManager.KEY_AUTHTOKEN)) {
accessProtectedResource.setAccessToken(bundle.getString(AccountManager.KEY_AUTHTOKEN));
onAuthToken();
}
} catch (Exception e) {
handleException(e);
}
}
}, null);
Refer the task sample for reference and the corresponding article.

Categories

Resources