I'm trying to retrieve a source's IP and hostname for logging purposes.
I've created a bean that gets has an object of both HttpServletRequest ServletContext. I have functions that gets the user's remote IP address and remote hostname.
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Context;
@RequestScoped
public class RequestDetailsConfig {
private HttpServletRequest httpRequest;
private ServletContext context;
public RequestDetailsConfig(@Context HttpServletRequest req, @Context ServletContext contx) {
this.httpRequest = req;
this.context = contx;
}
public void setHttpRequest(HttpServletRequest request) {
this.httpRequest = request;
}
public HttpServletRequest getHttpRequest() {
return this.httpRequest;
}
public String getRemoteAddress() {
return httpRequest.getRemoteAddr();
}
public String getRemoteHost() {
return httpRequest.getRemoteHost();
}
}
I have another bean that is used as my "log creator" and "log producer".
@Singleton
public class ProducerConfig {
@Inject
private RequestDetailsConfig requ;
// Create producer and other helper functions
// Making log which uses RequestDetailsConfig.getRemoteAddr() and getRemoteHost()
public NessLog makeViewingDashboardLog() {
...setters
setSourceHostIp4(requ.getRemoteAddress())
.setSourceHostHostname(requ.getRemoteHost())
.buildLog();
}
}
I then have a class that overrides my filter to set my HttpServletRequest object
public class HttpRequestFilter implements ContainerRequestFilter {
@Inject
private RequestDetailsConfig requestDetails;
@Context
HttpServletRequest request;
@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
System.out.println(containerRequestContext.getRequest());
requestDetails.setHttpRequest(request);
}
}
When I run my application and land on the page that sends out a request to retrieve data I get back the following error:
java.lang.IllegalStateException: UT000048: No request is currently active
at io.undertow.servlet.handlers.ServletRequestContext.requireCurrent(ServletRequestContext.java:84)
at io.quarkus.undertow.runtime.ServletProducer.request(ServletProducer.java:18)
at io.quarkus.undertow.runtime.ServletProducer_Subclass.request$$superaccessor3(ServletProducer_Subclass.zig:451)
I'm hoping someone may have some insight on helping me resolve this issue.