From http://skytteren.blogspot.com/2009/06/using-mysql-connection-pool-in.html
Using MySQL connection pool in Glassfish V3
I tried with a simple data source in Spring, but it isn't meant for production environments. So I wanted to move from:
<bean id="simpleDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/database"/>
<property name="username" value="database"/>
<property name="password" value="s3cr3t"/>
</bean>
to:
<bean id="jndiDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/databasePool" />
</bean>
This can be done from within Glassfish admin, by creating the connection pool with the specified jndi name.
Wednesday, December 28, 2011
c3p0 connection pool in broadleafdemo (instead of dbcp)
Why c3p0 ?
The old dbcp (1.2.2 is used in broadleafdemo) is less robust than c3p0.
http://stackoverflow.com/questions/520585/connection-pooling-options-with-jdbc-dbcp-vs-c3p0
Will do some performance testing with dbcp 1.4.
1. Open broadleafdemo.war\WEB-INF\applicationContext-demo.xml
The old dbcp (1.2.2 is used in broadleafdemo) is less robust than c3p0.
http://stackoverflow.com/questions/520585/connection-pooling-options-with-jdbc-dbcp-vs-c3p0
Will do some performance testing with dbcp 1.4.
1. Open broadleafdemo.war\WEB-INF\applicationContext-demo.xml
2. Modify your webDS and webStorageDS beans
2a. change the class to com.mchange.v2.c3p0.ComboPooledDataSource
2b. change property name to driverClass (from driverClassName)
2c. change property name to jdbcUrl (from url)
2d. change property name to user (from username)
<bean id="webDS" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/broadleaf" />
<property name="user" value="user" />
<property name="password" value="password" />
</bean>
<bean id="webStorageDS" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="org.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/broadleaf" />
<property name="user" value="user" />
<property name="password" value="password" />
</bean>
3. Download c3p0 from http://sourceforge.net/projects/c3p0/files/latest/download , extract, and copy c3p0-xxxx.jar (c3p0-0.9.1.2.jar at the time of this writing) into broadleafdemo.war\WEB-INF\lib
4. (Optional) You can also remove commons-dbcp.jar from broadleafdemo.war\WEB-INF\lib as it's no longer used.
References:
http://stackoverflow.com/questions/3002899/spring-configuration-of-c3p0-with-hibernate
http://stackoverflow.com/questions/520585/connection-pooling-options-with-jdbc-dbcp-vs-c3p0
http://sourceforge.net/projects/c3p0/
3. Download c3p0 from http://sourceforge.net/projects/c3p0/files/latest/download , extract, and copy c3p0-xxxx.jar (c3p0-0.9.1.2.jar at the time of this writing) into broadleafdemo.war\WEB-INF\lib
4. (Optional) You can also remove commons-dbcp.jar from broadleafdemo.war\WEB-INF\lib as it's no longer used.
References:
http://stackoverflow.com/questions/3002899/spring-configuration-of-c3p0-with-hibernate
http://stackoverflow.com/questions/520585/connection-pooling-options-with-jdbc-dbcp-vs-c3p0
http://sourceforge.net/projects/c3p0/
Monday, December 26, 2011
Running CLUSTERED Broadleaf Ecommerce 1.5.0 Demo in Oracle GlassFish Server 3.1.1
Once you have Broadleafdemo running in Oracle Glassfish 3.1.1 (read http://lydonchandra.blogspot.com/2011/12/running-broadleaf-ecommerce-150-demo-in_26.html), you might want to run it in a clustered Glassfish configuration using Apache 2.2 + mod_jk connector.
Most of the instructions below are obtained from http://tiainen.sertik.net/2011/03/load-balancing-with-glassfish-31-and.html
1. From Glassfish admin, create a new cluster, say cluster1
2. Once cluster1 is created, go to Instances tab, and create 2 new instances, instance1 and instance2
3. Create mod_jk listener, go to Configurations > Network Config > Network Listener , and click on New.
3a. Enter "mod-jk" on Name textbox,
3b. enter 28009 as port number and
3c. make sure you check the JK Listener checkbox. Click Save.
3d. Stop and start the cluster
4. Download Apache 2.2 and mod_jk (http://tomcat.apache.org/download-connectors.cgi), extract Apache 2.2 and mod_jk.so into Apache22/modules directory
5. Add the following to Apache httpd.conf
Include conf/mod-jk.conf
Most of the instructions below are obtained from http://tiainen.sertik.net/2011/03/load-balancing-with-glassfish-31-and.html
1. From Glassfish admin, create a new cluster, say cluster1
2. Once cluster1 is created, go to Instances tab, and create 2 new instances, instance1 and instance2
3. Create mod_jk listener, go to Configurations > Network Config > Network Listener , and click on New.
3a. Enter "mod-jk" on Name textbox,
3b. enter 28009 as port number and
3c. make sure you check the JK Listener checkbox. Click Save.
3d. Stop and start the cluster
4. Download Apache 2.2 and mod_jk (http://tomcat.apache.org/download-connectors.cgi), extract Apache 2.2 and mod_jk.so into Apache22/modules directory
5. Add the following to Apache httpd.conf
Include conf/mod-jk.conf
6. create conf/mod-jk.conf
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile conf/workers.properties
# Where to put jk logs
JkLogFile logs/mod_jk1.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
# JkOptions indicates to send SSK KEY SIZE
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"
# Mount your applications
JkMountFile conf/uriworkermap.properties
# Add shared memory.
# This directive is present with 1.2.10 and
# later versions of mod_jk, and is needed for
# for load balancing to work properly
JkShmFile logs/jk.shm
# Add jkstatus for managing runtime data
JkMount status
Order deny,allow
Deny from all
Allow from 127.0.0.1
7. Create worker.properties with the following information, put the correct ip address on worker.node1.host
worker.node1.port=28009
worker.node1.host=127.0.0.1
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.status.type=status
worker.loadbalancer.sticky_session=1
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1
worker.list=loadbalancer,status
8. Create uriworkermap.properties to tell mod_jk which webapp to mount
/=loadbalancer
/*=loadbalancer
/broadleafdemo=loadbalancer
/broadleafdemo/*=loadbalancer
9. Start httpd
Running Broadleaf Ecommerce 1.5.0 Demo in Oracle GlassFish Server 3.1.1
Once you got it deployed and running in JBoss 7 (read my previous post http://lydonchandra.blogspot.com/2011/12/running-broadleaf-ecommerce-150-demo-in.html)
you can just use the same broadleafdemo.war (which has modified compass JAR) and
deploy it as an Web-Application from the GlassFish Server administration page > Applications > Deploy
you can just use the same broadleafdemo.war (which has modified compass JAR) and
deploy it as an Web-Application from the GlassFish Server administration page > Applications > Deploy
Sunday, December 25, 2011
Running Broadleaf Ecommerce 1.5.0 Demo in JBoss 7.1.0.CR1b
A bit more complicated as it should be in the beginning, where JBoss changes the protocol name from vfszip to vfs,
1. so I had to build the latest Compass trunk (rev 3940) from http://svn.compass-project.org/svn/compass/trunk/
2. Modify http://svn.compass-project.org/svn/compass/trunk/src/main/src/org/compass/core/config/binding/scanner/ScannerFactoy.java
1. so I had to build the latest Compass trunk (rev 3940) from http://svn.compass-project.org/svn/compass/trunk/
2. Modify http://svn.compass-project.org/svn/compass/trunk/src/main/src/org/compass/core/config/binding/scanner/ScannerFactoy.java
to:
else if ( url.getProtocol().equals("vfszip") ||
url.getProtocol().equals("vfs") ) {
url = new URL(urlString);
return new JarScanner(basePackage, url.openStream(), filter);
}
3. Replaced the broadleaf's supplied compass-2.2.0.jar with the newly built Compass jar file ( available from http://www.multiupload.com/AY0F7UPKX6 as of Dec 25 2011)
4. Start JBoss (in standalone mode), everything should work fine!!
4. Start JBoss (in standalone mode), everything should work fine!!
/*
* Copyright 2004-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.compass.core.config.binding.scanner;
import java.io.File;
import java.io.IOException;
import java.net.URL;
/**
* @author kimchy
*/
public class ScannerFactoy {
public static Scanner create(String basePackage, URL url, Filter filter) throws IOException {
String urlString = url.toString();
urlString = urlString.substring(0, urlString.lastIndexOf(basePackage));
if (urlString.endsWith("!/")) {
urlString = urlString.substring(4);
urlString = urlString.substring(0, urlString.length() - 2);
url = new URL(urlString);
}
if (!urlString.endsWith("/")) {
return new JarScanner(basePackage, url.openStream(), filter);
} else if (url.getProtocol().equals("file")) {
File f = new File(url.getPath());
if (f.isDirectory()) {
return new FileScanner(basePackage, f, filter);
} else {
return new JarScanner(basePackage, url.openStream(), filter);
}
} else if ( url.getProtocol().equals("vfszip") ||
url.getProtocol().equals("vfs") ) {
url = new URL(urlString);
return new JarScanner(basePackage, url.openStream(), filter);
} else {
throw new IOException("Protocol [" + url.getProtocol() + "] is not supported by scanner");
}
}
}
Running Broadleaf eCommerce Demo 1.5.0 in JBoss 5.1
I had problems deploying Broadleaf eCommerce Demo 1.5.0 in JBoss 7.0. So I went back to JBoss 5.1 and followed this forum post and finally got the broadleafdemo.war to deploy in JBoss 5.1.
Why JBoss you ask ? Well some enterprise users use JBoss and we want to give them an easier option to deploy inside their JBoss app server, rather asking them to install Tomcat or run from Jetty.
If they have to install Tomcat or run from Jetty, then they will have to configure their network security settings etc etc, it's just not fun. So why JBoss again ? To make deployment easier, for now at least :)
Steps:
1. Download and extract JBoss 5.1 if you haven't already, and make sure you can run broadleaf with mysql as your database (follow my previous post about running broadleaf with mysql or google it).
2. Remove jboss-5.1.0.CR\common\lib\hibernate-validator.jar (or move it somewhere else)
3. Copy the expanded broadleafdemo.war to jboss-5.1.0.CR\server\default\deploy
4. Download compass-2.3.1-beta1.jar from either java2s.com or rutgersmaps and replace broadleafdemo.war\WEB-INF\lib\compass-2.2.0.jar
5. Start JBoss, and you should be able to access http://myserver:8080/broadleafdemo
Saturday, December 24, 2011
Running Broadleaf E-commerce demo in Various Java Application Server and Database
First we start using MySQL and Tomcat 7.0
1. Extract broadleafdemo.war file into an expanded war
2. As detailed here in http://www.broadleafcommerce.org/forum/viewtopic.php?f=9&t=379
2a. in META-INF/persistence-demo.xml' file replace
- org.hibernate.dialect.HSQLDialect by org.hibernate.dialect.MySQLDialect in the 'blPU' and 'blSecurePU' persistence unit configurations
2b. in WEB-INF/applicationContext-demo.xml' file replace the following lines
<bean id="webDS" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:broadleaf;ifexists=false" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
with
<bean id="webDS" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<!-- The JDBC Driver class name. -->
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/broadleaf" />
<property name="username" value="MY_USER_NAME" />
<property name="password" value="MY_PASSWORD" />
</bean>
and update the username and password properties accordingly!!!
3. login to mysql and create database 'broadleaf'
mysql>> create database broadleaf;
4. copy the expanded broadleaf.war directory created in #1 above into Tomcat 7.0 directory
5. download & copy mysql-connector-java-5.1.17.jar into broadleafdemo.war/WEB-INF/lib
6. start tomcat.
Caveat:
For some reason Spring Framework complains about NOT finding the com.mysql.jdbc.Driver ?
However the broadleafdemo site works OK.
[ INFO] 07:56:49 SchemaExport - exporting generated schema to database
Cannot load JDBC driver class 'org.mysql.jdbc.Driver'
java.lang.ClassNotFoundException: org.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoa
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoa
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource
at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.get
ataSourceConnectionProvider.java:71)
1. Extract broadleafdemo.war file into an expanded war
2. As detailed here in http://www.broadleafcommerce.org/forum/viewtopic.php?f=9&t=379
2a. in META-INF/persistence-demo.xml' file replace
- org.hibernate.dialect.HSQLDialect by org.hibernate.dialect.MySQLDialect in the 'blPU' and 'blSecurePU' persistence unit configurations
2b. in WEB-INF/applicationContext-demo.xml' file replace the following lines
<bean id="webDS" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:mem:broadleaf;ifexists=false" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
with
<bean id="webDS" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<!-- The JDBC Driver class name. -->
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/broadleaf" />
<property name="username" value="MY_USER_NAME" />
<property name="password" value="MY_PASSWORD" />
</bean>
and update the username and password properties accordingly!!!
3. login to mysql and create database 'broadleaf'
mysql>> create database broadleaf;
4. copy the expanded broadleaf.war directory created in #1 above into Tomcat 7.0 directory
5. download & copy mysql-connector-java-5.1.17.jar into broadleafdemo.war/WEB-INF/lib
6. start tomcat.
Caveat:
For some reason Spring Framework complains about NOT finding the com.mysql.jdbc.Driver ?
However the broadleafdemo site works OK.
[ INFO] 07:56:49 SchemaExport - exporting generated schema to database
Cannot load JDBC driver class 'org.mysql.jdbc.Driver'
java.lang.ClassNotFoundException: org.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoa
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoa
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource
at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.get
ataSourceConnectionProvider.java:71)
Subscribe to:
Posts (Atom)
