February 13th, 2014 by Team

Rewrite 2.0.11.Final Released – New i18n Features

We are proud to announce the release of Rewrite Servlet Toolkit 2.0.11.Final.

Highlights

This version includes new support for internationalization and localization. Additionally, support for annotation scanning on the WebLogic application server has been improved.

Security Notice

If you are currently using Rewrite 2.0.9.Final and have not yet updated, you should update to Rewrite 2.0.10.Final or 2.0.11.Final as quickly as possible, since we have fixed a minor concurrency issue when using the PhaseOperation configuration element that can potentially cause cross-request information bleeding.

Get Rewrite

http://ocpsoft.org/rewrite/
December 10th, 2013 by Lincoln Baxter III

Rewrite 2.0.9.Final and PrettyTime 3.2.3.Final Released (Introducing Proxy Support)

Rewrite 2.0.9.Final

We are proud to announce the availability of Rewrite 2.0.9.Final, which introduces “rewrite-config-proxy”, fixes several minor issues, and adds support for Response.isCommitted(), making it far simpler to perform certain operations if the response has already been committed by a prior rule or 3rd party servlet filter.

rewrite-config-proxy

Provides an easy-to-use Operation that allows any inbound request to be proxied to another URL – even on a different server. Headers, cookies, etc, are preserved:

To use this configuration extension, you will need to add it to your POM file:

<dependency>
   <groupId>org.ocpsoft.rewrite</groupId>
   <artifactId>rewrite-config-proxy</artifactId>
   <version>2.0.9.Final</version>
</dependency>
Now add a rule to your ConfigurationProvider:
.addRule()
.when(Direction.isInbound())
.perform(Proxy.to("http://example.com"))

And of course, it supports parameterization:

.addRule()
.when(Direction.isInbound().and(Path.matches("/{p}")))
.perform(Proxy.to("http://example.com/{p}?foo=bar"))

response.isCommitted()

Provides a simple condition for determining whether the response has been committed or not for the current request. This is useful for aborting rewrite processing after a certain point in your configuration:
.addRule()
.when(Response.isCommitted().and(Direction.isInbound()))
.perform(Lifecycle.abort())

More issues resolved in Rewrite 2.0.9.Final:

PrettyTime 3.2.3.Final

We are proud to announce the availability of PrettyTime 3.2.3.Final, which fixes several minor issues with translation and Natural Language Parsing:

Get the updates

Get Rewrite

Get PrettyTime

Lincoln Baxter, III

About the author:

Lincoln Baxter, III is a Principal Software Engineer at Red Hat, working on JBoss open-source projects; most notably as creator & project lead of JBoss Forge, and author of Errai UI. This blog represents his personal thoughts and perspectives, not necessarily those of his employer.

He is a founder of OCPsoft, the author of PrettyFaces and Rewrite, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also the author of PrettyTime, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals.

November 13th, 2013 by Lincoln Baxter III

Creating a simple static file server with Rewrite

Today, I’d like to take a quick moment to demonstrate how to make a simple file server using Rewrite, and any Servlet Container, such as Tomcat, Wildfly, or Jetty. This can enable much easier file updates for static content, such as preventing the need to re-deploy an entire application just to update an image, or document.

Rewrite is an open-source Routing ↑↓ and /url/{rewriting} solution for Servlet, Java Web Frameworks, and Java EE.

To start, you’ll need to include the Rewrite dependencies in your project. If you’re using maven, this is as simple as making sure your POM has the following entries (You’ll also need the Servlet API):

Lincoln Baxter, III

About the author:

Lincoln Baxter, III is a Principal Software Engineer at Red Hat, working on JBoss open-source projects; most notably as creator & project lead of JBoss Forge, and author of Errai UI. This blog represents his personal thoughts and perspectives, not necessarily those of his employer.

He is a founder of OCPsoft, the author of PrettyFaces and Rewrite, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also the author of PrettyTime, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals.

