How to link a web-item to a servlet rendering soy template to show up in repository settings?

I am using latest bitbucket server and trying to add some configuration form to repository settings page under add-ons section. This configuration is specific for each repository. I was able to add a web-tem which shows up as a link under add-ons in repository settings. Now i would like link this web-item to a servlet to render the configuration page (built using soy template). when my link is clicked, It shows up a 404. I couldn't find any doc related to this configuration.

1. What is the <link> value that i should be using to invoke my servlet? Here is what i am using.

<web-item name="My Configuration Tab" key="My-configuration-tab" section="bitbucket.repository.settings.panel/repository-settings-addons-section">
<label key="My Configuration">My Configuration</label>
<link linkId="My-configuration-tab-link">/projects/${project.key}/repos/${repository.slug}/settings/configservlet</link>
<tooltip key="My-configuration-tab.tooltip">My Configuration</tooltip>
</web-item>


2. What is the corresponding url-pattern i should be using ? Here's what i have

<servlet name="My Config Servlet Module" i18n-name-key="my-config-servlet.name" key="my-config-servlet" class="com.my.servlet.MyConfigServlet">
<description key="my-config-servlet.description">The My Config Servlet Plugin</description>
<url-pattern>/settings/configservlet</url-pattern>
</servlet>



3. What is the meta tag that i should be using in soy template? Here's what i have

<meta name="decorator" content="bitbucket.repository.settings">


Other than above 3, are there any other things i need to have to get this working?

2 answers

1 accepted

This widget could not be displayed.
Daniel Wester Community Champion Oct 22, 2017

You’re using a servlet so the path to it rooted at /plugins/servlet

so the link should be:

/plugins/servlet/settings/configservlet

It is still giving the 404 error. I tried this.

1. Inside web-item i gave this link path

<link linkId="my-configuration-tab-link">/plugins/servlet/settings/configservlet</link>

 

2. Inside the servlet i gave the below path.

<url-pattern>*/settings/configservlet</url-pattern>

 

Did i miss anything? does the above path in <link> links to repository settings? What is the best way to debug this?

Thanks for the help.

Daniel Wester Community Champion Oct 23, 2017

Make the url-pattern in the servlet be:

<url-pattern>/settings/configservlet</url-pattern>

 

By specifying

<url-pattern>*/settings/configservlet</url-pattern>

 

-the actual url pattern is /plugins/servlet/*/settings/configservlet

 - which you probably don't want :)

 

The other piece I would suggest is to have your add-on name in the url-pattern somewhere to avoid another add-on collding with your paths ( for example I try to have the Wittified add-ons at /wittified/....). This way likelihood of somebody else having the same path is a lot smaller :)

Thanks Daniel. that worked. In addition to the above one, i had to make few more changes in my soy template and in the servlet.

- I have added the necessary meta tags required for the repository settings decorater in the soy template.

<meta name="decorator" content="bitbucket.repository.settings">
<meta name="projectKey" content="{$repository.project.key}">
<meta name="repositorySlug" content="{$repository.slug}">

- I have declared the repository param in the soy template.

/**
* @param repository Repository object
*/

- I have passed in the project and repository names as part of the <link> tag and used those inside my servlet to get a repository instance like this and passed it on to the renderer.

<link linkId="my-configuration-tab-link">/plugins/servlet/settings/myconfig/${project.key}/${repository.slug}</link>
String pathInfo = req.getPathInfo();
String[] path = pathInfo.split("/");
String project = path[path.length-2];
String repo = path[path.length-1];
Repository repository = repositoryService.getBySlug(project, repo);

 

Hope this info helps someone with similar needs.

This widget could not be displayed.
Aleksandr Zuevich Community Champion Oct 20, 2017

Hi!

Try to use 

<url-pattern>*/settings/configservlet</url-pattern>

Sorry that didn't wok.  it still gives 404. I was building on top of decorator-plugin example. if i use the <link> , <url-pattern>, <meta> tags from that example it works but opens in user accounts section.  Any other suggestions?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 21, 2018 in Bitbucket

Branch Management with Bitbucket

As a project manager, I have discovered that different developers want to bring their previous branching method with them when they join the team. Some developers are used to performing individual wo...

1,352 views 8 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you