Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Java webservice

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java webservice

    Hello guys, I'm trying to get a client ip on a webservice and then save it to the logs. I've searched a lot on this topic but all the anwsers I got worked but I only could get the server IP not the client...

    How can I get the client IP?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,287
    My Mood
    Mellow
    Thanks
    252
    Thanked 777 Times in 762 Posts

    Default Re: Java webservice

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

  3. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,706
    Thanks
    25
    Thanked 338 Times in 313 Posts
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  4. #4
    Junior Member
    Join Date
    Jul 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java webservice

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.
    Thank you very much.

    Does this help? java - Geting the IP Address Of A client For a webservice - Stack Overflow
    I've tried them all none worked

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,287
    My Mood
    Mellow
    Thanks
    252
    Thanked 777 Times in 762 Posts

    Default Re: Java webservice

    Post any of your code that attempted "them all" and failed. Perhaps someone can spot why yours didn't work.

  6. #6
    Junior Member
    Join Date
    Jul 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java webservice

    I don't have them all because I'm always changing to find a code that works but I'm going to rewrite them:


    @Resource
    WebServiceContext wsContext;
    @Context
    private javax.servlet.http.HttpServletRequest hsr;

    @GET
    @Path("getServlet")
    @Produces("text/plain")
    public String getIP1() {
    return hsr.getRemoteAddr();
    }

    public String getIP2() {
    HttpServletRequest req = (HttpServletRequest) wsContext.getMessageContext().get(MessageContext.S ERVLET_REQUEST);
    return req.getRemoteAddr();
    }
    this is only 3 of the many that I tried.. still none worked. all returned my server IP.

  7. #7
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,706
    Thanks
    25
    Thanked 338 Times in 313 Posts

    Default Re: Java webservice

    Are you the person who writes the clients? If so, the easiest solution would be to attach the IP to the request header.
    Alternatively, the first thing I would suggest doing is temporarily logging every bit of information you can get from the request. Then review the log to see if the IP address can be found in some other part of the request, and attempt to get the IP address from that part instead. This is more a "flying blind" approach, but it will at least tell you where you can find the IP.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  8. #8
    Junior Member
    Join Date
    Jul 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java webservice

    for now I'm using the tester from glassfish to test it, can it be affected by that?

  9. #9
    Junior Member
    Join Date
    Jul 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java webservice

    I just made a client to test it and it was a problem of the glassfish... fixed! thanks for your time!

Similar Threads

  1. Java Based WebService
    By ashish12169 in forum Web Frameworks
    Replies: 0
    Last Post: October 5th, 2012, 04:34 AM
  2. Replies: 0
    Last Post: September 21st, 2012, 12:11 PM
  3. How to call webservice in java?
    By Subhasri in forum Web Frameworks
    Replies: 2
    Last Post: September 30th, 2011, 10:15 AM
  4. Java Webservice problem (Array)
    By Gadge in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 10th, 2010, 11:06 AM