Is this Google Endpoints error on the server or client? - java

I've been learning Google Endpoints from the tutorial at https://developers.google.com/appengine/docs/java/endpoints/. I got the Endpoint successfully deployed to Google App Engine and I managed to build a simple iPhone app that calls the Endpoint. However, my iPhone app gets the following error when it tries to call the Endpoint:
Error Message
error NSError * domain: #"com.google.GTLJSONRPCErrorDomain" - code: -32099 0x00000001094518a0
_userInfo __NSDictionaryI * 3 key/value pairs 0x00000001094452b0
[0] (null) #"error" : #"java.lang.IndexOutOfBoundsException: Index: 0, Size: 0"
[1] (null) #"NSLocalizedFailureReason" : #"(java.lang.IndexOutOfBoundsException: Index: 0, Size: 0)"
[2] (null) #"GTLStructuredError" : (no summary)
iPhone API Caller (in Objective-C running in Xcode Debugger)
- (IBAction)myButton:(id)sender {
NSInteger myId;
if (self.mySwitch.isOn) {
myId = 0;
}
else {
myId = 1;
}
GTLQueryHelloworld *query = [GTLQueryHelloworld queryForGreetingsGetGreetingWithIdentifier:myId];
[self.helloWorldService executeQuery:query completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
if (!error) {
[self.myLabel setText:object];
}
else {
[self.myLabel setText:[error description]]; // This line gets called
}
}];
}
I found the same error message reported in Youtube video upload fails after 100 % progress for some users with Backend Error code:-32099 but that pertained to calling YouTube and it was eventually closed as a bug that was fixed. So I don't think it's related.
I believe the bug is on the client side because I put some logging on the server (Java) and it does not appear to get called:
public class Greetings {
private static final Logger log = Logger.getLogger(Greetings.class.getName());
public static ArrayList<HelloGreeting> greetings = new ArrayList<HelloGreeting>();
static {
log.setLevel(Level.INFO);
greetings.add(new HelloGreeting("hello world!"));
greetings.add(new HelloGreeting("goodbye world!"));
}
public HelloGreeting getGreeting(#Named("id") Integer id) {
log.info("HelloGreeting called with getGreeting");
log.info("getGreeting id " + id);
return greetings.get(id);
}
I don't see "HelloGreeting called with getGreeting" in my Google server logs, all I see is the log message indicating that my Endpoint project was successfully deployed:
21:56:45.639 Endpoints: https://1-war-dot-firstendpointproject.appspot.com/_ah/api/helloworld#v1 Saved
I've also confirmed I can successfully test the helloworld.greetings.getGreeting API from the deployed API explorer for my project:
https://1-war-dot-firstendpointproject.appspot.com/_ah/api/explorer
When I call the API from the Explorer it generates a log message:
24.130.150.54 - - [19/Jun/2014:21:17:45 -0700] "POST /_ah/spi/com.google.appengine.samples.helloendpoints.Greetings.getGreeting HTTP/1.1" 200 93 "https://1-war-dot-firstendpointproject.appspot.com/ah/api/static/proxy.html?jsh=m%3B%2F%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.htta44JhPmg.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Fz%3Dzcms%2Frs%3DAItRSTPk1CJ1YqUCyb-H-zhkQTjKPZwvbQ" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/537.75.14" "1-war-dot-firstendpointproject.appspot.com" ms=17 cpu_ms=87 cpm_usd=0.000010 instance=00c61b117ce13f56d6eb483511c2c1bcd24241 app_engine_release=1.9.6
It does not generate "HelloGreeting called with getGreeting" but I suspect that is because I have not configured the logger. At any rate, when my client calls the Endpoint I get no log message at all. Since the API explorer call at least generates 1 log message, I suspect the problem is on the client.
Questions:
1] Is the error I'm seeing generated on the client or the server side?
2] Do you know what array this error is refering to?
3] What are some techniques for debugging a connection problem like this?
Thanks for your help StackOverflowers!
Michael

I think what's going on is as the following: The server runs into an unexpected situation (specifically: it throws an unhanded IndexOutOfBoundsException), hence it cannot return the kind of JSON that the generated client stub expects in its HTTP response (specifically: it returns HTTP status 500 instead of 2xx). The client stub reports this as NSError with domain com.google.GTLJSONRPCErrorDomain and code 32099. The JSON-RPC 2.0 spec defines this error code as "reserved for implementation-defined server-errors".
It would seem that the best way to handle this is add appropriate exception handling either on the server- or client-side, depending on what exactly caused the unexpected situation on the server. An IndexOutOfBoundsException is most likely for the server to handle, as it may stem from an application-level bug.
So to answer the verbatim question: the (original) error is on the server. BTW, unlike the OP I do see related JUL logging output in the Google Developers Console.

