on 10-15-2014 3:01 PM
Hi,
We have a ejb which is exposed as webservice in NW 7.3. We would like to know the ip of the caller who consumes the webservices. I cannot find any standard interfaces/class which can be accessed from ejb to read http headers.
Are there any methods available to read the http headers so that we can get the ip address of the consumer?
Thanks,
Sharadha
@WebService()
public class Test {
@Resource WebServiceContext context;
@WebMethod(operationName = "getInfo")
public String getInfo() {
HttpServletRequest request = (HttpServletRequest)context.getMessageContext() .get(MessageContext.SERVLET_REQUEST);
return "IP: " + request.getRemoteAddr() + ", Port: " + request.getRemotePort() + ", Host: " + request.getRemoteHost();
} }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try with below code...
import javax.servlet.http.HttpServletRequest;
@GET
@Path("/yourservice")
@Produces("text/xml")
public void activate(@Context HttpServletRequest requestContext,@Context SecurityContext context){
String yourIP = requestContext.getRemoteAddr().toString();
//If security is enabled
Principal principal = context.getUserPrincipal();
String userName = principal.getName();
}
-----------------------------------------------------
private SessionContext sessionContext;
public void setSessionContext(SessionContext context)
{
sessionContext = context;
}
public void method()
{
javax.xml.rpc.handler.soap.SOAPMessageContext msgCntxt = (SOAPMessageContext)sessionContext.getMessageContext();
String remoteAddress = (String)msgCtx.getProperty("REMOTE_ADDR");
}
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.