mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-22 23:45:02 +00:00
Api fix
This commit is contained in:
parent
5d611a2fa3
commit
4f6286845d
@ -27,17 +27,14 @@ public class MetricsFilter extends OncePerRequestFilter {
|
|||||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
String uri = request.getRequestURI();
|
String uri = request.getRequestURI();
|
||||||
|
|
||||||
//System.out.println("uri="+uri + ", method=" + request.getMethod() );
|
|
||||||
// Ignore static resources
|
// Ignore static resources
|
||||||
if (!(uri.startsWith("/js") || uri.startsWith("api-docs") || uri.endsWith("robots.txt") || uri.startsWith("/images") || uri.endsWith(".png") || uri.endsWith(".ico") || uri.endsWith(".css") || uri.endsWith(".svg")|| uri.endsWith(".js") || uri.contains("swagger") || uri.startsWith("/api"))) {
|
if (!(uri.startsWith("/api/v1/info") || uri.startsWith("/js") || uri.startsWith("api-docs") || uri.endsWith("robots.txt") || uri.startsWith("/images") || uri.endsWith(".png") || uri.endsWith(".ico") || uri.endsWith(".css") || uri.endsWith(".svg")|| uri.endsWith(".js") || uri.contains("swagger"))) {
|
||||||
Counter counter = Counter.builder("http.requests")
|
Counter counter = Counter.builder("http.requests")
|
||||||
.tag("uri", uri)
|
.tag("uri", uri)
|
||||||
.tag("method", request.getMethod())
|
.tag("method", request.getMethod())
|
||||||
.register(meterRegistry);
|
.register(meterRegistry);
|
||||||
|
|
||||||
counter.increment();
|
counter.increment();
|
||||||
//System.out.println("Counted");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
|
@ -1,27 +1,42 @@
|
|||||||
package stirling.software.SPDF.config;
|
package stirling.software.SPDF.config;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import io.swagger.v3.oas.models.Components;
|
import io.swagger.v3.oas.models.Components;
|
||||||
import io.swagger.v3.oas.models.OpenAPI;
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
import io.swagger.v3.oas.models.info.Info;
|
import io.swagger.v3.oas.models.info.Info;
|
||||||
|
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||||
|
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||||
|
import stirling.software.SPDF.model.ApplicationProperties;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class OpenApiConfig {
|
public class OpenApiConfig {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ApplicationProperties applicationProperties;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public OpenAPI customOpenAPI() {
|
public OpenAPI customOpenAPI() {
|
||||||
String version = getClass().getPackage().getImplementationVersion();
|
String version = getClass().getPackage().getImplementationVersion();
|
||||||
if (version == null) {
|
if (version == null) {
|
||||||
|
version = "1.0.0"; // default version if all else fails
|
||||||
|
}
|
||||||
|
|
||||||
version = "1.0.0"; // default version if all else fails
|
SecurityScheme apiKeyScheme = new SecurityScheme().type(SecurityScheme.Type.APIKEY).in(SecurityScheme.In.HEADER)
|
||||||
|
.name("X-API-KEY");
|
||||||
|
if (!applicationProperties.getSecurity().getEnableLogin()) {
|
||||||
|
return new OpenAPI().components(new Components())
|
||||||
|
.info(new Info().title("Stirling PDF API").version(version).description(
|
||||||
|
"API documentation for all Server-Side processing.\nPlease note some functionality might be UI only and missing from here."));
|
||||||
|
} else {
|
||||||
|
return new OpenAPI().components(new Components().addSecuritySchemes("apiKey", apiKeyScheme))
|
||||||
|
.info(new Info().title("Stirling PDF API").version(version).description(
|
||||||
|
"API documentation for all Server-Side processing.\nPlease note some functionality might be UI only and missing from here."))
|
||||||
|
.addSecurityItem(new SecurityRequirement().addList("apiKey"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return new OpenAPI().components(new Components()).info(
|
|
||||||
new Info().title("Stirling PDF API").version(version).description("API documentation for all Server-Side processing.\nPlease note some functionality might be UI only and missing from here."));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ public class GeneralWebController {
|
|||||||
@GetMapping("/add-elements")
|
@GetMapping("/add-elements")
|
||||||
@Hidden
|
@Hidden
|
||||||
public String addElements(Model model) {
|
public String addElements(Model model) {
|
||||||
model.addAttribute("currentPage", "sign");
|
model.addAttribute("currentPage", "add-elements");
|
||||||
model.addAttribute("fonts", getFontNames());
|
model.addAttribute("fonts", getFontNames());
|
||||||
return "add-elements";
|
return "add-elements";
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,8 @@ import stirling.software.SPDF.config.StartupApplicationListener;
|
|||||||
import stirling.software.SPDF.model.ApplicationProperties;
|
import stirling.software.SPDF.model.ApplicationProperties;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1")
|
@RequestMapping("/api/v1/info")
|
||||||
@Tag(name = "API", description = "Info APIs")
|
@Tag(name = "Info", description = "Info APIs")
|
||||||
public class MetricsController {
|
public class MetricsController {
|
||||||
|
|
||||||
|
|
||||||
@ -181,6 +181,7 @@ public class MetricsController {
|
|||||||
for (Meter meter : meterRegistry.getMeters()) {
|
for (Meter meter : meterRegistry.getMeters()) {
|
||||||
if (meter.getId().getName().equals("http.requests")) {
|
if (meter.getId().getName().equals("http.requests")) {
|
||||||
String method = meter.getId().getTag("method");
|
String method = meter.getId().getTag("method");
|
||||||
|
System.out.println("method=" + method + ", endpont=" + endpoint.get());
|
||||||
if (method != null && method.equals("POST")) {
|
if (method != null && method.equals("POST")) {
|
||||||
if (endpoint.isPresent() && !endpoint.get().isBlank()) {
|
if (endpoint.isPresent() && !endpoint.get().isBlank()) {
|
||||||
if (!endpoint.get().startsWith("/")) {
|
if (!endpoint.get().startsWith("/")) {
|
||||||
@ -217,10 +218,15 @@ public class MetricsController {
|
|||||||
Map<String, Double> counts = new HashMap<>();
|
Map<String, Double> counts = new HashMap<>();
|
||||||
|
|
||||||
for (Meter meter : meterRegistry.getMeters()) {
|
for (Meter meter : meterRegistry.getMeters()) {
|
||||||
|
|
||||||
|
System.out.println("meter.getId().getName()=" + meter.getId().getName());
|
||||||
if (meter.getId().getName().equals("http.requests")) {
|
if (meter.getId().getName().equals("http.requests")) {
|
||||||
String method = meter.getId().getTag("method");
|
String method = meter.getId().getTag("method");
|
||||||
|
System.out.println("method=" + method );
|
||||||
if (method != null && method.equals("POST")) {
|
if (method != null && method.equals("POST")) {
|
||||||
String uri = meter.getId().getTag("uri");
|
String uri = meter.getId().getTag("uri");
|
||||||
|
System.out.println("method=" + method + ", endpont=" + meter.getId());
|
||||||
|
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
double currentCount = counts.getOrDefault(uri, 0.0);
|
double currentCount = counts.getOrDefault(uri, 0.0);
|
||||||
if (meter instanceof Counter) {
|
if (meter instanceof Counter) {
|
||||||
|
@ -182,7 +182,7 @@
|
|||||||
<input type="text" class="form-control" id="sigText" name="sigText">
|
<input type="text" class="form-control" id="sigText" name="sigText">
|
||||||
<label th:text="#{font}"></label>
|
<label th:text="#{font}"></label>
|
||||||
<select class="form-control" name="font" id="font-select">
|
<select class="form-control" name="font" id="font-select">
|
||||||
<option th:each="font : ${fonts}" th:value="${font}" th:text="${font}" th:class="${font.toLowerCase()+'-font'}"></option>
|
<option th:each="font : ${fonts}" th:value="${font}" th:text="${font}" th:class="${font + '-font'}"></option>
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
<div class="margin-auto-parent">
|
<div class="margin-auto-parent">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user