Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
82e63e6
JSPWIKI-1310 Add the search of the REST API version 1, described by a…
arturobernalg Nov 7, 2026
4840737
ChangeLog for JSPWIKI-1310, pull request 589
arturobernalg Nov 7, 2026
a3a9ed8
JSPWIKI-1310 Add the page name suggestions and the list of plugins to…
arturobernalg Nov 7, 2026
17b4c6d
ChangeLog for the suggestions and the plugins of JSPWIKI-1310, pull r…
arturobernalg Nov 7, 2026
d3c8aad
Merge remote-tracking branch 'upstream/master' into HEAD
arturobernalg Nov 8, 2026
4084e09
Merge remote-tracking branch 'origin/feature/JSPWIKI-1310-search' int…
arturobernalg Nov 8, 2026
618e0a9
Merge remote-tracking branch 'upstream/master' into feature/JSPWIKI-1…
arturobernalg Nov 9, 2026
35973b5
Merge remote-tracking branch 'upstream/master' into feature/JSPWIKI-1…
arturobernalg Nov 9, 2026
1da6c02
Merge remote-tracking branch 'upstream/master' into feature/JSPWIKI-1…
arturobernalg Nov 12, 2026
f5f13dc
Merge remote-tracking branch 'upstream/master' into feature/JSPWIKI-1…
arturobernalg Nov 12, 2026
07857f8
JSPWIKI-1310 Add reading of pages, their history and their attachment…
arturobernalg Nov 19, 2026
6cefed4
Merge remote-tracking branch 'upstream/master' into feature/JSPWIKI-1…
arturobernalg Nov 19, 2026
534d95f
Merge remote-tracking branch 'origin/feature/JSPWIKI-1310-search' int…
arturobernalg Nov 19, 2026
3074537
Merge remote-tracking branch 'origin/feature/JSPWIKI-1310-plugins-sug…
arturobernalg Nov 19, 2026
f0b8b0f
JSPWIKI-1310 Add the list of pages, the references of a page and its …
arturobernalg Nov 19, 2026
3f5eec9
JSPWIKI-1310 Reject names of pages that could leave the directory of …
arturobernalg Nov 19, 2026
4d5766e
Merge remote-tracking branch 'origin/feature/JSPWIKI-1310-pages-read'…
arturobernalg Nov 19, 2026
6cf597d
JSPWIKI-1310 Wait for the search index in the tests of the search tha…
arturobernalg Nov 19, 2026
30c1f4d
Merge remote-tracking branch 'origin/feature/JSPWIKI-1310-search' int…
arturobernalg Nov 19, 2026
bc81d81
Merge remote-tracking branch 'origin/feature/JSPWIKI-1310-plugins-sug…
arturobernalg Nov 19, 2026
00acd49
Merge remote-tracking branch 'origin/feature/JSPWIKI-1310-pages-read'…
arturobernalg Nov 19, 2026
b66dfe0
Merge remote-tracking branch 'upstream/master' into feature/JSPWIKI-1…
arturobernalg Nov 20, 2026
d0dae77
ChangeLog and build number of JSPWIKI-1310 after the merge of master
arturobernalg Nov 20, 2026
35864ee
Merge remote-tracking branch 'origin/feature/JSPWIKI-1310-search' int…
arturobernalg Nov 20, 2026
6c49f1e
ChangeLog of JSPWIKI-1310 after the merge of master
arturobernalg Nov 20, 2026
bc9d486
Merge remote-tracking branch 'origin/feature/JSPWIKI-1310-plugins-sug…
arturobernalg Nov 20, 2026
9efacd5
Merge remote-tracking branch 'origin/feature/JSPWIKI-1310-pages-read'…
arturobernalg Nov 20, 2026
a86149b
JSPWIKI-1310 Move the REST API to the module jspwiki-rest-api and wri…
arturobernalg Nov 20, 2026
330e8e7
JSPWIKI-1310 Group the operations of openapi.yaml with tags and rewor…
arturobernalg Nov 21, 2026
e7c4f01
JSPWIKI-1310 Add the download of the content of an attachment to the …
arturobernalg Nov 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
**2026-11-20 Arturo Bernal (abernal AT apache DOT org)**

* _3.0.2-git-2_

* [JSPWIKI-1310](https://issues.apache.org/jira/browse/JSPWIKI-1310): `GET /api/v1/search` is the first endpoint of a versioned REST API, described by the OpenAPI file `openapi.yaml` ([PR#589](https://github.com/apache/jspwiki/pull/589))
* [JSPWIKI-1310](https://issues.apache.org/jira/browse/JSPWIKI-1310): `GET /api/v1/search/suggestions` and `GET /api/v1/plugins` are added to the REST API; the suggestions leave out the pages the caller may not view ([PR#590](https://github.com/apache/jspwiki/pull/590))
* [JSPWIKI-1310](https://issues.apache.org/jira/browse/JSPWIKI-1310): `GET /api/v1/pages/{name}`, `GET /api/v1/pages/{name}/history` and `GET /api/v1/pages/{name}/attachments` are added to the REST API, to read a page, its versions and its attachments if the caller may view the page
* [JSPWIKI-1310](https://issues.apache.org/jira/browse/JSPWIKI-1310): `GET /api/v1/pages`, `GET /api/v1/pages/{name}/references` and `GET /api/v1/pages/{name}/html` are added to the REST API, to list the pages in chunks, to read the links of a page and to read a page rendered to HTML
* [JSPWIKI-1310](https://issues.apache.org/jira/browse/JSPWIKI-1310): the REST API is in its own module `jspwiki-rest-api` and writes its JSON with Jackson, which the wiki already uses, and not with Gson
* [JSPWIKI-1310](https://issues.apache.org/jira/browse/JSPWIKI-1310): the operations of `openapi.yaml` are grouped with the tags Search, Plugins and Pages, so that code generators such as openapi-generator make one class per tag, and a description that made the generator for JAX-RS interfaces write code that does not compile is reworded. A client and the JAX-RS interfaces generated with openapi-generator 7.27.0 compile, and the client reads the responses of a running wiki.
* [JSPWIKI-1310](https://issues.apache.org/jira/browse/JSPWIKI-1310): `GET /api/v1/pages/{name}/attachments/{file}` is added to the REST API, to download the content of an attachment of a page the caller may view, as a download and never as a page of the wiki. `AttachmentServlet.encodeFileName` is public, so that the API writes the file name in the header the same way.

**2026-11-19 Arturo Bernal (abernal AT apache DOT org)**
* _3.0.2-git-1_

Expand Down
2 changes: 1 addition & 1 deletion jspwiki-api/src/main/java/org/apache/wiki/api/Release.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public final class Release {
* <p>
* If the build identifier is empty, it is not added.
*/
public static final String BUILD = "1";
public static final String BUILD = "2";

/**
* This is the generic version string you should use when printing out the version. It is of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,15 @@ public ProviderException( final String msg ) {
super( msg );
}

/**
* Creates a ProviderException that tells what caused it.
*
* @param msg exception message.
* @param cause the exception that made the provider fail.
* @since 3.0.1
*/
public ProviderException( final String msg, final Throwable cause ) {
super( msg, cause );
}

}
6 changes: 6 additions & 0 deletions jspwiki-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@
<version>${jspwiki.version}</version>
</dependency>

<dependency>
<groupId>org.apache.jspwiki</groupId>
<artifactId>jspwiki-rest-api</artifactId>
<version>${jspwiki.version}</version>
</dependency>

<dependency>
<groupId>org.apache.jspwiki</groupId>
<artifactId>jspwiki-portable</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions jspwiki-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ String getContentDisposition( final Attachment att, final String mimetype ) {
* @return The rest of the header value: the file name, the closing quote and the terminating semicolon.
* @since 3.0.1
*/
static String encodeFileName( final String fileName ) {
public static String encodeFileName( final String fileName ) {
boolean plain = true;
final StringBuilder fallback = new StringBuilder( fileName.length() );
for( int i = 0; i < fileName.length(); i++ ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.apache.wiki.api.core.ContextEnum;
import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.core.Page;
import org.apache.wiki.api.core.Session;
import org.apache.wiki.api.exceptions.FilterException;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import org.apache.wiki.api.filters.BasePageFilter;
import org.apache.wiki.api.search.SearchResult;
import org.apache.wiki.api.spi.Wiki;
import org.apache.wiki.auth.AuthorizationManager;
import org.apache.wiki.auth.permissions.PagePermission;
import org.apache.wiki.auth.permissions.PermissionFactory;
import org.apache.wiki.event.WikiEvent;
import org.apache.wiki.event.WikiEventManager;
Expand All @@ -59,6 +61,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.function.Predicate;
import org.apache.wiki.api.plugin.Plugin;
import org.apache.wiki.plugin.PluginManager;
import static org.apache.wiki.search.SearchManager.PLUGIN_SEARCH;
Expand Down Expand Up @@ -91,6 +94,52 @@ public DefaultSearchManager( final Engine engine, final Properties properties )
WikiAjaxDispatcherServlet.registerServlet( PLUGIN_SEARCH, new PluginSearch() );
}

/** {@inheritDoc} */
@Override
public List< String > suggestPages( final String text, final int max, final Session session ) {
final AuthorizationManager mgr = m_engine.getManager( AuthorizationManager.class );
return suggest( text, max, name -> mgr.checkPermission( session, new PagePermission( m_engine.getApplicationName() + ":" + name, PagePermission.VIEW_ACTION ) ) );
}

/**
* Looks for the names of the pages that start with the given text and that the filter accepts.
*
* @param wikiName the page name, optionally followed by a slash and the beginning of an attachment name
* @param maxLength maximum number of suggestions
* @param accepted tells whether a name may be suggested
* @return the suggestions
*/
private List< String > suggest( String wikiName, final int maxLength, final Predicate< String > accepted ) {
final StopWatch sw = new StopWatch();
sw.start();
final List< String > list = new ArrayList<>( Math.min( maxLength, 100 ) );
if( !wikiName.isEmpty() ) {
// split pagename and attachment filename
String filename = "";
final int pos = wikiName.indexOf("/");
if( pos >= 0 ) {
filename = wikiName.substring( pos ).toLowerCase();
wikiName = wikiName.substring( 0, pos );
}

final String cleanWikiName = MarkupParser.cleanLink(wikiName).toLowerCase() + filename;
final String oldStyleName = MarkupParser.wikifyLink(wikiName).toLowerCase() + filename;
final Set< String > allPages = m_engine.getManager( ReferenceManager.class ).findCreated();

for( final Iterator< String > i = allPages.iterator(); i.hasNext() && list.size() < maxLength; ) {
final String p = i.next();
final String pp = p.toLowerCase();
if( ( pp.startsWith( cleanWikiName ) || pp.startsWith( oldStyleName ) ) && accepted.test( p ) ) {
list.add( p );
}
}
}

sw.stop();
LOG.debug( "Suggestion request for {} done in {}", wikiName, sw );
return list;
}

/**
* Provides a JSON AJAX API to the JSPWiki Plugin discovery mechanism,
* primarily used for [{}] based auto complete
Expand Down Expand Up @@ -228,37 +277,8 @@ private boolean mayView( final Context wikiContext, final String pageName ) {
* @param wikiContext the context of the viewer, whose view permission decides which page names are suggested
* @return the suggestions
*/
public List< String > getSuggestions( String wikiName, final int maxLength, final Context wikiContext ) {
final StopWatch sw = new StopWatch();
sw.start();
final List< String > list = new ArrayList<>( maxLength );
if( !wikiName.isEmpty() ) {
// split pagename and attachment filename
String filename = "";
final int pos = wikiName.indexOf("/");
if( pos >= 0 ) {
filename = wikiName.substring( pos ).toLowerCase();
wikiName = wikiName.substring( 0, pos );
}

final String cleanWikiName = MarkupParser.cleanLink(wikiName).toLowerCase() + filename;
final String oldStyleName = MarkupParser.wikifyLink(wikiName).toLowerCase() + filename;
final Set< String > allPages = m_engine.getManager( ReferenceManager.class ).findCreated();

int counter = 0;
for( final Iterator< String > i = allPages.iterator(); i.hasNext() && counter < maxLength; ) {
final String p = i.next();
final String pp = p.toLowerCase();
if( ( pp.startsWith( cleanWikiName) || pp.startsWith( oldStyleName ) ) && mayView( wikiContext, p ) ) {
list.add( p );
counter++;
}
}
}

sw.stop();
LOG.debug( "Suggestion request for {} done in {}", wikiName, sw );
return list;
public List< String > getSuggestions( final String wikiName, final int maxLength, final Context wikiContext ) {
return suggest( wikiName, maxLength, name -> mayView( wikiContext, name ) );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ public Collection< SearchResult > findPages( final String query, final int flags
LOG.error( "Failed during lucene search", e );
} catch( final ParseException e ) {
LOG.error( "Broken query; cannot parse query: {}", query, e );
throw new ProviderException( "You have entered a query Lucene cannot process [" + query + "]: " + e.getMessage() );
throw new ProviderException( "You have entered a query Lucene cannot process [" + query + "]: " + e.getMessage(), e );
} catch( final InvalidTokenOffsetsException e ) {
LOG.error( "Tokens are incompatible with provided text ", e );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Licensed to the Apache Software Foundation (ASF) under one

import org.apache.wiki.api.core.Context;
import org.apache.wiki.api.core.Page;
import org.apache.wiki.api.core.Session;
import org.apache.wiki.api.exceptions.ProviderException;
import org.apache.wiki.api.filters.PageFilter;
import org.apache.wiki.api.search.SearchResult;
Expand All @@ -28,6 +29,7 @@ Licensed to the Apache Software Foundation (ASF) under one

import java.io.IOException;
import java.util.Collection;
import java.util.List;


/**
Expand Down Expand Up @@ -55,6 +57,17 @@ public interface SearchManager extends PageFilter, InternalModule, WikiEventList
*/
SearchProvider getSearchEngine();

/**
* Suggests the names of the pages that start with the given text, leaving out the pages the session may not view.
*
* @param text the beginning of a page name, optionally followed by a slash and the beginning of an attachment name.
* @param max the maximum number of names to return.
* @param session the session of the caller.
* @return the names of the pages, in no particular order.
* @since 3.0.1
*/
List< String > suggestPages( String text, int max, Session session );

/**
* Sends a search to the current search provider. The query is is whatever native format the query engine wants to use.
*
Expand Down
116 changes: 116 additions & 0 deletions jspwiki-rest-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<parent>
<groupId>org.apache.jspwiki</groupId>
<artifactId>jspwiki-builder</artifactId>
<version>3.0.2-SNAPSHOT</version>
</parent>

<artifactId>jspwiki-rest-api</artifactId>
<modelVersion>4.0.0</modelVersion>
<name>Apache JSPWiki REST API</name>
<description>Version 1 of the REST API of Apache JSPWiki, described by an OpenAPI file</description>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jspwiki-api</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jspwiki-main</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jspwiki-main</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>

<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>

<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading
Loading