Saturday, September 23, 2006

Zuzu Angel

0 comments
Assistam ao filme acima. Excelente produção nacional, contando uma parte da história do Brasil que muitos não conhecem. Muito boas interpretações.

Problems counting characters with JavaScript and Firefox?

1 comments
Basically Firefox, when counting a textarea string length, counts each breakline as one characters, but expands it to CRLF when submitting. If you have a database limit and relies on JavaScript to keep your textarea under this limit, a simple JavaScript function will not work. Surprising, but it will work perfectly in Internet Explorer, although commonly the inverse is true when we find JavaScript problems.

To solve that problem, I created a modified version that seems to be working so far:

function textCounter(field,cntfield,maxlimit) {
var extra = 0;
if (navigator.appName=="Netscape" &&
parseInt(navigator.appVersion)>=5) {
var index = field.value.indexOf('\n');
while(index != -1) {
extra += 1;
index = field.value.indexOf('\n',index+1);
}
}
if (field.value.length + extra > maxlimit)
field.value = field.value.substring(0, maxlimit-extra);
else
cntfield.value = maxlimit - field.value.length - extra;
}


In case of Firefox (and Netscape, for that matter), it counts the breaklines, adding or subtracting this amount when checking the number of characters.

If you find some problem here or know a better version available on the internet, please let me know. I searched, but couldn't find a version that overcomes this Firefox behavior.

Thursday, September 14, 2006

JSVC and APR do not work together for HTTPS connector

0 comments
That is an old bug that I did not have time to provider further information yet.

Anyway, I don't need jsvc any longer, since Apache is proxying to Tomcat, but it is an interesting thing to debug and help improving Tomcat.

Tuesday, September 05, 2006

Apache httpd proxying to Tomcat (with Acegi redirection)

0 comments
I ran into some problems when testing a Apache HTTPD server proxying, through AJP protocol, to Tomcat where the main application used Spring and Acegi. Acegi performs an excellent work of redirecting from HTTP to HTTPS (and vice-versa) when a given URL requires secure or insecure channel. However, it was not redirecting properly when Apache was proxying all the requests.

Initially I thought it was a problem with proxying, but after checking the log, I realized that Acegi was not redirecting to the correct places but only to the context root (e.g /context/). After checking its source code (if a simple Google search does not return what we expect, it is the second fastest way), I noticed that my portMapper object was not being used by the redirection classes (such as RetryWithHttpsEntryPoint). That would not be problem if I were not using non-standard ports (standard ones are 80->443 and 8080->8443).

So, in order to fix this problem, you may do the following:

1 - Change your ports to standard ones (even if only for testing purposes).

2 - Instantiate a portMapper object and define http->https ports (try to have 1-1 relationship, avoiding 80->443, 81->443, in order to avoid problems when Acegi redirects https to http).

3 - Inject this portMapper object in objects that perform redirection, such as: RetryWithHttpsEntryPoint, RetryWithHttpEntryPoint and AuthenticationProcessingFilterEntryPoint (I can't remember any other classes at this moment).

This last step may be somewhat tricky, since you must instantiate RetryWithHttpsEntryPoint, for example, inject portMapper in it. And you must inject your instantiated object into SecureChannelProcessor. The same goes for InsecureChannelProcessor and RetryWithHttpEntryPoint.

In my case, it was much simpler to move to standard ports :-) But at least I found out a way of solving it if I couldn't change the ports.

Log NullPointerException when starting Tomcat

5 comments
if you find the following stacktrace when starting Tomcat with commons-logging-1.1.jar and log4j:


java.lang.NullPointerException
at org.apache.log4j.Category.isEnabledFor(Category.java:757)
at org.apache.commons.logging.impl.Log4JLogger.isTraceEnabled(Log4JLogge
r.java:327)


It seems to be related to a bug in commons-logging related to the implementation of support for trace-level logging. Replace it with and older version (such as 1.0.4). At least for me it worked pretty well. It seems that commons-logging passes a wrong parameter to log4j.

