Transformatorhuis

September 2, 2009

Geronimo HTTPS, self signed keys and implementation in Java

Filed under: Coding, Configuration — Tags: , , , — cyberroadie @ 10:19 am

Geronimo

  • Create key in Geronimo (setup certificate)
  • CN needs to be the server name (e.g www.wordpress.com)
  • Create new Keystore (e.g wordpress)
  • In keystore create private key, again CN needs to be server name
  • Add Trust Certificate (copy paste it from the one you created before)
  • In Web Server edit the HTTPS listener and change the keystore file to the on you create before (e.g wordpress)
  • Optional: change address to fixed ip of server

Get certificate

In firefox got to https address -> Add exception -> Get Certificate -> View ->
Details -> Export: export certificate (PEM will do) (e.g. www.wordpress.com)

Shell

keytool -import -trustcacerts -storepass secretphrase -alias “Apache Geronimo Dev” -file www.wordpress.com.cer

The keystore is created in default location ${home}/.keystore

Java

System.setProperty("javax.net.ssl.trustStore", "/home/user/.keystore");
System.setProperty("javax.net.ssl.trustStorePassword","secretphrase");
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

PS Of course it shouldn’t be a static url (/home/user/.keystore), but this is for simplicities sake

January 27, 2009

Customizing hbm2java (Freemarker & Maven)

Filed under: Coding, Configuration — cyberroadie @ 4:24 pm

Copy the freemarker templates out the the hibernate-tools.jar into you maven directory tree (${basedir}).
In maven:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<componentProperties>
    ...
    <templatepath>${basedir}/templates</templatepath>
    <template>${basedir}/templates/pojo/Pojo.ftl</template>
</componentProperties>
</plugin>

The template needs to refer to the parent template, the rest is included automaticly.

Howto customize the freemarker templates

Example:
To pick up from a hibernate template (*.hbm.xml):

<property column="TestField" type="integer" name="testField">
    <meta attribute="annotation">@XmlElement</meta>
</property>

And generate:

@XmlElement
private Integer testField;

Add this in PojoFields.ftl:

<#if pojo.hasMetaAttribute(field, "annotation")>
${c2j.getMetaAsString(field, "annotation","\n")}
</#if>
${pojo.getFieldModifiers(field)} ${pojo.getJavaTypeName(field, jdk5)} ${field.name}<#if pojo.hasFieldInitializor(field, jdk5)> = ${pojo.getFieldInitialization(field, jdk5)}</#if>;
</#if>

May 5, 2008

Adding dependecies to Cargo Maven plugin

Filed under: Configuration — cyberroadie @ 9:40 am
Documented here (on the Cargo wiki)

This was to resolve a dependency clash between an old Sax parser implementation introduced via the CeWolf library.
CeWolf used crimson which doesn't support XML schema parser. For some reason the whole maven framework (cargo included) started to use this parser as the
default one instead of using the 'new' Xerces one, generating the following error:

javax.xml.parsers.ParserConfigurationException: Unable to validate
using XSD: Your JAXP provider[org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@ 302e67] does not
support XML Schema. Are you running on Java 1.4 or below with Apache
Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD support.


So to circumvent this I had to add the 'new' dependencies to the pom.xml in two places; the normal dependency place and in the cargo-maven plugin)

