Petstore - tomcat - jsf-impl.jar

follwing import in com.sun.faces.config.ConfigureListener is wrongimport com.sun.org.apache.commons.digester.Digester;it should be import org.apache.commons.digester.Digester;Causing deploytime problem for petstore on tomcat
[259 byte] By [akaranja] at [2007-11-26 14:21:34]
# 1
Please mail JAVA file of com.sun.faces.config.ConfigureListener (jsf-impl.jar .....1.2) to me on atulkjava@yahoo.com so that I can compile it and put it in jar
akaranja at 2007-7-8 2:13:21 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Hi,

we have not yet tried using petstpre 2.0 on tomcat. Petstore uses some Java EE 5 technoogies such as JSF 1.2 and Java persistence, so you would need to add somejars and set up[ tomcat environment to have extra functionalities. WE address this question on our FAQ at

https://blueprints.dev.java.net/petstore/faq.html#tomcat

which sort of outlines what might be needed to run on Tomcat.

Petstore should run on any Java EE 5 aplication server, though we have only tested it on the Java EE 5 SDK and Glassfish.

hth,

Sean

seanbrydona at 2007-7-8 2:13:21 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
Hi,I said one import is wrong. How can it beimport com.sun.org.apache.commons.digester.Digester; Its not allowing class to load.I had read instructions at https://blueprints.dev.java.net/petstore/faq.html#tomcat and working on same guidlines.
akaranja at 2007-7-8 2:13:21 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
Ok. I understood why it is com.sun.org.apache.Please let me know in what jar of J2EE 5 SDK I will get implementation of javax.el.
akaranja at 2007-7-8 2:13:21 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

If you have the Java EE SDK or a version of glassfish, the classes I believe you are looking for are in the javaee.jar in the lib directory.

Just for all to understand, the reason the apache classes are prefaced with "com.sun" is to distinguish the version of the Apache classes that the appserver's implementation uses from a version of the Apache classes that an application running on the appserver may use.

Hope this helps...

Thanks - Mark

markbaslera at 2007-7-8 2:13:21 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

Hi,

Yes, I think since the unified EL is now a separate jar outside of JSF jar, so you would need a another jar to include that includes the package for javax.el as well as jsf.jar.

Hmmm... I am starting to wonder about getting it to work on Tomcat. Are you using Tomcat 5 or Tomcat 6? I think you would need Tomcat 6 to start with since it has the latest JSP engine and unified el and then you could add in JSF 1.2 jars and modify that environment.

I think it may not work to try to take tomcat 5 and run a Java 5 web application on it just by modifying a few jars in the tomcat environment. I *think* you would need to strt with tomcat 6, and then add some extra jars to be able to run a Java EE 5 web app?

hth,

Sean

seanbrydona at 2007-7-8 2:13:21 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7

Hi Sean,

Tomcat 6.x: JSF classes call to some method of jsp-api is not compatible. Signature of method in jsp-api is different than what JSF calls resulting in Exception. I will post details when I go to office.

Tomact 5.5.X: I will wait till tommorrow on this. It may work or few more hurdles. JPA (with toplink) is woking on tomcat 5.5.x. For JSF tomcat looks for sun.beans.ValueExpressionEditor class which is not there. So causes JasperException jsp.error.beans.property.conversion". It is easy to solve (I think).

Please see:

class org.apache.jasper.runtime.JspRuntimeLibrary#getValueFromPropertyEditorManager(Class attrClass, String attrName, String attrValue)

java.beans.PropertyEditorManager#findEditor

For JTA which is best? Bitronix, Atomikos, jotm or simplejta.

akaranja at 2007-7-8 2:13:21 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8

Hi,

> Tomcat 6.x: JSF classes call to some method of

> jsp-api is not compatible. Signature of method in

> jsp-api is different than what JSF calls resulting in

> Exception. I will post details when I go to office.

Has anyone else tried to get JSF 1.2 working on tomcat 6?

I will see if I can ask someone too.

Actually, this could be a tricky adventure to get this working on tomcat as tomcat 6 is still getting worked on a lot, so dont try too hard else you may get frustrated :-)

hth,

Sean

seanbrydona at 2007-7-8 2:13:21 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 9
Petstore Web 2.0 application si fully working on Tomcat 5.5.16. Only thing remaining is Banner new.
akaranja at 2007-7-8 2:13:21 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 10
Hi,It would be great if you could summarize the steps you had to perform to get this working so others on the forum can benefit.Thanks in advance - Mark
markbaslera at 2007-7-8 2:13:21 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 11

Hi,

I spoke to Ed Burns about using JSF 1.2 from https://javaserverfaces.dev.java.net/ on Tomcat 6, and he mentioned that they test that periodically and it works. He mentioned that you need to ...

For Tomcat6 you need to delete the contents of your work directory and

restart.

So maybe you can try that?

