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

How can we get ServletContext reference?

srinivasp
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.
January 3, 2013

Plugin failed to load ServletContext in jira 5.

public static ServletContext servletContext = ServletContextProvider.getServletContext();

The above statement failed to load with sdk 4.

6 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
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.
January 7, 2013

OK, so JIRA HOME is working.

I can't give you a solution because it is environment specific. For example, you deploy a WAR version of JIRA, and then your 'application' path is what?

To be honest, if you're loading resources from the 'application' as opposed to JIRA_HOME, then putting them in atlassian-jira/WEB-INF/classes and loading via getClass().getClassloader().getResourcesAsStream("bla.props") is probably the simplest way to go, works in all containers and is not deployment specific.

Personally I think config files in JIRA_HOME would be the best solution. If you happen to have a JIRA_HOME folder inside or related to a standalone JIRA deployment folder, you could probably figure out where it lives.

0 votes
srinivasp
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.
January 6, 2013

I am getting NullPointerException.

0 votes
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.
January 5, 2013

Assuming a remote user interaction is underway, I use the following in JIRA 5:

ServletActionContext.getServletContext();

srinivasp
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.
January 6, 2013

Hi Andy, I am getting the same NullPointerException with the call ServletActionContext.getServletContext();

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.
January 7, 2013

Please expand onthe context of use (in what JIRA area are you running, what are you trying to do?) its possible you don't have one if there is no actual user http session involved, eg a postfunction.

srinivasp
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.
January 7, 2013

We have a custom plugin for doing some backend operations like User clean ups etc. Here i need to read some text files which are residing on jira home directory. So i need context path from the ServletContext object as I dont have to hard code the path of our linux file system. In jira 4.4.5, i used older sdk where the below statement was working as desired.

public static ServletContext servletContext = ServletContextProvider.getServletContext();

but in sdk new SDK, my plugin failed to execute because of the non availability of ServletContextProvider class hence resulted in NullPointerException.

srinivasp
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.
January 7, 2013

I remember i tried with JiraHome class but i got NullPointerException. Any way i will try again and let you know.

thanks!

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.
January 7, 2013

Loading resources located under your JIRA home directory is I think better done with: com.atlassian.jira.config.util.JiraHome

When you have one, use jiraHome.getDataDirectory()

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.
January 7, 2013

Constructor injection. JIRA5 is what Im using, youve mentioed it, Im assuming you're using this also?

srinivasp
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.
January 7, 2013

Hi Andy,

Could you please let me know how to get the reference of JiraHome in my class?

srinivasp
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.
January 7, 2013

Oh. I forgot to mention that my plugin is actually a service. We are not using atlassian-plugin.xml file for the configurations. So i cannot use dependency injection here.

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.
January 7, 2013

Does ComponentAccessor.getComponent(JiraHome.class); also give you null?

srinivasp
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.
January 7, 2013

I tested now and it is not returning Null but all the paths are related to Home directory. Could you please let me know how to get the paths of application without hardcoding?

srinivasp
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.
January 8, 2013

Hi Andy,

Thanks for your suggestion. i moved all the static properties files to Home directory and accessed from there using the JiraHome reference, but i have one question. When indexing takes place, will it wash the conents of the home directory which results in the loss of our properties files?

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.
January 8, 2013

No, the data folder contains things like attachments, (JEMH uses it for email archives), it won't get purged due to indexing.

0 votes
Renjith Pillai
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.
January 5, 2013

While I am not sure, I can attempt to help. What exception are you getting?

0 votes
srinivasp
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.
January 3, 2013

Hi Atlassians,

Any update please??

-Thanks

0 votes
srinivasp
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.
January 3, 2013

Hi Atlassians,

Any update please??

-Thanks

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events