custom groovy class - "unable to resolve class"es from other plugin

Dominik December 6, 2016

I have created a groovy class (in the script root dir) which uses a library included in an installed plugin

What I have

<root>/Testclass.groovy

import org.apache.log4j.*; // Logger
import com.atlassian.jira.component.ComponentAccessor;
import com.mks.api.*;
import com.mks.api.response.*;
import agileconnector.*;

public class Testclass {
  ...
  // Logger
  final static Logger log = Logger.getLogger("Testclass");
  
  final Long issueId;
  final String userName;
  String impersonatedUserName,
         impersonatedUserPw;
  boolean onProductiveServer = null ; // set by method setProdOrTestServer()
  
  // Integrity Classes
  final IntegrationPointFactory ipf;
  final IntegrationPoint ip;
  final Session session;
  final CmdRunner runner;

  public Testclass(String name, Long id){
    // ============================== init ==============================
    log.setLevel(Level.DEBUG);
    
    this.userName = name;
    this.issueId = id;

    setProdOrTestServer();
    setImpersonatedUser();
    
    try {
      // ==================== create Connection to IMS ====================
      ipf = IntegrationPointFactory.getInstance();
      
      if (onProductiveServer){
        ip = ipf.createIntegrationPoint(imsProdServerHostname, imsProdServerPort_si, imsApiMajorVersion, imsApiMinorVersion);
      } else {
        ip = ipf.createIntegrationPoint(imsTestServerHostname, imsTestServerPort_si, imsApiMajorVersion, imsApiMinorVersion);
      }
      session = ip.createSession(impersonatedUserName, impersonatedUserPw);
      session.setTimeout(imsSessionTimeout); // set Timeout 1.200.000 Millisekunden -&gt; 20 Minuten
      runner = session.createCmdRunner();
    
      // ======================== execute commands ========================
      command();
      ...
    }  
  }
  
  // methods...
}

 

<root>/test.groovy

import Testclass;
new Testclass("user", 1L );

 

When I call the script test.groovy at the script consolethe command is successfully executed.

 

Problem

But when I try creating the class in a REST Endpoint Script (called when pressing a Web Item Button) or Script Listener

REST Endpoint Script

<root>/do.groovy

...
import Testclass;
 
do(httpMethod: "GET") { MultivaluedMap queryParams -&gt;
    ...
    new Testclass(userName, issueId);
	...
}

 

I always get the error message:

2016-12-06 14:31:24,991 http-nio-8080-exec-10 ERROR user 871x153353x1 52et7rn  /rest/scriptrunner/latest/custom/doSomething [c.a.p.r.c.error.jersey.ThrowableExceptionMapper] Uncaught exception thrown by REST service: startup failed:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/C:/Program%20Files/Atlassian/Application%20Data/JIRA/scripts/Testclass.groovy: 31: unable to resolve class IntegrationPointFactory 
 @ line 31, column 3.
     final IntegrationPointFactory ipf;
     ^
file:/C:/Program%20Files/Atlassian/Application%20Data/JIRA/scripts/Testclass.groovy: 32: unable to resolve class IntegrationPoint 
 @ line 32, column 3.
     final IntegrationPoint ip;
     ^
file:/C:/Program%20Files/Atlassian/Application%20Data/JIRA/scripts/Testclass.groovy: 33: unable to resolve class Session 
 @ line 33, column 3.
     final Session session;
     ^
file:/C:/Program%20Files/Atlassian/Application%20Data/JIRA/scripts/Testclass.groovy: 34: unable to resolve class CmdRunner 
 @ line 34, column 3.
     final CmdRunner runner;
     ^

 

 

What is the difference between createing the class in a script outgoing from the script console, instead of a REST Endpoint Script or Script Listener??

 

JIRA v.7.1.9

ScriptRunner v4.3.13

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Dominik December 7, 2016

Could it be possible, that it relys on

part of log line:

/rest/scriptrunner/latest/user/exec/

where the script is successfully executed

 

and

part of log line:

/rest/scriptrunner/latest/custom/doSomething

where I can't use the classes of the plugin library

TAGS
AUG Leaders

Atlassian Community Events