Use the Eclipse File -> New JBoss ESB Project.
Name the project the name of the service.
E.g. AccountEntityService. |
Use the JBoss ESB editor to edit the jboss-esb.xml file.
First add the providers to jboss-esb.xml.
With ESB services deployed as web services there are no gateway providers required, instead only a single JMS provider
is required for the ESB Service endpoint (or the specification of InVM scope = global).
Create JCA provider specifying XAConnectionFactory.
|
Use the JBoss ESB Editor to create the service. Name it the same as the project, and name the Category EntityServices (or pick some other category naming convention).
Create a listener and choose the jms-jca-provider to let the container manage the transaction boundaries (i.e. the entire action chain).
Use the source tab to add the XSD of the request message, response message, and fault message.
E.g., <actions inXsd="/accountRequest.xsd" outXsd="/accountReply.xsd
faultXsd="/accountFault.xsd" >
|
Add a SmooksAction to map the XML to POJOs.
Create a smooks resource configuration file to configure this transformation based on domain model.
At least two POJOs will be created, a Task object and the Entity object.
Provide the following properties:class, name, smooksConfig, set-payload-location
E.g., <action class="org.jboss.soa.esb.smooks.SmooksAction"
name="CreateAccountObject">
<property name="smooksConfig"
value="AccountConfig.smooks"/>
<property name="resultType" value="JAVA"/>
<property name="set-payload-location" value="accountPayload"/>
</action>
|
Add action to create a JPA EntityManager, join the transaction in progress, determine and execute the appropriate task (create, get, update, or delete), and update the message.
public JPAAction(ConfigTree config) {
try {
_config = config;
// Because ESB services are not handled by EJB deployer, EJB
// dependency injection isn't going to work.
// Need to get transaction and entity manager manually
String entityManagerJNDIName = config.getAttribute("entityManagerJNDIName");
InitialContext jndiContext = new InitialContext();
SessionFactory sFactory =
(SessionFactory)jndiContext.lookup(entityManagerJNDIName);
emfImpl = new EntityManagerFactoryImpl(sFactory, PersistenceUnitTransactionType.JTA, true,
null);
tMgr = (TransactionManager)jndiContext.lookup("java:/TransactionManager");
}
public Message process(Message message) throws ActionProcessingException {
// make a copy of the message
newMessage = message.copy();
Map accountPayload = (Map) newMessage.getBody().get("accountPayload");
Task task = (Task) accountPayload.get("task");
String taskName = (String) task.getTaskName()
// create an entityManager and join the transaction
em = emfImpl.createEntityManager();
em.joinTransaction();
if (taskName.startsWith("create"))
Account account = (Account) accountPayload.get("account");
em.persist(account);
}
...
|
Add JPA action to jboss-esb.xml
E.g.,
<action class="org.acme.account.AccountPersistanceAction" name="JPAAction">
<property name="entityManagerJNDIName"
value="persistence.units:unitName=AccountEntity"/>
</action>
|
Add another SmooksAction to transform POJOs back to XML.
Test service with an ESB aware client created from examples.
Help -> Project Examples -> ESB Examples -> JBoss ESB HelloWorld Example –
Client
|
Test service as Web service using Eclipse Web Serivces explore, SoapUI, or other Web service client.
Use WSDL in jboss-as/server/default/data/wsdl/...(or copy it into workspace).
Copy in sample message data to populate message.
|
|