i have a lot of properties so i wanted to reuse as much as possible.
Therefore i have defined generic object :
db-user-generic{
db.host = mymachine
#mssql or oracle
db.type = oracle
db.username = user
db.password= password
mssql {
port = 1433
name = None
url = "jdbc:sqlserver://"${?host}":"${?port}
}
oracle {
port = 1521
serviceNameOrSID = ORCL
url = "jdbc:oracle:thin:#"${?host}":"${?port}":"${?serviceNameOrSID}
}
}
the problem with this code is for example :
"jdbc:oracle:thin:#"${?host}":"${?port}":"${?serviceNameOrSID}
port is not defined for this but db-user-generic.mssql.port is defined.
so now the inned property should know what it is the exact location , which means it could not be reused like this :
my-db= ${db-user-generic}
my-db= {
mssql {
port= 1111
}
}
since the url attribute should be overriden too because he reference to db-user-generic.mssql.port and not to my-db.mssql.port
anyone has idea how this could be resolved?
Related
We need in our company to connect to HP alm and get differents tests and defects using Java. I work on 64bits machine (jdk 1.8). I tried many solutions on the web, here is different tests and errors I get on each test.
First method: Connecting using comp4j
Here is my Java code:
String url = "https://*****.saas.hpe.com/qcbin/";
String domain = "DEFAULT_827852153";
String project = "827852153_DEMO";
String username = "****";
String password = "*****";
try {
ITDConnection itd = ClassFactory.createTDConnection();
itd.initConnectionEx(url);
System.out.println("Test1:" + itd.connected());
itd.connectProjectEx(domain, project, username, password);
} catch (Exception e) {
e.printStackTrace();
}
The exception I get:
com4j.ExecutionException: com4j.ComException: 80040154 CoCreateInstance failed : Classe non enregistrée : .\com4j.cpp:153
at com4j.ComThread.execute(ComThread.java:236)
at com4j.Task.execute(Task.java:26)
at com4j.COM4J.createInstance(COM4J.java:99)
at com4j.COM4J.createInstance(COM4J.java:74)
at com.mercury.qualitycenter.otaclient.ClassFactory.createTDConnection(Unknown Source)
at infrastructure.Test.main(Test.java:24)
Second method: Connecting using rest api
I followed this tutorial step by step
https://www.consulting-bolte.de/index.php/tech-blog/hp-alm/hp-alm-rest-api/115-connect-to-hp-alm-via-java-using-rest-api
This tutorial uses ALM REST API official documentation
( https://admhelp.microfocus.com/alm/en/12.60/api_refs/REST_TECH_PREVIEW/ALM_REST_API_TP.html#REST_API_Tech_Preview/CodeSamples/infrastructure/RestConnector.htm%3FTocPath%3DExample%2520Application%7Cinfrastructure%7C_____10).
Whatever user or password I pass to the login method it returns status code 200. So login and password aren't considered in the code. But when i try read defects using this code:
AlmConnector alm = new AlmConnector();
RestConnector conn = RestConnector.getInstance();
conn.init(new HashMap<String, String>(), Constants.HOST,
Constants.DOMAIN, Constants.PROJECT);
alm.login("***", "***");
conn.getQCSession();
String defectUrl = conn.buildEntityCollectionUrl("defect");
defectUrl += "/89";
Map<String, String> requestHeaders = new HashMap<String, String>();
requestHeaders.put("Accept", "application/xml");
conn.first = false;
Response res = conn.httpGet(defectUrl, null, requestHeaders);
String postedEntityReturnedXml = res.toString();
Entity entity = EntityMarshallingUtils.marshal(Entity.class,
postedEntityReturnedXml);
List<Field> fields = entity.getFields().getField();
for (Field field : fields) {
System.out.println(field.getName() + " : "
+ field.getValue().size());
}
alm.logout();
alm = null;
I get this exception:
Exception in thread "main" javax.xml.bind.UnmarshalException: élément inattendu (URI : "", local : "html"). Les éléments attendus sont <{}Entity>
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:681)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:247)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:242)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:109)
at
...........
I didn't change anything in the api infrastructure code.
I just want to write a simple Java code which allows me to connect to HP alm and just read defects.
For the COM4J case: you have three issues:
You have to use 32-bit version of Java, since OTAClient.dll is 32-bit and there is no 64-bit version of it unfortunately
You need to install ALM Connectivity Add-in from (https://yoursever/qcbin/PlugIns/TDConnectivity/TDConnect.exe) or register ALM Client
ALM server URL must end with qcbin, while you have: String url = "https://*****.saas.hpe.com/qcbin/"; (ends with /)
For the REST API case: looks like you got HTML instead of XML which is possible when error happens and return code is not 200, then ALM might return HTML with some error message. I would start with checking HTTP return code and checking what is in postedEntityReturnedXml
As a side note - we are developing a product for integration with ALM which is called Bumblebee (https://www.agiletestware.com/bumblebee), so maybe you might have a look at it.
There is an existing subnet say subnet-11223344. In my code I want to know the VPC it belongs to.
I am referring java SDK http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/ec2/model/Subnet.html
// I am not sure if this actually refres to a subnet that I want
Subnet subnet = new Subnet().withSubnetId("subnet-11223344");
String vpcId = subnet.getVpcId();
System.out.println("VPC id"+vpcId);
This returns null.
Here's an example of a general purpose solution provided by ProgramCreek:
public List<Subnet> getSubnets(List<String> subnetIds, AmazonEC2 ec2Client) {
DescribeSubnetsRequest request = new DescribeSubnetsRequest();
if (subnetIds != null && !subnetIds.isEmpty()) {
request = request.withSubnetIds(subnetIds);
}
DescribeSubnetsResult result = ec2Client.describeSubnets(request);
return result.getSubnets();
}
I am using Java JNDI to perform DNS lookups using the following basic syntax as per the SSCCE below, but I am trying to query all records using the "ANY" attribute:
import java.util.*;
import javax.naming.*;
import javax.naming.directory.*;
public class SSCCE {
public static void main(String[] args) {
try {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
InitialDirContext idc = new InitialDirContext(p);
Attributes attrs = idc.getAttributes("netnix.org", new String[] { "* *" });
Attribute attr = attrs.get("* *");
if (attr != null) {
for (int i = 0; i < attr.size(); i++) {
System.out.println("Found " + (String)attr.get(i));
}
}
else {
System.out.println("Found nothing");
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
My question is around being able to query a resource type of "ANY" which should return all the DNS resource records associated with a specific domain - example below using the "host" utility.
chrixm#puffy(:):~$ host -t ANY netnix.org
netnix.org has SPF record "v=spf1 include:_spf.google.com ~all"
netnix.org mail is handled by 10 aspmx2.googlemail.com.
netnix.org mail is handled by 5 alt1.aspmx.l.google.com.
netnix.org mail is handled by 1 aspmx.l.google.com.
netnix.org mail is handled by 5 alt2.aspmx.l.google.com.
netnix.org mail is handled by 10 aspmx3.googlemail.com.
netnix.org name server ns-1154.awsdns-16.org.
netnix.org name server ns-941.awsdns-53.net.
netnix.org name server ns-61.awsdns-07.com.
netnix.org name server ns-1880.awsdns-43.co.uk.
I have read http://docs.oracle.com/javase/7/docs/technotes/guides/jndi/jndi-dns.html, which says:
Superclass attribute identifiers are also defined. These may be useful when querying records using the DirContext.getAttributes() method. If an attribute name has "*" in place of a type name (or class name), it represents records of any type (or class). For example, the attribute identifier "IN *" may be passed to the getAttributes() method to find all internet class records. The attribute identifier "* *" represents records of any class or type.
However, Java JNDI doesn't understand a resource record of "*" or "* *" as the above code doesn't return any records (I am able to query "NS" or "SOA", etc individually) - has anyone had any experience of getting this working. I can of course query each individual resource type, but considering there is a valid record type of "ANY" as per RFC 1035 (Type ID 255) this seems very inefficient?
After examining the methods of the Attributes class I noticed a getAll() method. After further searching I was able to implement the following which now allows you to search using "*" as the record type and print all the records.
Attributes attrs = idc.getAttributes("netnix.org", new String[] { "*" });
NamingEnumeration<?> ae = attrs.getAll();
while (ae.hasMore()) {
Attribute attr = (Attribute)ae.next();
for (int i = 0; i < attr.size(); i++) {
Object a = attr.get(i);
if (a instanceof String) {
System.out.println(attr.getID() + " " + a);
}
else {
System.out.println(attr.getID() + " NOT ASCII");
}
}
}
ae.close();
You're inventing semantics here. There is no support anywhere in JNDI for "* *" as either an attribute set or an attribute name. The correct syntax for 'all attributes' as an attribute set to return is "*", and the correct way to enumerate them all is via Attributes.getAll().
I have a requirement to fetch the SenderName,SenderEmail,ToNames,ToEmails,CCNames,CcEmails from a lotus notes document instance.
Issue1
Looking into lotus.domino.Document API I found out the method getItems. When I write the elements to the system.out values for SenderEmail, ToEmails and CcEmails can be found.
However values for SenderName(a.k.a From), ToNames cannot be derived that easily.
The values seems to be using an common name format. For example check check my system.output below.
Principal = "CN=Amaw Scritz/O=fictive"
$MessageID = "<OF0FF3779B.36590F8A-ON80257D15.001DBC47-65257D15.001DC804#LocalDomain>"
INetFrom = "AmawScritz#fictive.com"
Recipients = "CN=Girl1/O=fictive#fictive"
MailOptions = "0"
SaveOptions = "1"
From = "CN=Amaw Scritz/O=fictive"
AltFrom = "CN=Amaw Scritz/O=fictive"
SendTo = "CN=Girl1/O=fictive#fictive"
CopyTo = "CN=Girl2/O=fictive#fictive"
BlindCopyTo = ""
InetSendTo = "Girl1#fictive.com"
InetCopyTo = "Girl2#fictive.com"
$Abstract = "sasdasda"
$UpdatedBy = "CN=Amaw Scritz/O=fictive"
Body = "Hello World"
The question is how can I get 'Amaw Scritz' from the common name 'CN=Amaw Scritz/O=fictive'. Is there any look up mechanism that can be used. (I would prefer to have a option other than doing a substring of the common name)
Issue2
is it possible to retrieve SentTime and ReceivedTime from mail document instance?
I know that there are two methods called getCreated and getLastModified. getCreated can be loosely associated with the SentTime and getLastModified can be loosely associated with ReceivedTime. Are there are other ways to get times for SentTime and ReceivedTime.
Issue3
How can one distinguish whether a mail document is a Sent mail or a Received Mail?
Issue1
You can use Name class.
Here example from this link:
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
// (Your code goes here)
// Create a hierarchical name
Name nam = session.createName(
"CN=John B Goode/OU=Sales/OU=East/O=Acme/C=US");
// Returns:
// John B Goode
// John B Goode/Sales/East/Acme/US
// CN=John B Goode/OU=Sales/OU=East/O=Acme/C=US
System.out.println(nam.getCommon());
System.out.println(nam.getAbbreviated());
System.out.println(nam.getCanonical());
} catch(Exception e) {
e.printStackTrace();
}
}
}
Issue2
Use values of PostedDate field and DeliveredDate field of mail document.
Issue3
Check that $Inbox folder contains your mail document. Or take a look at Dave Delay answer.
I agree with #nempoBu4 on Issues 1 and 2. I disagree with the answer to Issue 3. A received message can be removed from the inbox, so checking $Inbox doesn't help you distinguish between sent and received messages.
Assuming you have the document open, the best approach is to check two items. Sent and received messages both have a PostedDate item, but only a received message has a DeliveredDate item. Incidentally, a draft message has neither PostedDate or DeliveredDate.
I'm implementing a servlet as a JMX manager that runs in the same instance of Tomcat that all of the monitored servlets are running in. I can see the data of the monitored servlets when I open JConsole. From within my manager servlet I can enumerate all of the available standard MBeans, including the ones I've created in the monitored servlets, using this code like this:
JMXServiceURL url = new JMXServiceURL( "service:jmx:rmi://localhost:1099/jndi/rmi://localhost:1099/jmxrmi" );
mConnector = JMXConnectorFactory.connect( url );
mMBSC = mConnector.getMBeanServerConnection();
mObjectName = new ObjectName( "com.blahCompany.blah.blah:type=BlahBlah" );
// just looking for one specific bean
Set<ObjectName> myMbean = mMBSC.queryNames( mObjectName, null );
if( myMBean.size() == 1 ) // I know it exists
{
MBeanInfo mbeanInfo = mMBSC.getMBeanInfo( <ObjectName extracted from Set> );
MBeanAttributeInfo[] mbeanAttributeInfos = mbeanInfo.getAttributes();
for( MBeanAttributeInfo attribInfo : mbeanAttributeInfos )
{
if( attribInfo.isReadable() )
{
String attribName = attribInfo.getName();
String attribReturnType = attribInfo.getType();
// The data's somewhere ... where????
// In the MBeanInfo?
// In the MBeanAttributeInfo??
}
}
}
The problem is I don't know how to actually extract the data from these MBeans. The answer must be godawful obvious because no one else seems to have asked, but I do have a gift for overlooking the obvious. Your help will be gratefully appreciated.
Bill
All you need to do is something like the below:
Object value = mMBSC.getAttribute(objectName, attributeName);
Or create a proxy object that gets an instance of the MBean interface and allows you to access it that way. A tutorial on how to do this is here: http://docs.oracle.com/javase/tutorial/jmx/remote/custom.html
One note, this is assuming a remote connection, but from your question it seems your are accessing the beans locally? If that is the case then you can use platform.getMBeanServer() to get access to the MBeanServer more directly. E.g. MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();