Category Archives: Web Applications

Website Scalability

Scalability

Sessions. Unless you use ‘sticky’ load balancing, you will have to have some way of sharing session state between servers. This probably means storing session data on either shared storage, or in a DB.

File uploads and replication. If you allow users to upload files, or you have a CMS that allows you to upload images/documents, it needs to cater for the fact that these files will also need to find their way onto other nodes in your cluster. However, if you’ve gone down the shared storage route mentioned above, this should cover it.

DB scalability. If you’re using traditional DB servers, you might want to think about how you’ll implement scalability at that level. This may mean coding your app so you use one connection string for reads, and another for writes. Then, you are free to implement replication with one master node handling the inserts/updates cascading the changes to read only nodes that handle the bulk of the work.

Middleware. You might even want to go down the route of implementing some kind of message oriented middleware solution to completely hand off business logic functions – this will give you a great level of flexibility in how you wish to scale this business logic layer in the future. Although initially this will be a lot of complication and work for not a great deal of payoff.

Load balancer

Oracle SID error

If you get Oracle TNS listener like error below its probably due to incorrect configuration of the connect string in your application:-

INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory – Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3ddfd90f: defining beans [dataSource,org.springframework.jdbc.datasource.init.DataSourceInitializer#0]; root of factory hierarchy
ERROR: org.springframework.web.context.ContextLoader – Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.jdbc.datasource.init.DataSourceInitializer#0’: Invocation of init method failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Failed to execute database script; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:377)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:278)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4701)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5204)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5199)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: org.springframework.dao.DataAccessResourceFailureException: Failed to execute database script; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
)
    at org.springframework.jdbc.datasource.init.DataSourceInitializer.execute(DataSourceInitializer.java:115)
    at org.springframework.jdbc.datasource.init.DataSourceInitializer.afterPropertiesSet(DataSourceInitializer.java:86)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1479)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
    … 20 more
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
)
    at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
    at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
    at org.springframework.jdbc.datasource.init.DataSourceInitializer.execute(DataSourceInitializer.java:104)
    … 23 more
Caused by: java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
 
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:419)
    at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:536)
    at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:228)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
    at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
    at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
    at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
    at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
    … 26 more
Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
 
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:386)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1054)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:308)
    … 34 more
Jan 26, 2012 7:48:41 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Jan 26, 2012 7:48:42 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/appname] startup failed due to previous errors
Jan 26, 2012 7:48:42 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/appname] registered the JDBC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Solution
Make sure that you look into tnsnames.ora file and listener.ora file:-
My tnsnames.ora looks like
XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = xe)
)
)

listener.ora looks this
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
)
Compare these settings to your jdbc url configuration in your web application and it will most likely give you a clue if the string is wrong:-
jdbc:oracle:thin:@aHost:1521:theSID

Working Offline with Cloud Foundry in Windows

Cloud Foundry has this article on working offline without connecting to the internet. In this way you will not need the token and can work with no connection. My Micro Cloud Foundry v1.1.0 VM is installed on a Windows box
image
You can create a SSH tunnel using openSSH. Once installed you should be able to open a new command prompt and use the ssh command :-
image
Or you should be able to create PuTTY to create a SSH tunnel between your windows box and the VM as shown below:-
image
image
You can confirm that it is working by opening a new command window using following commands:-
vmc target api.vcap.me
vmc login admin@vcap.me
Then bring up the browser verify
image
image

Weblogic installation problems

I have found that installation of Weblogic does not work well if you change the default installation directory. When I changed installation directory to D:/Program Files/Middleware/ I received the following exceptions on deploying a Spring app. It worked well after changing directory to D:/Middleware

