Recent Posts
Archives

Archive for the ‘en-US’ Category

PostHeaderIcon Disable “Pointsec Protector Client”

Pointsec Protector Client is an application that blocks USB ports on a PC. This has an interest, especially for lamers who introduce viruses to great companies networks because of their contamined USB keys. But for developpers it’s very painful (unused resources and… other stuff 😉 ). Pointsec Protector Client is installed as “super admin” process: impossible to kill.
Here is the description of this application on its editor website:

Check Point Media Encryption secures sensitive corporate data and blocks incoming malware by encrypting removable media such as USB storage devices, CDs and DVDs and controlling activity (read, write and execute) on ports and devices. All device content is automatically encrypted in the background for a transparent end-user experience. Unique to Check Point, users can access encrypted media securely on unmanaged computers with no client installation. As the only device and port control solution integrated with a single endpoint security agent, Check Point Media Encryption simplifies compliance and reduces administrative overhead. Now supports Windows 7.

To get through Pointsec Protector Client, here is the way:

  • you need be admin in your local computer
  • Start > Control Panel > Administrative tools > Services > Select "Pointsec Protector Client" > stop the service
  • open Windows Explorer, go to C:\Program Files, rename CheckPoint folder as XXXCheckPoint
  • reboot your computer

You should have get rid of Pointsec Protector Client. I think this method should work on most applications started as service by a “super admin”, yet I have not tested.

PostHeaderIcon “Select for update” in Hibernate

Case:

You have to use an equivalent to “select for update” in Hibernate, for instance when you migrate en EJB entity to Hibernate.

Fix:

In your query, use the option LockMode.UPGRADE. For instance, you will have:

[java]sessionFactory.getCurrentSession().load(MyMappedClass.class, myPk, LockMode.UPGRADE);[/java]

PostHeaderIcon java.io.StreamCorruptedException: invalid type code: 31

Context:

Client-server communication over JMS.

Stacktrace:

[java]Caused by: java.rmi.UnmarshalException: failed to unmarshal class weblogic.security.acl.internal.AuthenticatedUser; nested exception is:
java.io.StreamCorruptedException: invalid type code: 31
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:203)
at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:224)
at weblogic.common.internal.RMIBootServiceImpl_921_WLStub.authenticate(Unknown Source)
at weblogic.security.acl.internal.Security$1.run(Security.java:185)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
at weblogic.security.acl.internal.Security.authenticate(Security.java:181)
at weblogic.jndi.WLInitialContextFactoryDelegate.authenticateRemotely(WLInitialContextFactoryDelegate.java:726)
at weblogic.jndi.WLInitialContextFactoryDelegate.pushSubject(WLInitialContextFactoryDelegate.java:659)[/java]

Explanation – Fix

The client JVM was in version 1.6, the server was in 1.5.
To fix the issue, the client must be run with Java 1.5.
Possibly, the client may laucnh the JVM with the option -Dsun.lang.ClassLoader.allowArraySyntax=true.

PostHeaderIcon javax.naming.ConfigurationException / java.net.MalformedURLException

Context

I have to send JMS messages on queues on clustered servers: t3://firstServer:1234 and t3://secondServer:5678.

The destination queues are retrieved in Spring, thanks to a property like:
[xml]<property name="providerURL" value="t3://firstServer:1234,t3://secondServer:5678"/>[/xml]

Error:

I receive the following error:

