Pega Connect EJB (EJB Connector) Tutorial
Pega does not provide any complete tutorial on the Connect EJB rules, so hopefully this may help you to build one from ground up.
Environment
Pega 7.2 on Tomcat 7.0.62 Java 1.8
JBoss EAP 6.4.0
My Pega instance is deplolyed on Tomccat with PostgeSQL database, I have to connect to an EJB deployed on JBoss Application Server using Remote EJB call.
Issues
There is only one small issue with the Pega Connect EJB rule. It does not support EJB3. It can only work with EJB2. I cannot understand this, as EJB3 has been used by many enterprise applications for more than 12 years, but Pega still does not support it. Maybe there are not many people using this connector. In our case, we have to use it to support one of our legacy systems.
Build A Testing EJB2 Session Bean
This EJB will perform a very simple task. It takes an input CreateMovementRequestDTO parameter and returns an CreateMovementResponseDTO object. "DTO" stands for Data Transfer Object.
Buld a new EJB application using JBoss Development Studio.
EJB module version : 2.1
Create an EJB Client JAR module to hold the client interfaces and classes ( This jar "PCEConnectorClient.jar" will be imported into Pega)
Create the following classes in the EJB Client JAR
package pce.ejb;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface MovementHome extends EJBHome {
public Movement create() throws CreateException, RemoteException;
}
package pce.ejb;
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
import pce.dto.CreateMovementRequestDTO;
import pce.dto.CreateMovementResponseDTO;
public interface Movement extends EJBObject {
public CreateMovementResponseDTO createMovement(CreateMovementRequestDTO movement) throws RemoteException;
}
package pce.dto;
import java.io.Serializable;
import java.util.Date;
public class CreateMovementRequestDTO extends RequestDTO implements Serializable{
private static final long serialVersionUID = -8763833692432891268L;
private String portCode;
private Date ArrivalDateTime;
public String getPortCode() {
return portCode;
}
public void setPortCode(String portCode) {
this.portCode = portCode;
}
public Date getArrivalDateTime() {
return ArrivalDateTime;
}
public void setArrivalDateTime(Date arrivalDateTime) {
ArrivalDateTime = arrivalDateTime;
}
}
package pce.dto;
import java.io.Serializable;
public class CreateMovementResponseDTO extends ResponseDTO implements Serializable
{
private static final long serialVersionUID = -4056812668015438921L;
private String movemntId;
public String getMovemntId() {
return movemntId;
}
public void setMovemntId(String movemntId) {
this.movemntId = movemntId;
}
}
package pce.dto;
public abstract class RequestDTO {}
package pce.dto;
public abstract class ResponseDTO
{
private String result;
private String errorCode;
private String errorDescription;
private String statckTrace;
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public String getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
public String getErrorDescription() {
return errorDescription;
}
public void setErrorDescription(String errorDescription) {
this.errorDescription = errorDescription;
}
public String getStatckTrace() {
return statckTrace;
}
public void setStatckTrace(String statckTrace) {
this.statckTrace = statckTrace;
}
}
Create the following classes in the EJB JAR
package pce.ejb;
import java.rmi.RemoteException;
import java.util.UUID;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import pce.dto.CreateMovementRequestDTO;
import pce.dto.CreateMovementResponseDTO;
public class MovementBean implements SessionBean{
private static final long serialVersionUID = 1L;
protected SessionContext sessionContext = null;
public void ejbCreate() {
}
public String saveMovement(String port) throws RemoteException
{
return port;
}
public CreateMovementResponseDTO createMovement(CreateMovementRequestDTO movement) throws RemoteException
{
CreateMovementResponseDTO response = new CreateMovementResponseDTO();
System.out.println("Save Movement DTO in database");
System.out.println("Port:" + movement.getPortCode());
response.setMovemntId(UUID.randomUUID().toString());
response.setResult("SUCCESS");
return response;
}
@Override
public void ejbActivate() throws EJBException, RemoteException {}
@Override
public void ejbPassivate() throws EJBException, RemoteException {}
@Override
public void ejbRemove() throws EJBException, RemoteException {}
@Override
public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException {
this.sessionContext = sessionContext;}
}
Import the following JARs into Pega and Restart Pega server (Tomcat)
You can find all these jboss jars from your Jboss server instance. Use Application->Distribution->Import to import all these jars into Pega.
Configure Pega JNDI Server
Navigate to : Integration-Resources->JNDI Server, Create a new JNDI Server instance.
URL_PKG_PREFIXES : org.jboss.ejb.client.naming
jboss.naming.client.ejb.context : true [ You will get an Jboss error, if you do not include this setting]
To test this JNDI Sever, you need to:
- Start your JBoss application sever
- Deploy your PCEConnector EJB
- Clock on the "Browse tree" button
- You should see your EJB JNDI name from the Pega JNDI Tree pop-up window
Create a Integration Class and Metadata classes
Create a new integration class to host all integration rules: XXX-Int-PCE-Movement
Use "Integraiton->Connector->Connector and Metadata Wizard" function to create Pega wrapper class to wrap java class
Ceate a wrapper class for CreateMovementRequestDTO java class
Cr
Suggest you to apend a "-" at the end of you base class "xxx-Int-PCE-Movement-", otherwise you will get a "Cannot find java class wrapper error." . I did not figure out why I got that error.
Select all java attribues and follow the wizard to create all the properties. The Wizard will also create new Pega inegration classes for the parent java class "RequestDTO".
Suggest you to use recommand name. Do not change generated class or proerty names.
Please follow the same steps to crate wrapper classes for the "CreateMovementResponseDTO" java class. The generated Pega class/properties for CreateMovementResponseDTO should look like this:
Create two new properties under XXX-Int-PCE-Movement class:
1. CreateMovementRequest [ Single Page property, Reference newly generated XXX-Int-PCE-Movement-CreateMovementRequestDTO class]
2. CreateMovementResponse [ Single Page property, Reference newly generated XXX-Int-PCE-Movement-CreateMovementResponseDTO class]
Create a data transform rule "InitializePCEMovement" to initialise the "CreateMovementRequest", so you can send something to the EJB.
Configure Pega Connect EJB Rule
Navigate to "Integration-Connectors->Connect EJB" to crate a new Connect EJB rule.
Parameters:
DataType: pce.dto.CreateMovementRequestDTO
Map from key: .CreateMovementRequest
Configure a Testing Activity
The Show-Page "PCEMovementServicePage" step should display the EJB returned values:
result = "SUCCESS"
movementId = [ Some Random Id]