Skip to content

Latest commit

 

History

History
57 lines (48 loc) · 1.45 KB

File metadata and controls

57 lines (48 loc) · 1.45 KB

Rewrite CDI Integration

Rewrite offers an extension that enables CDI support in your service implementations, such as ConfigurationProvider instances, listeners, and more. This is useful when you need to inject beans, or create CDI @Produces methods for information gathered in a ConfigurationProvider.

Get Started

  1. Include the CDI integration extension in your application’s POM file along with Rewrite itself:

    <dependency>
       <groupId>org.ocpsoft.rewrite</groupId>
       <artifactId>rewrite-servlet</artifactId>
       <version>${rewrite.version}</version>
    </dependency>
    <dependency>
       <groupId>org.ocpsoft.rewrite</groupId>
       <artifactId>rewrite-integration-cdi</artifactId>
       <version>${rewrite.version}</version>
    </dependency>
  2. Use CDI in your configuration providers or listeners:

    package com.example;
    
    public class ExampleConfigurationProvider extends HttpConfigurationProvider
    {
    	@Inject
    	private ExampleBean bean;
    
    	@Override
    	public int priority()
    	{
    	    return 10;
    	}
    
    	@Override
    	public Configuration getConfiguration(final ServletContext context)
    	{
    		return ConfigurationBuilder.begin()
    		.addRule()
    		.when(new HttpCondition()
    		{
    			public boolean evaluate(HttpServletRewrite event, EvaluationContext context) {
    			   // bean.doSomething();
    			}
    		})
    		.perform(Log.message("I did something with a CDI bean!"));
    	}
    }