Bogdan
Bogdan

Reputation: 5406

How do you get the ip address of a remote EJB client in Glassfish?

Like the title says:

I have a Swing standalone client which connects to an EJB application deployed on GF 3.0.1. I'd like to have access to client IP inside EJB methods.

Is this possible?

I also found this thread but the solution was for JBoss...

Upvotes: 1

Views: 1717

Answers (1)

atiruz
atiruz

Reputation: 2858

@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();
    }
}

Upvotes: 1

Related Questions