Fix Path name collision: use full @jakarta.ws.rs.Path for annotation, specific imports to avoid conflict with java.nio.file.Path

This commit is contained in:
David Alvarez
2026-05-25 09:40:50 +02:00
parent 5579afb5e7
commit f2bd6ca3fb
3 changed files with 19 additions and 12 deletions
@@ -1,7 +1,10 @@
package com.dostalgia; package com.dostalgia;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import jakarta.ws.rs.*; import jakarta.ws.rs.GET;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.StreamingOutput; import jakarta.ws.rs.core.StreamingOutput;
@@ -10,7 +13,7 @@ import java.nio.file.*;
import java.util.*; import java.util.*;
/** Serves game files for sockdrive streaming mode. */ /** Serves game files for sockdrive streaming mode. */
@Path("/api/sockdrive") @jakarta.ws.rs.Path("/api/sockdrive")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public class SockdriveResource { public class SockdriveResource {
@@ -18,7 +21,7 @@ public class SockdriveResource {
GameService svc; GameService svc;
@GET @GET
@Path("/{slug}/files") @jakarta.ws.rs.Path("/{slug}/files")
public Response listFiles(@PathParam("slug") String slug) { public Response listFiles(@PathParam("slug") String slug) {
Path gameDir = svc.gameDir(slug); Path gameDir = svc.gameDir(slug);
if (!Files.isDirectory(gameDir)) { if (!Files.isDirectory(gameDir)) {
@@ -40,7 +43,7 @@ public class SockdriveResource {
} }
@GET @GET
@Path("/{slug}/file") @jakarta.ws.rs.Path("/{slug}/file")
public Response getFile( public Response getFile(
@PathParam("slug") String slug, @PathParam("slug") String slug,
@QueryParam("path") String path @QueryParam("path") String path
@@ -1,7 +1,8 @@
package com.dostalgia; package com.dostalgia;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import jakarta.ws.rs.*; import jakarta.ws.rs.GET;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.StreamingOutput; import jakarta.ws.rs.core.StreamingOutput;
@@ -12,14 +13,14 @@ import java.nio.file.*;
import java.util.Map; import java.util.Map;
/** Serves game bundles (.jsdos) and artwork from the external data directory. */ /** Serves game bundles (.jsdos) and artwork from the external data directory. */
@Path("/") @jakarta.ws.rs.Path("/")
public class StaticResource { public class StaticResource {
@ConfigProperty(name = "dostalgia.data.dir", defaultValue = "data") @ConfigProperty(name = "dostalgia.data.dir", defaultValue = "data")
String dataDir; String dataDir;
@GET @GET
@Path("/games/{path: .*}") @jakarta.ws.rs.Path("/games/{path: .*}")
public Response getGameFile(@PathParam("path") String path) { public Response getGameFile(@PathParam("path") String path) {
Path file = Path.of(dataDir, "games", path).normalize(); Path file = Path.of(dataDir, "games", path).normalize();
Path base = Path.of(dataDir, "games").normalize(); Path base = Path.of(dataDir, "games").normalize();
@@ -38,7 +39,7 @@ public class StaticResource {
} }
@GET @GET
@Path("/artwork/{path: .*}") @jakarta.ws.rs.Path("/artwork/{path: .*}")
public Response getArtwork(@PathParam("path") String path) { public Response getArtwork(@PathParam("path") String path) {
Path file = Path.of(dataDir, "artwork", path).normalize(); Path file = Path.of(dataDir, "artwork", path).normalize();
Path base = Path.of(dataDir, "artwork").normalize(); Path base = Path.of(dataDir, "artwork").normalize();
@@ -58,7 +59,7 @@ public class StaticResource {
/** Health check */ /** Health check */
@GET @GET
@Path("/api/health") @jakarta.ws.rs.Path("/api/health")
public Response health() { public Response health() {
return Response.ok(Map.of("status", "ok", "version", "0.1.0")).build(); return Response.ok(Map.of("status", "ok", "version", "0.1.0")).build();
} }
@@ -1,7 +1,10 @@
package com.dostalgia; package com.dostalgia;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import jakarta.ws.rs.*; import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import org.jboss.resteasy.reactive.RestForm; import org.jboss.resteasy.reactive.RestForm;
@@ -12,7 +15,7 @@ import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.*; import java.util.*;
@Path("/api/upload") @jakarta.ws.rs.Path("/api/upload")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public class UploadResource { public class UploadResource {
@@ -103,7 +106,7 @@ public class UploadResource {
} }
@POST @POST
@Path("/{id}/cover") @jakarta.ws.rs.Path("/{id}/cover")
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadCover(@PathParam("id") String id, @RestForm("file") FileUpload upload) throws Exception { public Response uploadCover(@PathParam("id") String id, @RestForm("file") FileUpload upload) throws Exception {
if (upload == null) { if (upload == null) {