[java]javax.naming.ConfigurationException [Root exception is java.net.MalformedURLException: port expected: t3://firstServer:1234,t3://secondServer:5678][/java]

Explanation and fix:

When you send messages on many queues, you must not repeat the protocol (here: t3://)! Fixing the issue is very simple: you have to remove the second t3:// in Spring property:

[xml]<property name="providerURL" value="t3://firstServer:1234,secondServer:5678"/>[/xml]

PostHeaderIcon Spring using multi instances of JndiTemplate

Case

Spring application context file:

[xml]
<bean id="jmsQueueConnectionFactory"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jonathan.jms-connection-factory.external"/>
<property name="jndiEnvironment">
<props>
<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
<prop key="java.naming.provider.url">
t3://anOtherServer:8521
</prop>
<prop key="java.naming.security.principal">jonathan</prop>
<prop key="java.naming.security.credentials">jonathan</prop>
<prop key="weblogic.jndi.enableDefaultUser">true</prop>
</props>
</property>
</bean>
<bean id="mainJndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
<prop key="java.naming.provider.url">t3://mainServer:1234</prop>
<prop key="java.naming.security.principal">myPrincipal</prop>
<prop key="java.naming.security.credentials">myPassword</prop>
<prop key="weblogic.jndi.enableDefaultUser">false</prop>
</props>
</property>
</bean>
[/xml]

Description

I use two instances of JndiTemplate to send JMS messages on two different queues, on two different Weblogic domains, using two different Ldap directories. When I try to send messages on the second server, it does not work: I get an error because the second server receives credentials that should be sent to the first server.

[Security:090398]Invalid Subject: principals=[...]

Quick fix

Remove the properties weblogic.jndi.enableDefaultUser from within the XML.

PostHeaderIcon Short Tutorial: Migration from EJB Entity to Hibernate

Case

  • let’s consider an EJB Bean AnimalBean, linked to a table JL_Animal
  • let’s have a human understandable name for the Pojo, let’s say: Animal
  • let an EJB entity have following finders:

[java]
* @ejb.finder
* signature = "Collection findByBirthDate(java.lang.Integer birthDate)"
* query = "SELECT OBJECT(o) FROM AnimalBean AS o WHERE o.birthDate = ?1"
*
* @ejb.finder
* signature = "Collection findByCountryAndBirthDate(java.lang.String from,java.lang.Integer birthDate)"
* query = "SELECT OBJECT(o) FROM AnimalBean AS o WHERE o.country = ?1 AND o.birthDate = ?2"[/java]

Read the rest of this entry »

PostHeaderIcon Fake SMTP server in Java

Abstract

You need a fake SMTP server, for any reason: either your application does not deploy without an SMTP, or you need see what mails are sent and their attached files, etc.
Read the rest of this entry »

PostHeaderIcon Default method on interface implementing

Abstract:

Developpers happen to forget to implement concrete classes on creating new implementations. Indeed, IDEs fill methods content with canonical return values, (null for object, 0 for numerics, etc.). Consequently, errors appear only on deployment stage, when it is not on running.

To avoid this, here is the tip I use: raising a default exception. If unit tests are generated, then the exception is raised on development stage, which is better than after one hour compiling / deployment / execution ;-).

Process:

On IntelliJ IDEA, open:

  • Project Settings
    • File Templates
      • Code
        • Implemented Method Body
        • write: throw new UnsupportedOperationException("Class Name : ${CLASS_NAME} - Method Name : ${METHOD_NAME}");

PostHeaderIcon Copy all tables from a schema to another one

Case:

I need copy the content of all tables from one Oracle schema to another one, specifically: I must copy raw data from a production DB to a developper one.

Context:

  • The DBA do not allow DBLinks
  • Oracle source and destination schemas share the same structure (name of the tables, names and types of columns, etc.

Fix:

Here is a small script I wrote, of course it can be improved:
[bash]
#!/usr/bin/bash
SRC_LOGIN=XYZ
SRC_PASSWORD=XYZ
SRC_DB=production
DBDEST_LOGIN=XYZ
DEST_PASSWORD=XYZ
DEST_DB=developmentDB

echo "select object_name from user_objects where object_type = ‘TABLE’ order by object_name;" | \
sqlplus $SRC_LOGIN/$SRC_PASSWORD@$SRC_DB | \
grep -v OBJECT_NAME | grep -v "-" | grep -v "^$" | \
sed "1,9d" | tac | sed "1,3d" | tac | \
sort | uniq > allTables.txt

for table in `more allTables.txt`
do
rm -rf $table.sql
echo "exporting $table"
exp $SRC_LOGIN/$SRC_PASSWORD@$SRC_DB file=$table.sql buffer=10485867 tables="$table" direct=y
echo "importing $table"
echo "truncate table $table;" | \
sqlplus $DEST_LOGIN/$DEST_PASSWORD@$DEST_DB
imp $DEST_LOGIN/$DEST_PASSWORD@$DEST_DB file=$table.sql \
buffer=10485867 tables="$table" \
fromuser=$SRC_LOGIN touser=$DEST_LOGIN ignore=y
rm -rf $table.sql
done

rm -rf allTables.txt[/bash]

A little more explanations:

  • echo "select object_name from user_objects where object_type = 'TABLE';" | sqlplus $SRC_LOGIN/$SRC_PASSWORD@$SRC_DB: this allow to retrieve the names of all the tables from the DB
  • grep -v OBJECT_NAME | grep -v "-" | grep -v "^$" : this removes empty lines and useless trace from Oracle SQLPlus
  • sed "1,9d" | tac | sed "1,3d" | tac: removes the 9 first lines and the 3 last ones. tac in Unix allow to reverse the content of a file
  • sort | uniq : sort lines and remove duplicates
  • exp $SRC_LOGIN/$SRC_PASSWORD@$SRC_DB file=$table.sql buffer=10485867 tables="$table" direct=y: exports the content of the table $table
  • echo "truncate table $table;" | sqlplus $DEST_LOGIN/$DEST_PASSWORD@$DEST_DB: truncates destination table. This is useful in case the script must be played more than once, for instance.
  • imp $DEST_LOGIN/$DEST_PASSWORD@$DEST_DB file=$table.sql buffer=10485867 tables="$table" fromuser=$SRC_LOGIN touser=$DEST_LOGIN ignore=y: import the content of the table

Some improvement ideas:

  • handle sequences, triggers, stored procedures, etc.
  • create the complete destination DB owing to source DB, ie do not assume anymore that the DBs share the same structure

PostHeaderIcon DBUnit and Hibernate: Beware of Collisions!

Here is an interesting case I have encountered this morning.

Context

I must test a Hibernate implementation of a DAO, using DBUnit and its XML dataset files as a minimal database. A CRUD unit test fails, I get this trace:

WARN util.JDBCExceptionReporter – SQL Error: 0, SQLState: null
ERROR util.JDBCExceptionReporter – failed batch
ERROR def.AbstractFlushingEventListener – Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update

Explanation

In my dataset, I had set some primary keys at 0, 1, …, 10. Owing to my Hibernate mapping, the primary keys are generated thanks to a sequence.
On another hand, with the CRUD test, the primary keys 0, 1, …, 10 are also assigned to newly created objects.

Here is the issue: there are collisions between the XML dataset file objects and the objects created with Hibernate, because obviously two objects never share the same primary key!