November 12th, 2013 by Lincoln Baxter III

PrettyTime 3.2.1.Final Released – Now with Czech language support

We are proud to announce the 3.2.1.Final version of PrettyTime. This release includes several bug-fixes, an improved NLP (time parsing) module, and a new method for more convenient configuration of time units:
public void exampleUnitConfiguration() {
    JustNow unit = t.getUnit(JustNow.class);
    unit.setMaxQuantity(1);
    // This means that "just now" will only be used to represent one millisecond difference between the target time and reference time. (the default is 5 minutes.)
}

Improvements in the NLP module (based on Natty.) include more resilient parsing of date offsets such as “the day before yesterday,” which previously resulted in a date that actually represented “yesterday.”

Get PrettyTime 3.2.1.Final and PrettyTime NLP 3.2.1.Final.

Lincoln Baxter, III

About the author:

Lincoln Baxter, III is a Principal Software Engineer at Red Hat, working on JBoss open-source projects; most notably as creator & project lead of JBoss Forge, and author of Errai UI. This blog represents his personal thoughts and perspectives, not necessarily those of his employer.

He is a founder of OCPsoft, the author of PrettyFaces and Rewrite, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also the author of PrettyTime, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals.

October 3rd, 2013 by Lincoln Baxter III

Create a dynamic Logout URL without a Servlet or JSP, using Rewrite

The code below implements a simple command mapping that binds logout functionality to a URL. To use this example, you must include the following Rewrite dependency in your project:

<dependency>
   <groupId>org.ocpsoft.rewrite</groupId>
   <artifactId>rewrite-servlet</artifactId>
   <version>${rewrite.version}</version>
</dependency>

Once your project is set up to include Rewrite, just paste the following code into your application source folder.

@RewriteConfiguration
public class LogoutConfiguration extends HttpConfigurationProvider
{

   @Override
   public Configuration getConfiguration(ServletContext context)
   {
      return ConfigurationBuilder.begin()
               .addRule()
               .when(Direction.isInbound().and(Path.matches("/logout")))
               .perform(new HttpOperation() {
                  @Override
                  public void performHttp(HttpServletRewrite event, EvaluationContext context)
                  {
                     event.getRequest().getSession().invalidate();
                  }
               }.and(Redirect.temporary(context.getContextPath() + "/")));
   }

   @Override
   public int priority()
   {
      return Integer.MIN_VALUE;
   }
}
Lincoln Baxter, III

About the author:

Lincoln Baxter, III is a Principal Software Engineer at Red Hat, working on JBoss open-source projects; most notably as creator & project lead of JBoss Forge, and author of Errai UI. This blog represents his personal thoughts and perspectives, not necessarily those of his employer.

He is a founder of OCPsoft, the author of PrettyFaces and Rewrite, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also the author of PrettyTime, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals.

October 2nd, 2013 by lastcow

Help! RewriteFilter won’t start – Why? Look to web.xml DOCTYPE for answers.

I was developing JSF 2.2.1 web application using Rewrite for URL cleanup and navigation. It was simple to get started building an application using Rewrite on JBoss WildFly Beta 4 server. I installed the dependencies, starting using the appropriate configuration and components. All I wanted to do was map a few simple pages, and create links to them in the html – Rewrite was perfect for this.

Everything was working fine in the application except page mappings didn’t seem to work (I had to access pages via their direct URL,) and the <pretty:link> always rendered a link to the homepage.

I stopped by the #ocpsoft channel on IRC, and Lincoln helped me solved this ‘strange’ issue (and invited me to write a quick post about it.) Now of course you must be wondering what was wrong – It was because the doctype declaration of my web.xml was both invalid, and also specifying an out-of-date servlet version.

This is the original web.xml DOCTYPE declaration generated by Intellij IDEA:

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

