lauantai 21. huhtikuuta 2012

Jetty 8 and memcached sessions

Today I changed Uutispuro into using memcached as a session store.


Basically I followed the instructions from https://github.com/yyuu/jetty-nosql-memcached with minor tweaks.

etc/jetty.xml



  <Set name="sessionIdManager">
    <New id="memcachedSessionIdManager" class="org.eclipse.jetty.nosql.memcached.MemcachedSessionIdManager">
      <Arg><Ref id="Server" /></Arg>
      <Set name="serverString">localhost:11211</Set>
      <Set name="keyPrefix">session:</Set>
    </New>
  </Set>
  <Call name="setAttribute">
    <Arg>memcachedSessionIdManager</Arg>
    <Arg><Ref id="memcachedSessionIdManager" /></Arg>
  </Call>




contexts/uutiset.xml




  <Ref name="Server" id="Server">
    <Call id="sessionIdManager" name="getAttribute">
      <Arg>memcachedSessionIdManager</Arg>
    </Call>
  </Ref>
  <Set name="sessionHandler">
    <New class="org.eclipse.jetty.server.session.SessionHandler">
      <Arg>
        <New id="memcachedSessionManager" class="org.eclipse.jetty.nosql.memcached.MemcachedSessionManager">
          <Set name="sessionIdManager">
            <Ref id="sessionIdManager" />
          </Set>
        </New>
      </Arg>
    </New>
  </Set>

At the moment I have two jetty's running and I can stop each one of them at any time and user stays logged in as nothing has happened.

sunnuntai 22. tammikuuta 2012

Jetty 8 and using ssl with jetty:run

<plugin>
  <groupid>org.mortbay.jetty</groupid>
  <artifactid>jetty-maven-plugin</artifactid>
  <version>8.0.4.v20111024</version>
  <configuration>
    <scanintervalseconds>5</scanintervalseconds>
    <webappconfig>
      <contextpath>/</contextpath>
    </webappconfig>
    <connectors>
      <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <port>8080</port>
      </connector>
      <connector implementation="org.eclipse.jetty.server.ssl.SslSocketConnector">
        <port>8443</port>
        <keystore>/etc/keystore/keystore</keystore>
        <keypassword>password</keypassword>
        <password>password</password>
      </connector>
   </connectors>
</configuration>
</plugin>

Add this to your pom.xml inside <build> and <plugins> tags.
Of course you also need to have keystore in place. See Jetty/Howto/Configure_SSL.

lauantai 21. tammikuuta 2012

Spring-security start project with mongodb

I started up making a custom signup && login to Uutispuro and it was working nicely. A Couple of years ago I looked at spring-security for this, but it seemed like an overblow. When Spring 3.1 was out, I happened to look at spring-security again. And I tried it. No turning back now :)

I made a small start project to github: springsecuritylogin.

There is no ssl-support of course, you need to add to your application server. Handling sessions with memcached is something I'd still like to add. Maybe tomorrow ...

The project adds users with a signup page. Default role is ROLE_USER. You can modify a user to be an "ROLE_ADMIN" user by hand, and the index pages verifies the current role used.

torstai 17. marraskuuta 2011

Spring, Jetty 7 and jndi

jetty-env.xml needs to be in WEB-INF


<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
"http://www.eclipse.org/jetty/configure.dtd">
<Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext">
<New class="org.eclipse.jetty.plus.jndi.EnvEntry">
<Arg>jdbc/jndiname</Arg>
<Arg>
<New class="oracle.jdbc.pool.OracleDataSource">
<Set name="user">DBUSER</Set>
<Set name="password">DBPASSWORD</Set>
<Set name="URL">jdbc:oracle:thin:@URL</Set>
</New>
</Arg>
</New>
</Configure>


pom.xml:


<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
....


applicationContext:


<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/jndiname" />
</bean>

lauantai 14. toukokuuta 2011

How to find largest files on linux?

find . -type f | xargs ls -s | sort -rn | awk '{size=$1/1024; printf("%dMb %s\n", size,$2);}' | head -30

keskiviikko 2. maaliskuuta 2011

Googlebot, CookieLocaleResolver and default locale

Googlebot doesn't set a locale on request.

What does this mean? Well, in my case when I localized www.uutispuro.fi, googlebot only minded about english content. Even if I made different urls and sitemaps for webmaster tools.

Why such a behaviour? I'm using Spring's CookieLocalResolver, and ofcourse it had a default to en_US. This took a while for me to notice. Setting the default to "fi" does what I was expecting in the first place.


<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="fi"/>
</bean>

sunnuntai 10. lokakuuta 2010

jpa + hibernate + spring + c3p0 + hibernate-search pom.xml

Maven pom.xml file for a jpa, hibernate, spring, quartz, hibernate-search app.
Versions: jpa 2, Spring 3, hibernate 3.5, hibernate-search 3.2, c3p0 0.9.1.2

I have been using this for making a rss news site. I decided to share this if someone else is struggling with getting the versions match with hibernate-search and hibernate or getting the right dependencies with c3p0.

I'm using jetty and hsqldb for developing. In production, I have lighttpd in front of jetty and the production database is mysql which I'm using.
 


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fi.netbox</groupId>
<artifactId>news</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>news</name>
<description>Code</description>

<properties>
<spring.version>3.0.4.RELEASE</spring.version>
<hibernate.version>3.5.6-Final</hibernate.version>
<jetty.version>6.1.24</jetty.version>
<aspectj.version>1.6.0</aspectj.version>
<debug.level>DEBUG</debug.level>
</properties>

<dependencies>
<!-- Spring Dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.context.support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.transaction</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.web.servlet</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<version>3.2.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>3.2.4.GA</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>com.springsource.org.hsqldb</artifactId>
<version>1.8.0.10</version>
</dependency>
<dependency>
<groupId>com.mysql.jdbc</groupId>
<artifactId>com.springsource.com.mysql.jdbc</artifactId>
<version>5.1.6</version>
</dependency>
<!-- LOGGING DEPENDENCIES - LOG4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>

<!-- TestNG DEPENDENCY FOR TESTING -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.7</version>
<classifier>jdk15</classifier>
<scope>test</scope>
</dependency>

<!-- JETTY DEPENDENCIES FOR TESTING -->
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>6.1.24</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-management</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>com.springsource.javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>com.springsource.javax.servlet</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>com.springsource.javax.servlet.jsp</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>com.springsource.javax.servlet.jsp.jstl</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>com.springsource.javax.el</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.xmlcommons</groupId>
<artifactId>com.springsource.org.apache.xmlcommons</artifactId>
<version>1.3.4</version>
</dependency>

<dependency>
<groupId>com.sun.syndication</groupId>
<artifactId>com.springsource.com.sun.syndication</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>com.springsource.org.jdom</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>com.opensymphony.quartz</groupId>
<artifactId>com.springsource.org.quartz</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>com.mchange.c3p0</groupId>
<artifactId>com.springsource.com.mchange.v2.c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<build>
<finalName>news</finalName>
<resources>
<resource>
<filtering>false</filtering>
<directory>src/main/resources</directory>
</resource>
<resource>
<filtering>false</filtering>
<directory>src/main/config/${config.dir}</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.24</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>com.springsource.repository.bundles.release</id>
<name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/release</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.external</id>
<name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/external</url>
</repository>
<repository>
<id>jboss - public</id>
<name>jboss - public</name>
<url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
</repository>
</repositories>
</project>