It's all about the answers!

Ask a question

an exception when unassign a licesne i get com.ibm.team.repository.service.compatibility.util.http.CrossServerHttpClient$RestCommunicationException


0
1
eran meiri (2119) | asked Apr 13 '15, 2:08 a.m.
edited Apr 13 '15, 5:04 a.m. by Ralph Schoon (58.5k23642)
 hello , I am trying to unassign a license and getting this exception: 
com.ibm.team.repository.service.compatibility.util.http.CrossServerHttpClient$RestCommunicationException
this is my code:

NullProgressMonitor monitor = new NullProgressMonitor();
LoginHandler login = new LoginHandler("????", "?????");  
teamRepository.registerLoginHandler(login);
try {
teamRepository.login(monitor);
} catch (TeamRepositoryException e) {
e.printStackTrace();
System.out.print("this is not good");
}
ILicenseAdminService licenseAdmin = (ILicenseAdminService) ((TeamRepository) teamRepository).getServiceInterface(ILicenseAdminService.class);
System.out.print(licenseAdmin.toString());
//IContributorManager contributorManager = teamRepository.contributorManager();
IContributorHandle aUser;
try {
aUser = teamRepository.contributorManager().fetchContributorByUserId("user_id", null);
licenseAdmin.unassignLicense(aUser, "_0yFhJOGeEeSqbuNMcGcLkA"); // - exception !!
} catch (TeamRepositoryException e1) {
System.out.print(e1.toString());
e1.printStackTrace();
}

many thanks

4 answers



permanent link
Ralph Schoon (58.5k23642) | answered Apr 13 '15, 5:11 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Apr 13 '15, 5:13 a.m.
Dependent of this being a client side automation or a server extension the call to get the license manager would be:

Client API:

        ILicenseAdminService licAdin = (ILicenseAdminService)teamRepository.getClientLibrary(ILicenseAdminService.class);
        licAdin.unassignLicense(contributorHande, licenseId);

Server API (assuming you extend AbstractService):

        ILicenseAdminService licAdin = this.getService(ILicenseAdminService.class);
        licAdin.unassignLicense(contributorHande, licenseId);


Provided the license ID would be valid, I would assume that this works.


Comments
eran meiri commented Apr 13 '15, 5:43 a.m.

thanks for the answer.

the problem is that if I make the change you mentioned I get a null reference to the ILicenseAdminService object.

I am using client api...

thanks again


permanent link
Ralph Schoon (58.5k23642) | answered Apr 13 '15, 6:18 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Fascinating and you are right. The LicenseAdminService does not seem to be a regular client library and getClientLibrary does not work.

This code works for me:
		ILicenseAdminService licAdin = (ILicenseAdminService) ((IClientLibraryContext) teamRepository).getServiceInterface(ILicenseAdminService.class);
 		IContributor licenseUser = teamRepository.contributorManager().fetchContributorByUserId(licenseuser, monitor);
        licAdin.unassignLicense(licenseUser, licenseID); 


Where the user licenseuser is the ID as string, and licenseID is something like "com.ibm.team.rtc.developer".

I got the licenseID's this way:
	/**
	 * Build the license map only once
	 * 
	 * @param licenseService
	 * @param monitor
	 * @return
	 * @throws TeamRepositoryException
	 */
	private static HashMap getLicenseMapper(
			ILicenseAdminService licenseService, IProgressMonitor monitor)
			throws TeamRepositoryException {
		if (fLicenseMapp != null) {
			return fLicenseMapp;
		}
		fLicenseMapp = new HashMap();

		IContributorLicenseType[] types = licenseService.getLicenseTypes();
		for (IContributorLicenseType iContributorLicenseType : types) {
			// System.out.println("Lic:"+iContributorLicenseType.getId()+" " +
			// iContributorLicenseType.getName() + " " +
			// iContributorLicenseType.getProductName()+ " " +
			// iContributorLicenseType.getEditionName() +" " +
			// iContributorLicenseType.getDescription());
			fLicenseMapp.put(iContributorLicenseType.getId(),
					iContributorLicenseType.getProductName() + " "
							+ iContributorLicenseType.getName());
		}
		return fLicenseMapp;
	}




Comments
eran meiri commented Apr 13 '15, 7:36 a.m.

it is not working for me.

the

unassignLicense method is part of the ILicenseAdminService so I can't call it from the LicenseAdminLibrary.

I can't import the LicenseAdminLibrary  so I can't even test to see if the method is in there.

is it working for you that way?


permanent link
Ralph Schoon (58.5k23642) | answered Apr 13 '15, 7:43 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
This is my working code:

I call it with parameters:

"https://clm.example.com:9443/jts" "adminID" "adminPasswd" "userToDeleteLicense" "com.ibm.rtc.developer-iep.floating"

I use ILicenseAdminService as you did above. Note, it apears NOT to be a typical ClientLibrary, so you need to get it with the code you show in your original question.
/*******************************************************************************
 * Licensed Materials - Property of IBM
 * (c) Copyright IBM Corporation 2008. All Rights Reserved. 
 *
 * Note to U.S. Government Users Restricted Rights:  Use, duplication or 
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 *******************************************************************************/
package com.ibm.team.workitem.ide.ui.example;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;