Of course its just one step to getting Petstore 2.0 war running on Tomcat 6 plus some other jars like JSF 1.2

And it seems you already got some of it running on Tomcat 5 anyways. Hope you can share some of the steps you had to do for it to work. Maybe we can documenbt those steps and add them to the petstore project so others can try the same thing. Also, did you have to change any PS code?

thx,

Sean

> follwing import in

> com.sun.faces.config.ConfigureListener is wrong

>

> import com.sun.org.apache.commons.digester.Digester;

>

> it should be

>

> import org.apache.commons.digester.Digester;

>

> Causing deploytime problem for petstore on tomcat

seanbrydona at 2007-7-8 2:13:21 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 12
sean, Mark please give me your mail id.
akaranja at 2007-7-8 2:13:21 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 13
Hi,my email is Sean.Brydon@sun.com.And you can always post to the forum also to chat.hth,Sean
seanbrydona at 2007-7-8 2:13:21 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 14

Procedure to port Petstore to Tomcat:

1.Jars required in commons/lib:

EL api & its implementation. Presently I am using classes available from appserv-rt.jar of 5.0 J2EE SDK.

Database driver. I am using derbyclient.jar

JPA api and its implementation. We can use toplink jars available with J2EE 5.0 SDK.

Implemetation by Hibernet can also be used but it asks for some JBoss related Jars. (hibernate3.jar, hibernate-annotations.jar, hibernate-entitymanager.jar, jboss-common.jar, antlr-2.7.6.jar, cglib.jar, dom4j.jar, and javassist.jar)

JSF 1.2 api and its implementation. I am using reference implementation. No open source implementation is available for JSF 1.2.

JSTL jar.

You also need to create two classes MethodExpressionEditor and ValueExpressionEditor.

oThese classes must have name as above. This is required because tomcat looks for these classes. Pl. See JasperRuntime.java.

oThey must be in package 搒un.beans.editors?

oThey should extend MethodExpression /ValueExxpression and implement java,beans.PropertyEditor interface.

oCode should be same javax.el.MethodExpressionImpl/ javax.el.ValueExpressionImpl.

getValue method of ValueExpressionEdior needs to be like follows:

