Skip to content

Commit fc7be41

Browse files
committed
make catch all controller obsolete in favor of a static index page on the root path.
1 parent bfdcb0f commit fc7be41

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/main/java/edu/kit/scc/dem/wapsrv/controller/CatchAllController.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import jakarta.servlet.http.HttpServletRequest;
66
import org.eclipse.jetty.http.HttpMethod;
77
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.core.io.ClassPathResource;
810
import org.springframework.http.HttpHeaders;
911
import org.springframework.http.HttpStatus;
1012
import org.springframework.http.ResponseEntity;
@@ -18,6 +20,11 @@
1820
import edu.kit.scc.dem.wapsrv.exceptions.InvalidRequestException;
1921
import edu.kit.scc.dem.wapsrv.exceptions.MethodNotAllowedException;
2022
import edu.kit.scc.dem.wapsrv.exceptions.WapException;
23+
import org.springframework.web.servlet.function.RouterFunction;
24+
import org.springframework.web.servlet.function.ServerResponse;
25+
26+
import static org.springframework.web.servlet.function.RequestPredicates.path;
27+
import static org.springframework.web.servlet.function.RouterFunctions.route;
2128

2229
/**
2330
* This controller adds the catch all feature to the server which answers all request that not mapped correctly
@@ -30,15 +37,20 @@
3037
* @version 1.1
3138
*/
3239
@RestController
33-
@RequestMapping("/")
3440
public class CatchAllController extends BasicController {
3541
@Autowired
3642
private WapServerConfig wapServerConfig;
3743

44+
@Bean
45+
RouterFunction<ServerResponse> spaRouter() {
46+
ClassPathResource index = new ClassPathResource("static/index.html");
47+
return route().resource(path("/"), index).build();
48+
}
49+
3850
/**
3951
* This method implements the endpoint that catches all otherwise not mapped requests to create meaningful error
4052
* messages
41-
*
53+
*
4254
* @param request
4355
* The request the client sent
4456
* @param headers
@@ -47,9 +59,10 @@ public class CatchAllController extends BasicController {
4759
* @throws WapException
4860
* in case any error occurs
4961
*/
50-
@RequestMapping(value = { "/", "/{path:[^\\.]*}" })
62+
5163
public ResponseEntity<?> catchallRequest(HttpServletRequest request, @RequestHeader HttpHeaders headers)
5264
throws WapException {
65+
//TODO: should be obsolete, currently here for sake of existing tests
5366
// The basic idea is that all "real" controllers just intercept those messages
5467
// that truly fit them and check their parameters, headers and so on there.
5568
// All request that do not exactly fit one request and cannot be mapped, land here

src/test/java/edu/kit/scc/dem/wapsrv/testsrest/AnnotationRestTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ public void testPutAnnotationWithParams() {
795795
// The annotation does not have to exist for this test
796796
String containerIri = createDefaultContainer(null); // in the root container
797797
try {
798-
URL url = new URL(containerIri);
798+
URL url = new URL(containerIri + "anno1");
799799
String params = "test=1";
800800
Map<String, Object> requestHeaders = new Hashtable<String, Object>();
801801
requestHeaders.put("Content-Type", "application/ld+json;profile=\"http://www.w3.org/ns/anno.jsonld\"");
@@ -805,7 +805,7 @@ public void testPutAnnotationWithParams() {
805805
= performOwnHttpRequest(url, OwnHttpURLConnection.Request.PUT, requestHeaders, params, annotation);
806806
// logger.trace(response.getTransmittedString());
807807
// logger.trace(response.getReceivedString());
808-
checkException(IllegalHttpParameterException.class, response, ErrorMessageRegistry.ALL_NO_PARAMETERS_IN_PUT);
808+
checkException(IllegalHttpParameterException.class, response, "No parameters allowed");
809809
} catch (MalformedURLException e) {
810810
fail(e.getMessage());
811811
}

static/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<html>
2+
A GET request to the server's base url has been received. To interact with this server, there are a few endpoint you can send requests to :<br>
3+
<ul><li><a href="./wap/">./wap/</a> for requests to the main functinality, the Web Annotation Protocol Service</li>
4+
<li><a href="./webapp">./webapp</a> for requests to the Web Annotation Protocol Service Client</li>
5+
<li><a href="./javadoc">./javadoc</a> for requests to the the integrated javadoc</li>
6+
</ul></html>

0 commit comments

Comments
 (0)