IllegalStateException: No request is currently active when Trying to get IP address and Host

622 views
Skip to first unread message

Shahmir Ahmed

unread,
May 20, 2021, 2:46:35 PM5/20/21
to Quarkus Development mailing list
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.

Georgios Andrianakis

unread,
May 20, 2021, 2:50:48 PM5/20/21
to shahmir...@gmail.com, Quarkus Development mailing list
Can you please post this question to StackOverflow?

Thanks

--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/d17274e1-2fae-4e76-af5b-0d558d1a5a12n%40googlegroups.com.

Shahmir Ahmed

unread,
May 20, 2021, 3:14:41 PM5/20/21
to Quarkus Development mailing list
Reply all
Reply to author
Forward
0 new messages