2016-11-25 15:42:29 +01:00
|
|
|
package org.gcube.smartgears.extensions;
|
|
|
|
|
2023-02-06 17:34:18 +01:00
|
|
|
import static org.gcube.common.events.impl.Utils.valid;
|
2016-11-25 15:42:29 +01:00
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2024-03-11 10:22:25 +01:00
|
|
|
import jakarta.servlet.http.HttpServlet;
|
2016-11-25 15:42:29 +01:00
|
|
|
|
|
|
|
import org.gcube.common.validator.annotations.NotEmpty;
|
2023-02-06 17:34:18 +01:00
|
|
|
import org.gcube.smartgears.configuration.application.GCubeExclude;
|
2016-11-25 15:42:29 +01:00
|
|
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
|
|
|
/**
|
|
|
|
* An {@link ApplicationExtension} that implements the {@link HttpServlet} interface
|
|
|
|
*
|
|
|
|
* @author Fabio Simeoni
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public abstract class HttpExtension extends HttpServlet implements ApplicationExtension {
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enumeration of HTTP methods.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static enum Method {
|
2023-03-31 14:16:23 +02:00
|
|
|
GET("GET"),
|
|
|
|
PUT("PUT"),
|
|
|
|
POST("POST"),
|
|
|
|
HEAD("HEAD"),
|
|
|
|
DELETE("DELETE"),
|
|
|
|
OPTIONS("OPTIONS");
|
2022-03-29 15:05:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
private String value;
|
|
|
|
|
|
|
|
|
|
|
|
private Method(String value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String getValue() {
|
|
|
|
return this.value;
|
|
|
|
}
|
2016-11-25 15:42:29 +01:00
|
|
|
}
|
|
|
|
|
2023-02-06 17:34:18 +01:00
|
|
|
@NotEmpty
|
2016-11-25 15:42:29 +01:00
|
|
|
private String name;
|
|
|
|
|
2023-02-06 17:34:18 +01:00
|
|
|
@NotEmpty
|
2016-11-25 15:42:29 +01:00
|
|
|
private String mapping;
|
|
|
|
|
|
|
|
private ApplicationContext context;
|
|
|
|
|
|
|
|
protected HttpExtension() {}
|
|
|
|
|
|
|
|
public HttpExtension(String name, String mapping) {
|
|
|
|
|
|
|
|
valid("extension name",name);
|
|
|
|
valid("extension mapping",name);
|
|
|
|
|
|
|
|
name(name);
|
|
|
|
mapping(mapping);
|
|
|
|
}
|
|
|
|
|
|
|
|
//extensions use init(context) instead
|
2024-03-11 10:22:25 +01:00
|
|
|
public final void init() throws jakarta.servlet.ServletException {
|
2016-11-25 15:42:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void init(ApplicationContext context) throws Exception {
|
|
|
|
this.context=context;
|
|
|
|
}
|
|
|
|
|
2023-02-01 14:40:31 +01:00
|
|
|
@Override
|
|
|
|
public void stop() {}
|
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
@Override
|
2023-02-06 17:34:18 +01:00
|
|
|
public Set<GCubeExclude> excludes() {
|
|
|
|
return new HashSet<GCubeExclude>(); //all managed by default
|
2016-11-25 15:42:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected ApplicationContext context() {
|
|
|
|
return context;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String name() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void name(String name) {
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String mapping() {
|
|
|
|
return mapping;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void mapping(String mapping) {
|
|
|
|
this.mapping = mapping;
|
|
|
|
}
|
|
|
|
}
|