Unable to connect to HP Quality Center using Com4j - ota

OTAClient.dll version 10.0.0.2532
The following is the code I have used to connect to qc, apply filter and fetch qcpath and a field data. It is working fine with java 32 bit version 1.7.
import com.oracle.qcTasks.ClassFactory;
import com.oracle.qcTasks.IList;
import com.oracle.qcTasks.ISubjectNode;
import com.oracle.qcTasks.ITDConnection;
import com.oracle.qcTasks.ITDFilter;
import com.oracle.qcTasks.ITest;
import com.oracle.qcTasks.ITestFactory;
import com4j.Com4jObject;
public class qcClient {
public static void main(String[] args) {
ITest qcTestCase;
ISubjectNode qcTestCasePath;
Com4jObject SubjectField;
//QC url
String url = "http://fusionqc.us.oracle.com/";
//username for login
String username = "username";
//password for login
String password = "";
//domain
String domain = "domain";
//project
String project = "project";
ITDConnection itdc = ClassFactory.createTDConnection();
itdc.initConnectionEx(url);
itdc.connectProjectEx(domain, project, username, password);
boolean flag = itdc.connected();
System.out.println(itdc.projectName());
ITestFactory qcTestFactory = itdc.testFactory().queryInterface(ITestFactory.class);
ITDFilter qcFilter=qcTestFactory.filter().queryInterface(ITDFilter.class);
String query="^Subject\\path^";
qcFilter.clear();
qcFilter.filter("TS_SUBJECT", query);
IList qcTestList = qcFilter.newList();
for (Com4jObject com4jObject : qcTestList) {
qcTestCase = com4jObject.queryInterface(ITest.class);
System.out.println(qcTestCase.name());
System.out.println(qcTestCase.field("TS_USER_09"));
SubjectField = (Com4jObject)qcTestCase.field("TS_SUBJECT");
qcTestCasePath = SubjectField.queryInterface(ISubjectNode.class);
System.out.println(qcTestCasePath.path());
break;
}
System.out.println("command output :: "+flag);
System.out.println("OUT");
itdc.disconnectProject();
}
}
To the project requirement, I've downgraded the version of java to 64 bit version of 1.6. Post the downgrade, I'm receiving the following error.
Exception in thread "main" com4j.ExecutionException: com4j.ComException: 80040154 CoCreateInstance failed : Class not registered : .\com4j.cpp:153
at com4j.ComThread.execute(ComThread.java:203)
at com4j.Task.execute(Task.java:25)
at com4j.COM4J.createInstance(COM4J.java:97)
at com4j.COM4J.createInstance(COM4J.java:72)
at com.oracle.qcTasks.ClassFactory.createTDConnection(ClassFactory.java:16)
at com.oracle.qcCode.qcClient.main(qcClient.java:32)
Caused by: com4j.ComException: 80040154 CoCreateInstance failed : Class not registered : .\com4j.cpp:153
at com4j.Native.createInstance(Native Method)
at com4j.COM4J$CreateInstanceTask.call(COM4J.java:117)
at com4j.COM4J$CreateInstanceTask.call(COM4J.java:104)
at com4j.Task.invoke(Task.java:51)
at com4j.ComThread.run0(ComThread.java:153)
at com4j.ComThread.run(ComThread.java:134)
I've found similar threads but didn't found any particular solution for the same. Please help. Is there any impact wrt java versions

What version of com4j do you use? See this post for using com4j on a 64 bit Windows machine. Are there any COM objects you can use from your 64 bit environment?
According to this blog entry you will get a Class not Registered Exception when you try to access a 32 bit COM object in a 64 bit environment. It even contains a workaround using some registry hacks. Maybe it works?

Related

WinAppDriver not working with side loaded Universal Application

