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 don't want to be modifying IssueImpl...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You're not telling us what you're doing. On the assumption that you are writing a post-function, then you need to grab a handle on to the target custom field, then poke the value you extract from the request header into it. But I don't know what you've got so far or exactly where you might be stuck
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have added a custom field named IP. and i want to store the local ip address in this field, whenever a new issue is created. So, that there will be a record of reporter ip address corresponding to each issue. I tried using javascript to provide this vaue but nothing works appropriately. Now, i am thinking if it might be possible to provide this value to custom field by changes in source code or any other better approach
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, ok new issue, sorry, I didn't see that before.
I see you solved trapping and setting, although I 'd agree with Jamie in that you really don't want to mess with the code in that way - you really do want a post-function (that can use the code you've got to extract and set the field without messing with the main code)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.