Thursday, October 6, 2011

org.jasypt.exceptions.EncryptionOperationNotPossibleException

Many of us have come across this exception while using encryption in our functionality.

org.jasypt.exceptions.EncryptionOperationNotPossibleException: Encryption raised an excep tion. A possible cause is you are using strong encryption algorithms and you have not installed the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files in this Java Virtual Machine


Resolution:


As the exception indicates one need to install the latest JCE Policy Jar Files into your JAVA setup.

1. Download the JCE Policy jar files from the below location:

2. The zip file would contain two jar files (local_policy.jar and US_export_policy.jar). 

3. These jar files need to be placed under the following location:

%JAVA_HOME%\jre\lib\security\

Reference Link:

Monday, October 3, 2011

Mule - Expression Splitter Router

The following example is used to simulate the functionality of the expression-splitter-router in mule.

Java Classes:

Fruit:

package com.expressionsplitterrouter;

public abstract class Fruit {

    private String shape;

    public String getShape() {
        return shape;
    }

    public void setShape(String shape) {
        this.shape = shape;
    }

} 


Apple:

package com.expressionsplitterrouter;

public class Apple extends Fruit {

    private String type;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

}


Banana:

package com.expressionsplitterrouter;

public class Banana extends Fruit {

    private String form;

    public String getForm() {
        return form;
    }

    public void setForm(String form) {
        this.form = form;
    }

}


FruitBowl:

package com.expressionsplitterrouter;

import java.util.ArrayList;
import java.util.List;

public class FruitBowl {

    private List<Fruit> fruit;

    public List<Fruit> getFruit() {
        return fruit;
    }

    public void setFruit(List<Fruit> fruit) {
        this.fruit = fruit;
    }
    
    public void addFruit(Fruit fruit){
        if (this.fruit == null) {
            this.fruit = new ArrayList<Fruit>();
        }
        this.fruit.add(fruit);
    }

} 


CreateFruitComponent:

package com.expressionsplitterrouter;

public class CreateFruitComponent {

    public FruitBowl createFruit(String start) {
        
        FruitBowl bowl = new FruitBowl();
        
        Apple apple = new Apple();
        apple.setShape("Round");
        apple.setType("Green");
        
        Banana banana = new Banana();
        banana.setShape("Lengthy");
        banana.setForm("Yellow");
        
        bowl.addFruit(apple);
        bowl.addFruit(banana);
        
        apple = new Apple();
        apple.setShape("Rectangular Square");
        apple.setType("Red");
        
        bowl.addFruit(apple);
        return bowl;
    }
} 


AppleComponent:

package com.expressionsplitterrouter;

public class AppleComponent {

    public void displayApple(Apple apple) {

        System.out.println("Apple Component");
        System.out.println(apple.getShape() + "," + apple.getType());
    }
} 


BananaComponent:

package com.expressionsplitterrouter;

public class BananaComponent {

    public void displayBanana(Banana banana) {

        System.out.println("BananaComponent");
        System.out.println(banana.getShape() + "," + banana.getForm());
    }
} 


Mule-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2"
    xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
    xsi:schemaLocation="
          http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
          http://www.mulesource.org/schema/mule/stdio/2.2 http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd
          http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd">

    <stdio:connector name="stdioIN" promptMessage="Press any key to continue" />

    <model name="ExpressionSplitterRouterModel">
        <service name="CreateMsgService">
            <inbound>
                <stdio:inbound-endpoint
                    connector-ref="stdioIN" system="IN" />
            </inbound>
            <component
                class="com.expressionsplitterrouter.CreateFruitComponent" />
            <outbound>
                <expression-splitter-router
                    expression="fruit" evaluator="bean">
                    <vm:outbound-endpoint path="banana-channel">
                        <payload-type-filter
                            expectedType="com.expressionsplitterrouter.Banana" />
                    </vm:outbound-endpoint>
                    <vm:outbound-endpoint path="apple-channel">
                        <payload-type-filter
                            expectedType="com.expressionsplitterrouter.Apple" />
                    </vm:outbound-endpoint>
                </expression-splitter-router>
            </outbound>
        </service>
        
        <service name="BananaService">
            <inbound>
                <vm:inbound-endpoint path="banana-channel"/>
            </inbound>
            <component class="com.expressionsplitterrouter.BananaComponent"/>
        </service>
        
        <service name="AppleService">
            <inbound>
                <vm:inbound-endpoint path="apple-channel"/>
            </inbound>
            <component class="com.expressionsplitterrouter.AppleComponent"/>
        </service>
    </model>
</mule> 

Mule - Expression recipient list router

The following example is on the usage of the expression-recipient-list-router. This router can be used to extract the endpoints from the message and route it to the corresponding component.

Java Classes:

CreateXmlMessageComponent:


package com.expressrecipienttransformers;

public class CreateXmlMessageComponent {

    public String createMessage(String msg) {

        StringBuilder sb = new StringBuilder();
        sb.append("<message>");
        sb.append("<recipientList>");
        sb.append("<recipient>vm://display-message-channel</recipient>");
        sb.append("<recipient>vm://compute-message-channel</recipient>");
        sb.append("</recipientList>");
        sb.append("<info>");
        sb.append("Hi there");
        sb.append("</info>");
        sb.append("</message>");
        
        
        return sb.toString();
    }
} 

DisplayMessageComponent:

package com.expressrecipienttransformers;

public class DisplayMessageComponent {

    public void displayMessage(String msg) {
        
        System.out.println("Into displaymessage");
        System.out.println(msg);
    }
} 

ComputeMsgComponent:


package com.expressrecipienttransformers;

public class ComputeMsgComponent {

    public void compute(String msg) {
        
        System.out.println("Into compute component");
        System.out.println(msg.length());
    }
} 

mule-config.xml:



<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2"
    xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
    xsi:schemaLocation="
          http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
          http://www.mulesource.org/schema/mule/stdio/2.2 http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd
          http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd">

    <stdio:connector name="stdioIN" promptMessage="Press any key to continue" />

    <model name="expression-recipient-list-model">
        <service name="expression-recipient-list-serviec">
            <inbound>
                <stdio:inbound-endpoint
                    connector-ref="stdioIN" system="IN" />
            </inbound>
            <component
                class="com.expressrecipienttransformers.CreateXmlMessageComponent"></component>
            <outbound>
                <expression-recipient-list-router
                    expression="/message/recipientList/recipient"
                    evaluator="xpath" />
            </outbound>
        </service>

        <service name="DisplayService">
            <inbound>
                <vm:inbound-endpoint path="display-message-channel" />
            </inbound>
            <component
                class="com.expressrecipienttransformers.DisplayMessageComponent" />
        </service>

        <service name="ComputeService">
            <inbound>
                <vm:inbound-endpoint path="compute-message-channel" />
            </inbound>
            <component
                class="com.expressrecipienttransformers.ComputeMsgComponent" />
        </service>
    </model>
</mule