Question
Coforge
IN
Last activity: 15 Apr 2016 7:58 EDT
How to include custom java bean in Pega 7
Hi Team,
I would like to know if there is any possibilty of adding custom java bean in Pega 7. I can see there are spring classes(GenericXmlApplicationContext) available but not sure how/where to inject custom java bean.
I have already included all the desired jar but not able to figure out context.xml file.
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Pegasystems Inc.
US
are you simply trying to include your custom java bean jars to pega7? Looks like you are running on tomcat? In general you can add custom jars to tomcat classpath, check the tomcat classloader to get all the details: e.g. Apache Tomcat 8 (8.0.33) - Class Loader HOW-TO. Other approach is to import jars into pega database, but you have to be very careful in potential class conflicts with pega OOTB jars.
Coforge
IN
Kevin,
I have already added all the required Jars. I just want to configure bean definition. Where ideally i should keep below bean definition?
<bean id="demoClass" class="com.demoClass">
<property name="transport" ref="demoClient" />
</bean>
Pegasystems Inc.
US
I see, can you please elaborate what your intended use case/requirement is? I assume you already tested the javabeans outside pega through jsp/html, right?
Coforge
IN
Hi Kevin,
Earlier i thought of managing java project and try to invoke java methods from pega. In this scenario, i will have to maintain 2 applications one in jav and other in pega. What we are looking for is to manage all Java code in pega itself and get rid of Java application.
We have already test bean in java project and want to bring it to Pega.
Pegasystems Inc.
US
what I meant was that how you are planning to use the beans in pega? used in jsp? html rule? etc.
Coforge
IN
I would use it in activity, using java step, to initalise java objects and use some of the methods.
Pegasystems Inc.
US
in that case, it is purely java, have you encountered any issues at all?
Coforge
IN
Bean class which we want to use has dependency on some other class during initialization which are part of Jar and we are not aware about complete initialization sequence. Only way to initialize this class is via Bean only.
Pegasystems Inc.
US
you will need to figure out the dependency, can you show the complete error stack when you are trying to initialize the bean class?
Coforge
IN
Kevin,
this is not going to be right approach. If there is spring support available then we should try to include beans directly instead of initializing instance on our own.
Is there no way to include custom java beans in pega directly?
Pegasystems Inc.
US
I am not aware of such way of including custom java beans to pega directly, let's see other people in the community have any knowledge regarding this. I could not find references to spring-like capability in the product documentation.
Pegasystems Inc.
FR
Hello,
I have faced similar issue with a Spring interface (used to generate PDF files) some time ago. I solved it by implementing a wrapper class to be used through a Java connector rule. The bean was initialized in the constructor of the wrapper class:
import java.util.HashMap;
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
public class PdfGeneratorProxyWrapper {
private final HttpInvokerProxyFactoryBean pfb;
public PdfGeneratorProxyWrapper(String serviceUrl) {
pfb = new HttpInvokerProxyFactoryBean();
pfb.setServiceUrl(serviceUrl);
pfb.setServiceInterface(de.wwag.bsw.pdfgenerator.IBSWPdfGenerator.class);
pfb.afterPropertiesSet();
}
/**
*
* @param map
* @param pathToFormular
* @return String PDF-Dokument
*/
public String getBSWPdf(HashMap map, String pathToFormular){
IBSWPdfGenerator proxy = (IBSWPdfGenerator) pfb.getObject();
return new String(proxy.getBSWPdf(map, pathToFormular));
}
/**
* @param map
* @return String PDF-Dokument
*/
public String getBSWPdf(HashMap map) {
IBSWPdfGenerator proxy = (IBSWPdfGenerator) pfb.getObject();
return new String(proxy.getBSWPdf(map));
}
/**
* Liefert ein statisches PDF als Byte Array.
*
* @param filename
* @return String PDF
*/
Hello,
I have faced similar issue with a Spring interface (used to generate PDF files) some time ago. I solved it by implementing a wrapper class to be used through a Java connector rule. The bean was initialized in the constructor of the wrapper class:
import java.util.HashMap;
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
public class PdfGeneratorProxyWrapper {
private final HttpInvokerProxyFactoryBean pfb;
public PdfGeneratorProxyWrapper(String serviceUrl) {
pfb = new HttpInvokerProxyFactoryBean();
pfb.setServiceUrl(serviceUrl);
pfb.setServiceInterface(de.wwag.bsw.pdfgenerator.IBSWPdfGenerator.class);
pfb.afterPropertiesSet();
}
/**
*
* @param map
* @param pathToFormular
* @return String PDF-Dokument
*/
public String getBSWPdf(HashMap map, String pathToFormular){
IBSWPdfGenerator proxy = (IBSWPdfGenerator) pfb.getObject();
return new String(proxy.getBSWPdf(map, pathToFormular));
}
/**
* @param map
* @return String PDF-Dokument
*/
public String getBSWPdf(HashMap map) {
IBSWPdfGenerator proxy = (IBSWPdfGenerator) pfb.getObject();
return new String(proxy.getBSWPdf(map));
}
/**
* Liefert ein statisches PDF als Byte Array.
*
* @param filename
* @return String PDF
*/
public String getStaticPDF(String filename){
IBSWPdfGenerator proxy = (IBSWPdfGenerator) pfb.getObject();
return new String(proxy.getStaticPDF(filename));
}
}
Hope it can help....
Best Regards,
Rodolphe
Pegasystems Inc.
US
This is fantastic! I think this approach is similar to what we do in the connector meta data wizard. Also Pega 7 already ships with springframework jars, right? Furthermore, this could be a potential future enhancement as well.
Pegasystems Inc.
FR
Hello,
I did not have to import the Spring framework jar files in Pega. So I guess that these jars are available with Pega OOTB :-)
Best Regards,
Rodolphe
Pegasystems Inc.
US
thanks, just confirmed springframework jars are there in pega 7.2, version 4.1.4.