I looked at your endpoint and successfully called it in the explorer and with curl. I am pretty sure that the problem is in the client and the server doesn't understand the request.
If you are sure you are calling the client correctly, I would try regenerating it. Perhaps there has been a bugfix since the last time you generated.

Related

Failed getting affiliation at the time of user registration using Fabric Client Java SDK V1.0.1

I have a Hyperledger Fabric V1.0 network setup using Build Your First Network.
I have made the network up by running the command ./byfn.sh -m up.
Now all the Peers, Orderers and CAs(configured in docker-compose-e2e.yaml) are up and running.
This is my docker ps
And I am trying to connect to this network using fabric-sdk-java.
But when doing user registration using the following code
HFCAClient ca = sampleOrg.getCAClient();
final String orgName = sampleOrg.getName();
final String mspid = sampleOrg.getMSPID();
ca.setCryptoSuite(CryptoSuite.Factory.getCryptoSuite());
SampleUser admin = sampleStore.getMember("ädmin", orgName);
if (!admin.isEnrolled()) { //Preregistered admin only needs to be enrolled with Fabric caClient.
admin.setEnrollment(ca.enroll(admin.getName(), "adminpw"));
admin.setMspId(mspid);
}
sampleOrg.setAdmin(admin); // The admin of this org --
SampleUser user = sampleStore.getMember("user", sampleOrg.getName());
if (!user.isRegistered()) { // users need to be registered AND enrolled
RegistrationRequest rr = new RegistrationRequest(user.getName(), "org1.department1");
user.setEnrollmentSecret(ca.register(rr, admin// here comes the error
}
I am getting the error
2017-08-29 07:44:01,132 main ERROR HFCAClient:237 - com.test.blockchain.client.test.SampleUser#73846619
org.hyperledger.fabric_ca.sdk.exception.RegistrationException: Error while registering the user com.test.blockchain.client.test.SampleUser#73846619 url: https://192.168.99.100:7054 POST request to https://192.168.99.100:7054/api/v1/register failed request body {"id":"user1","type":"user","max_enrollments":0,"affiliation":"org1.department1","attrs":[]} with status code: 500. Response: {"success":false,"result":null,"errors":[{"code":0,"message":"Failed getting affiliation 'org1.department1': sql: no rows in result set"}],"messages":[]}
at org.hyperledger.fabric_ca.sdk.HFCAClient.register(HFCAClient.java:236)
at com.test.blockchain.client.test.Test.setup(Test.java:164)
at com.test.blockchain.client.test.Test.main(Test.java:982)
Caused by: java.lang.Exception: POST request to https://192.168.99.100:7054/api/v1/register failed request body {"id":"user1","type":"user","max_enrollments":0,"affiliation":"org1.department1","attrs":[]} with status code: 500. Response: {"success":false,"result":null,"errors":[{"code":0,"message":"Failed getting affiliation 'org1.department1': sql: no rows in result set"}],"messages":[]}
at org.hyperledger.fabric_ca.sdk.HFCAClient.httpPost(HFCAClient.java:609)
at org.hyperledger.fabric_ca.sdk.HFCAClient.register(HFCAClient.java:227)
... 2 more
I am referring the codes shown in the unit test class End2endIT.java
Someone please share your knowledge to find out where I am doing wrong.
Also I am not sure where it is configuring "affiliation":"org1.department1". Do I need to add anything in my .yaml file?
These are the affiliation which are bootstrapped for the any CA containers
> affiliations:
> org1:
> - department1
> - department2
> org2:
> - department1
But there function though which you can add New affiliation based on your organization
await caClient.newAffiliationService().create({ "name": "AFFILIATION_NAME }, adminObj)
You configure the affiliation when you create the crypto material. In your case when you generate the ./byfn.sh -m up command. You have created your keys (your certificates) when you executed the ./byfn.sh -m up, so you don't need to call the CA to register any user.
Also, your error code is the 500, so the cause of your error should be other. Could you try to invoke the chaincode?
Have you changed something in the crypto-config.yaml file? And in the docker-compose-e2e.yaml file?
I'm not sure about the error you are getting for org1.department1. But even I had faced this similar issue while creating new org3. I was getting error Failed getting affiliation 'org3.department1': : scode: 404, code: 63, msg: Failed to get Affiliation: sql: no rows in result set.
To answer where the setting of the Affiliation happens.
It is bootstrapped, which is defined the file /etc/hyperledger/fabric-ca-server/fabric-ca-client-config.yaml of CA Docker container
affiliations:
org1:
- department1
- department2
org2:
- department1
Link to the file : http://hyperledger-fabric-ca.readthedocs.io/en/latest/serverconfig.html
In line:
SampleUser admin = sampleStore.getMember("ädmin", orgName);
you may have to replace the ä in "ädmin".

TokenResponseException: missing scope when using the RemoteAPI of AppEngine in Java with OAuth 2.0 on stand-alone application

My goal is for my stand-alone application to access the datastore of a Google App Engine application so that I can query it. My application used to work with ClientLogin, but I have been asked to use OAuth 2.0 for the authentication (and using ClientLogin doesn't work anymore).
I follow the instructions on this page: https://cloud.google.com/appengine/docs/java/tools/remoteapi
I use the provided code, have made an service account, downloaded the json key, made an environment variable pointing to this key. The result is that I get the following exception:
Exception in thread "main" java.lang.ExceptionInInitializerError
at myApplication.myClass4.moveResultsOfFeature(myClass4.java:51)
at myApplication.myClass2.migrate(MyClass3.java:32)
at myApplication.myClass1.main(Starter.java:11)
Caused by: java.lang.RuntimeException: Failed to acquire Google Application Default credential.
at com.google.appengine.tools.remoteapi.RemoteApiOptions.useApplicationDefaultCredential(RemoteApiOptions.java:163)
at commonMigration.RemoteOptions.<clinit>(RemoteOptions.java:18)
... 3 more
Caused by: com.google.appengine.repackaged.com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "invalid_scope",
"error_description" : "Empty or missing scope not allowed."
}
at com.google.appengine.repackaged.com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105)
at com.google.appengine.repackaged.com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287)
at com.google.appengine.repackaged.com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)
at com.google.appengine.repackaged.com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:384)
at com.google.appengine.repackaged.com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)
at com.google.appengine.tools.remoteapi.RemoteApiOptions.useApplicationDefaultCredential(RemoteApiOptions.java:160)
... 4 more
which seems to point to a missing scope argument, a concern which isn't mentioned in the explication on the web page. Is there an easy way to fix this issue?
Per request, my code (simplified):
public class StackOverflow {
private static RemoteApiOptions REMOTE_OPTIONS = new RemoteApiOptions().server(
<application-id>.appspot.com, 443)
.useApplicationDefaultCredential();
public static void main(String[] args0) throws IOException {
// MAKING THE CONNECTION
RemoteApiInstaller installer = new RemoteApiInstaller();
// LOAD FROM Local
installer.install(REMOTE_OPTIONS);
try {
// MY OPERATIONS
} finally {
installer.uninstall();
}
}
}
This is a current limitation of the Remote API. See the note here:
Note: The Remote API call to useApplicationDefaultCredential() can only use credentials provided by the gcloud command.
(It's possible you followed the instructions before the note was added, since it is a recently discovered limitation). The limitation will be fixed in a future release. For now, you should either run:
gcloud auth login
And use your user account to authenticate using useApplicationDefaultCredential(). Or, you can use a service account with .useServiceAccountCredential, which accepts the service account email and a path to a p12 file instead of the json file.

Java embedded browser

I'm using the embedded browser.
import org.eclipse.swt.browser.Browser;
.....
final Browser g11_embedded_browser = new Browser(g11_capture_script, SWT.NONE);
g11_embedded_browser.setBounds(0, 0, 1000, 260);
g11_embedded_browser.setVisible(true);
...........
try {
uri = new URI("http://127.0.0.1:" + g11_txt_PATH_portnumber.getText());
} catch (URISyntaxException e1) {
System.out.println("failed setting uri");
e1.printStackTrace();
}
System.out.println("uri=" + uri.toString());
try {
url = uri.toURL();
The full url is: http://127.0.0.1:6500
The C program listening on 6500 sometimes responds first time. At other times it takes 2 attempts.
I believe it returns a 204 when the connection fails.
My questions in the hope someone can point me in the right direction are:
Is there any way I can detect the 204? It displays nothing in the browser as it is deemed a successful reply.
Any clue as to why the 204 as the C program never issues a 204 when the request comes from any browser on any OS, just when from the embedded browser.
Note:
The browser displays an internet page before the localhost request so it isn't an embedded browser start up issue. Tried it with and without that.
Tried interleaving requests to the C program from browsers and the Java browser but 100% success externally and about 50% failures from Java on first attempt. Occasionally needs three or even 4 attempts but always works in the end.
A 204 is "204 - The server successfully processed the request, but is not returning any content. Usually used as a response to a successful delete request." However the localhost call is a request for the display of a simple form.

ADAL 4 Android not passing client secret

I'll first say that I'm sure it is just me since people have probably got this to work out of the box without having to edit the ADAL 4 Android Library without editing the source.
When running the sample program and authenticating with a token I get an error from AZURE that it is not passing the client_secret in the message body. I can confirm that this is in fact the case - it is not passing the client_secret.
Although if I edit the OAuth2.java file and change the method buildTokenRequestMessage to something like the following the workflow works perfectly
public String buildTokenRequestMessage(String code) throws UnsupportedEncodingException {
String message = String.format("%s=%s&%s=%s&%s=%s&%s=%s&%s=%s",
AuthenticationConstants.OAuth2.GRANT_TYPE,
StringExtensions.URLFormEncode(AuthenticationConstants.OAuth2.AUTHORIZATION_CODE),
AuthenticationConstants.OAuth2.CODE, StringExtensions.URLFormEncode(code),
AuthenticationConstants.OAuth2.CLIENT_ID,
StringExtensions.URLFormEncode(mRequest.getClientId()),
AuthenticationConstants.OAuth2.REDIRECT_URI,
StringExtensions.URLFormEncode(mRequest.getRedirectUri())
// these are the two lines I've added to make it work
AuthenticationConstants.OAuth2.CLIENT_SECRET,
StringExtensions.URLFormEncode("<MY CLIENT SECRET>")
);
return message;
}
Am I doing something wrong? If not, what is the correct way to access the client secret?
My implementation is straight from the demo application with only changes being setting up the strings to match my endpoints.
Thanks
You need to register your app as a Native application at Azure AD portal. You don't need client secret for native app.

Twiiter4J getDirectMessages() does not work anymore?

I am using Twitter4J 2.2.5 (latest, tried other versions). And can no longer get direct messages to work at all. The same code used to work a while ago. I assume Twitter changed something.
I'm using
Twitter.getDirectMessages()
and it gives the error below. No idea why, I can see the direct messages for the account if I login, but always get this error. The limit error makes no sense, as the account is no where near the limit.
Other API work, like followers/fried/status/etc.
403:The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits (http://support.twitter.com/forums/10711/entries/15364).
Relevant discussions can be on the Internet at:
http://www.google.co.jp/search?q=00919618 or
http://www.google.co.jp/search?q=332bf6ca
TwitterException{exceptionCode=[00919618-332bf6ca], statusCode=403, retryAfter=0, rateLimitStatus=RateLimitStatusJSONImpl{remainingHits=107, hourlyLimit=350, resetTimeInSeconds=1328297, secondsUntilReset=1116, resetTime=Fri Feb 03 14:39:45 EST 2012}, version=2.2.2}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:189)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)
at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:93)
at twitter4j.TwitterImpl.get(TwitterImpl.java:1721)
at twitter4j.TwitterImpl.getDirectMessages(TwitterImpl.java:874)
at org.pandora.sense.twitter.TwitterDirectMessaging.checkDirectMessages(TwitterDirectMessaging.java:44)
at org.pandora.sense.twitter.TwitterDirectMessaging.checkProfile(TwitterDirectMessaging.java:35)
at org.pandora.sense.twitter.Twitter$1.run(Twitter.java:100)
at java.lang.Thread.run(Thread.java:662)
Twitter has some time ago changed the rules for direct messages. An app must be especially authorized by the user to access the direct messages.
Did you make sure this is true for you? You may go to the twitter web site and check for the app.
To get the direct message you should try the below code.It works for me.
getDirectMessages(); gives list of direct messages. We need to put for loop to get text of each message.
List<DirectMessage> messages = twitter.getDirectMessages();
for (DirectMessage message : messages)
{
System.out.println(message.getText());
}
Let me know if you get any error.

Categories

Resources