Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

 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

1

0 votes



4 answers

Permanent link

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

0 votes

Comments

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.


Permanent link
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;
	}
}

0 votes


Permanent link
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;
	}



0 votes

Comments

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
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.

0 votes

Comments

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

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,927
× 411

Question asked: Apr 13 '15, 2:08 a.m.

Question was seen: 5,433 times

Last updated: Apr 13 '15, 10:04 a.m.

Confirmation Cancel Confirm