Making a request to JIRA as an add on from Spring Boot

I’ve set up a connect app in Spring Boot which can happily accept requests from JIRA and then make requests back into JIRA all within the scope of that one request. I’m doing this using code such as:

atlassianHostRestClients.authenticatedAsAddon().put( "/rest/api/3/issue/10050", mapData, String.class );

What I’d like to do is be able to initiate a call into JIRA using this API from an external trigger (e.g. a call from an external system). In this context, the above example is failing with:

java.lang.IllegalArgumentException: URI is not absolute
	at ~[na:1.8.0_181]
	at org.springframework.http.client.SimpleClientHttpRequestFactory.createRequest( ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
	at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute( ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
	at com.atlassian.connect.spring.internal.request.AtlassianConnectHttpRequestInterceptor.intercept( ~[atlassian-connect-spring-boot-core-1.5.1.jar:na]
	at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute( ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
	at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal( ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
	at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal( ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
	at org.springframework.http.client.AbstractClientHttpRequest.execute( ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
	at org.springframework.web.client.RestTemplate.doExecute( ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
	at org.springframework.web.client.RestTemplate.execute( ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
	at org.springframework.web.client.RestTemplate.postForEntity( ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]

This seems fair, as in this case the framework doesn’t know which AtlassianHost it should be hitting. I can successfully make a request as a specific user by reading the AtlassianHost out of the database, but I want to call the API as the addon user.

Is there a way to do this?

Figured it out. The fallback is to use the base URL to fetch the host from the repository. In our case we had only set a relative URI (no base URL) and therefore the framework couldn’t figure out all the information it needed.

The following is now working for us:

atlassianHostRestClients.authenticatedAsAddon().put( "", mapData, String.class );

1 Like