I commented it in Tomcat bug 39090 (actually the same stacktrace is refered in 39631, but it was set as duplicated).

Thursday, August 24, 2006

Mercado de Serviços

0 comments
[For English version, please refer to rengolin blog]

Uma nova plataforma para a prestação de serviços no Brasil está disponível, o Mercado de Serviços.

O objetivo é que o Mercado de Serviços se torne uma comunidade de prestação de serviços no Brasil. Nessa plataforma, compradores (empresas ou indivíduos) que precisem de serviços feitos são conectados a prestadores (freelancers, profissionais liberais ou empresas) que buscam projetos para executar.

O Mercado de Serviços abrange mais de 110 categorias de serviços, não se restringindo somente a projetos de TI (como desenvolvimento de aplicativos e sites web), mas também a categorias como engenharia, design, assessoria legal e administrativa, negócios, vendas, entre outros.

Thursday, August 10, 2006

Acegi: Redirecing Users to Different Start Pages

0 comments
Redirect Users based on their Roles: check here.

I had to change Acegi implementation a little bit to be suitable to my needs. My suggestions to Spring were made in this thread in their forum.

MySQL: Error No. 1033 Incorrect information in file: 'filename'

15 comments
Before trying other things or desperate thinking that you MySQL database is corrupted, simply check if you temp directory (/tmp on Linux) exists and accessible. In my case, my /tmp directory got deleted and MySQL could not access database information no longer. Restoring /tmp fixed the problem.

Wednesday, August 09, 2006

Spring (JstlView) and Tomcat ignoring precompiled JSPs

0 comments
I had a problem with precompiled JSPs that made me think that it was due to the use of Spring MVC. Basically, after precompiling and inserting web.xml fragment generated by jspc tomcat task, I still could see the work dir full of Java generated source code and their classes. What did it mean? Tomcat was ignoring completely my precompiled JSPs.

After checking Spring code, I noticed a subtle thing that caused this error. A double slash maded all this mess. For example, instead of having

/web/WEB-INF/pages/index.jsp

I had

/web/WEB-INF/pages//index.jsp

because my view resolver had been set with prefix "/web/WEB-INF/pages/", suffix ".jsp" and the view name was being set as "/index". For this reason, Tomcat did not find a servlet mapping and ended up generating a new Java file for the JSP and compiling it on demand.

I don't know yet if this should be handled by Spring view resolver, but check if this is your case (and you are facing the same problem).

Tuesday, August 08, 2006

Hibernate: reattaching objects to the same session

2 comments
Check this patch I developed to fix two nagging problems I faced when clearing a hibernate session:

- reassociated object has dirty collection reference
- Found two representations of same collection: (collection type)

It is against Hibernate 3.1.3 and it solved the scenarios I faced. I hope it works for you too. Any comments are very welcome.

Saturday, August 05, 2006

Dumbster returns empty header (eg "To")?

24 comments
Dumbster is very useful, but it has been a tough time for me to make it work with multiple line headers, in particular "To". Vanilla dumbster does not have support for that, so I am unable to check in my unit tests if the "To" header is correct.

If you have similar problems, check this patch that is over an year old.

But also read the comment I wrote about a potential bug in this patch. Replace the code I mention in the comment if it is also your case.

Tuesday, June 20, 2006

Referendum Costituzionale del 25-26 giugno

0 comments
Se você é um cidadão italiano, não se esqueça do referendo popular. É necessário que o seu voto chegue ao consulado até dia 22/06/2006 (pelo menos é a regra para o consulado de São Paulo). Para saber exatamente do que se trata, veja esse PDF que menciona o que estamos votando. Na verdade, basicamente aprovamos ou não o que está nesse documento. E, diferemente do referendo sobre células-tronco, esse vale independente do número de votantes.

