How to create a MQQueueManager object in JMeter? - java

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.

Related

Network interface: you don't have permission to capture on that device (socket: Operation not permitted)

Currently I'm writing a small project that views the local bandwidth. I installed the package and implemented the code that's available on the pcap4j site just to try it out like so:
import org.pcap4j.core.*;
import org.pcap4j.core.PcapNetworkInterface.PromiscuousMode;
import org.pcap4j.packet.IpV4Packet;
import org.pcap4j.packet.Packet;
import java.io.EOFException;
import java.lang.*;
import java.net.*;
import java.util.concurrent.TimeoutException;
public class BandwidthViewer {
public static void main(String[] args) throws UnknownHostException, PcapNativeException, EOFException, TimeoutException, NotOpenException {
InetAddress addr = InetAddress.getByName("192.168.1.8");
PcapNetworkInterface nif = Pcaps.getDevByAddress(addr);
int snapLen = 65536;
PromiscuousMode mode = PromiscuousMode.PROMISCUOUS;
int timeout = 10;
PcapHandle handle = nif.openLive(snapLen, mode, timeout);
Packet packet = handle.getNextPacketEx();
handle.close();
IpV4Packet ipV4Packet = packet.get(IpV4Packet.class);
Inet4Address srcAddr = ipV4Packet.getHeader().getSrcAddr();
System.out.println(srcAddr);
}
}
Once run I get this error:
/usr/lib/jvm/java-11-openjdk/bin/java -javaagent:/usr/share/idea/lib/idea_rt.jar=46685:/usr/share/idea/bin -Dfile.encoding=UTF-8 -classpath /home/ivan/mdrive/Projects/IdeaProjects/BandwidthViewer/target/classes:/home/ivan/.m2/repository/org/pcap4j/pcap4j-core/2.0.0-alpha.6/pcap4j-core-2.0.0-alpha.6.jar:/home/ivan/.m2/repository/org/slf4j/slf4j-api/1.7.26/slf4j-api-1.7.26.jar:/home/ivan/.m2/repository/net/java/dev/jna/jna/5.3.1/jna-5.3.1.jar:/home/ivan/.m2/repository/org/pcap4j/pcap4j-packetfactory-static/2.0.0-alpha.6/pcap4j-packetfactory-static-2.0.0-alpha.6.jar BandwidthViewer
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.pcap4j.core.PcapNativeException: enp3s0: You don't have permission to capture on that device (socket: Operation not permitted)
at org.pcap4j.core.PcapNetworkInterface.openLive(PcapNetworkInterface.java:238)
at BandwidthViewer.main(BandwidthViewer.java:19)
Process finished with exit code 1
It makes sense that I can sniff any packets since I'm running it as a non-root user. I tried to fix this by using a solution like this but ultimately it didn't work. I know this should be possible, since programs like Wireshark also need you to log in as a root user in order to look at all the packets. Does anybody know what can fix this? Obviously I could run my IDE as root but that just seems unnecessary. I'm running this on Manjaro Linux.
I fixed it. After further investigation I figured out that the file I was trying to add permissions to was within my java-8-openjdk folder, but my project uses java-11-openjdk. So I set the permissions for the correct executable and it now works. Changing the permissions can be done by logging in as root in a terminal and executing: setcap cap_net_raw,cap_net_admin=eip /path/to/java

How to run downloaded App Router via Service Marketplace

