Skip to main content
4-Participant
January 15, 2014
Question

mks java api connection error

  • January 15, 2014
  • 2 replies
  • 7818 views

Hello

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 =

null;

try {

cmdRunner = ipf.createLocalIntegrationPoint(4, 10)

.getCommonSession().createCmdRunner();

Command cmd =

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

resp = cmdRunner.execute(cmd);

}

catch (APIException e) {

System.

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,

    2 replies

    21-Topaz I
    January 15, 2014

    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:

    daemon.connectionPolicy=mks.ic.common.policy.ICAllowAllConnectionPolicy

    And make sure this line is commented-out:

    #daemon.connectionPolicy=mks.ic.common.policy.ICAllowSpecificConnectionPolicy

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

    4-Participant
    January 16, 2014

    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!

    21-Topaz I
    January 16, 2014

    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.io.IOException;

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

    apie.printStackTrace();

    System.exit(1);

    }

    Command cmd = new Command();

    // **** IM VIEWISSUE EXAMPLE ****

    cmd.setApp(Command.IM);

    cmd.setCommandName("viewissue");

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

    try {

    Response response = cr.execute(cmd);

    if (response != null) {

    WorkItemIterator wii = response.getWorkItems();

    while (wii.hasNext()) {

    WorkItem wi = wii.next();

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

    while (iterator.hasNext()) {

    Field field = iterator.next();

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

    }

    }

    }

    } catch (APIException e) {

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

    e.printStackTrace();

    }

    try {

    session.release();

    } catch (IOException e) {

    e.printStackTrace();

    } catch (APIException e) {

    e.printStackTrace();

    }

    } //main method

    } //class

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

    1-Visitor
    July 18, 2017

    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