I am unable to load a side loaded Windows Universal application using WinAppDriver
I have verified my code works if I try to load the Windows Calculator application but I am unable to load my target application. I get an error message "The system cannot find the file specified". I used the Get-AppxPackage method in PowerShell to get the application information for my target application. The method returned the data structure below:
Name : AACE4B69.MazikAXCashier
Publisher : CN=XXXXXXXXXXX
Architecture : Neutral
ResourceId :
Version : 2.4.1.9
PackageFullName : AACE4B69.MazikAXCashier_2.4.1.9_neutral__gfhc11b3bvd9y
InstallLocation : C:\Program Files\WindowsApps\AACE4B69.MazikAXCashier_2.4.1.9_neutral__gfhc11b3bvd9y
IsFramework : False
PackageFamilyName : AACE4B69.MazikAXCashier_gfhc11b3bvd9y
PublisherId : gfhc11b3bvd9y
IsResourcePackage : False
IsBundle : False
IsDevelopmentMode : False
NonRemovable : False
Dependencies : {Microsoft.WinJS.2.0_1.0.9600.17018_neutral__8wekyb3d8bbwe}
IsPartiallyStaged : False
SignatureKind : Developer
Status : Ok
I have tried to load the application using the following fields in the AppID field:
Name
PackageFullName
PackageFamilyName
[TestFixture]
public class Tests
{
protected static WindowsDriver<WindowsElement> windowSession;
public const String AppID = "AACE4B69.MazikAXCashier_2.4.1.9_neutral__gfhc11b3bvd9y";
public const String driverURL = "http://127.0.0.1:4723";
[SetUp]
public void Setup()
{
if (windowSession == null)
{
// Configure the application connection and load data
AppiumOptions opt = new AppiumOptions();
opt.AddAdditionalCapability("app", AppID);
try
{
// Create the driver object
windowSession = new WindowsDriver<WindowsElement>(new Uri(driverURL), opt);
Assert.IsNotNull(windowSession);
}
catch (Exception e)
{
Console.WriteLine("Unable to open application with error: " + e.Message);
}
}
}
[Test]
public void Test1()
{
Assert.Pass();
}}
I would expect one of these names to be the required Application ID and result in the app loading. Instead I get the error message "The system cannot find the file specified".
This application is side loaded and I am wondering if there is something different about that. Any help or suggestions are appreciated.
OK, I figured out the trick. I needed to user the PackageFamilyName appended with a qualifier. In my case this came out to be
public const String AppID = "AACE4B69.MazikAXCashier_gfhc11b3bvd9y!App";
I got this value via a two step process. I used the Powershell Get-appxPackage Mazik to get the PackageFamilyName as I previously did. I then appended "!App" to this string to get the required value. I determined the "!App" string based on another Powershell script I found in an online article. I used the following script to determine what the appended ID value was:
(Get-AppxPackageManifest (Get-AppxPackage Mazik)).package.applications.application.id
This returned "App" and I constructed the final string as described above. It looks like the "!App" is the typical ending to the required AppID but I have to assume there are different values for different situations. Once I got the correct AppID value everything worked as expected and the side loaded application was not an issue
The application key is usually a little shorter I believe. Are you sure you didn't make a mistake while copying it over to your code? Please double check app IDs for errors.
I created a shortcut to the Clocks app and then right clicked it. The "Target type" and "Target" fields contain the exact application key that work.

java.lang.ClassNotFoundException:net.ucanaccess.jdbc.ucanaccessDriver

I'm beginner with java and using console to compile and run my programs. I'm trying to read data from MS Access .accdb file with ucanaccess driver. As i have added 5 ucanaccess files to C:\Program Files\Java\jdk1.8.0_60\jre\lib\ext, but still getting Exception java.lang.ClassNotFoundException:net.ucanaccess.jdbc.ucanaccessDriver.
Here is my code.
import java.sql.*;
public class jdbcTest
{
public static void main(String[] args)
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
String url = "jdbc:ucanaccess://C:javawork/PersonInfoDB/PersonInfo.accdb";
Connection conctn = DriverManager.getConnection(url);
Statement statmnt = conctn.createStatement();
String sql = "SELECT * FROM person";
ResultSet rsltSet = statmnt.executeQuery(sql);
while(rsltSet.next())
{
String name = rsltSet.getString("name-");
String address = rsltSet.getString("address");
String phoneNum = rsltSet.getString("phoneNumber");
System.out.println(name + " " + address + " " + phoneNum);
}
conctn.close();
}
catch(Exception sqlExcptn)
{
System.out.println(sqlExcptn);
}
}
}
Please add JDBC driver jar to lib folder.
Download URL download jar
I tried the method mentioned by Gord in his post Manipulating an Access database from Java without ODBC and used eclipse instead of command line compile and run. Also to learn eclipse basics, i watched video tutorial https://www.youtube.com/watch?v=mMu-JlBrYXo.
Finally i was able to read my MS Access data base file from my java code.

error setting linkConfig.connectionString on sqoop 1.99.4

