Calling plug-in actions from anywhere?

Kinto Soft
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2012

Hi,

Does it exists a global function similar to the provided by the following method;

com.atlassian.jira.web.action.JiraWebActionSupport.getRedirect(String arg0)

It returns the url for any other action defined in the plugin, but it can only be invoked by an action extending the JiraWebActionSupport class.

I need to call an action from a menu.

Many thanks,

Pablo

1 answer

1 accepted

1 vote
Answer accepted
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2012

You should be able to call it from anywhere using a link like this:

/secure/YouActionName!viewName.jspa

Doesn't that work? For a menu, use a web-item.

Kinto Soft
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 26, 2012

/secure/YouActionName!viewName.jspa

Just what I was looking for!

But it has a little problem: the context of the JIRA application:

  1. In production usually: http://localhost/ (empty)
  2. In SDK or other times: http://localhost/jira</li<>>

In the first case, it must be invoked: /secure/YourActionName.jspa

Inthe second: /jira/secure/YourActionName.jspa

Is there an API function providing the context? Maybe by analyzing the JIRA base url to get it...

Florin Manaila
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 26, 2012

I believe ActionContext.getResponse().sendRedirect(location) will append the correct contextPath. Haven't tried it though, but the Javadocs seem accurate enough

This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.

Florin Manaila
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 26, 2012

You can also build the url client-side. There should be a

&lt;script type="text/javascript"&gt;var contextPath = '';&lt;/script&gt;

on every page, with the appropriate value.

Andy Brook [Plugin People]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 26, 2012

Florin is right, but there is an even easier way, your Action classes (should?) probably subclass JiraWebActionSupport, and so, can call: getRedirect("secure/yourapp/Thing!view.jspa"); so long as your action then returns NULL, you will get redirected, with context set accordingly if present.

Kinto Soft
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 26, 2012

The problem is that the code is not inside an action, it's in a menu builder. Hence, neither

<script type="text/javascript">var contextPath = '';</script>

can be invoked because is a client based solution nor

ActionContext.getResponse().sendRedirect(location)

because I don't want redirect anything. Simply, pass the menu links to JIRA and let it decide when to redirect (due an user action).

I got at my email another suggestion from from Andy Brook (and not listed in answers !?):

JiraWebActionSupport, and so, can call: getRedirect("secure/yourapp/Thing!view.jspa");

but as the code is not within an action... I tried to create an object by:

JireWebActionSupport jwas = new JiraWebActionSupport();
jwas.getRedirect(...);

but it did not work.

Based on a Florin's suggestion I tried to get the context from the servlet:

ActionContext.getRequest().getContextPath();

that would be perfect. Unfortunately, as it's not invoked from within an action, ActionContext.getRequest() returns null :(

Anyway it opens a new way: is it possible to get the HttpServletRequest from ANYWHERE (not only from an action)?

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 26, 2012

If it is from a web-item, you don't need to append context path. If not, where is your code? What kind of plugin module is it?

Florin Manaila
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 27, 2012

Jobin is right. Web-items do not require a context path. So if those aren't web-items, what are they? What is that menu builder you are using? When is it called and what does it do?

Kinto Soft
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 27, 2012

The action is called from a SimpleLinkFactory (implemented by a class) as described in the following link and in the Jobin's book:

https://answers.atlassian.com/questions/69412/adding-dynamic-links-to-user-s-top-navigation-bar

The links are built from within that class. If the contextPath is not added (/jira/secure/MyAction.jspa) then the action is not found. When the context path is present, then it works.

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 27, 2012

This will get you the full base url.

ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL)

Use ComponentManager is the older JIRA versions.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events