java.net.URISyntaxException: Illegal character in opaque part at index 14: zip:D:/Program Files/Middleware/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_user/EclipseLinkSpringTest/4ov5mg/war/WEB-INF/lib/spring-core-3.0.2.RELEASE.jar!/org/springframework/core/SpringVersion.class
    at java.net.URI$Parser.fail(URI.java:2809)
    at java.net.URI$Parser.checkChars(URI.java:2982)
    at java.net.URI$Parser.parse(URI.java:3019)
    at java.net.URI.(URI.java:578)
    at java.net.URL.toURI(URL.java:918)
    at com.bea.wls.redef.io.ClassChangeNotifier.toURI(ClassChangeNotifier.java:251)
    at com.bea.wls.redef.io.ClassChangeNotifier.isRelative(ClassChangeNotifier.java:211)
    at com.bea.wls.redef.io.ClassChangeNotifier.updateCache(ClassChangeNotifier.java:80)
    at com.bea.wls.redef.RedefiningClassLoader.findClass(RedefiningClassLoader.java:115)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:179)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at weblogic.spring.monitoring.instrumentation.SpringInstrumentationUtils.addSpringInstrumentor(SpringInstrumentationUtils.java:52)
    at weblogic.servlet.internal.WebAppServletContext.initClassLoader(WebAppServletContext.java:3038)
    at weblogic.servlet.internal.WebAppServletContext.(WebAppServletContext.java:447)
    at weblogic.servlet.internal.WebAppServletContext.(WebAppServletContext.java:493)
    at weblogic.servlet.internal.HttpServer.loadWebApp(HttpServer.java:418)
    at weblogic.servlet.internal.WebAppModule.registerWebApp(WebAppModule.java:972)
    at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:382)
    at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:176)
    at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:199)
    at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:517)
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
    at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:159)
    at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:45)
    at weblogic.application.internal.BaseDeployment$1.next(BaseDeployment.java:613)
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
    at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:184)
    at weblogic.application.internal.SingleModuleDeployment.prepare(SingleModuleDeployment.java:43)
    at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:154)
    at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:60)
    at weblogic.deploy.internal.targetserver.operations.ActivateOperation.createAndPrepareContainer(ActivateOperation.java:207)
    at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doPrepare(ActivateOperation.java:98)
    at weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:217)
    at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:747)
    at weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1216)
    at weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:250)
    at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:159)
    at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentReceiverCallbackDeliverer.java:171)
    at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$000(DeploymentReceiverCallbackDeliverer.java:13)
    at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$1.run(DeploymentReceiverCallbackDeliverer.java:46)
    at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:528)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)

Test @Transactional annotation using log4j

 

The easiest way to test @Transactional annotations is using a logger. For example I have used log4j in this example.

In log4j.properties I turned up the logging of springframework to DEBUG level which is very verbose.

log4j.logger.org.springframework=DEBUG

The method is annotated to be @Transactional with no write back to the database and hence readOnly=true.

@Transactional(propagation= Propagation.REQUIRED, noRollbackForClassName="Exception.class", readOnly=true)
void method(){
}

And here are the magic logs which help me determine if the @Transactional annotation is working. I have used JUnit, EclipseLink JPA, Log4J and Netbeans for testing:-

2011-09-02 10:17:46 [main] DEBUG org.springframework.transaction.annotation.AnnotationTransactionAttributeSource     - Adding transactional method 'method' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; ''
2011-09-02 10:17:46 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory     - Returning cached instance of singleton bean 'transactionManager'
2011-09-02 10:17:46 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager     - Creating new transaction with name [com.company.method]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; ''
2011-09-02 10:17:46 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager     - Opened new EntityManager [org.eclipse.persistence.internal.jpa.EntityManagerImpl@43ad4a] for JPA transaction
2011-09-02 10:17:46 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager     - Initiating transaction commit
2011-09-02 10:17:46 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager     - Committing JPA transaction on EntityManager [org.eclipse.persistence.internal.jpa.EntityManagerImpl@43ad4a]
2011-09-02 10:17:46 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager     - Closing JPA EntityManager [org.eclipse.persistence.internal.jpa.EntityManagerImpl@43ad4a] after transaction
2011-09-02 10:17:46 [main] DEBUG org.springframework.orm.jpa.EntityManagerFactoryUtils     - Closing JPA EntityManager

Try it and enjoy the beauty of Spring 🙂

What the heck does this mean Twitter??

Twitter

Hi, ejvyas

Twitter believes that your account may have been compromised by a website or service not associated with Twitter. We’ve reset your password to prevent others from accessing your account.
You’ll need to create a new password for your Twitter account. You can select a new password at this link:
https://YouWontFindTheLink!!

As always, you can also request a new password from our password-resend page: http://twitter.com/account/resend_password

Please don’t reuse your old password and be sure to choose a strong password (such as one with a combination of letters, numbers, and symbols).
Once you log in, be sure to:

  • Review your approved connections on your Connections page at http://twitter.com/account/connections. If you see any applications that you don’t recognize, click the Revoke Access button.
  • Avoid using websites or services that promise to get you lots of followers. These sites have been known to send spam updates and damage user accounts.

As a reminder, when logging in always check that your browser’s address bar is on a http://twitter.com website before entering your password.
You can also visit our help page for hacked or compromised accounts.

The Twitter Team
Please do not reply to this message; it was sent from an unmonitored email address. This message is a service email related to your use of Twitter. For general inquiries or to request support with your Twitter account, please visit us at Twitter Support.