Friday, January 15, 2010

Setting up drupal

  • Install drupal/ Db etc. Don't use command line for loading DB
  • install modules Nice Menu/ Views/ tinyMCE/ Image Assist
  • set up categories
  • Add content , this creates menu
  • Adjust setting/ Content Types to have correct defaults for adding content
  • Configure tinyMCE, and imageAssist. Follow install.txt in tinyMce modules dir
  • Create Admin role. administrator/ access control
  • Add tinyMCE permissions to different roles

Weblogic slow to start (and slow cryptography) on linux (unix),

This is a doozie.

Weblogic takes many minutes to start on unix.


Note this would also apply for any java process that uses the random number generator such as cryptography.


Turns out Weblogic uses random number generator during start up. Because of the bug in java it reads ‘randomness’ from /dev/random. /dev/random is very good random numbers generators but it is extremely slow. It takes sometimes 10 minutes or more to generate one number. /dev/urandom is not that good, but it is instant.
Java somehow maps /dev/urandom file to /dev/random. That’s why default settings in $JAVA_HOME/jre/lib/security/java.security are useless.

Possible solutions:
1) Add “-Djava.security.egd=file:/dev/./urandom” (/dev/urandom does not work) to java parameters.

Worse but working solution is:
2) mv /dev/random /dev/random.ORIG ; ln /dev/urandom /dev/random

3) Best solution is to change $JAVA_HOME/jre/lib/security/java.security
Replace securerandom.source with

securerandom.source=file:/dev/./urandom

This problem does not happen under windows because it uses different implementation of /dev/random.

It takes seconds to start weblogic server now.

Wednesday, January 13, 2010

Using AES from Java

The following exception

java.security.InvalidKeyException: Illegal key size or default parameters
at javax.crypto.Cipher.a(DashoA13*..)
at javax.crypto.Cipher.a(DashoA13*..)
at javax.crypto.Cipher.a(DashoA13*..)
at javax.crypto.Cipher.init(DashoA13*..)
at javax.crypto.Cipher.init(DashoA13*..)
...

Searching java forums reveals that I need to download the Unrestricted Policy Files from JDK Distribution Center.

After much searching I found it at

Under Additional Resources/ Other Downloads.

Simply copy the jars included in it into %JRE_HOME%/lib/security overwriting what is there

On my system that means doing it in multiple locations (eclipse JRE/ Oracle JRE etc.) to make

Monday, December 14, 2009

Keytool keystore Cannot store non-PrivateKeys

Don't believe the error, or a lot of websites....

I have a requirement to encrypt passwords in a file. I figured I'd use the java security tools to store the encryption key.

Step 1/ Generate the secret key (Using AES as encryption algorithm)
.\keytool -genseckey -alias aestest -keyalg AES -keysize 192

This results in error
keytool error: java.security.KeyStoreException: Cannot store non-PrivateKeys

After much searching, and some incorrect pointers (Keytool cannot generate symmetric keys, keytool cannot generate AES keys etc.), I found the solution. The problem is the default Keystore type is JKS. This cannot store symmetric keys. However if you change the keystore type to JCEKS then it works.

e.g.
.\keytool -genseckey -alias aestest -keyalg AES -keysize 192 -storetype JCEKS

One side effect of this is that you then need to specify the storeType in every command there-after.

e.g.
keytool -list
keytool error: java.io.IOException: Invalid keystore format

keytool -list -storetype JCEKS
Your keystore contains 3 entries

aestest, 14-Dec-2009, SecretKeyEntry,
aestest2, 14-Dec-2009, SecretKeyEntry,
test, 14-Dec-2009, SecretKeyEntry,

Tuesday, November 10, 2009

Xquery to mask CreditCard number

declare function local:maskString($input as xs:string, $numClearDigits as xs:int)
as xs:string{
let $len := fn:string-length($input)
let $maskLen := $len - $numClearDigits
let $clearText := fn:substring($input, $maskLen+1)
let $mask := fn:string-join (
(for $i in (1 to $maskLen) return "X", $clearText)
,'')
return
$mask
};

Detect Java method name from code

http://www.rgagnon.com/javadetails/java-0420.html

JDK1.4
public class MyTest {
public static void main(String args[]) {
new MyTest().doit();
}
public void doit() {
System.out.println
(new Exception().getStackTrace()[0].getMethodName());
}
}
The output
doit

JDK1.5
While the above snippet is not bad, it is expensive since we need to create an Exception.
With JDK1.5, a new technique is available.

public class Test {
public static void main(String args[]) {
trace(Thread.currentThread().getStackTrace());
new Test().doit();
trace(Thread.currentThread().getStackTrace());
}
public void doit() {
trace(Thread.currentThread().getStackTrace());
doitagain();
}
public void doitagain() {
trace(Thread.currentThread().getStackTrace());
}

public static void trace(StackTraceElement e[]) {
boolean doNext = false;
for (StackTraceElement s : e) {
if (doNext) {
System.out.println(s.getMethodName());
return;
}
doNext = s.getMethodName().equals("getStackTrace");
}
}
}

