I have been trying to import classes from com.atlassian.sal.api.net in order to do authentication through application links (between BitBucket and Jira) but have continually run into compilation failures when running atlas-debug, specifically this error:
[ERROR] /C:/AtlasPlugin/plugin/src/main/java/com/atlassian/branchenforce/util/JiraProjects.java:[68,47] cannot find symbol
symbol: variable Response
location: variable response of type com.atlassian.sal.api.net.Response
I have the line specifying the import of the class
`import com.atlassian.sal.api.net.Response;`
The constructor and the Component Import annotation
private final Response response;
@Inject
public JiraProjects(@ComponentImport final ApplicationLinkService applicationLinkService, @ComponentImport final Response response)
{
this.applicationLinkService = applicationLinkService;
this.response = response;
}
As well as the dependency in the pom.xml file which was generated when first creating the plugin.
The only possible thing I can think of is that the version of the SAL api it’s compiling with, is not compatible with the version of BitBucket I’m trying to load when running atlas-debug.
Are there any additional dependencies that should be added? Or a known problem with the SAL api package?
Response isn’t injectable (which you already knew ).
To get you started properly, let’s create an app that just executes http requests over to Jira from Bitbucket. First we’ll create a service called JiraRemoteConnectionService (because well it will connect to a remote Jira - and I have no imagination) - it has a single method: getContent
@Component
public class JiraRemoteConnectionService
{
@ComponentImport
private final ApplicationLinkService applicationLinkService;
@Inject
public JiraRemoteConnectionService( final ApplicationLinkService applicationLinkService)
{
this.applicationLinkService = applicationLinkService;
}
public String getContent(final String url)
{
final StringBuffer stringBuffer = new StringBuffer();
for(final ApplicationLink applicationLink: this.applicationLinkService.getApplicationLinks(JiraApplicationType.class))
{
try
{
Request request = applicationLink.createImpersonatingAuthenticatedRequestFactory().createRequest(Request.MethodType.GET, url);
request.executeAndReturn(new ReturningResponseHandler() {
public Object handle(Response response) throws ResponseException
{
if( response.isSuccessful())
{
stringBuffer.append( applicationLink.getName());
stringBuffer.append("\n");
stringBuffer.append(url);
stringBuffer.append("\n");
stringBuffer.append( response.getResponseBodyAsString());
stringBuffer.append("\n\n");
}
else
{
stringBuffer.append( response.getStatusCode());
}
return null;
}
});
}
catch(Exception e)
{
stringBuffer.append("Error received\n");
}
}
return stringBuffer.toString();
}
}
The important pieces here is the looping through the applicationLinks that are configured: for(final ApplicationLink applicationLink: this.applicationLinkService.getApplicationLinks(JiraApplicationType.class))
then we create a Request object:
we can at this point add headers and other “fun” things to the request object, but in this case we’ll just execute it:
public Object handle(Response response) throws ResponseException
{
....
}
});
To use all of this - I put together a very basic servlet (and wire it up in the Atlassian-plugin.xml):