Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8932543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:20:15+00:00 2026-06-15T09:20:15+00:00

I’m trying to retrieve the client IP with JAX-WS, I used: @Resource WebServiceContext wsContext;

  • 0

I’m trying to retrieve the client IP with JAX-WS, I used:

@Resource
WebServiceContext wsContext; 

MessageContext mc = wsContext.getMessageContext();
HttpServletRequest req = (HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST); 

log.info("["+req.getRemoteAddr()+"])

I get a NullPointerException in req, mc is not null.

My question is which JAR to use for HttpServletRequest because I’m using a Java stand-alone application?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:20:16+00:00Added an answer on June 15, 2026 at 9:20 am

    How to get the webservice client address for a jax-ws service depends on whether you are:

    • Running your webservice as a servlet (in a Java EE container), or
    • Running your webservice as a stand-alone application (Java SE 6 or 7).

    Servlet Webservices
    If your webservice is a servlet then use the solution of the first post that contains the following:

    HttpServletRequest req = (HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST);
    

    Application Webservices : JAX-WS 2.1
    If you are using a Java application (Java SE) you have no servlet context, so the HttpServletRequest will be null. You need to use the method of the later post, the one that has the following line:

    HttpExchange exchange = (HttpExchange)msgx.get(JAXWSProperties.HTTP_EXCHANGE);
    

    Note: this only works with the JAX-WS 2.1 stack/reference implementation.

    Application Webservices : JAX-WS 2.2

    In JAX-WS 2.2 the value of JAXWSProperties.HTTP_EXCHANGE has changed from “com.sun.xml.ws.http.exchange” (the value it was in JAX-WS 2.1) to “com.sun.xml.internal.ws.http.exchange”. That means that a call to

    HttpExchange exchange = (HttpExchange)msgx.get(JAXWSProperties.HTTP_EXCHANGE);
    InetSocketAddress remoteAddress = exchange.getRemoteAddress();
    String remoteHost = remoteAddress.getHostName();
    

    will return null in JAX-WS 2.2 and you’ll get a NullPointerException on the second line, and more importantly, cannot get the remote address of the client.

    If you use the following call instead (using the literal value, ugh!):

    HttpExchange exchange = (HttpExchange)msgx.get("com.sun.xml.ws.http.exchange");
    InetSocketAddress remoteAddress = exchange.getRemoteAddress();
    String remoteHost = remoteAddress.getHostName();
    

    you will get a non-null value and will be able to obtain the client address.

    So, how you get the remote address of the client depends on how you deploy your code (servlet or application) and which version of JAX-WS you are using (JAX-WS 2.1 or 2.2).

    Recommendations

    • Servlets: If you are deploying your JAX-WS webservice in a servlet you can always use the call to get the property MessageContext.SERVLET_REQUEST no matter what version of JAX-WS 2 you are using.

    • Applications: If you are deploying your JAX-WS webservice in an application you can always use the call HttpExchange exchange = (HttpExchange)msgx.get("com.sun.xml.ws.http.exchange"); no matter whether you are using JAX-WS 2.1 or 2.2, therefore it is probably better to use the string literal in your code rather than the symbolic JAXWSProperties.HTTP_EXCHANGE.

    As distasteful as using the literal is, it is better to have more robust code that works across JAX-WS versions rather than prettier code that doesn’t.

    I hope the JAX-WS team correct the issue sometime and restore the value of JAXWSProperties.HTTP_EXCHANGE to the useful value again.

    Many thanks to the earlier posters that showed the various ways of finding the remote address of JAX-WS clients. The information was very useful 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.