Get project key in HttpServlet

Hi,

 

I have a web-item in section atl.jira.proj.config/projectgroup3 also I have a Servlet that implements my requirement. Now I need add in my velocity tag meta with the projectKey for example:

<meta name="projectKey" content="KEY" />

 

My problem is that I can't get projectKey form HttpServlet. I try with 

 

Any ideas??

 

I try with https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-get-current-project-in-jira/qaq-p/479097 but doesn't work

5 answers

1 accepted

1 vote
Aleksandr Zuevich Community Champion Aug 21, 2017

I can't figure out why BrowseContext or JiraHelper injection doesn't work in this case (for example UserManager is injected ok in the servlet). But you can add query parameters to the web-item link inside atlassian-plugin.xml:

<link linkId="iq-propagate-component-link">/plugins/servlet/iq-propagate?pid=${helper.projectObject.id}&amp;key=${project.key}</link>

Thank so much for your answer, now I have projectKey.

 

Best regards.

1 vote
Aleksandr Zuevich Community Champion Aug 18, 2017

Have you correctly injected your BrowseContext?

I mean component-import in the atlassian-plugin.xml or @Inject and @ComponentImport annotations if you're using atlassian-spring-scanner?

<component-import key="browseContext" name="Browse Context Interface" interface="com.atlassian.jira.project.browse.BrowseContext

">

<description>Provides access to browse context</description>

</component-import>

0 vote
Aleksandr Zuevich Community Champion Aug 18, 2017

Hi,

what exactly doesn't work? Do you have any errors, e.g. NullPointerException? How is your servlet described in the atlassian-plugin.xml?

Hi Aleksandr,

 

Thanks for your reply :)

 

My problem is that I don,'t have clase or method which get project key.

I try with projectService but don't have method for my problem, also I try with BrowseContext but If I try add in my contructor is null in my Servlet

 

Best regards

In the log show the below:

 

never resolved service '&browseContext' with filter '(&(objectClass=com.atlassian.jira.project.browse.BrowseContext)(objectClass=com.atlassian.jira.project.browse.BrowseContext))'

 

I'm using atlassian-spring-scanner:

@Scanned
public class ComponentSyncAdmin extends HttpServlet {

@ComponentImport
private final BrowseContext browserContext;

private final ComponentSyncService componentSyncService;
private static final Logger log = LoggerFactory.getLogger(ComponentSyncAdmin.class);

@Inject
public ComponentSyncAdmin(ComponentSyncService componentSyncService, BrowseContext browserContext) {
this.componentSyncService = checkNotNull(componentSyncService);
this.browserContext = checkNotNull(browserContext);

}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res)

throws ServletException, IOException {


Project project = browserContext.getProject();

.
.
.
.

I have a mistake using ComponentImport?

 

Best regards

I add defintion web item

 

<!-- Link in tab panel project's administrator -->
<web-item key="iq-propagate-component" name="Propagate Component"
section="atl.jira.proj.config/projectgroup3" weight="200">
<description key="iq-propagte-component-desc">Configure propagate</description>
<label key="Propagate Component" />
<link linkId="iq-propagate-component-link">/plugins/servlet/iq-propagate</link>
</web-item>

Í add too my servlet definition:

 <!-- Servlet to management plugin -->
<servlet name="Issue CRUD" i18n-name-key="issue-crud.name" key="issue-crud"
class="com.inlogiq.jira.plugins.admin.ComponentSyncAdmin">
<description key="issue-crud.description">The Issue CRUD Plugin</description>
<url-pattern>/iq-propagate</url-pattern>
</servlet>

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Agile

How Davin Studer gets Confluence to do everything he wants it to do...except dishes

  @Davin Studer holds many interests, including but not limited to health tech and Star Trek. Read on to discover more about Davin, from his favorite Confluence macros to his favorite lit...

201 views 1 9
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