It's all about the answers!

Ask a question

get clientLibrary from plain java (Hello Jazz tutorial)


Martin Dam Pedersen (1352814) | asked Nov 20 '12, 7:42 a.m.
edited Nov 20 '12, 7:43 a.m.
 I have successfully followed the "Hello Jazz tutorial" located at https://jazz.net/library/article/118. The example uses a JUnit test class to test the service call, and it runs just fine without any errors.

My problem is that it doesn't work when i try to call the service from a plain java class. My test class looks like the the JUnit test class, the main difference is that it doesn't extend TestCase. 
The problem is that the repo.getClientLibrary clause returns null.

I have read the thread https://jazz.net/forum/questions/648/client-library-not-found-during-the-service-call but that didn't help me.

Can anyone please help me in understanding what i am doing wrong ?
Isn't possible to call a ClientLibrary from a plain java class ?

Here is the test code. 
package com.example.hellojazz.client.tests;
import com.example.hellojazz.client.IHelloJazzClientLibrary;
import com.ibm.team.repository.client.ITeamRepository;
import com.ibm.team.repository.client.TeamPlatform;
import com.ibm.team.repository.common.TeamRepositoryException;
public class SimpleTest {
private ITeamRepository repo;

public static void main(String[] args) throws TeamRepositoryException{
SimpleTest test = new SimpleTest();
test.helloJazz();
 
}
private void helloJazz() throws TeamRepositoryException {
if (!TeamPlatform.isStarted())
TeamPlatform.startup();
repo = login();
if(repo!=null){
IHelloJazzClientLibrary library = (IHelloJazzClientLibrary) repo.getClientLibrary(IHelloJazzClientLibrary.class);
String result = library.sayHello();
System.out.println("resultat = "+result);
}
repo.logout();
}
/**
* The URI scheme <code>"local:"</code> creates a Jazz server on the same
* thread as the client.
*/
private static final String REPOSITORY_URI = "https://localhost:7443/jazz";
private ITeamRepository login() throws TeamRepositoryException {
ITeamRepository repository = TeamPlatform.getTeamRepositoryService()
.getUnmanagedRepository(REPOSITORY_URI);
repository.registerLoginHandler(new ITeamRepository.ILoginHandler() {
public ILoginInfo challenge(ITeamRepository repo) {
return new ILoginInfo() {
public String getUserId() {
return "TestJazzAdmin1";
}
public String getPassword() {
return "TestJazzAdmin1";
}
};
}
});
repository.login(null);
return repository;
}
}



Comments
Ralph Schoon commented Nov 20 '12, 11:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Martin, I haven't used the code above. I would assume the library would at least need to be in the classpath. My automation usually does not create a new client library. So I can't say if there is a registration process that needs to be added. I started here: https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation for what its worth.


Martin Dam Pedersen commented Nov 20 '12, 5:24 p.m.

I am quite sure that IHelloJazzClientLibrary.class is in my classpath. When running the JUnit test I have no problems getting an instance of IHelloJazzClientLibrary, and no problem calling sayHello. But when I try to get an instance from a plain java application it doesn't work. 


The call repo.getClientLibrary(IHelloJazzClientLibrary.class)
returns null when called from a plain java application. But it returns an instance of HelloJazzClientLibrary when called from JUnit test program.

Has anyone succeeded in calling a custom clientLibrary from a plain java app.?
What am i missing here, some kind of registration as Ralph mentions ? 

I am quite familiar with the client library, and have made lots of automation classes that works just fine. This is just another approach that i would like to give a try. For some of my automation this would be very useful.

Accepted answer


permanent link
sam detweiler (12.5k6195201) | answered Nov 20 '12, 12:05 p.m.
looks like you need to insure the
IHelloJazzClientLibrary.class is in the classpath

it is pre-compiled in the zip file here

com.example.hellojazz-plugins-source.zip\com.example.hellojazz-plugins-source\com.example.hellojazz.service\bin\com\example\hellojazz\service\internal
Martin Dam Pedersen selected this answer as the correct answer

3 other answers



permanent link
Martin Dam Pedersen (1352814) | answered Nov 21 '12, 2:13 a.m.
Finally I managed to get it working. 

The problem was indeed the classpath. 
In my first eclipse launcher(the one that didn't work) I added the projects com.example.hellojazz.common and com.example.hellojazz.client on my classpath, but that didn't work. 

Then i exported com.example.hellojazz.client and com.example.hellojazz.common to jar files and added them to my classpath in the launcher instead of the projects, and then it worked like a charm. 

could anyone explain to me why the first attempt didn't work ?  I would expect it to work similar to the second attempt, but it didn't.

Thank you for your help.


permanent link
sam detweiler (12.5k6195201) | answered Nov 21 '12, 6:58 a.m.
yes, I should have noted that I created a jar file to hold my client library class as well..

permanent link
sam detweiler (12.5k6195201) | answered Nov 20 '12, 6:19 p.m.
I have a plain java client app that calls thru a client library without problem.

here is my call to my client library
    // TODO Auto-generated method stub
      private static IMemoryClient IMemService=null;
      private static IMemoryClient getMemoryService(String url)
      {
          if(IMemService==null)
              IMemService=(IMemoryClient)getRepository(url).getClientLibrary(IMemoryClient.class);
          if(IMemService==null)
              System.out.println("parm client get library failed");   
          return IMemService;
      }


Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.