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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,462,531
Community Members
 
Community Events
176
Community Groups

Can't access TrustedRequestFactory with ContainerManager

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

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

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.

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.

@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

Atlassian Community Events