As it turns out, this caused Wildfly to use an older version of Servlet support, which meant that I needed to either register Rewrite in the application manually, by adding the RewriteFilter configuration to my web.xml file, or simply update the web.xml file to use the more recent (and correct) document type (which is by far the simpler solution!)

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
   metadata-complete="false">

Now everything works fine, the old declaration deactivated servlet 3.0, which actually prevented Rewrite to start up (Rewrite bundles a web-fragment.xml file which requires Servlet 3.0 in order to support automatic activation.)

Thanks again to Lincoln, saved my life. ;)

~Lastcow (zhijiang)

September 30th, 2013 by Lincoln Baxter III

Rewrite 2.0.8.Final Released – Fixes critical parameterization bug

Bug Fixes

If you experienced problems with rule parameterization in Rewrite 2.0.7.Final, then sorry about that, and this release of Rewrite is for you: https://github.com/ocpsoft/rewrite/issues/133

Erroneous failures such as the following exception should be fixed by this release:

org.ocpsoft.rewrite.exception.ParameterizationException: The value of required parameter [s] was null.
	at org.ocpsoft.rewrite.param.RegexParameterizedPatternBuilder.extractBoundValues(RegexParameterizedPatternBuilder.java:262)
	at org.ocpsoft.rewrite.param.RegexParameterizedPatternBuilder.build(RegexParameterizedPatternBuilder.java:136)
	at org.ocpsoft.rewrite.servlet.config.Forward.performHttp(Forward.java:85)
	at org.ocpsoft.rewrite.servlet.config.HttpOperation.perform(HttpOperation.java:42)
	at org.ocpsoft.rewrite.servlet.config.rule.Join.perform(Join.java:264)

New Features

Lincoln Baxter, III

About the author:

Lincoln Baxter, III is a Principal Software Engineer at Red Hat, working on JBoss open-source projects; most notably as creator & project lead of JBoss Forge, and author of Errai UI. This blog represents his personal thoughts and perspectives, not necessarily those of his employer.

He is a founder of OCPsoft, the author of PrettyFaces and Rewrite, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also the author of PrettyTime, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals.

September 17th, 2013 by Lincoln Baxter III

Simplest RVM Installation Guide

Run this command to install the rvm command, a very simple and intuitive “Ruby Version Manager”:
mkdir -p ~/.rvm/src && cd ~/.rvm/src && rm -rf ./rvm && \
git clone --depth 1 git://github.com/wayneeseguin/rvm.git && \
cd rvm && ./install && \
echo "if [[ -s $HOME/.rvm/scripts/rvm ]]; then source $HOME/.rvm/scripts/rvm; fi" >> ~/.bashrc
Edit: Oops, I guess it can get even simpler: (Yes, the ‘\’ is intentional.)
\curl -L https://get.rvm.io | bash
Now use it:
rvm install 1.9.3
Source: An awesome Canadian website.
Lincoln Baxter, III

About the author:

Lincoln Baxter, III is a Principal Software Engineer at Red Hat, working on JBoss open-source projects; most notably as creator & project lead of JBoss Forge, and author of Errai UI. This blog represents his personal thoughts and perspectives, not necessarily those of his employer.

He is a founder of OCPsoft, the author of PrettyFaces and Rewrite, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also the author of PrettyTime, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals.

September 15th, 2013 by Lincoln Baxter III

Rewrite 2.0.7.Final Released – Bug fixes and enhancements

We are glad to announce the latest version of Rewrite, servlet toolkit and URL-rewriting extensions. This release includes serveral bug fixes and enhancements:

Simplified Configuration

We heard you! It is now much easier to register ConfigurationProvider objects. You can forget about creating a service file, and simply use the convenient @RewriteConfiguration annotation:

import org.ocpsoft.logging.Logger.Level;
import org.ocpsoft.rewrite.annotation.RewriteConfiguration;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.config.Log;
import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;

