Tomcat, web.xml and "[xX][mM][lL]" is not allowed

Problem

So, I had the following issue when trying to run my web application from Eclipse deploying to a local Tomcat.

The processing instruction target matching "[xX][mM][lL]" is not allowed.

Solution

It turned out that I had an empty line at the beginning of my web.xml!

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Incremental Backups on Ubuntu using Duplicity with Samba

Based on Ubuntu 12.04, Samba client [1] and Duplicity [2].

  • Mount samba (see [1])
    • install cifs-utils
      sudo apt-get install cifs-utils
    • create file /home/your_username/Documents/.backup-samba-credentials with content

      username=your_samba_username 
      password=***
    • create mount directory

      mkdir /home/your_username/backup
    • edit /etc/fstab

      # samba - backup - kali
      //samba_server_ip/your_samba_username       /home/your_username/backup     cifs    credentials=/home/your_username/Documents/.backup-samba-credentials,uid=1000,gid=1000,noauto,users     0       0

      You can get the uid and the gid via

      id -u your_username # the uid
      id -g your_username # the gid
    • Now you can mount and unmount:
      mount /home/your_username/backup # mount
      umount /home/your_username/backup # unmount
  • Run the following script which uses duplicity [2]:
    BACKUP_FOLDER=/home/your_username/backup
    SOURCE_FOLDER=/media/data/content
    FULL_BACKUP_INTERVAL=2W
     
    echo "Mounting backup folder: $BACKUP_FOLDER"
    mount $BACKUP_FOLDER
     
    echo "Sleeping for a few seconds."
    sleep 3
     
    echo "Backing up: $SOURCE_FOLDER"
    COMMAND="duplicity --full-if-older-than $FULL_BACKUP_INTERVAL $SOURCE_FOLDER file://$BACKUP_FOLDER"
    $COMMAND
     
    echo "Sleeping for a few seconds."
    sleep 3
     
    echo "Unmounting backup folder: $BACKUP_FOLDER"
    umount $BACKUP_FOLDER
VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

On first glance this seems to be a nice tutorial for circular replication in MySQL:
http://dba.stackexchange.com/questions/17529/setting-circular-replication-in-mysql

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

MyBatis, MySQL and Zero Dates

I was using MyBatis together with MySQL, now I kept getting something like

13:42:32.681 [main] DEBUG o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
Exception in thread "main" org.springframework.dao.TransientDataAccessResourceException: 
### Error querying database.  Cause: java.sql.SQLException: Value '
6181070861^L39078830@N04^S0000-00-00 00:00:00   13.371369       52.515972^@^@' can not be represented as java.sql.Timestamp
### The error may exist in de/uniwue/dmir/flickr/db/mapper/FlickrMapper.java (best guess)
### The error may involve de.uniwue.dmir.flickr.db.mapper.FlickrMapper.retrieve-Inline
### The error occurred while setting parameters
### SQL: SELECT id, owner, datetaken, longitude, latitude, tags FROM photo ORDER BY datetaken DESC LIMIT ?
### Cause: java.sql.SQLException: Value '
6181070861^L39078830@N04^S0000-00-00 00:00:00   13.371369       52.515972^@^@' can not be represented as java.sql.Timestamp
; SQL []; Value '
6181070861^L39078830@N04^S0000-00-00 00:00:00   13.371369       52.515972^@^@' can not be represented as java.sql.Timestamp; nested exception is java.sql.SQLException: Value '
6181070861^L39078830@N04^S0000-00-00 00:00:00   13.371369       52.515972^@^@' can not be represented as java.sql.Timestamp
        at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:107)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
        at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:71)
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:364)
        at sun.proxy.$Proxy8.selectList(Unknown Source)
        at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:194)
        at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:114)
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:58)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)
        at sun.proxy.$Proxy12.retrieve(Unknown Source)
        at de.uniwue.dmir.flickr.db.FlickrDbDao.retrieve(FlickrDbDao.java:19)
        at de.uniwue.dmir.flickr.Flickr.main(Flickr.java:90)
Caused by: java.sql.SQLException: Value '
6181070861^L39078830@N04^S0000-00-00 00:00:00   13.371369       52.515972^@^@' can not be represented as java.sql.Timestamp
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
        at com.mysql.jdbc.ResultSetRow.getTimestampFast(ResultSetRow.java:1102)
        at com.mysql.jdbc.BufferRow.getTimestampFast(BufferRow.java:576)
        at com.mysql.jdbc.ResultSetImpl.getTimestampInternal(ResultSetImpl.java:6592)
        at com.mysql.jdbc.ResultSetImpl.getTimestamp(ResultSetImpl.java:6192)
        at com.mysql.jdbc.ResultSetImpl.getTimestamp(ResultSetImpl.java:6230)
        at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:59)
        at sun.proxy.$Proxy17.getTimestamp(Unknown Source)
        at org.apache.ibatis.type.DateTypeHandler.getNullableResult(DateTypeHandler.java:36)
        at org.apache.ibatis.type.DateTypeHandler.getNullableResult(DateTypeHandler.java:25)
        at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:51)
        at org.apache.ibatis.executor.resultset.FastResultSetHandler.getPropertyMappingValue(FastResultSetHandler.java:325)
        at org.apache.ibatis.executor.resultset.FastResultSetHandler.applyPropertyMappings(FastResultSetHandler.java:306)
        at org.apache.ibatis.executor.resultset.FastResultSetHandler.getRowValue(FastResultSetHandler.java:275)
        at org.apache.ibatis.executor.resultset.FastResultSetHandler.handleRowValues(FastResultSetHandler.java:221)
        at org.apache.ibatis.executor.resultset.FastResultSetHandler.handleResultSet(FastResultSetHandler.java:193)
        at org.apache.ibatis.executor.resultset.FastResultSetHandler.handleResultSets(FastResultSetHandler.java:159)

The problem were timestamps with value 0000-00-00 00:00:00 as mentioned by a Stackoverflow entry (source: MySQL Manual):

Datetimes with all-zero components (0000-00-00 ...) — These values can not be represented reliably in Java. Connector/J 3.0.x always converted them to NULL when being read from a ResultSet.

Connector/J 3.1 throws an exception by default when these values are encountered as this is the most correct behavior according to the JDBC and SQL standards. This behavior can be modified using the zeroDateTimeBehavior configuration property. The allowable values are:

exception (the default), which throws an SQLException with an SQLState of S1009.
convertToNull, which returns NULL instead of the date.
round, which rounds the date to the nearest closest value which is 0001-01-01.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Arduino - Serial Port not visible

I was trying to upload some firmware to an Arduino board. There are several places which give good hints on this.

It boils down to:

sudo usermod -a -G dialout yourusename

And then

logout and login

.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

R - global settings for packages

I was trying to create a function with default values which could be set from outside the package (this is probably bad practice, but it took me so long to figure this out, I just had to write it down).

In package "example"

# package: example
default.value = "internal value"
example.print <- function(text = default.value) {
    print(text)
}

My code

# import package
library("example")
 
# assign default value
default.value <- "my new value"
 
# run function from package
example.print()

This does not work. The output is [1] "internal value". Yet, I found a way to get this to work:

In package "example"

# package: example
default.value = "internal value"
example.print <- function(text = get("default.value", envir = globalenv())) {
    print(text)
}

Now, this returns [1] "my new value", but ignores the default value from the package. Here is my final solution based on options:

My code

# import package
library("example")
 
# assign default value
options(default.value = "my new value")
 
# run function from package
example.print()

In package "example"

# package: example
default.value = "internal value"
example.print <- function(text = getOption("example.default.value", default = default.value)) {
    print(text)
}
VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Project Specific Maven Repository

If often come across Java libraries which I cannot find in a Maven repository. Now, this can be solved by adding these libraries to the project directly. How can this be done? This link gives a few ideas:

Summary

Here I will summarize the method I liked best:

Add this to the repository section of the pom.xml:

<repository>
    <id>repo</id>
    <releases>
        <enabled>true</enabled>
        <checksumPolicy>ignore</checksumPolicy>
    </releases>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
    <url>file://${project.basedir}/repository</url>
</repository>

Create the following folder structure in your project:

reposoitory/
| - x/
|   | - y/
|   |   | - z/
|   |   |   | - ${artifactId}/
|   |   |   |   | - ${version}/
|   |   |   |   |   | - ${artifactId}-${version}.jar

Then you can refer to the library by adding this to the dependencies section of the pom.xml:

<dependency>
	<groupId>x.y.z</groupId>
	<artifactId>${artifactId}</artifactId>
	<version>${version}</version>
</dependency>

And that's it.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Apache, Tomcat and Gzip

I wanted GZipped packets arriving at the Apache Http Server to be uncompressed and redirected to Tomcat. I am now using :

  • mod_proxy_http, to connect Apapche with Tomcat and
  • mod_deflate, to uncompress incoming requests.

I am running a Ubuntu. Let us say we are running a webapp at http://localhost:8080/test. I did the following to setup my system:

I enabled the mods.

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod deflate

I edited proxy.conf.

sudo vim /etc/apache2/mods-enabled/proxy.conf

I added these lines:

ProxyPass / http://localhost:8080/test/
ProxyPassReverse / http://localhost:8080/test/

I edited deflate.conf.

sudo vim /etc/apache2/mods-enabled/proxy.conf

All I added here was:

<Location /url/to/uncompress/requests/for>
        SetInputFilter DEFLATE
</Location>

Well, that's it. Finally, run:

sudo /etc/init.d/apache2 restart

Details: My Story

Well, first thing is to decide which approach to take to connect Apache and Tomcat. I found three options:

  • mod_jk
  • mod_proxy_http
  • mod_proxy_ajp

There are comprisons between the three:

  • http://www.tomcatexpert.com/blog/2010/06/16/deciding-between-modjk-modproxyhttp-and-modproxyajp
  • http://stackoverflow.com/questions/1081918/apache-to-tomcat-mod-jk-vs-mod-proxy
  • http://higherlogic.com.au/2010/http-vs-mod_proxy_ajp-vs-mod_jk-part-1-speed/

I went for mod_jk. However, in combination with mod_deflate, this does not work since mod_deflate does not change the Content-Length header field after uncompressing. This results in the uncompressed content being longer than specified by the Content-Length. mod_jk will then only send data to Tomcat until the output reaches the Content-Length. The rest of the message is truncated.

This behvior is filed as a bug:
https://issues.apache.org/bugzilla/show_bug.cgi?id=34526

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Disable CheckDisk

I have been working with an SSD hard drive. All the sudden Windows reported some problems resulting in a CheckDisk run. This process scrambled and moved a lot of file without any file extensions to found.xxx folders. So just in case I was looking for a way to disable automatic executions of CheckDisk and found these two solutions at a microsoft support board.

Registry:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager
In the right hand pane, double click BootExecute.
The default value of the key is autocheck autochk *
* means every drive is checked for consistency. Just add /K:C at the end before *. /K switch will disable autocheck on C: drive at Windows startup. So the final value should look like this:
autocheck autochk /k:C *
If you want to add more drives, the key should look like this: (disabling C and D drives)
autocheck autochk /k:C /k:D *
If you want to restore everything to default, just replace the key with the default one i.e.
autocheck autochk *

chkntfs:

There are some people suggested to edit the registry but the proper way to disable CHKDSK from starting up is using the /x switch on chkntfs command in command prompt. The /x switch will exclude a drive from the default boot-time check. If you have drive C: as your hard drive, then the command to disable chkdsk from scanning C: drive would be:
chkntfs /x c:
If you have 2 drive, C and D, you can disable chkdsk with the command below
chkntfs /x c: d:
then go ahead and reboot.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

tn5250j: a 5250 terminal emulator for the AS/400

For archiving purposes:
The tn5250j is a 5250 terminal emulator for the AS/400 written in Java.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)