Skip to content

Commit

Permalink
Updated Spring to 3.2.1, updated to Java 21
Browse files Browse the repository at this point in the history
  • Loading branch information
maddingo committed Jan 20, 2024
1 parent ebd62a1 commit 8cba4cb
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 52 deletions.
1 change: 1 addition & 0 deletions .sdkmanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java=21-local
2 changes: 1 addition & 1 deletion plantuml-docker/src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:11-jdk-slim as build
FROM eclipse-temurin:21-jdk-jammy as build

USER root
RUN apt-get update && \
Expand Down
2 changes: 1 addition & 1 deletion plantuml-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.58.0</version>
<version>2.70.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package net.sourceforge.plantuml.server;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.OptionFlags;
Expand All @@ -37,8 +39,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -53,16 +53,12 @@
@Controller
public class DiagramController {

static {
OptionFlags.ALLOW_INCLUDE = "true".equalsIgnoreCase(System.getenv("ALLOW_PLANTUML_INCLUDE"));
}

@RequestMapping(
path = "/svg/{encodedDiagram}",
method = {RequestMethod.GET},
produces = "image/svg+xml"
)
public ResponseEntity<?> getSvg(@PathVariable String encodedDiagram, HttpServletRequest request, HttpServletResponse response) throws IOException {
public ResponseEntity<?> getSvg(@PathVariable("encodedDiagram") String encodedDiagram, HttpServletRequest request, HttpServletResponse response) throws IOException {
return doGet(encodedDiagram, request, response, FileFormat.SVG);
}

Expand All @@ -81,7 +77,7 @@ public ResponseEntity<?> postSvg(HttpServletRequest request, HttpServletResponse
method = {RequestMethod.GET},
produces = MediaType.TEXT_PLAIN_VALUE
)
public ResponseEntity<?> getTxt(@PathVariable String encodedDiagram, HttpServletRequest request, HttpServletResponse response) throws IOException {
public ResponseEntity<?> getTxt(@PathVariable("encodedDiagram") String encodedDiagram, HttpServletRequest request, HttpServletResponse response) throws IOException {
return doGet(encodedDiagram, request, response, FileFormat.UTXT);
}

Expand All @@ -90,7 +86,7 @@ public ResponseEntity<?> getTxt(@PathVariable String encodedDiagram, HttpServlet
method = {RequestMethod.GET},
produces = MediaType.IMAGE_PNG_VALUE
)
public ResponseEntity<?> getPng(@PathVariable String encodedDiagram, HttpServletRequest request, HttpServletResponse response) throws IOException {
public ResponseEntity<?> getPng(@PathVariable("encodedDiagram") String encodedDiagram, HttpServletRequest request, HttpServletResponse response) throws IOException {
return doGet(encodedDiagram, request, response, FileFormat.PNG);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,20 @@
*/
package net.sourceforge.plantuml.server;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import net.sourceforge.plantuml.*;
import net.sourceforge.plantuml.code.Base64Coder;
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.error.PSystemError;
import net.sourceforge.plantuml.version.Version;
import org.springframework.http.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Map;


Expand All @@ -62,9 +60,6 @@ class DiagramResponse {
FileFormat.UTXT, "text/plain;charset=UTF-8",
FileFormat.BASE64, "text/plain; charset=x-user-defined");
}
static {
OptionFlags.ALLOW_INCLUDE = "true".equalsIgnoreCase(System.getenv("ALLOW_PLANTUML_INCLUDE"));
}

DiagramResponse(HttpServletResponse r, FileFormat f, HttpServletRequest rq) {
format = f;
Expand All @@ -80,8 +75,9 @@ ResponseEntity<?> sendDiagram(String uml, int idx) throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final DiagramDescription result = reader.outputImage(baos, idx, new FileFormatOption(FileFormat.PNG));
baos.close();

final String encodedBytes = "data:image/png;base64,"
+ Base64Coder.encodeLines(baos.toByteArray()).replaceAll("\\s", "");
+ Base64.getEncoder().encodeToString(baos.toByteArray()).replaceAll("\\s", "");
return new ResponseEntity<>(encodedBytes, headers, HttpStatus.OK);
}
final BlockUml blockUml = reader.getBlocks().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ public class UIController {

private static final String DEFAULT_ENCODED_TEXT = "SyfFKj2rKt3CoKnELR1Io4ZDoSa70000";

static {
OptionFlags.ALLOW_INCLUDE = "true".equalsIgnoreCase(System.getenv("ALLOW_PLANTUML_INCLUDE"));
}

@GetMapping("/")
public String index(Model model) {return "redirect:/uml/" + DEFAULT_ENCODED_TEXT;
}

@GetMapping("/uml/{encodedDiagram}")
public String uml(Model model, @PathVariable String encodedDiagram, UriComponentsBuilder uriBuilder) throws NoPlantumlCompressionException {
public String uml(Model model, @PathVariable("encodedDiagram") String encodedDiagram, UriComponentsBuilder uriBuilder) throws NoPlantumlCompressionException {
updateModel(model, encodedDiagram, uriBuilder);
return "uml";
}
Expand All @@ -50,7 +46,7 @@ private void updateModel(Model model, String encodedDiagram, UriComponentsBuilde
path = "/form",
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE
)
public String form(Model model, UriComponentsBuilder uriBuilder, String text) throws IOException {
public String form(Model model, UriComponentsBuilder uriBuilder, @RequestParam("text") String text) throws IOException {
String encodedText;
if (text != null) {
encodedText = getTranscoder().encode(text);
Expand All @@ -65,7 +61,7 @@ public String form(Model model, UriComponentsBuilder uriBuilder, String text) th
path = "/url",
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE
)
public String url(Model model, UriComponentsBuilder uriBuilder, String url) throws IOException {
public String url(Model model, UriComponentsBuilder uriBuilder, @RequestParam("url") String url) throws IOException {
String encodedText = UriComponentsBuilder.fromHttpUrl(url).build().getPathSegments().stream().skip(1).findAny().orElse(DEFAULT_ENCODED_TEXT);
return "redirect:/uml/"+encodedText;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
*/
public class UmlExtractor {

static {
OptionFlags.ALLOW_INCLUDE = "true".equalsIgnoreCase(System.getenv("ALLOW_PLANTUML_INCLUDE"));
}

/**
* Build the complete UML source from the compressed source extracted from the HTTP URI.
*
Expand Down
6 changes: 3 additions & 3 deletions plantuml-web/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
debug: false
debug: true
spring:
jmx:
enabled: false
backgroundpreinitializer:
ignore: true
# backgroundpreinitializer:
# ignore: true
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ContextConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.context.ContextConfiguration;

import javax.imageio.ImageIO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.sourceforge.plantuml.server.Application;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.context.ContextConfiguration;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.sourceforge.plantuml.server.Application;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.context.ContextConfiguration;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.web.client.RestTemplate;

import java.net.MalformedURLException;
import java.net.URL;
Expand Down
27 changes: 15 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<version>2.1.0-SNAPSHOT</version>

<properties>
<spring.boot.version>2.6.3</spring.boot.version>
<spring.boot.version>3.2.1</spring.boot.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<dockerfile.repository>maddingo/plantuml-new</dockerfile.repository>
<dockerfile.tag>${project.version}</dockerfile.tag>
<dockerfile.webcontext>ROOT</dockerfile.webcontext>
<plantuml.version>1.2022.1</plantuml.version>
<plantuml.version>1.2023.13</plantuml.version>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
<modules>
Expand All @@ -36,40 +36,43 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<version>3.3.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<version>3.3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.12.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<version>3.2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<version>3.2.5</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<version>3.6.1</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand Down

0 comments on commit 8cba4cb

Please sign in to comment.