Output
main
doit
doitagain
main

Tuesday, October 20, 2009

Mvn Mojo architype type

Quick note.

This maven page (on your first mojo) has a typo.

When creating a default mojo project using the architype the instruction says run

mvn archetype:create -DgroupId=quinn -DartifactId=maven-loop-task -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-mojo

This fails. In fact you need to include the version attribute like so

mvn archetype:create -DgroupId=quinn -DartifactId=maven-loop-task -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-mojo -DarchetypeVersion=1.0


Friday, September 04, 2009

USB drive won't go

I was been particularly stupid one day, trying to repartition my backup USB drive without first backing it up.

Yes I know I was stupid ,and frankly I probably deserved to lose everything, but I was lucky. The drive woulldn't appear on my laptop, and yet after running all the windows diagnostics , I could find no problems.

Running the following prog solved the problem

diskmgmt.msc

Select a drive letter and away you go.

Wednesday, July 08, 2009

Grails cheatsheet

Getting Started
grails set-proxy (if necessary to set proxy)
grails create-app AppName
cd AppName
grails create-domain-class Domain
grails generate-all Domain

Install Acegi
grails install-plugin acegi
grails create-auth-domains
grails generate-manager
grails generate-registration

Tools
grails schema-export (Export a DDL sql script for the domain classes)
grails generate-hbm-xml (Generate hibernate mapping file (From grails 1.3)
grails install-templates (Install base scaffolding files. Can then update them before generating scaffolding.
e.g. I update list default size to 50 (from 10)), Increase number of columns displayed in list tables (max by defauilt is 6 columns), changing if (i < 6){ { allows you to increase this (change in 2 places)

DB-Plugin
grails install-plugin db-stuff
grails create-db
grails export-data
grails export-data-diff
grails export-ddl
grails load-data

Maven integration
Build a new grails project with maven.
mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate -DarchetypeGroupId=org.grails -DarchetypeArtifactId=grails-maven-archetype -DarchetypeVersion=1.2.0 -DgroupId=example -DartifactId=my-app

mvn initialize

Misc
  1. GORM Non numeric ID field
See my question, and someone elses helpful answer on the grails mailing list for how to create a non-numeric ID field, and rename it to something other than ID. Its a bit sneaky but works perfectly. http://grails.1312388.n4.nabble.com/Non-numeric-ID-tt2073698.html#none
  1. Dependency Injection.
Ran into a stupid problem with Dependency injection. I was trying to inject the DataSource into a Service (and into a Java library). It appeared the Data source was not getting injected into grails Service class. Dependency injection was not working!!
As usual it was working fine, and the problem was mine...
Dependency Injection (DI) is configured by default to occur by name. If you create a property in your Domain/ Controller/ Service class with the same name as another Service or property you want injected, then it will automatically get injected. See this article http://www.grails.org/Services
To inject the DataSource into your Service, All you need to do is add the line
def dataSource
to your Service. Thats all.. nothing else is needed.

I also had to add the following to initialize the java libraries dataSource, so I also needed
class BenefitService implements InitializingBean{
void afterPropertiesSet() {
println "Initializing BenefitService "+dataSource
BenefitWrapper.setDataSource(dataSource)
}
This all would work. My problem was I (helpfully) added an accessor method for the dataSource
def getDataSource(){return dataSource)
This simple method modifies the groovy class dataSource property, effectively making the setter of the dataSource unavailable, thus effectively blocking dependency injection.
Moral: Groovy is designed to help reduce the number of code lines you write. Don't add unneccessary lines or there may be unexpected side-effects.

Monday, June 15, 2009

Shutdown hook in Groovy... Inner Classes in Groovy

Groovy doesn't support Inner classes directly. I was in a hurry to implement a shutdown hook in Java so I came accross the groovy workaround
http://groovy.codehaus.org/Groovy+Alternatives+to+Inner+Classes

I had to tweak the script slightly to get it to work for the shutdown hook (see below).

To implement the shutdown hook in Java a Thread instance is passed to the addShutdownHook() method of the Runtime instance.

In Java we could create an Inner class that extends Thread, or that implements Runnable.

In Groovy we must create a Map. The Map contains a list of key/ values. These correspond to method names (key), and method implementations (closure). For this case the closure will represent the Thread that we pass to the Runtime.addShutdownHook() method. Therefore we are implmenting the run() method, so the key in the map must be run().

The ProxyGenerator is then used to dynamically add the interface to the close. Finally since Runtime.addShutdownHook() expects a Thread instance (not simply a class that implements Runnable) ,we must add the Thread.class to the call to ProxyGenerator.instantiateAggregate().



def shutdownClosureMap = [run: {
outputFile.close();
println "Shutting down";
}
]
def interfaces = [Runnable]
def shutdownListener = ProxyGenerator.instantiateAggregate(shutdownClosureMap, interfaces, Thread.class)

Runtime.getRuntime().addShutdownHook((Thread)shutdownListener);

Friday, June 12, 2009

Groovy GString/ STring

A few Gotchas that I've been getting stung with in Groovy.

GStrings and Strings

Be careful with Groovy Strings and Sql.

Make sure you know the rules of when Strings become GStrings, and therefore can support dynamic variable replacements.

GString docs can be found
http://docs.codehaus.org/display/GROOVY/Strings+and+GString

These rules are listed here: (Note this doc is aproposal for changnig GString)
http://docs.codehaus.org/display/GroovyJSR/Groovy+String+Handling

For example in the code below, if you simply use "def" to declare your variable, you will not see explicitly which types get converted to GStrings and which get converted to plain Strings.

By been explicit in your definitions however you can see that sql6 will not cast by default to a GString. This is becausei t is a multiline java.lang.String (see rules in link above). You will get this exception.

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object "..." with class 'java.lang.String' to class 'groovy.lang.GString'

To fix it.


Date startDate = new Date() -1;
Date endDate = new Date();
def Format = "yyyy-MM-dd"
def OFormat = "YYYY-MM-DD"
String startString = startDate.format(Format);
String endString = endDate.format(Format);
println "Running between $startString and $endString";
def sql = []
def sql1 ="""
select * from prov_auditing_master m where EVENTTIMECOMPLETED > to_date($startString,$OFormat) and EVENTTIMECOMPLETED < sql2 =""> to_date($startString,$OFormat) and EVENTTIMECOMPLETED < sql3 =""> to_date($startString,$OFormat)"+
" and EVENTTIMECOMPLETED < sql4 =""> to_date($startString,$OFormat) and EVENTTIMECOMPLETED < sql5 =" "> to_date($startString,$OFormat) and EVENTTIMECOMPLETED < sql6 = ""> to_date($startString,$OFormat)"+
" and EVENTTIMECOMPLETED < db =" int" i="1">
println i+": $sq"
i++
}

To fix

GString sql7 = "$sql6" ;
sql <<>

Tuesday, May 05, 2009

DB/ Database notes (sql tips)

JDBC Format 

Sybase  (jconn3.jar)
jdbc:sybase:Tds:server:1050


Oracle
Use Service Name (format /)
jdbc:oracle:thin:@server:1521/fmwa
user SID (format :)
jdbc:oracle:thin:@bggwrsoa12:1521:fmwa

Limit Rows

// mysql
select col from tbl limit 20;


//Sybase / SqlServer
select top 10 * from people
 //Also
SET ROWCOUNT 10 // use SET ROWCOUNT 0 to turn off

// Oracle
select col from tbl where rownum <=20;

Using rank()

This query will return the top 10 rows..
select col1,col2 from (select rank() over (order by col1) r , col1,col2 from TABLE) where r<11 For bottom 10 rows use select col1,col2 from (select rank() over (order by col1 DESC) r , col1,col2 from TABLE) where r<11


Select unique

//Sybase / SqlServer
select distinct col from table

Oracle

MySql

Outer Join

// Oracle left outer Join
select * from Customer, Order where Order.customerId (+) = Customer.id
//right join
select * from Customer, Order where Order.customerId = Customer.id (+)


Backup

Mysql



>mysqldump --host vc2c09mmk0326.fmr.com --port=3306 -u datasift2 -p --set-gtid-purged=OFF datasift2  > datasift.sql
  • This will create a sql with all the tables. Note the --set-gtid-purged=OFF is required on newer versions of the client. If you are running on vc2c09mmk0326 it is probably not required.
  • Note the sql will be over 100MB in size


Oracle drop all tables
BEGIN
   FOR cur_rec IN (SELECT object_name, object_type
                     FROM user_objects
                    WHERE object_type IN
                             ('TABLE',
                              'VIEW',
                              'PACKAGE',
                              'PROCEDURE',
                              'FUNCTION',
                              'SEQUENCE'
                             ))
   LOOP
      BEGIN
         IF cur_rec.object_type = 'TABLE'
         THEN
            EXECUTE IMMEDIATE    'DROP '
                              || cur_rec.object_type
                              || ' "'
                              || cur_rec.object_name
                              || '" CASCADE CONSTRAINTS';
         ELSE
            EXECUTE IMMEDIATE    'DROP '
                              || cur_rec.object_type
                              || ' "'
                              || cur_rec.object_name
                              || '"';
         END IF;
      EXCEPTION
         WHEN OTHERS
         THEN
            DBMS_OUTPUT.put_line (   'FAILED: DROP '
                                  || cur_rec.object_type
                                  || ' "'
                                  || cur_rec.object_name
                                  || '"'
                                 );
      END;
   END LOOP;
END;
/


// HSQL
from Customer left join Order where Order.customerId = Customer.id

Could only get this working by explicitly linking the join in the hbm file, and marking it as optional e.g.

Need some more testing to see if this can be done without updating the hbm file

<class name="AdjustmentCode" table="adjustment_code">
<id name="id" column="adjustment_code" type="string">
<generator class="native">
<property name="description" column="description" type="string">
<property name="adjustmentCode" column="adjustment_code" type="string" insert="false" update="false">
<join table="adjustment_message">optional="true">
<key column="adjustment_code">
</join>
<class>
Insert if row not Exists

// MySql
if not exists (select * from url where url = ...)
insert into url...

//Oracle (where not exists)
insert into <table> (<row1>, <row2>)
select <value1>, <value2> from dual
where not exists (
select * from <table> where <col1> = <value1>)

//SQL Server
if not exists (select * from url where url = ...)
insert into url...
Date Operations GetDate //MySql DATE() see (http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html) //Oracle SYSDATE // Sql Server getDate() To Date //Oracle to_date('2009-01-01','YYYY-MM-DD') to_date('2009-05-19 18:32','YYYY-MM-DD HH24:MI') http://www.dba-oracle.com/f_to_date.htm Detecting Duplicates (group by criteria) Say you want to detect duplicates (instances of more than one value) in a column. This is how to do it select dupCol, count(dupCol) from table group by dupCol having count(dupCol)>1 Listing Constrainsts Oracle SELECT * FROM USER_CONSTRAINTS WHERE TABLE_NAME = 'myTable';

Wednesday, April 15, 2009

Online XPath Tester

After looking for a quick online XPath Tester I decided to write my own.

This is an online xpath tool written in Javascript

Online XPath Tester

The following articles were helful in getting it running

Javascript Xpath tutorial


This article here is the Official Javascript guide to XPATH

These articles links to the Reference guides for XML. The  API for the XPath objects and the API for the w3c Xml objects

Not used here but useful nonetheless is a Javascript Reflection API. This article shows how to do it. I modified the code slightly to get it working

This article described

Friday, April 10, 2009

Weblogic Jms error.. "Peer Gone"

"It is likely that the remote side declared peer gone on this JVM"

This error had been causing me grief for a long time.

The problem was fixed by updating my etc hosts file on the client machine... (/windows/system32/drivers/etc/hosts on windows).

Some of our weblogic servers display the server name including domain name e.g. server.domain.com and some only display the server name (e.g. servername). By adding an entry for the target weblogic server in the etc/hosts the problem was fixed.

e.g.
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
192.168.1.10 servername servername.domain.com

Bea Articles on Oracle

When Oracle acquired BEa they began moving all the bea and weblogic sites into the oracle.com domain.

Problem of course is that a lot of good articles are referenced on the web to their old original Bea urls.

This page lists where the equivilent sections exist on the oracle site

Overview of migration -> http://wiki.oracle.com/page/Dev2Dev+%2F+Arch2Arch+Status+and+Migration+Update?t=anon

Dev2dev and arch2arch -> http://www.oracle.com/technology/pub/articles/dev2arch/index.html

Weblogic JMS rollback

I was getting the following error in a Weblogic 9.2 deployment.

####<10-apr-2009> <info> <ejb> <vmmiddleware11> <mwalsb11> <[ACTIVE] ExecuteThread: '11' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <> <1239355884374> <bea-010213> <message-driven xid="BEA1-23F28F44E9B311BE176F(110581804),Status="Rolled" reason="weblogic.transaction.internal.AppSetRollbackOnlyException],numRepliesOwedMe="0,numRepliesOwedOthers="0,seconds" begin="0,seconds" left="60,XAServerResourceInfo[WLStore_MWALSBDomain_JDBCStore_MWALSB11]="(ServerResourceInfo[WLStore_MWALSBDomain_JDBCStore_MWALSB11]="(state="rolledback,assigned="MWALSB11),xar="WLStore_MWALSBDomain_JDBCStore_MWALSB1146900074,re-Registered" state="rolledback),OwnerTransactionManager="ServerTM[ServerCoordinatorDescriptor="(CoordinatorURL="MWALSB11+vmmiddleware11:7011+MWALSBDomain+t3+," xaresources="{WLStore_MWALSBDomain_JDBCStore_MWALSB11," nonxaresources="{})],CoordinatorURL="MWALSB11+vmmiddleware11:7011+MWALSBDomain+t3+).">

First steps are to get more informative error messages by enabling debugging for JTA

This is done by adding the following switches to weblogic on startup

-Dweblogic.debug.DebugJDBCJTA=true
-Dweblogic.log.StdoutSeverity="Debug"

This article give a list of other possible switches available on Weblogic
http://www.questtech.co.uk/index.php?option=com_content&view=article&id=163&Itemid=40

Sunday, March 29, 2009

Google Map getting latitude and longitude

Simple.

Search for wanted address. This will centre the location in the map.

Run the following command from the address bar

javascript:void(prompt('',gApplication.getMap().getCenter()));

Magic

Thursday, January 08, 2009

ssh tunnels that stay alive

Don't have time for an explanation but heres a command to setup a ssh tunnel. (linux)

This will keep the tunnel alive after you logout, and also send keepAlive pings in order to stop any other proceses from deciding that its a dead link and shutting it down.

ssh -2 -x -L <localport>:<remotehost>:<remoteport> <remotelogin>@<remotehost> -N -n –f

Tuesday, December 23, 2008

Eclipse and Maven

This one is really stupid, but it had me scratching my head for a long time, so ... in it goes.

I develop mainly on a powerful desktop machine in work. Recently however I was transferring some work to my laptop, so I could potentially work on some problems from home.

When I imported the project I was working on onto the same version of eclipse on my laptop it was producing errors.

We use mvn for our builds, so I did the usual thing, of running

mvn eclipse:clean eclipse:eclipse

Still no luck.

After much head scratching te problem was that I had never initialized my M2_REPO variable within my laptops version of eclipse. Therefore all the M2_REPO based libs that mvn eclipse:eclipse generates, were not pointing to anything.

Very annoying.

Tuesday, December 09, 2008

Weblogic states

WE had a question on our weblogic status recently. SOme libraries were listed as been in the "Installed" state, as opposed to the usual "Active" state.

Heres a breakdown on the various states in Bea Weblogic:

1. There is no valid deployment state as "Installed".

2.. The deployment state is stored in "weblogic.management.runtime.AppRuntimeStateRuntimeMBean". As per the documentation these are the states:
STATE_ACTIVE, STATE_ADMIN, STATE_FAILED, STATE_NEW, STATE_PREPARED, STATE_RETIRED, STATE_UPDATE_PENDING
This is the link to documentation: http://e-docs.bea.com/wls/docs90/javadocs_mhome/weblogic/management/runtime/AppRuntimeStateRuntimeMBean.html

3. You can also check this runtime MBean on the MBean Reference: http://e-docs.bea.com/wls/docs92/wlsmbeanref/core/index.html

4. I got some known issues where it is stated that "Installed" is a console text string that indicates the LibraryMBean is present in the configuration.The Installed state can be changed by rebooting the domain. The problem can happen unexpectedly. Also the library works fine with Installed state as well.

5. It may be possible that the console is picking up a wrong state for the deployment.

6. We can verify this by using WLST to reach the AppRuntimeStateRuntimeMBean and then get the status.
i) First access the DomainRuntimeMBean using the following link: http://e-docs.bea.com/wls/docs92/config_scripting/nav_edit.html#wp1001225
ii) The DomainRuntimeMBean has the handle to AppRuntimeStateRuntimeMBean. Please check the API docs for the method getAppRuntimeStateRuntime(): http://e-docs.bea.com/wls/docs92/javadocs_mhome/weblogic/management/runtime/DomainRuntimeMBean.html
iii) Then get the module IDs and then access the status using AppRuntimeStateRuntimeMBean.getCurrentState(..).

Please let me know what are the results of this test.

Moreover this seems to be a non-reproduceable issue as we can see this occurs only in Production but not in Test.

Please let me know whether the provided information is sufficient. Also let me know if you face any problems in testing the deployment status using WLST.

Monday, December 01, 2008

svn externals

It often useful to link to an external resource within a svn project.

for instance you may store Wsdl and Xsd files in one location, but your implementation code may need to access it. You don't want to copy and paste it since you will end up with 2 copies to maintain.

for these cases you can use svn externals to link to an external svn directory (note only directories can be linked to, not individual files)

e.g. (I set svn:externals via eclipse)

Use Team> Set Property > [select svn:externals]
Enter the name of the directory link you want, (a revision number if required, e.g. -r123), followed by the remote directory to link to.

wsdl [-r rev] http://svnHost/repos/trunk/MyProject/myDir1/wsdl

xsd [-r rev] http://svnHost/repos/trunk/MyProject/myDir1/xsd

SVN Ignore
Svn can be instructed to ignore certain files etc.

For example when working with eclipse projects you will want to specify that .classpath, and .project files will not be included in svn, checkin's or diff's.

Ignores can be setup globally or per directory.

Global
This can be done via eclipse (in the windows/ preferences/ Team control),

or find your subversion config file. e.g. ~/.subversion/config then edit the following line, e.g.

global-ignores = .project .claspath *.o *.lo *.la #*# .*.rej *.tmproj

Local
cd to project directory,
svn propset svn:ignore "target/*

This should ignore the target directory (e.g. for maven builds)

Wednesday, November 19, 2008

ALSB install problems

On of our servers was throwing up an exception, while trying to start the Adminserver

####<19-Nov-2008 16:17:22 o'clock GMT> <Critical> <WebLogicServer> <vmmiddleware06> <AdminServer> <Main Thread> <<WLS Kernel>> <> <> <1227111442502> <BEA-000386> <Server subsystem failed. Reason: java.lang.NumberFormatException: null
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:415)
at java.lang.Integer.parseInt(Integer.java:497)
at weblogic.ldap.EmbeddedLDAP.validateVDEDirectories(EmbeddedLDAP.java:1035)
at weblogic.ldap.EmbeddedLDAP.start(EmbeddedLDAP.java:212)
at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)

The solution appears to be
"This usually happens if your machine is running low on space and WebLogic Server corrupted a file in the embedded LDAP.
To fix this problem you can delete the file /servers//data/ldap/config/replicas.prop or add 'replica.num=0' to replicas.prop file. "


Thanks to the following link
http://satya-ghattu.blogspot.com/2008/10/number-format-exception-while-starting.html

Thursday, September 25, 2008

Search jar files for class

Heres a handy little command for searching classes withen jar files (for example when searching all the jars in a war file)

find <dirs> -name '*.jar' -exec jar tvf {} \; > outputfile

THis will produce a list of all files in the jar files outputted to outputfile.

This script below will print out the filename of each jar, and each associated file within.


list=$(find /apps/bea -print | grep .jar)

for el in $list; do

printf "Searching in %s\n" "$el";

case $el in

jar -tf $el | grep com.bea.console.utils.ConsoleRequestListener

;;

esac

done

Thursday, August 07, 2008

Jaxb Multiple namespace definitions

I was mildly concerned about the number of namespace definitions that Jaxb was printing every time it marshaleld an Xml document.

I'm using Spring-ws with jaxb bindings. In my definition of the Spring Marshaller I declare the jaxb packages which this marshaller will marshall. Each of these is turned into a namespace definiton on the resulting xml doc.

<bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.company.package1:com.company.package2:com.company.package3:com.company.package4">
</property>
</bean>

Results in

<ns1:request ns1="http://www.company.com/Package1" ns2="http://www.company.com/Package2" ns3="http://www.company.com/Package3" ns4="http://www.company.com/Package4">
<ns1:data>text
</ns1:data>
</request>

This was mildly irritating.

After a bit of searching I find its a 'performance feature' in Jaxb2

https://jaxb.dev.java.net/issues/show_bug.cgi?id=103

So they won't be fixing it.

The alternative from my point of view is to declare multiple marshallers, and use them where appropriate.

<bean id="jaxb2Marshaller1" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.company.package1">
</property>
</bean>
<bean id="jaxb2Marshaller2" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.company.package2">
</property>
</bean>
..etc..

Tuesday, August 05, 2008

Python gotcha

This Seemingly innocuous indentation error in python was annoying me.

Problem invoking WLST - Traceback (innermost last):
(no code object) at line 0
File "C:\apps\installWls.py", line 249
toDeploy = sys.argv[3]
^
SyntaxError: inconsistent dedent

Looking at my code (wlst code to auto deploy application into weblogic server), it was all indented correctly.

Well of course the computer was right. It wasn't indented correctly, but it was no obvious.

The issue was some copy and paste code I took from the internet.

It was indented using spaces, whereas I was using tabs.

Replacing the space indentation with tabs fixed the issue (but its not obvious uinless you set your editor to display non visible characters.

Tuesday, July 29, 2008

StackoverFlow using spring-ws on weblogic 9.2


We finally got our spring-ws application deployed.

Or so we thought. The next day when we arrived int he code was crashing, and the JMS queue was not been read....

The img to the right shows the non-heap memory growth. Something is not clearing.

Below is the stack trace we get





Edit

Two things to check that might help: (I have not been able to test this now, as I no longer work on this project or for this client.)

* Make sure that you haven't somehow configured a foreign JNDI or foreign JMS server that is self referencing.

* Make sure that you haven't specified a URL when there's no need to specify a URL. (Server side applications and configuration should never specify a URL for a resource unless the resource is in a different cluster. When a resource is located in the same cluster, JNDI lookups should simply be made directly in the cluster's JNDI name-space. The way to ensure that the lookup is direct is simply to use initial contexts that were created without an URL.)

http://forums.oracle.com/forums/message.jspa?messageID=2675334#2675334




10:12:31 INFO [org.springframework.jms.listener.DefaultMessageListenerContainer
] - Successfully refreshed JMS Connection
10:12:31 DEBUG [org.springframework.jndi.JndiTemplate] - Looking up JNDI object
with name [java:comp/env/jms.queue.provisioning.request]
10:12:36 INFO [org.springframework.jms.listener.DefaultMessageListenerContainer
] - Setup of JMS message listener invoker failed - trying to recover
java.lang.StackOverflowError
at java.lang.String.indexOf(String.java:1564)
at java.lang.String.indexOf(String.java:1546)
at weblogic.jndi.internal.AbstractURLContext.removeURL(AbstractURLContext.java:24)
at weblogic.jndi.factories.java.javaURLContextFactory$JavaURLContext.rem
oveURL(javaURLContextFactory.java:130)
at weblogic.jndi.internal.AbstractURLContext.lookup(AbstractURLContext.j
ava:130)
at weblogic.jndi.factories.java.ReadOnlyContextWrapper.lookup(ReadOnlyCo
ntextWrapper.java:45)
....
at weblogic.jndi.internal.AbstractURLContext.lookup(AbstractURLContext.j
ava:130)
at weblogic.jndi.factories.java.ReadOnlyContextWrapper.lookup(ReadOnlyCo
ntextWrapper.java:45)



It appears that the first exception thrown is

2008-07-26 00:14:08,679 DEBUG org.springframework.jms.listener.DefaultMessageListenerContainer - Consumer [weblogic.jms.client.WLConsumerImpl@14f7bad] of session [weblogic.jms.client.WLSessionImpl@15015db] did not receive a message
2008-07-26 00:14:08,696 INFO org.springframework.jms.listener.DefaultMessageListenerContainer - Setup of JMS message listener invoker failed - trying to recover
weblogic.jms.common.TransactionRolledBackException: Attempt to resume an inactive transaction: BEA1-11D22EBAEF18F82704CC:error resuming transacted session's internal transaction
at weblogic.jms.dispatcher.DispatcherAdapter.convertToJMSExceptionAndThrow(DispatcherAdapter.java:110)
at weblogic.jms.dispatcher.DispatcherAdapter.dispatchSyncNoTran(DispatcherAdapter.java:61)
at weblogic.jms.client.JMSSession.receiveMessage(JMSSession.java:797)
at weblogic.jms.client.JMSConsumer.receive(JMSConsumer.java:579)
at weblogic.jms.client.WLConsumerImpl.receive(WLConsumerImpl.java:167)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveMessage(AbstractPollingMessageListenerContainer.java:404)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:285)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:260)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:944)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:874)
at org.springframework.scheduling.commonj.DelegatingWork.run(DelegatingWork.java:61)
at weblogic.work.j2ee.J2EEWorkManager$WorkWithListener.run(J2EEWorkManager.java:259)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
Caused by: weblogic.jms.common.TransactionRolledBackException: Attempt to resume an inactive transaction: BEA1-11D22EBAEF18F82704CC:error resuming transacted session's internal transaction
at weblogic.jms.frontend.FESession.transactedException(FESession.java:2024)
at weblogic.jms.frontend.FESession.throwTransactedException(FESession.java:2039)
at weblogic.jms.frontend.FESession.transactedInfect(FESession.java:2140)
at weblogic.jms.frontend.FEConsumer.receive(FEConsumer.java:527)
at weblogic.jms.frontend.FEConsumer.invoke(FEConsumer.java:780)
at weblogic.messaging.dispatcher.Request.wrappedFiniteStateMachine(Request.java:759)
at weblogic.messaging.dispatcher.DispatcherServerRef.invoke(DispatcherServerRef.java:276)
at weblogic.messaging.dispatcher.DispatcherServerRef.handleRequest(DispatcherServerRef.java:141)
at weblogic.messaging.dispatcher.DispatcherServerRef.access$000(DispatcherServerRef.java:36)
at weblogic.messaging.dispatcher.DispatcherServerRef$2.run(DispatcherServerRef.java:113)
... 2 more
Caused by: javax.transaction.InvalidTransactionException: Attempt to resume an inactive transaction: BEA1-11D22EBAEF18F82704CC
at weblogic.transaction.internal.TransactionManagerImpl.resume(TransactionManagerImpl.java:360)
at weblogic.transaction.internal.ServerTransactionManagerImpl.resume(ServerTransactionManagerImpl.java:356)
at weblogic.jms.frontend.FESession.transactedInfect(FESession.java:2085)
... 9 more
2008-07-26 00:14:08,709 INFO org.springframework.jms.listener.DefaultMessageListenerContainer - Successfully refreshed JMS Connection
2008-07-26 00:14:08,713 DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/meteor.jms.queue.provisioning.request]
2008-07-26 00:14:13,758 INFO org.springframework.jms.listener.DefaultMessageListenerContainer - Setup of JMS message listener invoker failed - trying to recover
java.lang.StackOverflowError
at java.lang.String.indexOf(Ljava.lang.String;I)I(Unknown Source)
at java.lang.String.indexOf(Ljava.lang.String;)I(Unknown Source)
at weblogic.jndi.internal.AbstractURLContext.removeURL(AbstractURLContext.java:24)

Wednesday, June 18, 2008

Spring-ws and weblogic incompatibilities

I wrote about incompatible versions of spring before resulting in cryptic error messages.

Well my solution there wasn't the full picture, if you are running xml /web servicse on weblogic. (Though at least this time I recognised the error as incompatible jars)

I was getting various different non-intuitive errors when trying to run a spring-ws application on weblogic 9.2.1.

e.g.
<User defined listener org.springframework.web.context.ContextLoaderListener failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webServiceTemplateProxy' defined in class path resource [com/meteor/provisioning/servicecategory/serviceBeansSpringConfig.xml]: Cannot resolve reference to bean 'webServiceTemplate' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean withname 'webServiceTemplate' defined in class path resource [com/meteor/provisioning/servicecategory/serviceBeansSpringConfig.xml]: Cannot resolve reference to bean 'messageFactory' while setting bean property 'messageFactory'; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'messageFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.aop.support.AopUtils.getTargetClass(Ljava/lang/Object;)Ljava/lang/Class;.org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webServiceTemplateProxy' defined in class path resource [com/meteor/provisioning/servicecategory/serviceBeansSpringConfig.xml]: Cannot resolve reference to bean 'webServiceTemplate' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creatingbean with name 'webServiceTemplate' defined in class path resource [com/meteor/provisioning/servicecategory/serviceBeansSpringConfig.xml]: Cannot resolve reference to bean 'messageFactory' while setting bean property 'messageFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception isjava.lang.NoSuchMethodError: org.springframework.aop.support.AopUtils.getTargetClass(Ljava/lang/Object;)Ljava/lang/Class;
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1244)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1008)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)
Truncated. see log file for complete stacktrace

or

java.lang.NoClassDefFoundError: org/apache/axiom/soap/SOAPFactory

After a lot of effort and with help from various postings (namely here, and here ), I managed to track down the various xml jars I needed to override weblogics internal jars.

These include the following taken from my maven pom.xml file. (Note I can't guarantee that this is the full list, or that this list does not contain jars that are in fact not needed. All I can say is that this list worked for me). BTW some of these I had to manually install in my maven repository myself, as I couldn't find them on remote repositories.

<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-dom</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>apache-xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.3.03</version>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>wstx-asl</artifactId>
<version>3.2.6</version>
</dependency>


The problem is with weblogic (various versions, 9.2, 9.2.1, 8.1, and I believe 10) and spring-ws. Weblogic comes with various xml libraries, most of which have been superseded by newer versions. Spring-ws requires some of these newer jars (e.g. saaj, and axiom), which in turn refer to newer versions of base xml libraries. Thus you have an incompatibility.


Also from Arjens post you need to update your weblogic.xml file, adding the following, to instruct weblogic to take the supplied files before already installed files int he weblogic system
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>


BTW I was only able to finally fix the problem by firstly deploying it on Tomcat.

The above example works much easier in Tomcat, since it doesn't have any conflicting xml libraries causing grief. By actually getting the application running in tomcat, I was able to (relatively) quickly find out which jars I needed.

Tomcat would throw a NoClassDefFound exception when it came across a jar it didn't have. This doesn't happen in weblogic since it has xml jars, just the wrong versions. Once I had the application running in tomcat, I knew I had found all the required jars. When I moved it back to weblgoic the problem was solved.

Note: unlike Ajens post, I required saaj1.3 in my WEB-INF/lib folder

Actually I wasn't quite there yet, (see next post), but I this had finally sorted out this problem

Failure executing javac

There's nothing quite so deflating as seeing a message like the following

[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
Failure executing javac, but could not parse the error:
An exception has occurred in the compiler (1.5.0_06). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
com.sun.tools.javac.code.Symbol$CompletionFailure: file javax\xml\ws\WebServiceClient.class not found


You really begin to wonder if you're doing something very wrong.
Fortunately you're not, and there is a quick and easy workaround.
This it turns out is a bug with javac on windows

My quick solution. Compile using cygwin. (If you haven't got cygwin, simply download setup.exe, and install)

This worked fine. My details was using jdk 1.5.0_06 (the bug has been reported on 1.5.0_04, and seen on 1.6 as well), on windows xp building using maven 2.0.8. Running my maven script in a cygwin bash window worked fine.

Tuesday, June 10, 2008

spring versions

Beware of mixing tools with different Spring versions.

I was using spring ws 1.5.3, and getting the following error

java.lang.NoSuchMethodError: org.springframework.util.ResourceUtils.toURI(Ljava/net/URL;)Ljava/net/URI;
....

Problem is that I had spring 2.0.x on my path, but spring-ws requires spring 2.5.x

Once I updated to using spring 2.5.x the problem was solved.

Could be a nasty problem, since the error message could easily lead you on a wild goose chase