I have an HttpServlet running on Google App Engine. My doGet() method looks like this:
public class IpServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
String ra = req.getRemoteAddr();
resp.setContentType("text/plain");
resp.setCharacterEncoding("UTF-8");
resp.getWriter().write(ra);
}
}
I would like for this getRemoteAddr to always return an IPv4 address. The following answer appears to indicate that this is configurable:
HttpServletRequest.getRemoteAddr() in Tomcat returns IPv6 formatted IP address
Can I somehow add this parameter -Djava.net.preferIPv4Stack=true to my Google App Engine startup commandline? In appengine-web.xml or web.xml perhaps?
Edit:
After some more looking around, I added the following to system-properties in appengine-web.xml:
<property name="java.net.preferIPv4Stack" value="true"/>
But this doesn't appear to work as expected.