I am not able to Create primary index on couchbase using groovy script. Below are the lines of code I used:-
#Grab('com.couchbase.client:java-client:2.2.6')
import java.util.concurrent.CountDownLatch;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject;
import com.couchbase.client.java.CouchbaseCluster
import com.couchbase.client.java.query.N1qlQuery;
import com.couchbase.client.java.query.N1qlQueryResult;
import com.couchbase.client.java.query.N1qlQueryRow;
import com.couchbase.client.java.query.SimpleN1qlQuery;
import com.couchbase.client.java.env.CouchbaseEnvironment;
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder().connectTimeout(10000).build();
def cluster = CouchbaseCluster.create(env, IPADDRESS);
def bucket = cluster.openBucket(BUCKET_NAME, BUCKET_PASSWORD);
log.info "Connection done"
String queryString = "CREATE PRIMARY INDEX `PrimInd` ON BUCKET_NAME"
bucket.query(N1qlQuery.simple(queryString))
log.info "Primary index created"
It gives me error as below :-
java.lang.RuntimeException: java.util.concurrent.TimeoutException at this line:-
bucket.query(N1qlQuery.simple(queryString))
Connection is being done properly and same query works in couchbase server. So, I think there is problem with my code.
Could you please help me on this?
In the Couchbase Java client, the query() method delegates to a Blocking API which uses JavaRx under the covers. The source code for the Blocking API states:
If an error happens inside the Observable, it will be raised
as an Exception. If the timeout kicks in, a TimeoutException nested in a RuntimeException is thrown to be fully compatible with the Observable.timeout(long, TimeUnit) behavior.
You're experiencing a TimeoutException nested in a RuntimeException, hence the root cause is that your query is timing out.
DefaultCouchbaseEnvironment defaults to a queryTimeout (the timeout used for N1qlQuery queries) of 75 milli-seconds. You can change this default with the environment builder:
def env = DefaultCouchbaseEnvironment.builder()
.connectTimeout(10000)
.queryTimeout(10000) // This is the query timeout
.build()
Related
I need some help to understand why my library not working for MQQUEUEMANAGER.
This is my code :
import java.util.Hashtable;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQQueue;
import com.ibm.mq.constants.MQConstants;
Hashtable mqProps = new Hashtable();
mqProps.put(MQConstants.CHANNEL_PROPERTY, "my_channel");
mqProps.put(MQConstants.PORT_PROPERTY, my_port);
mqProps.put(MQConstants.HOST_NAME_PROPERTY, "my_host");
mqProps.put(MQConstants.USER_ID_PROPERTY, "my_user_id");
mqProps.put(MQConstants.PASSWORD_PROPERTY, "my_password");
MQQueueManager qMgr = new MQQueueManager("my_QM", mqProps);
vars.putObject("QMGR", qMgr);
I imported the following library : com.ibm.mq.allclient-9.2.3.0
But I have an error :
Target exception: com.ibm.mq.MQException: MQJE001: Completion Code '2', Reason '2035'.
in inline evaluation of: ``import java.util.Hashtable; import com.ibm.mq.MQQueueManager; import com.ibm.mq. . . . '' at line number 14
javax.script.ScriptException: Sourced file: inline evaluation of: ``import java.util.Hashtable; import com.ibm.mq.MQQueueManager; import com.ibm.mq. . . . '' : Typed variable declaration : Object constructor : at Line: 14 : in file: inline evaluation of: ``import java.util.Hashtable; import com.ibm.mq.MQQueueManager; import com.ibm.mq. . . . '' : new MQQueueManager ( "my_QM" , mqProps )
Do I need to use another specific param in the constructor?
Do you have any idea why JMeter generate an error?
Target exception: com.ibm.mq.MQException: MQJE001: Completion Code
'2', Reason '2035'.
MQ Reason Code of 2035 (MQRC_NOT_AUTHORIZED) means that the UserId that the application is using does not have permission to connect to the queue manager.
mqProps.put(MQConstants.CHANNEL_PROPERTY, "my_channel");
"my_channel" is a sample but make sure it does not begin with "SYSTEM". You should be using your own uniquely named channel.
mqProps.put(MQConstants.USER_ID_PROPERTY, "my_user_id");
mqProps.put(MQConstants.PASSWORD_PROPERTY, "my_password");
Do those credentials exist on the remote server, so that the queue manager can authenticate those credentials? Have you given that UserId permission to connect to the queue manager? i.e. using setmqaut command
What about giving permission to the UserId to open the queue(s)? (again with setqmaut command).
It is always best to grant permission to the UserId's group rather than the UserId (aka principle).
setmqaut -m {QM_NAME} -t qmgr -g {GROUP} +connect +inq +dsp
setmqaut -m {QM_NAME} -n ABC.** -t queue -g {GROUP} +allmqi +dsp
Note: The "**" wildcard is correct. IBM MQ makes a distinction between "*" and "**" wildcards.
Those 2 setmqaut commands will:
set permissions for connecting to a queue manager and
set permissions for opening all queues that begin with "ABC."
It looks like you're using Beanshell and this is not something you should be doing as since JMeter 3.1 you're supposed to be using Groovy
If despite this you are still willing to use Beanshell be aware that it masks the problem so you either need to put debug(); operator somewhere in "your" script (however it looks like taken from here)or surround your code into try block like:
try {
//the code you copied and pasted without understanding what it is doing
}
catch (Exception ex) {
log.error("Failure in the copied and pasted script", ex);
throw ex;
}
this way you will see more human-friendly stacktrace in jmeter.log file and will be able to figure out what is the root cause of the issue
I don't see any problems with the code, it works okay even with Beanshell, here is the evidence:
You may also find IBM MQ testing with JMeter - Learn How article useful.
I have deployed this Python app on Heroku and i want it to connect to a MongoDB Atlas cluster. I used my string to connect to the cluster, but for some reason i keep getting raise OperationFailure(msg % errmsg, code, response)
pymongo.errors.OperationFailure: bad auth Authentication failed. I checked twice and both the user and the password are correct. Any idea on why this is happening?
from pymongo import MongoClient
import time
import random
import time
import datetime
client = MongoClient('mongodb+srv://USER:<MYPASSWORD>#test-2liju.mongodb.net/test?retryWrites=true')
db = client.one
mycol = client["tst"]
while True:
test = int(random.randrange(-99999990,90000000,1))
dic = {"num": test}
result = db.tst.insert_one(dic)
print(test)
time.sleep(5)
Stupid error, i had to type MYPASSWORD instead of <MYPASSWORD>, without the <>
Don't use any special char in password, like '+' or '='.
I use OpenSSL to generate a password like u4wY9AOwnOLMY+h9EQ==. Came across bad auth Authentication failed.
After using MongoDB Compass it told me don't use special char, so I remove those and use like 'u4wY9AOwnOLMYh9EQ'.
Then it works.
check the compatibility of the version of the Python driver you choose from the Mongodb Atlas Connections. versions above 3.4 are not supported by mongoengine flask
I am using a Google Cloud SQL using Java-SQL connector. The issue I am facing is that the connection to database drops unexpectedly. While Googling I came across this question and tried the solution suggested in the same question.
In your console click the project, on the left side click Storage > CloudSQL then click on your database name. You will see an 'Edit' button on top. Click that and scroll down to Activation Policy, change it to Always On and then click save.
But I'm still facing the same issue. Fortunately I have been keeping the logs on Google App Engine and I have attached the snapshot of the exception that occurred while connecting to database.
Gist of the code that I've posted below is used to establish connection to the database.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import com.google.appengine.api.utils.SystemProperty;
import static com.google.appengine.api.utils.SystemProperty.environment;
import static com.google.appengine.api.utils.SystemProperty.Environment.Value.Development;
import static com.google.appengine.api.utils.SystemProperty.Environment.Value.Production;
Connection con=null;
SystemProperty.Environment.Value env = environment.value();
if(env == Production)
{
System.out.println("Inside Production Phase");
// Load the class that provides the new "jdbc:google:mysql://" prefix.
Class.forName("com.mysql.jdbc.GoogleDriver");
url = "jdbc:google:mysql://<my-project-id>:<cloud-sql-instance>/<database-name>?user=<user-name>&password=<database-password>&useUnicode=true&characterEncoding=UTF-8";
}//if
else if(env == Development)
{
System.out.println("Inside Development Phase");
// This will load the MySQL driver, each DB has its own driver
Class.forName("com.mysql.jdbc.Driver");
url = "jdbc:mysql://127.0.0.1:3306/<database-name>?user=root";
}//else if
con = DriverManager.getConnection(url);
Is anyone facing the same problem, Please help.
Got a temporary fix, used following parameters while making connection to Google Cloud SQL
url = "jdbc:google:mysql://my-app:mysql2/project-name?user=root&password=password&autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
Reference URL: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html
I tried to run next code, but for 2.1.6 vertex library occurs io.vertx package not found problem.
Or if somebody have a small project with Java and JS code for this, give please a link.
Also I tried 3.x.x version, but it has no io.vertx method.
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import io.vertx.core.eventbus.EventBus;
import io.vertx.core.http.HttpServer;
import org.vertx.java.core.sockjs.SockJSServer;
import org.vertx.java.core.sockjs.impl.DefaultSockJSServer;
//...
Vertx vertx = Vertx.newVertx();
EventBus eventBus = vertx.eventBus()
HttpServer server = vertx.createHttpServer();
JsonArray permitted = new JsonArray();
permitted.add(new JsonObject());
SockJSServer sockJSServer = new DefaultSockJSServer(vertx, server);
sockJSServer.bridge(new JsonObject().putString("prefix", "/pusher"), permitted, permitted);
server.listen(<some port>);
Vert.x versions 2.x used the org.vertx package, whereas the 3.x branch uses io.vertx, this is why you're running into problems.
For version 2 there are some examples regarding the event bus bridge:
https://github.com/vert-x/vertx-examples/tree/master/src/raw/java/eventbusbridge
And a lot of examples for Vert.x 3:
https://github.com/vert-x3/vertx-examples
So basically you should just stick to one of the versions and you should be fine.
I have started to work with spring social and following the tutorial from here. and pages that follow.
My java file looks like this.
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
//import org.springframework.boot.SpringApplication;
//import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionFactory;
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.support.ConnectionFactoryRegistry;
import org.springframework.social.facebook.api.Comment;
import org.springframework.social.facebook.api.CommentOperations;
import org.springframework.social.facebook.connect.FacebookConnectionFactory;
import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.api.impl.FacebookTemplate;
import org.springframework.social.oauth2.AccessGrant;
import org.springframework.social.oauth2.GrantType;
import org.springframework.social.oauth2.OAuth2Operations;
import org.springframework.social.oauth2.OAuth2Parameters;
//import org.springframework.social.UserIdSource;
//import org.springframework.social.connect.ConnectionFactoryLocator;
//import org.springframework.social.connect.ConnectionRepository;
//import org.springframework.social.connect.web.ConnectController;
#Configuration
#EnableAutoConfiguration
#Import(FacebookConfig.class)
#ComponentScan
public class App {
static private String accessToken = "accesstoken";
static private String secretKey = "secretkey";
static private String clientId = "clientid";
public static void main(String[] args) {
FacebookConnectionFactory connectionFactory = new FacebookConnectionFactory(clientId, secretKey);
OAuth2Operations oauthOperations = connectionFactory.getOAuthOperations();
OAuth2Parameters params = new OAuth2Parameters();
params.setRedirectUri("http://facebook.com");
String authorizeUrl = oauthOperations.buildAuthorizeUrl(GrantType.IMPLICIT_GRANT, params);
AccessGrant accessGrant = new AccessGrant(accessToken);
System.out.println(accessGrant.getAccessToken());
System.out.println(accessGrant.getExpireTime());
System.out.println(accessGrant.getScope());
ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();
registry.addConnectionFactory(connectionFactory);
Facebook facebook = new FacebookTemplate(accessToken);
}
}
When i run this code i get the error as stated.
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:exec (default-cli) on project mavenproject3: Command execution failed. Process exited with an error: 1(Exit value: 1) -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
When i comment out this line:
Facebook facebook = new FacebookTemplate(accessToken);
It works fine.
Can someone suggest me the requisite. I am a newbie so please bear with me.
The URL you mentioned isn't really a tutorial as much as it is a reference. Admittedly, it gets a bit detailed and isn't very helpful for the new user. Duly noted...expect a new tutorial to be written as soon as I get a moment to do so.
Where did you get the value of accessToken? If you didn't get it via an OAuth2 "dance" with Facebook, then it's not going to work.
First, I see you creating a FacebookConnectionFactory to obtain an OAuth2Operations, through which you set a redirect URI, etc, etc..and then build an authorization URL for IMPLICIT grant. There are several things out of sorts there:
Facebook doesn't support IMPLICIT grant. It only supports authorization code grant and client token grant. Even so, with implicit grant and authorization code grant your app must redirect to Facebook (in a web browser) to obtain permission from the user. Once that's granted, then it will redirect back to your app...speaking of which...
The redirect URI you set is http://facebook.com. That should be the URL of your application where Facebook will redirect back to after authorization.
After all of that, you never even use the authorizeUrl...it's just in a String. It wouldn't work even if you did use it, for the reasons already mentioned, but the first 5 or so lines are all for nothing.
You create a ConnectionFactoryRegistry and register the FacebookConnectionFactory with it...but then you do nothing with the ConnectionFactoryRegistry. That's okay...you almost never need to do anything with it anyway, because it primarily exists as a helper to ConnectController.
There's simply no good way of obtaining a user-oriented access token without the redirect "dance". It's important to get permission from the user you'll be accessing Facebook on behalf of. If it were any easier than that, it'd be way too easy to create an app that spams Facebook and essentially ruins the experience for everyone.
The work of obtaining an access token via that redirect "dance" is handled automatically by the framework using ConnectController. Sure, you can do it yourself if you'd rather, but ConnectController will handle all of that for you.
For lack of a proper tutorial at the moment, I recommend that you have a look at https://github.com/spring-projects/spring-social-samples/tree/master/spring-social-showcase. Also, there's a Spring Boot-oriented version of it at https://github.com/spring-projects/spring-social-samples/tree/master/spring-social-showcase-boot that simplifies the configuration more (albeit, it relies on changes that aren't in an official Spring Boot release yet).