(the correct version of the libraries is taken from the dependencies elsewhere in the pom.xml
<plugin>
                        <groupId>org.codehaus.cargo</groupId>
                        <artifactId>cargo-maven2-plugin</artifactId>
                        <version>0.3</version>
                        <configuration>
                            <wait>${cargo.wait}</wait>
                            <container>
                                <containerId>${cargo.container}</containerId>
                                <home>${cargo.container.home}</home>
                                <dependencies>
                                    <dependency>
                                        <groupId>xerces</groupId>
                                        <artifactId>xercesImpl</artifactId>
                                    </dependency>
                                    <dependency>
                                        <groupId>xalan</groupId>
                                        <artifactId>xalan</artifactId>
                                    </dependency>
                                </dependencies>
                                <systemProperties>
                                    <javax.xml.parsers.DocumentBuilderFactory>
                                        org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
                                    </javax.xml.parsers.DocumentBuilderFactory>
                                    <javax.xml.parsers.SAXParserFactory>
                                        org.apache.xerces.jaxp.SAXParserFactoryImpl
                                    </javax.xml.parsers.SAXParserFactory>
                                </systemProperties>
                                <zipUrlInstaller>
                                    <url>${cargo.container.url}</url>
                                    <installDir>${installDir}</installDir>
                                </zipUrlInstaller>
                            </container>
                            <configuration>
                                <home>${project.build.directory}/${cargo.container}/container</home>
                                <properties>
                                    <cargo.hostname>${cargo.host}</cargo.hostname>
                                    <cargo.servlet.port>${cargo.port}</cargo.servlet.port>
                                </properties>
                            </configuration>
                        </configuration>

March 15, 2008

Apache Virtual Host on Gentoo

Filed under: Configuration — cyberroadie @ 8:26 am

Create dirctories:

mkdir /var/www/dragon3d.cyberroadie.org/
mkdir /var/www/dragon3d.cyberroadie.org/htdocs

Create file /etc/apache2/vhosts.d/00_dragon3d.cyberroadie.org.conf

ServerName dragon3d.cyberroadie.org
ServerAlias dragon3d.cyberroadie.org
DocumentRoot "/var/www/dragon3d.cyberroadie.org/htdocs"
Options Indexes FollowSymLinks
AllowOverride None Order allow,deny
Allow from all
## Redirecting should be done here
# ProxyPass /jira http://dragon3d.cyberroadie.org:8080/jira
# ProxyPassReverse /jira http://dragon3d.cyberroadie.org:8080/jira
SuexecUserGroup treee users
CustomLog /var/log/apache2/dragon3d.cyberroadie.org.log combined

Restart apache, done!

Olivier

March 2, 2008

CVS on top of GIT

Filed under: Configuration — cyberroadie @ 10:23 am

Since none of the continuous integration tools support git I had to find a workaround. Fortunately git can emulate a cvs server via xinetd and git-cvs-server.

Some small configurations:

/etc/xinetd.d/git-cvs-server:

service git-cvsserver
{
disable = no
socket_type = stream
wait = no
user = nobody
type = UNLISTED
protocol = tcp
log_on_failure += USERID
server = /usr/bin/git-cvsserver
port = 2401
server_args = git-cvsserver pserver –export-all –base-path=/var/git
}

Added to the config file of the repos:

[gitcvs "ext"]
enabled=1
logfile=/var/log/gitcvs

(Log file needs proper write access, otherwise all cvs action will fail)

On the client:
# export CVSROOT=:ext:cyberroadie@www.cyberroadie.org:/var/git/example.git
# export CVS_SERVER=git-cvsserver
# cvs co -d example master

Voila, cvs emulation :-)

Olivier

March 1, 2008

Setup Spring MVC project + debug with appfuse

Filed under: Configuration — cyberroadie @ 9:29 am

Followed this page: Archetypes list on codehouse

(Tip: in the conf/settins.xml file in your MAVEN_HOME directory, you can add: C:\.m2
to change repository path, prevents of dos related long path problems)

Create the project:
# mvn archetype:create -DgroupId=net.transformatorhuis.admin -DartifactId=th-admin -DarchetypeArtifactId=appfuse-modular-spring -DarchetypeGroupId=org.appfuse.archetypes

Get all the source (good for debugging and studying):
# mvn appfuse:full-source

Compile/test/package project:
# mvn install

Install MySQL database:
#mysql> create database th_admin
#mysql> grant all privileges on th_admin.* to th_admin@’%’ identified by ‘password’;

Make sure in MySQL config file (my.cnf) bind-address is not set to localhost (127.0.0.1), this to accept external connections.

In pom.xml change the jdbc username/host/password

Create Intellij IDEA project file:
# mvn idea:idea

Create run script with debugging enabled in web/ directory (run_jetty_debug.sh):
#!/bin/bash
export MAVEN_OPTS=”-Xmx1024m -Xms512m -Xdebug \ -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005″
mvn jetty:run

Add in Intellij a Remote session in The Run /Debug configuration, the debug line must be the same as the MAVEN_OPTS above.

In the web/ director execute ./run_jetty_debug.sh

In Intellij: set your breakpoints and start debugging via browser: http://localhost:8080/

TIP: No need to restart mvn jetty:run if you compile (mvn compile) or change configuration files of th application. Jetty automaticly picks them up :-)

Olivier

February 26, 2008

Linux Raid Recovering

Filed under: Configuration — cyberroadie @ 8:29 am

Remove disk:
# mdadm /dev/md2 –fail /dev/hda3

Add disk:
# mdadm /dev/md2 -a /dev/hda3

Check rebuild status:
# wacth -n 0.1 ‘cat /proc/mdstat’

Stop raid device
# mdadm /dev/md2 –stop

Start raid devices (config in /etc/mdadm.conf)
# mdadm -A -s

Bandwidth conversion

Recovering RAID

Blog at WordPress.com.