Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can't access TrustedRequestFactory with ContainerManager

netsparker April 15, 2018

I am trying to make a rest call to "/rest/api/latest/info" bamboo rest endpoint within Bamboo plugin by using "TrustedRequestFactory". However, I am getting the following error.

com.atlassian.spring.container. : Failed to find component: No bean named 'trustedRequestFactory' available

I have imported "TrustedRequestFactory" interface in atlassian-plugin.xml.


<component-import
name="Trusted Request Factory" key="trusted-request-factory" interface="com.atlassian.sal.api.net.TrustedRequestFactory"/>

My code:


try
{
final String baseUrl = getAdministrationConfiguration().getBaseUrl();
final TrustedRequestFactory trustedRequestFactory = (TrustedRequestFactory) ContainerManager.getComponent("trustedRequestFactory");
final TrustedRequest trustedRequest = trustedRequestFactory.createTrustedRequest(Request.MethodType.GET, baseUrl+"/rest/api/latest/info");
final String result = trustedRequest.execute();
bambooVersion=result;
} catch (Exception e) {
e.printStackTrace();
bambooVersion=e.toString();
}

  

I have found following documents for this purpose.

https://docs.atlassian.com/atlassian-bamboo/6.3.2/com/atlassian/sal/bamboo/trusted/BambooHttpClientTrustedRequestFactory.html

https://community.atlassian.com/t5/Answers-Developer-Questions/Call-Confluence-REST-from-within-Confluence/qaq-p/570337

 

I have two question for this problem:

  1. How can i make use of trustedRequestFactory?
  2. Is there an alternative way to call bamboo rest endpoint within the plugin. sd

2 answers

1 vote
netsparker April 15, 2018

Injecting "TrustedRequestFactory" by Constructor Injection solved the problem. However, getting some of the dependencies through Container Manager and some of them via constructor is strange.

 

On the other, My actual problem is still continuing. I am now getting following error:

com.atlassian.sal.api.net.ResponseStatusException: Unexpected response received. Status code: 401

I have tried following code and the code with the previous post.

try {
final String baseUrl = getAdministrationConfiguration().getBaseUrl();
final TrustedRequest trustedRequest = trustedRequestFactory.createTrustedRequest(Request.MethodType.GET, baseUrl+"/rest/api/latest/info");
trustedRequest.addTrustedTokenAuthentication(AppCommon.getDomainName(baseUrl));
final String result = trustedRequest.execute();
bambooVersion=result;
} catch (Exception e) {
e.printStackTrace();
bambooVersion=e.toString();
}
public static String getDomainName(String url) throws MalformedURLException {
return new URL(url).getHost();
}
0 votes
Krystian Brazulewicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 25, 2018

Can you please try explaining what are you trying to achieve?

I understand the attempt to access "/rest/api/latest/info" is just an example - otherwise I don't see a point in checking Bamboo server version from a Bamboo plugin by calling REST endpoint.

netsparker June 6, 2018

We want to access server version info which will be sent to Netsparker Cloud and used by our support team. (Assume that there is a problem reported which only occurs in particular version of the Bamboo server. This can point out a compatibility issue.) 

Then, It turns out, we can retrieve it from API which needs authentication. See: How can I obtain bamboo server version in Scan Task plugin.  What we want is accessing server version info. It can be obtained through API or something else. As long as we are obtaining it, we are fine.

Krystian Brazulewicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 27, 2018

@netsparker see BuildUtils class in bamboo-api package - it will contain Bamboo version. This package is also available on remote agent JVM and you can be assured that agent will always have its binaries synced with the server.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events