You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
common-smartgears/src/main/java/org/gcube/smartgears/handlers/application/RequestEvent.java

73 lines
1.7 KiB
Java

package org.gcube.smartgears.handlers.application;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.gcube.smartgears.context.application.ApplicationContext;
/**
* An {@link ApplicationEvent} that occurs when an application receives a request.
*
* @author Fabio Simeoni
*
*/
public class RequestEvent extends ApplicationEvent<RequestHandler> {
private final String servlet;
private final HttpServletRequest request;
private final HttpServletResponse response;
/**
* Creates an instance with the application context, the client request, and the name of the target servlet.
*
* @param context the context of the application
* @param servlet the name of the target servlet
* @param request the client request
*/
public RequestEvent(String servlet,ApplicationContext context, HttpServletRequest request, HttpServletResponse response) {
super(context);
this.request = request;
this.response=response;
this.servlet = servlet;
}
/**
* Returns the name of the target servlet.
*
* @return the name of the servlet.
*/
public String servlet() {
return servlet;
}
public String uri() {
String query = request().getQueryString();
return query==null?request().getRequestURI():request().getRequestURI()+"?"+query;
}
/**
* Returns the client request.
*
* @return the request
*/
public HttpServletRequest request() {
return request;
}
/**
* Returns the response.
*
* @return the response
*/
public HttpServletResponse response() {
return response;
}
@Override
public String toString() {
return getClass().getSimpleName() + "[req=" + request().getRemoteHost() + ",resp="
+ response.toString().substring(0, 12) + "]";
}
}