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-importname="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.
I have two question for this problem:
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();
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.