Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Hello,
is it possible to access a PTC Integrity Server / Cloud directly through the JAVA API i.e. via https:// protocol without use of any other local PTC Client installation files? So far, i could not see any information about this in the documentation which is not using command line interface in the end.
Thank you for your support!
API Version of PTC 11.0 - 4.16.506
JRE 8 u172 is used for my own application
Solved! Go to Solution.
Well, i think i have to rephrase the question:
What could be the cause for failing to connect to our PTC Integrity Server with our direct access through the API?
This behaviour also leads to two other questions:
Does PTC Server require any specific configuration?
Is a specific Port for the SSL Connection required? If so, which port is it?
The code we used for testing:
public static void main(String[] args) {
IntegrationPointFactory.enableAPILogging(new File(LOG_FILE));
IntegrationPointFactory ipf = IntegrationPointFactory.getInstance();
IntegrationPoint ip = null;
Session session = null;
CmdRunner cmdRunner = null;
try {
String sessionId = "session0815";
/*
* secure integration point to server
*/
ip = ipf.createIntegrationPoint(
HOST, PORT, true, APIVersion.API_4_16);
session = ip.createNamedSession(
sessionId, APIVersion.API_4_16, USER, PASSWORD);
cmdRunner = session.createCmdRunner();
cmdRunner.setDefaultHostname(HOST);
cmdRunner.setDefaultPort(PORT);
cmdRunner.setDefaultUsername(USER);
cmdRunner.setDefaultPassword(PASSWORD);
Command cmd = new Command("im", "issues");
cmd.addOption(new Option("query", QUERY));
cmd.addOption(new Option("fields", "id,state,type,project,summary,assigned user"));
Response response = cmdRunner.execute(cmd);
Result result = response.getResult();
WorkItemIterator wii = response.getWorkItems();
WorkItem workItem;
int id;
Item stateItem;
Item typeItem;
Item projectItem;
while(wii.hasNext()) {
workItem = wii.next();
id = workItem.getField("id").getInteger();
stateItem = workItem.getField("state").getItem();
typeItem = workItem.getField("type").getItem();
projectItem = workItem.getField("project").getItem();
Project p = new Project (id, stateItem.getId(),
typeItem.getId(), projectItem.getId());
System.out.println(p.toString());
}
cmdRunner.release();
session.release();
ip.release();
} catch (APIException apie) {
apie.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
cmdRunner.release();
session.release();
ip.release();
} catch (Exception e) {
e.printStackTrace();
}
}
You can find error logs from both hosts attached in this reply. It might help to find a solution.
Thank you in advance!
You can add a boolean to the createIntegrationPoint method to create a secure connection to the Integrity Server. From the API Java Docs for IntegrationPointFactory:
public IntegrationPoint createIntegrationPoint(java.lang.String host, int port, boolean secure, int apiMajorVersion, int apiMinorVersion) throws APIException
Well, i think i have to rephrase the question:
What could be the cause for failing to connect to our PTC Integrity Server with our direct access through the API?
This behaviour also leads to two other questions:
Does PTC Server require any specific configuration?
Is a specific Port for the SSL Connection required? If so, which port is it?
The code we used for testing:
public static void main(String[] args) {
IntegrationPointFactory.enableAPILogging(new File(LOG_FILE));
IntegrationPointFactory ipf = IntegrationPointFactory.getInstance();
IntegrationPoint ip = null;
Session session = null;
CmdRunner cmdRunner = null;
try {
String sessionId = "session0815";
/*
* secure integration point to server
*/
ip = ipf.createIntegrationPoint(
HOST, PORT, true, APIVersion.API_4_16);
session = ip.createNamedSession(
sessionId, APIVersion.API_4_16, USER, PASSWORD);
cmdRunner = session.createCmdRunner();
cmdRunner.setDefaultHostname(HOST);
cmdRunner.setDefaultPort(PORT);
cmdRunner.setDefaultUsername(USER);
cmdRunner.setDefaultPassword(PASSWORD);
Command cmd = new Command("im", "issues");
cmd.addOption(new Option("query", QUERY));
cmd.addOption(new Option("fields", "id,state,type,project,summary,assigned user"));
Response response = cmdRunner.execute(cmd);
Result result = response.getResult();
WorkItemIterator wii = response.getWorkItems();
WorkItem workItem;
int id;
Item stateItem;
Item typeItem;
Item projectItem;
while(wii.hasNext()) {
workItem = wii.next();
id = workItem.getField("id").getInteger();
stateItem = workItem.getField("state").getItem();
typeItem = workItem.getField("type").getItem();
projectItem = workItem.getField("project").getItem();
Project p = new Project (id, stateItem.getId(),
typeItem.getId(), projectItem.getId());
System.out.println(p.toString());
}
cmdRunner.release();
session.release();
ip.release();
} catch (APIException apie) {
apie.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
cmdRunner.release();
session.release();
ip.release();
} catch (Exception e) {
e.printStackTrace();
}
}
You can find error logs from both hosts attached in this reply. It might help to find a solution.
Thank you in advance!
Hello @fjacksch,
In both host1_mksapi.txt and host2_mksapi.txt, you see this:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
That suggests that the server you're trying to connect to is secure HTTP (https://) rather than clear HTTP. Based on that, I'd suggest looking at CS138333 - How to use Java API with an SSL enabled Integrity Server.
These other articles might also be relevant:
Kind Regards,
Kael Lizak
Senior Technical Support Engineer
Integrity Lifecycle Manager
PTC