Thursday, November 13, 2008

Where not to put presistance.xml

Where to put persistence.xml in web app? In all cases, persistence.xml always resides in {root-of-persistence-unit}/META-INF/ directory. For example,

foo.war: WEB-INF/classes/META-INF/persistence.xml //good WEB-INF/classes/com/foo123/jpa/Project.class WEB-INF/web.xml index.jsp You may also package entity classes and persistence.xml inside a library jar, which is packaged inside the war: WEB-INF/lib foo.war: WEB-INF/lib/my-entities.jar WEB-INF/web.xml index.jsp my-entities.jar: META-INF/persistence.xml //good com/foo123/jpa/Project.class For comparison, some invalid configurations are: foo.war: WEB-INF/persistence.xml //invalid WEB-INF/web.xml WEB-INF/classes/com/foo123/jpa/Project. index.jsp ----------------------------------------------- foo.war: META-INF/persistence.xml //invalid WEB-INF/classes/com/foo123/jpa/Project.class WEB-INF/web.xml index.jsp ----------------------------------------------- foo.war: persistence.xml //invalid WEB-INF/classes/com/foo123/jpa/Project.class WEB-INF/web.xml index.jsp ----------------------------------------------- foo.war: META-INF/persistence.xml //invalid com/foo123/jpa/Project.class WEB-INF/web.xml index.jsp
In all these invalid configurations, EntityManager lookup will fail with javax.naming.NameNotFoundException, or @PersistenceContext injection will be silently skipped and the em variable is always null, and hence NullPointerException when referenced.

Wednesday, July 30, 2008

SCP between two remote hosts

scp emartine@localhost:/var/eone/batch/production/data/exports/*.csv emartine@192.168.100.5:/home/emartine Now it will ask for. emartine@localhost's password: emartine@192.168.100.5's password:

Monday, July 14, 2008

MYSQL Error29

mysqldump: Got error: 29: File './databasename/tablename.MYD' not found (Errcode: 24) when using LOCK TABLES The best way to get to the bottom of the error is to find out what it means: $ perror 24 OS error code 24: Too many open files
There’s two ways to fix the problem. First, if you find that you only hit the limit during mysqldumps and never during normal database operation, just add
--single-transaction to your mysqldump command line options. ex: mysqldump -h localhost --single-transaction
This will cause mysql to keep only one table open at a time. However, if this happens while backups aren’t running, you may want to increase the open_files_limit in your MySQL configuration file. By default, the variable is set to 1,024 open files.

Saturday, May 17, 2008

FireGPG on Linux

How GPG works for the email.

Scenario 1: Sam creates public and private key Sam Publishes Sam's public Key to Key server. Bob Creates his public and private key Bob publishes Bob's public Key to Key Server.
Scenario 2:
No Sam and Bob need to engage a secured email communication. Sam pulls Bob's public key from key server and imports that public key into his trusted keyring using seahorse or gpg command line. Sam use Bob's Public Key to sign the message and send to Bob. Bob use his Private Key to decrypt and verify Sam's Message which was signed and encrypted using Bob's Public key.
Tools Needed
FireGPG GPG seahorse
Generate Key Pairs.
gpg --key-gen now the keys are generated and stored to keystore. Use the Seahorse to manual edit the keys and export keys. gpg normally get installed in usr/bin if you install with apt-get. Now install FireGPG plugin to FireFox.
Run the FireFox as ROOT. Here is the catch all the key genereration and keystore are acessible only for the root user. Firefox launch itself as firefox user, so when you launch the FireGPG it wont able to find the KEY's. It took me a while what was going wrong. If you launch the firefox as ROOT user or install the KEY's as universal user this issue can be fixed. Once you are in gmail and type the subject you should be able to see the encrypt and decrypt button and when you click the encrypt it should prompt for the public keys. If you are not a privilaged user to access the KEY store you wont see the KEYS.

Friday, May 9, 2008

NYI - Not Yet Implemented error

If you are getting this error

Exception in thread "main" java.lang.RuntimeException: NYI at cryptix.jce.provider.elgamal.ElGamalCipher.engineGetParameters(ElGamalCipher.java:120) at javax.crypto.Cipher.a(DashoA12275)
Reason is the suns default policy doesn't have the strength to encrypt/decrypt with higher strength keys. Got to SUN downloads and install/replace it in you JRE/lib/security Other Downloads Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 6

Wednesday, May 7, 2008

Formating Currencies and Dates in Struts 2

Create a Global message property so that the formating can be applied to all the pages name it globalMessages.properties

item.listprice = {0,number,$##0.00}
Now add the property to struts.properties
struts.custom.i18n.resources=globalMessages
Now how to Call the formating string in JSP where listprice comes from the stack and the formating string from the global resource we set earlier.
<s:text name="%{getText('item.listprice')}"> <s:param name="value" value="listprice"/> </s:text>
And now the Output
$12.20
Make sure to put the property files in the correct folder of your project.

Monday, April 21, 2008

Another Session Iteration

<s:if test="#session.cartitems.size > 0"> <table> <s:iterator value="#session.cartitems"> <tr id="row_<s:property value="itemid"/>"> <td> <s:property value="itemName" /> </td> <td> <s:property value="listprice" /> </td> <td> <s:url id="removeUrl" action="removeItemFromCart"> <s:param name="itemid" value="itemid" /> </s:url> <s:a href="%{removeUrl}" theme="ajax" targets="basket">Remove</s:a> <s:a id="a_%{id}" theme="ajax" notifyTopics="/edit">Edit</s:a> </td> </tr> </s:iterator> </table> </s:if>