Showing results for 
Search instead for 
Did you mean: 
Showing results for 
Search instead for 
Did you mean: 

The PTC Community email address has changed to Learn more.

mks java api connection error


mks java api connection error


I am trying to connect to Mks using the mks java api and encounter the Connection refused: connect error.

I am using the following code



IntegrationPointFactory ipf = IntegrationPointFactory.getInstance();

CmdRunner cmdRunner;

Response resp =


try {

cmdRunner = ipf.createLocalIntegrationPoint(4, 10)


Command cmd =

new Command(Command.SI, "about");

resp = cmdRunner.execute(cmd);


catch (APIException e) {


out.println("Error " + e.getMessage());

resp = e.getResponse();



to connect at mks client (I am using MKS Integrity Client 2009) and I encounter the following error


Connection refused: connect


How can I improove the above code in order to successfully connect to mks and skyp the error ?

Best regards,


Have you made sure that the Integrity Server is configured to allow API connections? I think it's covered under the Integration Builder's Guide but to make sure, you should go to <Integrity Server Install>\config\client\IntegrityclientSite.rc and ensure that the following line is uncommented:


And make sure this line is commented-out:


The Integrity Server service would need to be restarted for these changes to take effect.

Hi again,

I just checked the Integrity Server settings, and they are as described in your previous Reply...nothing to change inside the .rc file..

Do you have any other idea how to solve this?...Also I am using Proxy server to conect to the main Server.

Many thanks in advance!

Hello Cristian, here is a very small bit of sample code I use when trying to troubleshoot API problems. The connection portion does appear to be a bit different from your code snippet, so try modifying the code below to suit your needs and see if that works for you:


import java.util.Iterator;

import com.mks.api.CmdRunner;

import com.mks.api.Command;

import com.mks.api.IntegrationPoint;

import com.mks.api.IntegrationPointFactory;

import com.mks.api.MultiValue;

import com.mks.api.Option;

import com.mks.api.Session;

import com.mks.api.response.APIException;

import com.mks.api.response.Field;

import com.mks.api.response.Response;

import com.mks.api.response.WorkItem;

import com.mks.api.response.WorkItemIterator;

public class MyClass {

public static void main(String args[]) {

String hostname = "<server name>";

int port = <port number>;

String username = "<user name>";

String password = "<password>";

CmdRunner cr = null;

Session session = null;

try {

IntegrationPointFactory ipf = IntegrationPointFactory.getInstance();

IntegrationPoint ip = ipf.createLocalIntegrationPoint();

session = ip.createSession(username, password);

cr = session.createCmdRunner();

} catch (APIException apie) {

System.out.println("Error occurred during initialization: " + apie.getMessage());




Command cmd = new Command();




cmd.addSelection("<item ID>");

try {

Response response = cr.execute(cmd);

if (response != null) {

WorkItemIterator wii = response.getWorkItems();

while (wii.hasNext()) {

WorkItem wi =;

Iterator<Field> iterator = wi.getFields();

while (iterator.hasNext()) {

Field field =;

System.out.println(field.getName() + " : " + field.getValueAsString());




} catch (APIException e) {

System.out.println("Error occurred when running command: " + e.getMessage());



try {


} catch (IOException e) {


} catch (APIException e) {



} //main method

} //class

That particular bit of code will do a simple "im viewissue" command.


I runned your example and I encountered the following error :


Error occurred when running command: Connection refused: connect


I tried with following commands:


// Command cmd = new Command();
// // **** IM VIEWISSUE EXAMPLE ****
// cmd.setApp(Command.IM);
// cmd.setCommandName("viewissue");
// cmd.addSelection("<item ID>");

} (without comments)



Command cmd = new Command(Command.SI, "co");
cmd.addOption(new Option("mergeType", "confirm"));
cmd.addOption(new Option("sandbox", sandbox.getAbsolutePath()));
cmd.addOption(new Option("changePackageId", ":none"));


Hmm... there must be something else not configured correctly. I would suggest opening a case with PTC Support to take a more in-depth look at the set-up.

It's perfectly working for me. Thank you very much!!


I appreciate that this is very old now, but I thought I would reply in case it helps someone seeing this error. I had the same thing. In my case CS158691 was applicable. I had to add -Djava.library.path option on the command line.

java -Djava.library.path=C:\Integrty.106\bin -jar ViewDocument-1.0.3.jar