public void showMeJDK8() throws Exception { PrettyTime t = new PrettyTime(); Assert.assertEquals("3 months from now", t.format(LocalDateTime.now().plusMonths(3))); } }
Improvements in the NLP module (based on Natty.) Updated to version 0.13.0
public void showMeJDK8() throws Exception { PrettyTime t = new PrettyTime(); Assert.assertEquals("3 months from now", t.format(LocalDateTime.now().plusMonths(3))); } }
Improvements in the NLP module (based on Natty.) Updated to version 0.13.0
Several years ago I wrote a tutorial about using Acegi/Spring Security with JavaServer Faces (JSF) to create a simple authentication / Login page; however, times have changed and Java EE is back in action. I would no longer consider Spring a “requirement” when building a Java EE application. More specifically, if you are using the core Contexts and Dependency Injection (CDI) framework that serves as the backbone for the entire Java EE framework, Spring Security becomes less attractive (because it’s not compatible without using Spring itself, and Spring is a replacement for CDI).
This article will explore how to create a JSF login backed by the standards-compliant CDI framework (that is included with Java EE), and the PicketLink security framework (an open-source project from JBoss). Examples for this article were sourced from the very comprehensive, and quite understandable quick-start application from the PicketLink project itself.
PrettyTime allows you to create human-readable timestamps such as “3 minutes ago” or “just now”, and is used in other open-source tools such as JBoss Tools, and JBoss Developer Studio.
Enjoy, and happy holidays,
Lincoln and the OCPsoft team.
public class LongRunningRegexExample { public static void main(String[] args) throws InterruptedException { final Pattern pattern = Pattern.compile("(0*)*A"); final String input = "00000000000000000000000000"; long startTime = System.currentTimeMillis(); Matcher matcher = pattern.matcher(input); matcher.find(); // runs for a long time! System.out.println("Regex took:" + (System.currentTimeMillis() - startTime) + "ms"); } }
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.
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> |
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")) |
.addRule() .when(Response.isCommitted().and(Direction.isInbound())) .perform(Lifecycle.abort()) |
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):
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.”
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; } }
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)
Rewrite will now display version information at application boot time: https://github.com/ocpsoft/rewrite/issues/129
02:37:34,570 INFO [org.ocpsoft.rewrite.servlet.RewriteFilter] (ServerService Thread Pool -- 68) Rewrite 2.0.8.Final initialized.
Compilation mode may now be set on JRuby based Transform modules: https://github.com/ocpsoft/rewrite/issues/131
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
\curl -L https://get.rvm.io | bash
rvm install 1.9.3