Algo que achei interessante é que diminui o número geral de deputados, aumentando o número de deputados dos italianos no exterior de 12 para 18. Também diminui o número mínimo de senadores por região italiana. Infelizmente são 79 páginas e não poderei ler todas, mas se você encontrar pontos interessantes ou discutíveis nesse referenco, por favor comente aqui.

Sunday, April 23, 2006

Enterprise Integration Patterns

0 comments
This Enterprise Integration Patterns book is a must read for everyone trying to understand how messaging system works. It was essential to understand some patterns and terms used in the implementation that are taken for granted for users and developers.

ActiveMQ and redelivery issues

1 comments
Last week I tried ActiveMQ. I knew it integrated well with Spring and decided to give it a try to solve a problem with asynchronous processing for email delivery.

First I tested ActiveMQ 4, which is not a stable release, and then 3. To be completely honest, first I tested ActiveMQ 4 with Jencks for message-driven beans (pojos, not EJBs). It didn't work pretty well and Jencks seemed to me not mature enough yet. For this reason, I decided to have a singleton message listener with ActiveMQ. However, it did not prove to work so well either: redelivery simply didn't happen with an asynchronous message listener in version 4. Since this version is not stable, I tested version 3, but surprisingly redelivery did not work as I expected either. It redelivers, but does not take into account the redelivery initial timeout and back off mode. I contributed with the project with two junit tests to test these issues. Nothing like some problem like that to show us how useful can be a JUnit test. And also how useful it is for our own tests where everything seems to work without extensive testing.

Besides that, it seems dead queue letter does not work in ActiveMQ 3 for queues, only for topics. I had to code a home-made solution for my problem, since ActiveMQ did not seem to work pretty well. Maybe JBoss has a better implementation with JBossMQ. But I was really curious about this comparison between jbossmq and activemq.

Wednesday, March 29, 2006

Your Cake

0 comments
You can't have your cake and let your neighbor eat it too.
-- Ayn Rand

Tuesday, March 21, 2006

Comparison innerHTML vs DOM and IE vs Firefox

0 comments
Check here for a performance comparison between the usage of innerHTML and DOM to set an element's value. It is surprising its difference. After that, try to compare Firefox and Internet Explorer performance. IE is so much slower that I couldn´t believe.

Saturday, March 18, 2006

Bach

0 comments
"Bach opens a vista to the universe. After experiencing him, people feel there is meaning to life after all."
- Helmut Walcha

Think alike?

0 comments
Where all think alike, no one thinks very much.
- Walter Lippmann

Tuesday, February 21, 2006

DenyHosts

0 comments
Important tool for those that have SSH services available and want to reduce dictionary attacks.

Friday, February 10, 2006

Lazy Initialization + DAO + Hibernate + Spring?

0 comments
Check this blog out.

Don't forget that eager initialization is an option, but it will use an outer join!

Wednesday, February 08, 2006

Resistance

0 comments
It is easier to resist at the beginning than at the end. -- Leonardo da Vinci

Monday, February 06, 2006

Pagination and Hibernate

0 comments
Interesting way to do pagination in Hibernate. I have implemented using these available methods in Criteria class, but having a Page object may be more interesting.

Saturday, February 04, 2006

Java Concurrency

0 comments
Doug Lea's book on Java Concurrency never got updated, but soon a new book on this subject is to be released. The author's articles are very interesting, so I think we may expect this book to have a high quality.

Another book that may be interesting is Thinking Recursively with Java, that has been released recently.

Axis: WSDL styles and initialization exception

1 comments
Which style of WSDL should I use?

By the way, if you are using Apache Axis (1.2.1) and have NoSuchMethodException likes these below, don't worry. It prints out the stack trace, but it is only a leftover code that doesn't indicate any bug (since the object is correctly instantiated after this stack trace is printed):

java.lang.NoSuchMethodException:
org.apache.axis.encoding.ser.ArrayDeserializerFactory
.create(java.lang.Class, javax.xml.namespace.QName)

