Skip to content

Commit f06e2b9

Browse files
committed
TIKA-4809: Fix welcome-page links, and two bad URLs from the README commit
1 parent fad8226 commit f06e2b9

2 files changed

Lines changed: 33 additions & 10 deletions

File tree

tika-server/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ $ java -jar tika-server/target/tika-server.jar --help
3333
```
3434

3535
Everything beyond host, port and id is configured in the tika-config JSON file
36-
passed with `-c`, not on the command line. See
37-
[Configuration](https://tika.apache.org/configuration/index.html).
36+
passed with `-c`, not on the command line.
3837

3938
Running via Docker
4039
------------------
@@ -50,8 +49,8 @@ Note the `127.0.0.1:` prefix. Unlike the jar, which binds `localhost` by default
5049
the Docker images start the server with `-h 0.0.0.0`, so publishing the port
5150
without an explicit interface exposes it on every interface of the host.
5251
tika-server performs no authentication and parses untrusted files; only expose it
53-
on a trusted, access-controlled network. See
54-
[Security](https://tika.apache.org/security.html).
52+
on a trusted, access-controlled network. See the
53+
[Tika Security Model](https://tika.apache.org/security-model.html).
5554

5655
You may also be interested in the https://github.com/apache/tika-docker project
5756
which provides prebuilt Docker images.

tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/resource/TikaWelcome.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@
4747
*/
4848
@Path("/")
4949
public class TikaWelcome {
50-
private static final String DOCS_URL = "https://wiki.apache.org/tika/TikaJAXRS";
50+
private static final String DOCS_URL =
51+
"https://cwiki.apache.org/confluence/display/TIKA/TikaJAXRS";
52+
53+
/** Matches {@code {name : regex}} in a JAX-RS path, capturing the parameter name. */
54+
private static final Pattern PATH_TEMPLATE_REGEX =
55+
Pattern.compile("\\{\\s*(\\w+)\\s*:[^}]*}");
5156

5257
private static final Map<Class<? extends Annotation>, String> HTTP_METHODS = new HashMap<>();
5358

@@ -164,13 +169,21 @@ public String getWelcomeHTML() {
164169

165170
h.append("<ul>\n");
166171
for (Endpoint e : identifyEndpoints()) {
172+
String displayPath = simplifyPathTemplate(e.path);
167173
h.append("<li><b>");
168174
h.append(e.httpMethod);
169-
h.append("</b> <i><a href=\"");
170-
h.append(e.path);
171-
h.append("\">");
172-
h.append(e.path);
173-
h.append("</a></i><br />");
175+
h.append("</b> <i>");
176+
// Only linkify concrete paths; one with a {param} is not fetchable as written.
177+
if (displayPath.indexOf('{') < 0) {
178+
h.append("<a href=\"");
179+
h.append(displayPath);
180+
h.append("\">");
181+
h.append(displayPath);
182+
h.append("</a>");
183+
} else {
184+
h.append(displayPath);
185+
}
186+
h.append("</i><br />");
174187
h.append("Class: ");
175188
h.append(e.className);
176189
h.append("<br />Method: ");
@@ -213,6 +226,17 @@ public String getWelcomePlain() {
213226
return text.toString();
214227
}
215228

229+
/**
230+
* Strips the regex from a JAX-RS path template so {@code /rmeta/{handler : (\w+)?}}
231+
* renders as {@code /rmeta/{handler}}.
232+
*/
233+
static String simplifyPathTemplate(String path) {
234+
if (path == null || path.indexOf('{') < 0) {
235+
return path;
236+
}
237+
return PATH_TEMPLATE_REGEX.matcher(path).replaceAll("{$1}");
238+
}
239+
216240
protected static class Endpoint {
217241
public final String className;
218242
public final String methodName;

0 commit comments

Comments
 (0)