It's all about the answers!

Ask a question

Login exception org.eclipse.swt.SWTException: Invalid thread


Jagadish R Rao (10612111) | asked Apr 06 '10, 12:25 a.m.
Hi

I am trying to access different repository and copy the work item .. from the selection .. It works fine when I try copying from RTC server A to localhost (RTC on my machine) but fails when I try to copy across different RTC server B.

Code:

public void run(IAction action) {
// TODO Auto-generated method stub
if (!(fSelection instanceof IStructuredSelection))
return;

final IWorkItemHandle handle= (IWorkItemHandle) ((IStructuredSelection) fSelection).getFirstElement();

Job job= new FoundationJob("Copying Work item across repository ...") {
@Override
protected IStatus runProtected(IProgressMonitor monitor) throws Exception {

ITeamRepository teamRepository=(ITeamRepository) handle.getOrigin();
IAuditableClient auditableClient= (IAuditableClient) teamRepository.getClientLibrary(IAuditableClient.class);
IWorkItemClient workItemClient= (IWorkItemClient) teamRepository.getClientLibrary(IWorkItemClient.class);

if (handle instanceof IWorkItem && ((IWorkItem) handle).isNewItem())
return new Status(IStatus.ERROR, PLUGIN_ID, "The original work item must be saved first.");

IWorkItem workItem=auditableClient.resolveAuditable(handle, IWorkItem.FULL_PROFILE, monitor);
IWorkItemType type= workItemClient.findWorkItemType(workItem.getProjectArea(), workItem.getWorkItemType(), monitor);
if (type == null)
return new Status(IStatus.ERROR, PLUGIN_ID, "The original work item's type no longer defined: " + workItem.getWorkItemType());

int orgWorkItemID=workItem.getId();
IWorkItemWorkingCopyManager srcCopyManager= workItemClient.getWorkItemWorkingCopyManager();
List<Integer> srcWIList = new ArrayList<Integer> ();
srcWIList.add(orgWorkItemID);
IWorkItemHandle srcWIHandle = workItemClient.findWorkItemsById(srcWIList,null).get(0);
srcCopyManager.connect(srcWIHandle, IWorkItem.FULL_PROFILE, null);
WorkItemWorkingCopy srcWorkingCopy = srcCopyManager.getWorkingCopy(srcWIHandle);

Display display = PlatformUI.createDisplay();
getLoginDetails operation=new getLoginDetails(display);
displayWorkItemCopyStatus dWICS=new displayWorkItemCopyStatus(display);

try{
//operation.createContents();
//copyWorkItemToDestProjectArea(auditableClient, workItem, srcWorkingCopy, teamRepository, repositoryURI, username, password, projectAreaName);
copyWorkItemToDestProjectArea(auditableClient, workItem, srcWorkingCopy, teamRepository, "https://ch2dlfi074:9443/jazz/", "jramakri", "q1w2e3r4", "TestPA");
}

private void copyWorkItemToDestProjectArea(IAuditableClient srcAuditableClient, IWorkItem srcWorkItem,WorkItemWorkingCopy srcWorkingCopy,ITeamRepository srcTeamRepository,String dstRepositoryURI,String dstUserId,String dstPassword,String dstProjectAreaName)
throws TeamRepositoryException, NullPointerException, FileNotFoundException
{


Display display = PlatformUI.createDisplay();
displayWorkItemCopyStatus dWICS=new displayWorkItemCopyStatus(display);

ITeamRepository dstTeamRepository=null;
IProjectArea dstProjectArea=null;
IWorkItemClient dstWorkItemClient;

String categoryName="Backlog";

//Login to Destination repository

System.out.println("URI "+dstRepositoryURI);
System.out.println("User "+dstUserId);
System.out.println("Password "+dstPassword);

dstTeamRepository= TeamPlatform.getTeamRepositoryService().getTeamRepository(dstRepositoryURI);
System.out.println("Get repository ...");
dstTeamRepository.registerLoginHandler(new LoginHandler(dstUserId, dstPassword));
System.out.println("Get Login handle ...");
dstTeamRepository.login(null);
System.out.println("logged in ...");
IProcessClientService dstProcessClient= (IProcessClientService) dstTeamRepository.getClientLibrary(IProcessClientService.class);
//IAuditableClient dstAuditableClient= (IAuditableClient) dstTeamRepository.getClientLibrary(IAuditableClient.class);
dstWorkItemClient= (IWorkItemClient) dstTeamRepository.getClientLibrary(IWorkItemClient.class);
...
...
}
The exception when I run is as follows ...

URI https://ch2dlfi074:9443/jazz/
User jramakri
Password q1w2e3r4
Get repository ...
Get Login handle ...
com.ibm.team.repository.common.transport.ServiceMethodInvocationError: org.eclipse.swt.SWTException: Invalid thread access
at com.ibm.team.repository.transport.client.RemoteTeamService.getAppropriateException(RemoteTeamService.java:638)
at com.ibm.team.repository.transport.client.RemoteTeamService.executeMethod(RemoteTeamService.java:496)
at com.ibm.team.repository.transport.client.RemoteTeamService.invoke(RemoteTeamService.java:201)
at com.ibm.team.repository.transport.client.ServiceInvocationHandler.invoke(ServiceInvocationHandler.java:43)
at $Proxy0.describe(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at com.ibm.team.repository.client.internal.ServiceInterfaceProxy.invokeServiceCall(ServiceInterfaceProxy.java:149)
at com.ibm.team.repository.client.internal.ServiceInterfaceProxy.invoke(ServiceInterfaceProxy.java:84)
at $Proxy0.describe(Unknown Source)
at com.ibm.team.repository.client.internal.TeamRepository$4.run(TeamRepository.java:1382)
at com.ibm.team.repository.client.internal.TeamRepository$4.run(TeamRepository.java:1)
at com.ibm.team.repository.client.internal.TeamRepository$3.run(TeamRepository.java:1169)
at com.ibm.team.repository.common.transport.CancelableCaller.call(CancelableCaller.java:79)
at com.ibm.team.repository.client.internal.TeamRepository.callCancelableService(TeamRepository.java:1162)
at com.ibm.team.repository.client.internal.TeamRepository.internalLogin(TeamRepository.java:1375)
at com.ibm.team.repository.client.internal.TeamRepository.login(TeamRepository.java:570)
at com.ibm.team.workitem.ide.ui.copyWorkitemCR.copyWorkItemToDestProjectArea(copyWorkitemCR.java:118)
at com.ibm.team.workitem.ide.ui.copyWorkitemCR.access$0(copyWorkitemCR.java:94)
at com.ibm.team.workitem.ide.ui.copyWorkitemCR$1.runProtected(copyWorkitemCR.java:325)
at com.ibm.team.foundation.client.util.FoundationJob.run(FoundationJob.java:68)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:3777)
at org.eclipse.swt.SWT.error(SWT.java:3695)
at org.eclipse.swt.SWT.error(SWT.java:3666)
at org.eclipse.swt.widgets.Display.error(Display.java:1180)
at org.eclipse.swt.widgets.Display.checkDevice(Display.java:703)
at org.eclipse.swt.widgets.Display.getSystemColor(Display.java:2211)
at com.ibm.team.process.internal.rcp.ui.RepositoryCertificateDialog.createDialogArea(RepositoryCertificateDialog.java:115)
at org.eclipse.jface.dialogs.Dialog.createContents(Dialog.java:760)
at org.eclipse.jface.window.Window.create(Window.java:431)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1089)
at com.ibm.team.process.internal.rcp.ui.RepositoryCertificateDialog.create(RepositoryCertificateDialog.java:81)
at org.eclipse.jface.window.Window.open(Window.java:790)
at com.ibm.team.process.internal.rcp.ui.RepositoryCertificateHandler.ask(RepositoryCertificateHandler.java:41)
at com.ibm.team.process.internal.rcp.ui.RepositoryCertificateHandler.evaluate(RepositoryCertificateHandler.java:102)
at com.ibm.team.repository.client.internal.TeamRepository$6.validate(TeamRepository.java:1621)
at com.ibm.team.repository.transport.client.SecureInterruptableSocketFactory.handleCertificateHostnameMismatch(SecureInterruptableSocketFactory.java:202)
at com.ibm.team.repository.transport.client.SecureInterruptableSocketFactory.createSocket(SecureInterruptableSocketFactory.java:165)
at com.ibm.team.repository.transport.client.SecureInterruptableSocketFactory.createSocket(SecureInterruptableSocketFactory.java:317)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1321)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
at com.ibm.team.repository.transport.client.ClientHttpUtil.executeHttpMethod(ClientHttpUtil.java:155)
at com.ibm.team.repository.transport.client.RemoteTeamService.executeCancelableHttpMethod(RemoteTeamService.java:561)
at com.ibm.team.repository.transport.client.RemoteTeamService.invokePost(RemoteTeamService.java:531)
at com.ibm.team.repository.transport.client.RemoteTeamService.executeMethod(RemoteTeamService.java:471)
... 22 more

Any Help ... what is wrong here ?
Thanks & Regards
Jagadish

2 answers



permanent link
Patrick Streule (4.9k21) | answered Apr 06 '10, 4:25 a.m.
JAZZ DEVELOPER
Job job= new FoundationJob("Copying Work item across repository
..") {
@Override
protected IStatus runProtected(IProgressMonitor monitor) throws
Exception {

...
Display display = PlatformUI.createDisplay();
getLoginDetails operation=new getLoginDetails(display);
displayWorkItemCopyStatus dWICS=new
displayWorkItemCopyStatus(display);


Caused by: org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:3777)
at org.eclipse.swt.SWT.error(SWT.java:3695)
at org.eclipse.swt.SWT.error(SWT.java:3666)
at org.eclipse.swt.widgets.Display.error(Display.java:1180)
at org.eclipse.swt.widgets.Display.checkDevice(Display.java:703)
at org.eclipse.swt.widgets.Display.getSystemColor(Display.java:2211)
at
com.ibm.team.process.internal.rcp.ui.RepositoryCertificateDialog.createDialogArea(RepositoryCertificateDialog.java:115)

Any Help ... what is wrong here ?

You must not use SWT (Display in this case) from a background thread,
but only from the UI thread. You should ask the user for credentials
first (e.g in public void run(IAction action) ) and then pass the
credentials to the background job.

--
Regards,
Patrick
Jazz Work Item Team

permanent link
Jagadish R Rao (10612111) | answered Apr 06 '10, 11:51 p.m.
Hi Patrick,

Many thanks .. it is working bueatifully now ..

Thanks & Regards
Jagadish

Job job= new FoundationJob("Copying Work item across repository
..") {
@Override
protected IStatus runProtected(IProgressMonitor monitor) throws
Exception {

...
Display display = PlatformUI.createDisplay();
getLoginDetails operation=new getLoginDetails(display);
displayWorkItemCopyStatus dWICS=new
displayWorkItemCopyStatus(display);


Caused by: org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:3777)
at org.eclipse.swt.SWT.error(SWT.java:3695)
at org.eclipse.swt.SWT.error(SWT.java:3666)
at org.eclipse.swt.widgets.Display.error(Display.java:1180)
at org.eclipse.swt.widgets.Display.checkDevice(Display.java:703)
at org.eclipse.swt.widgets.Display.getSystemColor(Display.java:2211)
at
com.ibm.team.process.internal.rcp.ui.RepositoryCertificateDialog.createDialogArea(RepositoryCertificateDialog.java:115)

Any Help ... what is wrong here ?

You must not use SWT (Display in this case) from a background thread,
but only from the UI thread. You should ask the user for credentials
first (e.g in public void run(IAction action) ) and then pass the
credentials to the background job.

--
Regards,
Patrick
Jazz Work Item Team

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.