public Object getValue(ELContext context) throws PropertyNotFoundException, ELException {

EvaluationContext ctx = new EvaluationContext(context, fnMapper, varMapper);

Object value = getNode().getValue(ctx);

Object ret = null;

if(value == null){

return value;

}

if(expectedType != null) {

ret = ELSupport.coerceToType(value, expectedType);

return ret;

} else {

Integer in = null;

try{

in = new Integer(value.toString());

return in;

} catch(NumberFormatException nex){

}

String v = value.toString().toLowerCase();

if("true".equals(v) || "false".equals(v)){

return new Boolean(v);

}

return value;

}

2.Jars required in shared/lib folder

appserv-jstl.jar this is taken from J2EE 5 SDK.

commons-beanutils.jar

commons-collections.jar

toplink-essentials.jar

toplink-essentials-agent.jar

3.Web.xml following changes are required.

Add <resource-ref>

<res-ref-name>jdbc/PetstoreDB</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

<res-sharing-scope>Shareable</res-sharing-scope>

</resource-ref>

There are two <context-param>

<param-name>com.sun.faces.verifyObjects</param-name>

Remove one that is not required. Tomcat does not allow both.

Comment out or remove <servlet>

<description>Persistence Test Servlet</description> and related mapping <servlet-mapping>

<servlet-name>PersistenceTestServlet</servlet-name>

Change Google map key if required.

Search:

You need to unzip petstoreIndexes.zip (in PETSTORE_HOME) into CATALINA_HOME.

Changes in PetstoreConstants.java are

public static final String PETSTORE_INDEX_DIRECTORY= "../searchindex";

public static final String PETSTORE_IMAGE_DIRECTORY= "..";

Search index

Persistence.xml

<?xml version="1.0" encoding="UTF-8"?>

<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">

<persistence-unit name="PetstorePu">

<provider>oracle.toplink.essentials.PersistenceProvider</provider>

<class>com.sun.javaee.blueprints.petstore.model.Address</class>

<class>com.sun.javaee.blueprints.petstore.model.Category</class>

<class>com.sun.javaee.blueprints.petstore.model.Item</class>

<class>com.sun.javaee.blueprints.petstore.model.Product</class>

<class>com.sun.javaee.blueprints.petstore.model.SellerContactInfo</class>

<class>com.sun.javaee.blueprints.petstore.model.Tag</class>

<class>com.sun.javaee.blueprints.petstore.model.ZipLocation</class>

<properties>

<property name="toplink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>

<property name="toplink.jdbc.url" value="jdbc:derby://localhost:1527/petstore"/>

<property name="toplink.jdbc.user" value="APP"/>

<property name="toplink.jdbc.password" value="APP"/>

</properties>

</persistence-unit>

</persistence>

rssbar.js needs changes other wise it results in javascript errors. It needs to be repackaged in bp-ui-5.jar

if(!handleJsonRss(data)){

return;

}

function handleJsonRss(json) {

jsonData = json;

// setting top title and link

if (!headTitle) {

headTitle = json.channel.title;

}

if(json.channel != null && json.channel.link != null){

generateFeedView(headTitle, json.channel.link, "rss-channel");

} else {

return false;

}

// setting items

var shortTitle = "....";

if(json.channel != null && json.channel.item != null && json.channel.item[0] != null && json.channel.item[0].title != null) {

shortTitle = cutStringatWs(json.channel.item[0].title, limitCharNum) + " ...";

} else {

return false;

}

if(json.channel != null && json.channel.item != null && json.channel.item[0] != null && json.channel.item[0].title != null && json.channel.item[0].link != null){

generateHref(shortTitle, json.channel.item[0].link, "rss-item");

} else {

return false;

}

CatalogFacade.java

Remove annotations for

private EntityManagerFactory emf;

UserTransaction utx;

Change following method

public void contextInitialized(ServletContextEvent sce) {

Context ctx = null;

try{

ctx = new InitialContext();

Context envCtx = (Context) ctx.lookup("java:comp/env");

utx = (UserTransaction)envCtx.lookup("jta/UserTransaction");

} catch(NamingException ex){

ex.printStackTrace();

}

emf = Persistence.createEntityManagerFactory("PetstorePu");

JTA parts needs to be tested. I will document it after testing. Application can run even if you comment out transaction related code.

I tried to use SimpleJTA. I could configure

1. Context path="/petstore" docBase="petstore" debug="5" reloadable="true" crossContext="true">

<Logger className="org.apache.catalina.logger.FileLogger"

prefix="localhost_petstore_log." suffix=".txt"

timestamp="true"/>

<Resource name="jta/UserTransaction" auth="Container"

type="javax.transaction.UserTransaction"

factory="org.simplejta.tm.ut.SimpleUserTransactionFactory"

tmgrId="TM1" tmgrRecoveryUser="recouser" tmgrRecoveryPassword="recouser"

tlogDriver="DERBY.EMBEDDED" tlogUrl="./TLOG"

tlogUser="APP" tlogPassword="APP"

/>

</Context>

2. create database using DERBY.EMBEDDED with name TLOG in CATALINA_HOME/bin.

3.You need to create table in TLOG database using following code.

private static void prepareLog() throws Exception

{

Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();

Connection conn = null;

try

{

conn =DriverManager.getConnection("jdbc:derby:./TLOG;create=true");

try

{

Statement st = conn.createStatement();

if( st != null)

{

st.executeUpdate("create table sjta_transactions (tid bigint generated always as identity,"+

"tmid varchar(30), formatid int, gtid varchar(64) for bit data,"+

"bqual varchar(64) for bit data,state smallint)");

st.executeUpdate("create table sjta_transaction_branches ("+

"tid bigint, bid int, formatid int, gtid varchar(64) for bit data,"+

"bqual varchar(64) for bit data, state smallint, url varchar(128),"+

"userid varchar(30), password varchar(30), typeid varchar(30))" );

st.executeUpdate("create table dept (deptno decimal(2) not null constraint dept_pk primary key,"+

"dname varchar(30), loc varchar(30))");

}

}

catch( Exception e){}

}

finally

{

if( conn != null)

conn.close();

}

}

jyotibaa at 2007-7-8 2:13:21 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 15
Thank you for spreading your knowledge and experience.- Mark
markbaslera at 2007-7-21 16:08:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 16
I just made it work by any means. Pl. review steps and post all improvements and comments so I will implement them and come up with better document.
jyotibaa at 2007-7-21 16:08:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 17
Thank you for reconfirming.We will update the procedure if we have any improvements.Thanks again - Mark
markbaslera at 2007-7-21 16:08:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 18

Hi,

this is great. I started a page on the wiki of the GlassFish project

http://www.glassfishwiki.org/gfwiki/Wiki.jsp?page=Petstore_Tomcat

should we move the instructions to the wiki on this page, so others can try them and enhance them?

Then we can link to them from blueprints site and other places maybe. Its kind of hard to edit instructions and link to them in a forum thread.

Does someone want to move them there? GlassFish wiki is public and you can create a user account.

Just trying to share this work with other people and put it in the spotlight so others can use it.

hth,

Sean

seanbrydona at 2007-7-21 16:08:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 19

KIndly help me on this issue.

I have netbeans IDE 5.5

java EE5 sdkc:\sun\application server

petstore 2.0

i configure every thing based on this video

http://blogs.sun.com/alexismp/?entry=java_pet_store_short_video

Now i am not getting any error. but catalog is not working.

i can't view the images.

if u have solution kindly mail me :prakasamr@gmail.com

awaiting your reply.

prakasamra at 2007-7-21 16:08:46 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...