I need to store the local ip address in a custom field, whenever an issue is created. Any idea how that can be possible?? Thanks for help in advance
I was able to get it done by modifying the setCustomValue fucntion in issueimpl class as follows
public void setCustomFieldValue(CustomField customField, Object value)
{
HttpServletRequest request = ExecutingHttpRequest.get();
if(customField.getName().equalsIgnoreCase("IP") && value == null || value.toString().trim().length()==0)
value = (String)request.getRemoteAddr(); ModifiedValue modifiedValue = new ModifiedValue(getCustomFieldValue(customField), value);
customFieldValues.put(customField, value);
modifiedFields.put(customField.getId(), modifiedValue);
}
You should be able to get it from the HttpServletRequest.
You can get access to that object here - https://developer.atlassian.com/pages/viewpage.action?pageId=4227147
The method getRemoteAddr should return it, although it may also return the last proxy address instead. Someone with more knowledge of servlets might have a better way
I can vouch for the point about proxies - the Jira here only records two ip addresses - the corporate proxy and the internet gateway.
I'd also point out that unless you're capturing inside a single network, you are almost certainly going to catch the wrong IP address. Example - even if there weren't an internet gateway here, I have three machines at home that I use to connect to Jira. According to the requests, they all have the same IP address - that of my router.
Thanks a lot for your reply Collin.. but m still not able to get it worked. Do u know where i need to make changes to use this method to set the value of custom field?? i really appreciate your response.
@Nic Brough- I agree.. But i am not able to find any way to store even the router ip in custom field and i am kind of stuck now. Any help will be really appreciated
You don't want to be modifying IssueImpl...
Any other way we can do that?
Use the following code snippet to find out ip address :
public class IPTest { public static void main(String args[]) throws UnknownHostException { InetAddress addr = InetAddress.getLocalHost(); //Getting IPAddress of localhost - getHostAddress return IP Address // in textual format String ipAddress = addr.getHostAddress(); System.out.println("IP address of localhost from Java Program: " + ipAddress); //Hostname String hostname = addr.getHostName(); System.out.println("Name of hostname : " + hostname);after that , you can store it by using any new variable . You can implement any of the ip-address look up sites like Ip-details.com to find out ip address and store it as directly . thank you !
Use the following code snippet to find out ip address :public class IPTest { public static void main(String args[]) throws UnknownHostException { InetAddress addr = InetAddress.getLocalHost(); //Getting IPAddress of localhost - getHostAddress return IP Address // in textual format String ipAddress = addr.getHostAddress(); System.out.println("IP address of localhost from Java Program: " + ipAddress); //Hostname String hostname = addr.getHostName(); System.out.println("Name of hostname : " + hostname);after that , you can store it by using any new variable . You can implement any of the ip-address look up sites like Ip-details.com to find out ip address and store it as directly . thank you !
It looks like you're new here. Sign in or register to get started.