import com.ibm.team.repository.client.ITeamRepository;
import com.ibm.team.repository.client.ITeamRepository.ILoginHandler;
import com.ibm.team.repository.client.ITeamRepository.ILoginHandler.ILoginInfo;
import com.ibm.team.repository.client.TeamPlatform;
import com.ibm.team.repository.client.util.IClientLibraryContext;
import com.ibm.team.repository.common.IContributor;
import com.ibm.team.repository.common.ILicenseAdminService;
import com.ibm.team.repository.common.TeamRepositoryException;

/**
 * Example code, see
 * https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation.
 */
public class LicenseDelete {

	private static class LoginHandler implements ILoginHandler, ILoginInfo {

		private String fUserId;
		private String fPassword;

		private LoginHandler(String userId, String password) {
			fUserId = userId;
			fPassword = password;
		}

		public String getUserId() {
			return fUserId;
		}

		public String getPassword() {
			return fPassword;
		}

		public ILoginInfo challenge(ITeamRepository repository) {
			return this;
		}
	}

	public static void main(String[] args) {

		boolean result;
		TeamPlatform.startup();
		try {
			result = run(args);
		} catch (TeamRepositoryException x) {
			x.printStackTrace();
			result = false;
		} finally {
			TeamPlatform.shutdown();
		}

		if (!result)
			System.exit(1);

	}

	private static boolean run(String[] args) throws TeamRepositoryException {

		if (args.length != 5) {
			System.out
					.println("Usage: LicenseDelete     ");
			System.out.println("  for example 'bob' ");
			System.out.println("  for example 'com.ibm.team.rtc.developer' ");
			return false;
		}

		IProgressMonitor monitor = new NullProgressMonitor();
		String repositoryURI = args[0];
		String userId = args[1];
		String password = args[2];
		String licenseuser = args[3];
		String licenseID = args[4];

		ITeamRepository teamRepository = TeamPlatform
				.getTeamRepositoryService().getTeamRepository(repositoryURI);
		teamRepository.registerLoginHandler(new LoginHandler(userId, password));
		teamRepository.login(null);

		
		ILicenseAdminService licAdin = (ILicenseAdminService) ((IClientLibraryContext) teamRepository).getServiceInterface(ILicenseAdminService.class);
 		IContributor licenseUser = teamRepository.contributorManager().fetchContributorByUserId(licenseuser, monitor);
        licAdin.unassignLicense(licenseUser, licenseID); 


		teamRepository.logout();

		return true;
	}
}


permanent link
eran meiri (2119) | answered Apr 13 '15, 9:53 a.m.

still no go.

I still get the original error CrossServerHttpClient$RestCommunicationException with a cause reason null.

here is my code :


import java.util.HashMap;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;

import com.ibm.team.filesystem.client.internal.rest.util.LoginUtil.LoginHandler;
import com.ibm.team.repository.client.IContributorManager;
import com.ibm.team.repository.client.ITeamRepository;
import com.ibm.team.repository.client.ITeamRepository.ILoginHandler;
import com.ibm.team.repository.client.ITeamRepository.ILoginHandler.ILoginInfo;
import com.ibm.team.repository.client.TeamPlatform;
import com.ibm.team.repository.client.internal.TeamRepository;
import com.ibm.team.repository.client.util.IClientLibraryContext;
import com.ibm.team.repository.common.IContributorHandle;
import com.ibm.team.repository.common.IContributorLicenseType;
import com.ibm.team.repository.common.ILicenseAdminService;
import com.ibm.team.repository.common.ILicenseType;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.common.IContributor;
import com.ibm.team.repository.common.TeamRepositoryException;
//import com.ibm.team.rtc.foundation.api.common.progress.IProgressMonitor;

public class first
{

	public static ITeamRepository getTeamRepository() {		
		String repositoryURI = "https://????????????:9443/ccm";		
		TeamPlatform.startup();		
		ITeamRepository teamRepository = TeamPlatform.getTeamRepositoryService().getTeamRepository(repositoryURI);		
		return teamRepository;
	}	
	
	public static void main (String[] args){
		ITeamRepository test = getTeamRepository();
		assignClientAccessLicenseToUser(test);
		System.out.print(test.toString());
	}
	
	public static void assignClientAccessLicenseToUser(ITeamRepository teamRepository) 
	{
		NullProgressMonitor monitor = new NullProgressMonitor();
		LoginHandler login = new LoginHandler("?????", "?????");		 
		teamRepository.registerLoginHandler(login);
		try {
			teamRepository.login(null);
		} catch (TeamRepositoryException e) {			
			e.printStackTrace();
			System.out.print("this is not good");
		}
		ILicenseAdminService licenseAdmin = (ILicenseAdminService) ((IClientLibraryContext) teamRepository).getServiceInterface(ILicenseAdminService.class);
		
		try {
			IContributorHandle aUser = teamRepository.contributorManager().fetchContributorByUserId("?????", monitor);
			licenseAdmin.unassignLicense(aUser, "com.ibm.team.rtc.?????????????");
		} catch (TeamRepositoryException e1) {			
			System.out.print(e1.toString());
			e1.printStackTrace();
		}
	}
}


Comments
Ralph Schoon commented Apr 13 '15, 10:04 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I can only tell you, that my code works for me. Try to set up a test system on Tomcat and Derby. Have a look into your server logs to try to figure out what the issue is.

Your answer


Register or to post your answer.