Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Rufus Williams   on Jun 14 In Java Category.

  
Question Answered By: Maria Miller   on Jun 14

I forgot to let you know that it is possible to have access to http  request and response using webservice context. Following exmaple show you how to access the client IP address.


package yourpackage;

import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.ejb.Stateless;
import javax.servlet.http.HttpServletRequest;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;


@WebService()
@Stateless()
public class YourWebService {

@Resource
private WebServiceContext wsContext;

/**
* Web service operation
*/
@WebMethod(operationName = "retrieveClientIPAddress")
public String retrieveClientIPAddress() {
HttpServletRequest req = (HttpServletRequest) wsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST);
return req.getRemoteAddr();
}
}

see https://jax-ws.dev.java.net/nonav/2.1.1/docs/api/javax/xml/ws/handler/MessageContext.html
to know other webservice context features.

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on HTTP header Or get search suggestion and latest updates.


Tagged: