Thursday, December 5, 2013

Tapestry 5 Invalid configuration

I met following configuration exception in logs:
Caused by: java.lang.IllegalArgumentException: Service 'ChangeLogProcessor' is configured using 
org.apache.tapestry5.ioc.OrderedConfiguration, not org.apache.tapestry5.ioc.Configuration.
 at org.apache.tapestry5.ioc.internal.util.WrongConfigurationTypeGuard.findResource(WrongConfigurationTypeGuard.java:40)
 at org.apache.tapestry5.ioc.internal.util.DelegatingInjectionResources.findResource(DelegatingInjectionResources.java:36)
 at org.apache.tapestry5.ioc.internal.util.DelegatingInjectionResources.findResource(DelegatingInjectionResources.java:38)

Problem was related to Tapestry 5 chain of commands builder. It's Tapestry 5 build-in service that helps to implement that design pattern. My chain of commands definition was:
public static ChangeLogProcessor buildChangeLogProcessor(List<ChangeLogProcessor> commands,
    @InjectService("ChainBuilder") ChainBuilder chainBuilder) {
    return chainBuilder.build(ChangeLogProcessor.class, commands);
}

public static void contributeChangeLogProcessor(
    final Configuration<ChangeLogProcessor> configuration,
    final @Autobuild ChangeLogBoxProcessor changeLogBoxProcessor) {
    configuration.add(changeLogBoxProcessor);
}
After some time I found that problem was in contribute method, in build method is configuration defined as List which should be in contribute method defined as OrderedConfiguration not as Configuration. So following corrected code works fine:
public static void contributeChangeLogProcessor(
    final OrderedConfiguration<ChangeLogProcessor> configuration,
    final @Autobuild ChangeLogBoxProcessor changeLogBoxProcessor) {
    configuration.add("boxProcessor", changeLogBoxProcessor);
}

Monday, November 4, 2013

Apache HTTPD and Tomcat configuration

I run some application at linux server. It's quite simple installation but sometimes it's difficult for me to remember why it's configure in such way. This post helps me to understand current state. Hopefully it will be useful for someone else.
Server is just one linux box with CentOS. There are no dependencies to other nodes or services. It's really simple.
On server is installed Apache HTTPD service. Service could be started stopped via commands /etc/init.d/https {stop|start| ...}. Among others apache contains module mod_jk which is responsible for communication with AJP protocol load balancing and other stuff. Closer description of mod_jk could be found at http://tomcat.apache.org/connectors-doc/. The reason why I need Apache HTTPS in front of Tomcat server is that I need more tomcats for different hosted domains and Apache HTTPD server is used also for PHP. Connection between Apache HTTPD server and Tomcat servers is at following image.
Applications are also split between few linux system accounts. It's because of security.
Now let's look at configuration of Apache HTTPD:

<VirtualHost *:80>
   ServerName www.domain2.com 
   ServerAlias *.domain2.com
   ServerAlias *.domain3.com
   ErrorLog /var/log/httpd/domain2.com.err.log
   CustomLog /var/log/httpd/domain2.com.log combined

   <Proxy *>
     AddDefaultCharset Off
     Order deny,allow
     Allow from all
   </Proxy>
 
   ProxyPass / ajp://localhost:7001/
   ProxyPassReverse / ajp://localhost:7001/
</VirtualHost>


<VirtualHost *:80>
   ServerName www.domain1.com
   ServerAlias *domain1.com
   ErrorLog /var/log/httpd/domain1.com.err.log
   CustomLog /var/log/httpd/domain1.com.log combined

   <Proxy *>
     AddDefaultCharset Off
     Order deny,allow
     Allow from all
   </Proxy>
 
   ProxyPass / ajp://localhost:7005/
   ProxyPassReverse / ajp://localhost:7005/
</VirtualHost>
Finally there have to be some configuration at Tomcats side. Here is configuration from tomcat2 ./conf/server.xml file:
<Connector port="7001" protocol="AJP/1.3" redirectPort="8443" />

<Engine name="Catalina" defaultHost="www.domain2.com">

<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>

    <Host name="repo.domain2" appBase="domain/repo.domain2.com"
        unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">
    </Host>

    <Host name="www.domain2.com" appBase="domain/www.domain2.com"
        unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">
        <Alias>domain2.com</Alias>
    </Host>

    <Host name="www.domain3.com" appBase="domain/www.domain3.com"
        unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">
        <Alias>domain2.com</Alias>
    </Host>

</Engine>

curl - GET single file

Curl is simple yet powerful tool for creating HTTP and FTP requests of all kind. I have permanent problem with simple getting file with curl and storing in to file system. This little post should remember it to me. Basically works like this:
curl -v --location --max-redirs 10 \
 --output install_1.3.0.sql \
 http://somesite.com/somefile.sql
One trick is to use --location which tell to curl to follow redirects until number of redirect reach value specified in --max-redirs. Second trick is to specify output file in --output. When output file is not specified retrieved data are send to console (STDOUT).

Monday, October 14, 2013

Compile maven project for Java 1.4

I had problem with configuring maven. I want to compile some project to Java 1.4. After some I found following configuration which is really working:

<!--
  Strictly speaking, we did not need to generate this for you from
  the prototype, but we use it to illustrate how you can get
  the JDK 6 Java compiler to accept 1.5 or 1.6 targeted source code
  but produce class files that are compatible with JRE 1.4. As
  Michael Caine might not say, "Not a lot of people know that!"
  -->
<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
        <source>1.6</source>
        <target>jsr14</target>
        <sourceDirectory>src</sourceDirectory>
    </configuration>
</plugin>

It's not my idea. I wrote down this example long time ago. Now I can't found place where I originally found it. Sorry.

Wednesday, October 2, 2013

Linux server response times

Before few days I had problem with response times on linux server. I use CentOS. There is apache HTTPD covering about 5 tomcat instances. Inside tomcat instances are 7 different application. Main problem was incredibly slow responses from all pages. When I logged in I seen this:
top - 22:37:01 up 104 days,  7:59,  1 user,  load average: 3.59, 5.09, 3.33
Tasks: 103 total,   1 running, 102 sleeping,   0 stopped,   0 zombie
Cpu(s): 15.7%us,  0.1%sy,  0.0%ni, 84.1%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1018236k total,   988976k used,    29260k free,     1012k buffers
Swap:  2064344k total,  1031440k used,  1032904k free,    20592k cached

meaning of wa is waiting for I/O to complete. I also tried to order processes in top command by used memory "shift + f" and press n and than Enter. After that I run following:

ps axf show among other following problem:

 5627 ?        Ss     0:03 /usr/sbin/httpd
...
10289 ?        D      0:00  \_ /usr/sbin/httpd

It says that HTTPD is waiting for finishing disk IO operation. After checking memory consumption 988976k + 1031440k was clear that all tomcats eat about 2 Gb of memory and there is only 1 Gb of physical memory.

Than it was simple I just reconfigured all tomcats, so now I have just two. One is for critical application and second one contains all resting applications. And after restart response times are again good.

Sunday, September 1, 2013

maven site-deploy - [ERROR] Unsupported protocol: 'scp'

During executing
mvn site-deploy
I met strange error.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:2.4:deploy (default-deploy) on project 
cubiculus-interface: Unsupported protocol: 'scp': Cannot find wagon which supports the requested protocol: scp: java.util.NoSuchElementException
I didn't found anything about this problem on net. So hopefully it will by useful for someone. My problem was in maven-site-plugin which was in version 2.4. This works fine with maven 2.* but not with maven 3.*. Solution is to remove plugin explicit versioning or use version 3.2 like this:

 maven-site-plugin
 3.2

Friday, August 30, 2013

svn: E160005: Invalid control character '0x08' in path 'dist.xml'

When following errors appears during SVN committing:
svn: E160005: Invalid control character '0x08' in path 'dist.xml'
than problem is 'dist.xml' file name. File name contains some invisible character that cause this problem. Solution is to rename file.