Hi i am using SmartFoxServer with a Java extension. Inside that extension i am trying to get firestore instance. Below is the code i am using to connect to service that is working fine inside IDE (Eclipse). but when i deploy my extension on SmartFoxServer it gives a null pointer exception on firestoreOptions.getService
String jsonPath = "data/************.json";
GoogleCredentials credentials = null;
try {
credentials = GoogleCredentials.fromStream(new FileInputStream(jsonPath))
.createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform"));
} catch (FileNotFoundException e1) {
trace("Exception" + e1.toString());
} catch (IOException e1) {
trace("Exception" + e1.toString());
}
FirestoreOptions firestoreOptions = FirestoreOptions.newBuilder().setCredentials(credentials).build();
Firestore db = firestoreOptions.getService();
this.db = db;
try {
run();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
trace("Exception : " + e);
}
Here is the exception i am getting.
com.google.cloud.firestore.FirestoreException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: com.google.cloud.firestore.FirestoreException
Message: java.lang.NullPointerException
Description: Extension initialization failed.
+--- --- ---+
Stack Trace:
+--- --- ---+
com.google.cloud.firestore.FirestoreException.networkException(FirestoreException.java:70)
com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreRpcFactory.create(FirestoreOptions.java:81)
com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreRpcFactory.create(FirestoreOptions.java:71)
com.google.cloud.ServiceOptions.getRpc(ServiceOptions.java:506)
com.google.cloud.firestore.FirestoreOptions.getFirestoreRpc(FirestoreOptions.java:306)
com.google.cloud.firestore.FirestoreImpl.<init>(FirestoreImpl.java:76)
com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreFactory.create(FirestoreOptions.java:62)
com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreFactory.create(FirestoreOptions.java:55)
com.google.cloud.ServiceOptions.getService(ServiceOptions.java:493)
sfs2x.extension.game.quiz.QuizExtension.init(QuizExtension.java:159)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createExtension(SFSExtensionManager.java:303)
com.smartfoxserver.v2.entities.managers.SFSZoneManager.createZone(SFSZoneManager.java:426)
i am new to firestore. Don't know if any jar file/library is missing to run this code on server. any help would be appreciated.
GOOGLE_APPLICATION_CREDENTIALS
environment variable must be added with the correct credential's file path and name to run firestore on server.
Related
Following their guide in usage here I couldn't get started.
The code:
KucoinClientBuilder builder = new KucoinClientBuilder()
.withApiKeyVersion(2)
.withBaseUrl("https://openapi-sandbox.kucoin.com")
.withApiKey("MyKey", "MySecret", "MyPass");
KucoinRestClient kucoinRestClient = builder.buildRestClient();
KucoinPrivateWSClient kucoinPrivateWSClient;
try {
kucoinPrivateWSClient = builder.buildPrivateWSClient();
KucoinPublicWSClient kucoinPublicWSClient = builder.buildPublicWSClient();
} catch (IOException e) {
e.printStackTrace();
}
builder.buildPrivateWSClient() throws an exception with this message:
KucoinApiException{code='400003', message='KC-API-KEY not exists'}
I copied the Api Key and Secret and pass from the api page
What am I missing here? Why the KC-API-KEY does not exist?
The "sandbox" account is different than the original account.
Its domain is different and you need to register in the sandbox version of the website here
I'm trying to send messages to single devices using their token from a Java application. I'm using the Firebase Admin SDK. Below is what I have
FileInputStream serviceAccount = null;
try {
serviceAccount = new FileInputStream("google-services.json");
} catch (FileNotFoundException e2) {
e2.printStackTrace();
}
FirebaseOptions options = null;
try {
options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://MYPROJECTID.firebaseio.com/")
.build();
} catch (IOException e1) {
e1.printStackTrace();
}
FirebaseApp.initializeApp(options);
String registrationToken = "MYDEVICETOKEN";
// See documentation on defining a message payload.
Message message = Message.builder().putData("time", "2:45").setToken(registrationToken)
.build();
// Send a message to the device corresponding to the provided
// registration token.
String response = null;
try {
response = FirebaseMessaging.getInstance().sendAsync(message).get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);
But I get the following exception
java.io.IOException: Error reading credentials from stream, 'type' field not specified.
What am I doing wrong here?
Click on Generate new private key button.
The error means that your google-services.json file contains invalid data. GoogleCredentials class expects your file to have a type property, but it's not there.
Brief googling gave me this post regarding very similar problem. It says:
From the API Manager, just create select "Create credentials" >
"Service Account key" and generate a new key for the Service
that is associated to your Google Play account.
I am writing a sample program using HCatalogue Streaming api
I have a running hadoop, Hiveserver and a Hivemetastore server.
I write a java program to connect to hive metastore.The source code is given below
public class HCatalogueStreamingclient {
public static void main(String[] args) {
System.setProperty("hadoop.home.dir", "E:\\midhun\\hadoop\\hive\\winutils");
String dbName = "hive_streaming";
String tblName = "alerts";
ArrayList<String> partitionVals = new ArrayList<String>(2);
partitionVals.add("Asia");
partitionVals.add("India");
HiveEndPoint hiveEP = new HiveEndPoint("thrift://192.168.10.149:8000", dbName, tblName, partitionVals);
HiveConf conf = new HiveConf();
conf.set("hive.exec.scratchdir", "/tmp/hivetmp");
try {
StreamingConnection connection = hiveEP.newConnection(true,conf);
} catch (ConnectionError e) {
e.printStackTrace();
} catch (InvalidPartition e) {
e.printStackTrace();
} catch (InvalidTable e) {
e.printStackTrace();
} catch (PartitionCreationFailed e) {
e.printStackTrace();
} catch (ImpersonationFailed e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
While running the program I am getting following exception
Exception in thread "main" java.lang.RuntimeException: The root scratch dir: /tmp/hivetmp on HDFS should be writable. Current permissions are: rw-rw-rw-
at org.apache.hadoop.hive.ql.session.SessionState.createRootHDFSDir(SessionState.java:690)
at org.apache.hadoop.hive.ql.session.SessionState.createSessionDirs(SessionState.java:622)
at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:550)
at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:513)
at org.apache.hive.hcatalog.streaming.HiveEndPoint$ConnectionImpl.createPartitionIfNotExists(HiveEndPoint.java:445)
at org.apache.hive.hcatalog.streaming.HiveEndPoint$ConnectionImpl.<init>(HiveEndPoint.java:314)
at org.apache.hive.hcatalog.streaming.HiveEndPoint$ConnectionImpl.<init>(HiveEndPoint.java:278)
at org.apache.hive.hcatalog.streaming.HiveEndPoint.newConnectionImpl(HiveEndPoint.java:215)
at org.apache.hive.hcatalog.streaming.HiveEndPoint.newConnection(HiveEndPoint.java:192)
at org.apache.hive.hcatalog.streaming.HiveEndPoint.newConnection(HiveEndPoint.java:113)
at com.mj.HCatalogueStreamingclient.main(HCatalogueStreamingclient.java:27)
Any one have an Idea on how to grand write permission to the hdfs folder /tmp/hivetmp
The problem is identified.
We need to grand all permission for hadoop directory /tmp/hivetmp.The command for granding permission is $HADOOP_HOME/bin/hadoop fs -chmod 777 -R /tmp/hivetmp
I was running the program in Windows 7 64 bit OS.We need to download winutils appropriate to the operating system and version.
After doing above given points I was able to establish connection using Hive HCatalogue Streaming api
Can someone please explain me how to access the protected web api using a web app client?
I am trying something mentioned here in the following link. But I am always getting
The provided access grant is invalid or malformed.
https://msdn.microsoft.com/en-us/library/azure/dn645542.aspx
Here is the code i am using for java
AuthenticationResult result = null;
try {
final Future<AuthenticationResult> resultFuture = context.acquireTokenByAuthorizationCode(
code, new URI(redirectUri), new ClientCredential(clientId, clientSecret), RESOURCE_GRAPH_API, null);
result = resultFuture.get();
} catch (InterruptedException | ExecutionException e) {
LOG.info("Failed to obtain access token: " + e.getMessage());
} catch (URISyntaxException e) {
}
I'm trying to access my database while using SqlJet Transactions, but I get this error all the time
org.tmatesoft.sqljet.core.SqlJetException: MISUSE: error code is MISUSE
Here is my code:
SqlJetDb db = null;
try {
File dbFile = new File(Configuration.DATABASE_NAME);
db = SqlJetDb.open(dbFile, true);
db.getOptions().setAutovacuum(true);
db.beginTransaction(SqlJetTransactionMode.READ_ONLY);
ISqlJetTable table = db.getTable("customers");
ISqlJetCursor cursor = table.order(table.getPrimaryKeyIndexName());
if (!cursor.eof()) {
do {
getInitData(cursor);
} while (cursor.next());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
db.commit();
} catch (Exception e) {
e.printStackTrace();
}
}
Does anybody know what's wrong with the issue? Due to this list, the actuall library usage was improper, but I've checked it out and there wasn't anything wrong to me. http://grepcode.com/file/repo1.maven.org/maven2/org.tmatesoft.sqljet/sqljet/1.0.2/org/tmatesoft/sqljet/core/SqlJetErrorCode.java#SqlJetErrorCode
Thanks!
It happens because you are trying to open a DB that is already opened by another process .
it happened to me because the db was opened by Firefox SQLite Manager, but basically it could happen by any other thread or process accessing your DB .