@RewriteConfiguration
public class ApplicationConfigurationProvider extends HttpConfigurationProvider
{
   @Override
   public Configuration getConfiguration(ServletContext context)
   {
      return ConfigurationBuilder.begin()
         .addRule()
         .perform(Log.message(Log.message(Level.INFO, "Rewrite is active.")))
      ;
   }

   @Override
   public int priority()
   {
      return 0;
   }
}

Issues resolved

Upgrade to 2.0.7.Final

Read the installation guide, or configuration manual.

<dependency>
   <groupId>org.ocpsoft.rewrite</groupId>
   <artifactId>rewrite-servlet</artifactId>
   <version>2.0.7.Final</version>
</dependency>
Lincoln Baxter, III

About the author:

Lincoln Baxter, III is a Principal Software Engineer at Red Hat, working on JBoss open-source projects; most notably as creator & project lead of JBoss Forge, and author of Errai UI. This blog represents his personal thoughts and perspectives, not necessarily those of his employer.

He is a founder of OCPsoft, the author of PrettyFaces and Rewrite, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also the author of PrettyTime, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals.

September 11th, 2013 by Lincoln Baxter III

OpenShift Pro-tip – scaling: tail server logs on all gears of your app at once

UPDATE: I’ve filed an issue for this feature request. Until it is completed, you will need to use the command below.

So i’ve recently started working on making http://redoculous.io function better in a cluster, to support scaling out for large-scale use, and I’ve been working with http://openshift.com/ as my PaaS hosting provider. I started to run into some problems where I wasn’t sure if the cluster was responding how I wanted to.

Being a good developer, my application has logging, so I know that if I can just watch the logs as they occur (or sift through them after the fact), I can probably figure out what is wrong, and fix it.

Unfortunately, running rhc tail will tail the gear running HA-proxy, but not the gears running the actual application, or any of the duplicate gears if HA-proxy is sharing a gear with an app! You’ll just get HA-proxy logs or maybe one of your application gears if you are lucky. What to do? I ran crying for help to the #openshift channel on IRC, where the openshift gurus quickly set me straight. This is all you need to do (for the ‘jbosseap’ cartridge, at least):

rhc ssh <app> --gears 'tail -f jbosseap/logs/*';

The rhc ssh command will execute a command on each of your gears simultaneously, and stream the output to your termainal, which is just an absolute perfect match for tail -f. Note, though, that you’ll need to pass in your application name, and the path to your logs on each gear (which should be fairly easy to find out if you ssh in and take a look around. The log location is even documented for your cartridge on the openshift site: ) I retrieved it using the same rhc ssh command:

sharktop:gems lb3$ rhc ssh redoculous --gears 'echo $OPENSHIFT_JBOSSEAP_LOG_DIR';
[gear1name jbosseap-6+haproxy-1.4] /var/lib/openshift/gear1name/jbosseap/logs/
[gear2name jbosseap-6+haproxy-1.4] /var/lib/openshift/gear2name/jbosseap/logs/
[gear3name jbosseap-6+haproxy-1.4] /var/lib/openshift/gear3name/jbosseap/logs/

So in this case, the log-dir relative to the home directory is just, jbosseap/logs. Good to go!


Now, I do think that this would be much better suited as rhc tail-all (DOES NOT CURRENTLY WORK), but I’ll just have to file an issue request, or maybe take a stab at the code here if nobody beats me to it:

https://github.com/openshift/rhc/blob/master/lib/rhc/commands/tail.rb#L18
https://github.com/openshift/rhc/blob/master/lib/rhc/commands/ssh.rb#L37

I hope this helps. Good luck, openshifters!

Lincoln Baxter, III

About the author:

Lincoln Baxter, III is a Principal Software Engineer at Red Hat, working on JBoss open-source projects; most notably as creator & project lead of JBoss Forge, and author of Errai UI. This blog represents his personal thoughts and perspectives, not necessarily those of his employer.

He is a founder of OCPsoft, the author of PrettyFaces and Rewrite, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also the author of PrettyTime, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals.