URLRewriteFilter
rewrite
The open-source Routing ↑↓ and /url/{rewriting} solution for Servlet, Java Web Frameworks, and Java EE / Jakarta EE
Rewrite is an OpenSource, Filter-based Servlets extension for Java – enabling creation of bookmark-able, pretty URLs. Rewrite solves the “RESTful URL” problem elegantly, including features such as: page-load actions, managed parameter parsing, seamless integration with CDI, Spring, and configuration-free compatibility with other web frameworks. Get involved in the project »
Get Started, Rewrite how you think about Servlets (3 simple steps)
Come join us on in #ocpsoft
– our channel on irc.freenode.net. Additionally, you are welcome to attend the dev meeting, every [[Calendar|Monday at 1pm EST]]. Also, please join the discussion on our dev email list.
1. Include Rewrite in your Project
The first step to installing is to add the required Maven dependencies to your pom.xml file. If you are not using Maven, you may also download the Rewrite distribution from the Maven central repository and include rewrite-servlet.jar in your project – a list of all available versions can be found here.
<!-- Jakarta EE 10+ --> <dependency> <groupId>org.ocpsoft.rewrite</groupId> <artifactId>rewrite-servlet</artifactId> <version>10.0.1.Final</version> </dependency> <!-- Jakarta EE 9 --> <dependency> <groupId>org.ocpsoft.rewrite</groupId> <artifactId>rewrite-servlet</artifactId> <version>9.0.1.Final</version> </dependency> <!-- Jakarta EE 8 --> <dependency> <groupId>org.ocpsoft.rewrite</groupId> <artifactId>rewrite-servlet</artifactId> <version>8.0.1.Final</version> </dependency> <!-- Java EE <= 7 --> <dependency> <groupId>org.ocpsoft.rewrite</groupId> <artifactId>rewrite-servlet</artifactId> <version>3.5.2.Final</version> </dependency> <!-- To use snapshots, you must also use the Sonatype Snapshots respository --> <repository> <id>sonatype-snapshots</id> <url>https://oss.sonatype.org/content/repositories/snapshots/</url> </repository>
2. Implement a ConfigurationProvider
Add one class, a configuration provider, which implements the primaryorg.ocpsoft.rewrite.config.ConfigurationProvider
interface. In a Servlet environment, you may also extend from the abstract HttpConfigurationProvider
class for convenience:
@RewriteConfiguration
annotation must be added to your provider class to activate your configuration; otherwise, Rewrite will ignore it!package com.example; @RewriteConfiguration public class ExampleConfigurationProvider extends HttpConfigurationProvider { @Override public int priority() { return 10; } @Override public Configuration getConfiguration(final ServletContext context) { return ConfigurationBuilder.begin() .addRule() .when(Direction.isInbound().and(Path.matches("/some/{page}/"))) .perform(Forward.to("/new-{page}/")); } }
3. Add rules to your configuration
Condition objects such asDirection.isInbound()
and Path.matches(...)
can be found in the common org.ocpsoft.rewrite.config.*
and org.ocpsoft.rewrite.servlet.config.*
packages. If you can describe what you want to do, you can use fluent rewrite conditions and operations.
4. Use Rewrite extensions for extra power
- JodaTime Integration
- Tuckey URLRewriteFilter Integration
- CDI Integration
- GWT History PushState Integration
- And more…
<dependency> <groupId>org.ocpsoft.rewrite</groupId> <artifactId>rewrite-integation-gwt</artifactId> <version>${rewrite.version}</version> </dependency>
Run your “rewritten” application!
You should now be ready to go! Rewrite is installed, and your first configuration provider is enabled. If everything has been done correctly, you should see Rewrite log a message confirming registration of your configuration providers (in priority order.)RewriteFilter starting up... Loaded [1] org.ocpsoft.rewrite.config.ConfigurationProvider [com.example.ExampleRewriteConfiguration<0>] RewriteFilter initialized.
Read the Documentation
Our Rewrite Manual is a work in progress, but continues to grow daily. There is a lot you can do with this framework, and we are taking our time to make sure that our examples behave as advertised.
You may also wish to read the installation guide or configuration manual, including instructions for using Rewrite annotations, or migrating from PrettyFaces 3.x.
Get involved. Get the code.
Source: https://github.com/ocpsoft/rewriteForums: ocpsoft.org/support/forum/rewrite-users/
Get updates: ocpsoft.org/subscribe/
Continuous Integration: https://travis-ci.org/ocpsoft/rewrite
Having trouble? Have an idea? Report an issue.