java.lang.NoSuchMethodException:
org.apache.axis.encoding.ser.ArrayDeserializerFactory
.(java.lang.Class, javax.xml.namespace.QName)

Another lesson from using Axis and Eclipse Webtools is that, as a default behaviour, it accepts either the operation name or the part name as the root element for an operation call. I mean, if you have an operation named "CalculateTest", declared like this:

<wsdl:operation name="CalculateTest">
<wsdl:input message="tns:CalculateTestRequest"/>
<wsdl:output message="tns:CalculateTestResponse"/>
</wsdl:operation>

It will accept a SOAP call with "CalculateTest" or "CalculateTestRequest" elements. If any given element is not found in the operations hash (what happens when the element matches the operation name), Axis will search for matching root elements of operations (in this case, CalculateTestRequest), and it will work.

MySQL: insert duplicate keys

0 comments
Very nice feature in MySQL 5.0. Basically the insert clause has an extension like this: "insert into ... on duplicate update a = b + c". Check the documentation.

Tuesday, January 24, 2006

Work and Time

0 comments
Work expands to fill the time available.
-- Cyril Northcote Parkinson, "The Economist", 1955

Friday, January 20, 2006

KMail and missing spam buttons

0 comments
After upgrading to 3.5 I faced another problem: kmail spam buttons (to classify as spam or ham) are no longer available in its toolbar. They are very important to classify spam emails and now I have to use the context menu. After searching for bug reports, I found one for it, but the proposed workaround does not work for me. I hope we can fix that soon.

KDE and hard disks on the desktop

0 comments
Upgrading to KDE 3.5 introduced a problem for me. No longer my partitions were displayed on the desktop, what was something very convenient for me. The USB drive, CD and floppy drives still worked, but no hard disk. But finally, after sometime searching how to solve this problem, I found a solution: simply add hal user to disk group and everything works perfectly :-)

Thursday, January 19, 2006

StringTokenizer and empty tokens

0 comments
If you need StringTokenizer to work with empty tokens, check this implementation. I need that to keep track of which cell the data was from (in a CSV file) and this implementation was exactly what I needed.

Friday, January 13, 2006

Eclipse WTP and SSL certificates

3 comments
Using Web Services Explorer is a very good tool to test web services during development. However, if you want to test a web services that uses a secure server, Web Services Explorer still does not provide an extensive support for that, like what happens with regular web browsers. You will probably have this error:

IWAB0135E An unexpected error has occurred.
IOException
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

To solve it, it is necessary to import the server certificate into your $JAVA_HOME/jre/lib/security/cacerts file. To do that, make a backup of this file and use the Java keytool. Here has a better description of how to use it.

Enabling SSL in Eclipse WTP

1 comments
If you want to enable SSL in Eclipse Web Tools Project and you already have a server defined, you must delete and recreate the server. It makes a copy of the $TOMCAT_HOME/conf/server.xml at the creation time and does not update the file when you update the source configuration. Therefore, even if you enable SSL in your $TOMCAT_HOME/conf/server.xml, it won't be enabled in WTP. After recreating, everything works.

This behaviour is not desired, but that the way it still works, one year after a post in the Eclipse newsgroup about it.

Saturday, January 07, 2006

Citizen and the government

0 comments
When Alexander the Great visited the philosopher Diogenes and asked whether he could do anything for him, Diogenes is said to have replied: "Yes, stand a little less between me and the sun.". It is what every citizen is entitled to ask of his government.

Henry Hazlitt - "Economics in One Lesson"

Just finished this book. Excellent book on economics concepts and fallacies. Although it was written in the 40s, it is very current. I am very grateful to a friend of mine for this suggestion.

Wednesday, January 04, 2006

Quote - Drucker

0 comments
Here I am, fifty-eight, and I still don't know what I want to be when I grow up. -- Peter Drucker

Monday, January 02, 2006

Music and Nietzsche

0 comments
Without music, life would be a mistake. - Friedrich Nietzsche.