I followed https://sqoop.apache.org/docs/1.99.4/RESTAPI.html for trying out sqoop2. But Iam getting error "Exception in thread "main" org.apache.sqoop.common.SqoopException: MODEL_011:Input do not exist - Input name: linkConfig.connectionString" on the line linkConfig.getStringInput("linkConfig.connectionString").setValue("jdbc:mysql://localhost/my");
i tested sqoop2, mysql, database etc from terminal and working fine. please help. thanks in advance.
here is the code i am trying
import org.apache.sqoop.client.SqoopClient;
import org.apache.sqoop.model.MLink;
import org.apache.sqoop.model.MLinkConfig;
import org.apache.sqoop.validation.Status;
public class Sqoop2 {
public static void main(String[] args) {
//Initialization SqoopClient
String url = "http://<myip>:12000/sqoop/";
SqoopClient client = new SqoopClient(url);
// create a placeholder for link
long connectorId = 1;
MLink link = client.createLink(connectorId);
link.setName("Vampire");
link.setCreationUser("Buffy");
MLinkConfig linkConfig = link.getConnectorLinkConfig();
// fill in the link config values
linkConfig.getStringInput("linkConfig.connectionString").setValue("jdbc:mysql://<myip>/<dbname>");
linkConfig.getStringInput("linkConfig.jdbcDriver").setValue("com.mysql.jdbc.Driver");
linkConfig.getStringInput("linkConfig.username").setValue("root");
linkConfig.getStringInput("linkConfig.password").setValue("root");
// save the link object that was filled
Status status = client.saveLink(link);
if(status.canProceed()) {
System.out.println("Created Link with Link Id : " + link.getPersistenceId());
} else {
System.out.println("Something went wrong creating the link");
}
}
}
I faced the same issue. As per the documentation generic-jdbc connector id =1 and hdfs-connector id =2. But after we upgraded to 5.3.2 the id's were swapped.
Don't hard code the connector Id's(as said in the documentation). Use client.getConnectors(); or show connector --all method to look for existing connectors and get the connector Id you need. There is currently an issue logged for this https://issues.apache.org/jira/browse/SQOOP-1965.
Looks like connector 1 is already exists. Can you try with another id ?

"A registration already exists for URI" when using HttpSelfHostServer

We are having an issue unit test failing because previous tests haven't closed session of HttpSelfHostServer.
So the second time we try to open a connection to a sever we get this message:
System.InvalidOperationException : A registration already exists for URI 'http://localhost:1337/'.
This test forces the issue (as an example):
[TestFixture]
public class DuplicatHostIssue
{
public HttpSelfHostServer _server;
[Test]
public void please_work()
{
var config = new HttpSelfHostConfiguration("http://localhost:1337/");
_server = new HttpSelfHostServer(config);
_server.OpenAsync().Wait();
config = new HttpSelfHostConfiguration("http://localhost:1337/");
_server = new HttpSelfHostServer(config);
_server.OpenAsync().Wait();
}
}
So newing up a new instance of the server dosent seem to kill the previous session. Any idea how to force the desposal of the previous session?
Full exception if it helps?
System.AggregateException : One or more errors occurred. ----> System.InvalidOperationException : A registration already exists for URI 'http://localhost:1337/'.
at
System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait()
at ANW.API.Tests.Acceptance.DuplicatHostIssue.please_work() in DuplicatHostIssue.cs: line 32
--InvalidOperationException
at System.Runtime.AsyncResult.End(IAsyncResult result)
at System.ServiceModel.Channels.CommunicationObject.EndOpen(IAsyncResult result)
at System.Web.Http.SelfHost.HttpSelfHostServer.OpenListenerComplete(IAsyncResult result)
You might want to write a Dispose method like below and call it appropriately to avoid this issue
private static void HttpSelfHostServerDispose()
{
if (server != null)
{
_server.CloseAsync().Wait();
_server.Dispose();
_server = null;
}
}
This will clear the URI register.

org.apache.catalina.ServerFactory.getServer() equivalent in Tomcat 7

What is the equivalent of org.apache.catalina.ServerFactory.getServer() in Tomcat 7 or what would be the best way to retrieve org.apache.catalina.Session instances ?
Here is a sample code that used to work on Tomcat 6.0:
public List<org.apache.catalina.Session> findActiveSessions() throws ServiceException {
StandardEngine engine = (StandardEngine) ServerFactory.getServer().findService("Catalina").getContainer();
StandardContext context = (StandardContext) engine.findChild(engine.getDefaultHost())
.findChild(ServletActionContext.getServletContext().getContextPath());
List<org.apache.catalina.Session> list = new ArrayList<org.apache.catalina.Session>();
for (org.apache.catalina.Session session : context.getManager().findSessions()) {
list.add(session);
}
return list;
}
You can look it up via its management registration..
import javax.management.*;
import org.apache.catalina.Server;
MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0);
ObjectName name = new ObjectName("Catalina", "type", "Server");
Server server = (Server) mBeanServer.getAttribute(name, "managedResource");
Obviously that code is devoid of error checking but is functional.

Resources