I downloaded XS_JSCRIPT14_10-70001363 package from Service Marketplace.
Please suggest me how to run this App Router Login form with localhost
I am trying with npm startcommand, but getting UAA service exception. How to handle from localhost.
When you download the approuter, either via npm or service marketplace you have to provide two additional files for a basic setup inside the AppRouter directory (besides package.json, xs-app.json, etc.).
The default-services.json holds the variables that tell the approuter where to find the correct authentication server (e.g., XSUAA). You have to provide at least the clientid, clientsecret, and URL of the authorization server as part of this file like this:
{
"uaa": {
"url" : "http://my.uaa.server/",
"clientid" : "client-id",
"clientsecret" : "client-secret",
"xsappname" : "my-business-application"
}
}
You can get this parameters, for example, after binding on SAP Cloud Platform, CloudFoundry your application to an (empty) instance of XSUAA where you can retrieve the values via cf env <appname> from the `VCAP_SERVICES/xsuaa' properties (they have exactly the same property names).
In addition, you require the default-env.json file which holds at least the destination variable to which backend microservice you want to send the received Json Web Token to. It may look like this:
{
"destinations": [ {
"name": "my-destination", "url": "http://localhost:1234", "forwardAuthToken": true
}]
}
Afterwards, inside the approuter directory you can simply run npm start which runs the approuter per default under http://localhost:5000. It also writes nice console output you can use to debug the parameters above.
EDIT: Turns out I was incorrect, it is apparently possible to run the approuter locally.
First of all, here is the documentation for the approuter: https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/01c5f9ba7d6847aaaf069d153b981b51.html
As far as I understood, you need to provide to files to the approuter for it to run locally, default-services.json and default-env.json (put them in the same directory as your package.json.
The default-services.json has a format like this:
{
"uaa": {
"url" : "http://my.uaa.server/",
"clientid" : "client-id",
"clientsecret" : "client-secret",
"xsappname" : "my-business-application"
}
}
The default-env.json is simply a json file holding the environment variables that the approuter needs to access, like so:
{
"VCAP_SERVICES": <env>,
...
}
Unfortunately, the documentation does not state which variables are required, therefore I cannot provide you with a working example.
Hope this helps you! Should you manage to get this running, I'm sure others would appreciate if you share your knowledge here.

Unable to create primary index on couchbase using groovy script

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()

Utgard - Access denied

I have been unable to find a solution that fixes my issue, so I am opening a new topic.
Utgard (http://openscada.org/projects/utgard) seems like a very useful tool to me. In this phase I just want to be able to access the TOP OPC Server locally on a Windows 8 OS via Eclipse. However, when trying to run their tutorial I end up with an "Access is denied". I do not think that I have made any mistakes with username, password and so on.
The Exele OPC DA Test Client does not return any errors. I can connect, retrieve and rewrite values.
Please note that I am a newbie when it comes to OPC and OpenSCADA. Any help will be greatly appreciated.
package org.openscada.opc.tutorial;
import java.util.concurrent.Executors;
import org.jinterop.dcom.common.JIException;
import org.openscada.opc.lib.common.ConnectionInformation;
import org.openscada.opc.lib.da.AccessBase;
import org.openscada.opc.lib.da.DataCallback;
import org.openscada.opc.lib.da.Item;
import org.openscada.opc.lib.da.ItemState;
import org.openscada.opc.lib.da.Server;
import org.openscada.opc.lib.da.SyncAccess;
public class UtgardTutorial1 {
public static void main(String[] args) throws Exception {
// create connection information
final ConnectionInformation ci = new ConnectionInformation();
//final ConnectionInformation connectionInformation = new ConnectionInformation();
ci.setHost("127.0.0.1");
//ci.setDomain("");
ci.setUser("Me");
ci.setPassword("Password");
ci.setProgId("SWToolbox.TOPServer.V5");
//ci.setClsid("680DFBF7-C92D-484D-84BE-06DC3DECCD68"); // if ProgId is not working, try it using the Clsid instead
// create an id for the tag you want to retrieve
final String itemId = "_System._Time_Second";
// create a new server
final Server server = new Server(ci, Executors.newSingleThreadScheduledExecutor());
//final Server serverServer = new Server(connectionInformation, Executor.newSingleThreadSchedulesExecutor);
try {
// connect to server
server.connect();
// add sync access, poll every 500 ms
final AccessBase access = new SyncAccess(server, 500);
access.addItem(itemId, new DataCallback() {
#Override
public void changed(Item item, ItemState state) {
System.out.println(state);
}
});
// start reading
access.bind();
// wait a little bit
Thread.sleep(10 * 1000);
// stop reading
access.unbind();
} catch (final JIException e) {
System.out.println(String.format("%08X: %s", e.getErrorCode(), server.getErrorMessage(e.getErrorCode())));
}
}
}
Error stack trace:
INFO org.openscada.opc.lib.da.Server - Failed to connect to server
org.jinterop.dcom.common.JIException: Access is denied, please check whether the [domain-username-password] are correct. Also, if not already done please check the GETTING STARTED and FAQ sections in readme.htm. They provide information on how to correctly configure the Windows machine for DCOM access, so as to avoid such exceptions. [0x00000005]
at org.jinterop.winreg.smb.JIWinRegStub.winreg_OpenKey(Unknown Source) ~[org.openscada.jinterop.core_2.0.8.201303051454.jar:na]
at org.jinterop.dcom.core.JIProgId.getIdFromWinReg(Unknown Source) ~[org.openscada.jinterop.core_2.0.8.201303051454.jar:na]
at org.jinterop.dcom.core.JIProgId.getCorrespondingCLSID(Unknown Source) ~[org.openscada.jinterop.core_2.0.8.201303051454.jar:na]
at org.jinterop.dcom.core.JIComServer.<init>(Unknown Source) ~[org.openscada.jinterop.core_2.0.8.201303051454.jar:na]
at org.openscada.opc.lib.da.Server.connect(Server.java:123) ~[org.openscada.opc.lib_1.0.0.201303051455.jar:na]
at org.openscada.opc.tutorial.UtgardTutorial1.main(UtgardTutorial1.java:32) [bin/:na]
Caused by: org.jinterop.dcom.common.JIRuntimeException: Access is denied, please check whether the [domain-username-password] are correct. Also, if not already done please check the GETTING STARTED and FAQ sections in readme.htm. They provide information on how to correctly configure the Windows machine for DCOM access, so as to avoid such exceptions. [0x00000005]
at org.jinterop.winreg.IJIWinReg$openKey.read(Unknown Source) ~[org.openscada.jinterop.core_2.0.8.201303051454.jar:na]
at ndr.NdrObject.decode(Unknown Source) ~[org.openscada.jinterop.deps_1.0.0.201303051454.jar:na]
at rpc.ConnectionOrientedEndpoint.call(Unknown Source) ~[org.openscada.jinterop.deps_1.0.0.201303051454.jar:na]
at rpc.Stub.call(Unknown Source) ~[org.openscada.jinterop.deps_1.0.0.201303051454.jar:na]
You don't have access to the local Windows Registry, so the client fails to convert the server's ProgID to CLSID. Make sure you run the application with enough privileges in there, i.e. that you are an Administrator user.
Alternatively, you can just configure the connection using the server's CLSID, so you will not need the registry.
An OPC client should actually use the OpcEnum service running on the server computer to do the ProgID to CLSID conversion. Perhaps the service is not available or Utgard only tries the registry (I do not know Utgard myself). If you don't have the server installed on the client machine, the registry-based ProgID to CLSID conversion will fail anyway, since that information is not available in the local Windows Registry. The worst case is that Utgard will try to open the remote Windows Registry, which only rarely succeeds (or you need to ensure that it's enabled separately).
Note that as I do not know Utgard, I am just guessing which strategies it is attempting. Nevertheless, using CLSID only will bypass the whole conversion part, which is your problem.
E: Considering that your other client can connect without a problem, I suspect that Utgard does not try to use OpcEnum at all.
I got the same error, and solve the problem by
applying the following patch to the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
create or modify 32-bit DWORD: LocalAccountTokenFilterPolicy
set the value to: 1

javax.naming.NoInitialContextException: Failed to create InitialContext using factory specified in hashtable

I have small program which just creating intial context in unmanaged environment i.e. outside the container.I have been using Websphere 7.0.
I have written following program to do the connection with application which is running on WAS 7 using corba url,
package snippet;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
public class test {
public static void main(String[] args) {
try {
// create initial context
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
env
.put(Context.PROVIDER_URL,
"corbaloc:iiop:1.0#x1devapp63.dev.freightliner.com:2809/NameService");
InitialContext ctx = new InitialContext(env);
System.out.println(ctx);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
I have created runnable jar and executing using shell script given below,
#!/bin/sh
WAS_ROOT_PATH=/application/WebSphere/AppServer
SCHEDULER_JAR=/application/apps/JobScheduler/testJNDI.jar
SCHEDULE_FILE=/application/apps/JobScheduler/schedule.xml
. "$WAS_ROOT_PATH"/bin/setupCmdLine.sh
CLASSPATH="$MQLIB":"$WAS_CLASSPATH"
"$JAVA_HOME"/bin/java -classpath "$CLASSPATH" -jar "$SCHEDULER_JAR"
Ater running i have been facing below exception,
$ testJNDI.sh
javax.naming.NoInitialContextException: Failed to create InitialContext using factory specified in hashtable {java.naming.provider.url=corbaloc:iiop:1.0#x1devapp63.dev.freightliner.com:2809/NameService, java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory} [Root exception is java.lang.NullPointerException]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:243)
at javax.naming.InitialContext.initializeDefaultInitCtx(InitialContext.java:327)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:357)
at javax.naming.InitialContext.internalInit(InitialContext.java:295)
at javax.naming.InitialContext.<init>(InitialContext.java:212)
at snippet.test.main(test.java:19)
Caused by: java.lang.NullPointerException
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:235)
... 5 more
$
I got stuck on above problem but i could not get why this is happening.
Please do the needful to get out me from above problem.
Don't forget to include the thinclient-jars to your buildpath.
You will need them to do a jndi lookup from a standalone client.
%WAS_HOME%/runtimes is where they can be found.
http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.nd.multiplatform.doc/info/ae/ae/ccli_standaloneclient.html
The Provider URL helps you to identify the server and the root # which you connect to the name space.
As an example, if you wanted to connect to the Cell Persisent root, you would specify the the Provider_URL as:
env.put(Context.PROVIDER_URL,
"corbaloc:iiop:myhost.mycompany.com:2809/NameServiceCellPersistentRoot");
Server Root NameServiceServerRoot
Cell Persistent Root NameServiceCellPersistentRoot
Cell Root NameServiceCellRoot
Node Root NameServiceNodeRoot
The default object key is:"NameService" so stating that in the URL is not required if you want to connect to the default location.
Also, is there anything else in the stack trace that states any other information?
Also from the client machine is the DNS name: x1devapp63.dev.freightliner.com resolvable?
Is this the name that is used by the WAS Server to identify itself? When WAS is installed you do specify a host name and does that match this name?
Can you also run the same from the same machine as the WAS Server and use localhost and see if the errors are the same.
I am just thinking about potential network related errors which are probably causing trouble.
Have a look at this for the various values that help you could connect to for the root context.
http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.nd.multiplatform.doc/info/ae/ae/rnam_example_prop5.html
HTH
Manglu
Are you sure the provider URL is correct? According to various examples like this one (WAS Express 6) or this one (WAS 8) (couldn't find a reference for WAS 7 but it looks like things didn't change), the code to use a CORBA object URL with the WAS JNDI implementation is described as follows:
Using a CORBA object URL
This example shows a CORBA object URL.
...
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
...
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.PROVIDER_URL, "corbaloc:iiop:myhost.mycompany.com:2809");
Context initialContext = new InitialContext(env);
...
Don't know if this will help though.

Categories

Resources