merry christmas
Thursday, December 24, 2009 at 5:07PM 
The christmas number one 2009 in England, covered by Mambo Kurt.
And here is the original version by Rage Against the Machine. Still pretty fresh, even though it's 17 years old.
But Hitler is a Joe McElderry and X-Factor fan.
Mailadressen validieren mit ruby
Wednesday, December 9, 2009 at 11:27PM In meinem Twitterstream ist heute eine Frage nach automatisierter Email-Validation aufgetaucht. Ich hab vor längerem ein kleines, sehr einfaches ruby-Script geschrieben, dass eine Liste von Mailadressen überprüft, indem es den MX-Record des hostteils (der Teil hinter dem @) auflöst und dann versucht, sich an den ersten rausgefundenen Mailserver auf dem SMTP Port zu verbinden. Eine Adresse gilt als valid, wenn beides funktioniert. Nun ist das natürlich ein sehr oberflächlicher Test, weil ja nur der hostteil der Adresse überprüft wird, und das Script spricht auch kein smtp mit dem Server, sondern schaut nur, ob man sich an Port 25 verbinden kann. Trotzdem kann man damit einen Grossteil von Adressen, die zwar der Form entsprechen, aber invalid sind, rausfiltern. Ich bin auch nicht sicher, ob kommerzielle Email-Validation-Software da gross etwas anderes macht(?).
Jedenfalls, falls wieder einmal jemand so etwas braucht: Hier ist das Script (Bis ich das File rausgesucht hatte war der Fragesteller schon manuell durch... :/). Man kann das natürlich sehr leicht so erweitern, dass die Mailadressen aus einem File gelesen werden.
require 'rubygems'
require 'net/dns/resolver'
require 'socket'
include Socket::Constants
def is_valid?(address)
return false if address.count("@") != 1
packet = Net::DNS::Resolver.start(address.split("@").last, Net::DNS::MX)
mx = packet.answer.first
return false if mx.nil?
sock = TCPSocket.new(mx.exchange[0..-2], 25)
if (sock) then
sock.close
return true
end
return false
end
#only the first is valid
addresses = ["spam@mgroh.net", "foo@bla.blub", "nomail@example.com"]
valid_addresses = addresses.map{|a| a if is_valid?(a)}.compact
puts valid_addresses
JSON and REST with Spring 3.0
Friday, November 27, 2009 at 12:28AM The version 3 of the Spring framework, which is available as ReleaseCandidate2 now, brings some nice new features for developers who want to add RESTful web services to a Java web project. I feel it offers a real alternative to the different JAX-RS implementations, because you need less code and less (but still a bit, it's spring after all :)) configuration of xml files, especially if you use spring anyway.
Interesting enough, Springsource (the company behind spring) decided to add this feature to the spring-mvc project, not spring-ws. The reason behind this is that "There were a number of technical issues [...] most importantly the approach felt 'clunky' and unnatural for a developer who was already used to Spring MVC 2.5." (as stated here, which is a nice introduction to the new REST features in spring 3 btw).
Version 3.0 of spring-mvs adds, among other things, a view to render JSON representations of your data objects: the JacksonJsonView. Regarding the growing number of rich javascript frontends built with jQuery et al, this of particular interest. As the name suggests, this view relies on the Codehaus Jackson JSON processor, a parser and generator which is especially known to be really fast. While there were some third-party solutions to add JSON support to spring based webapps before (http://spring-json.sourceforge.net for example, to name just one of them), it is nice to have this feature in the framework itself.
To use the JacksonJsonView, you need the current spring-mvc and spring-aop artifacts (3.0.0.RC2 by the time of this writing), and the jackson mapper 1.3.0. The maven dependencies are:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.0.0.RC2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.0.0.RC2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
As spring 3 has not yet been released, (the current version is RC2), you need to add the spring maven repo to your pom file as well:
<repositories>
<repository>
<id>springsource maven repo</id>
<url>http://maven.springframework.org/milestone</url>
</repository>
</repositories>
Spring 3 adds the possibility to use content negotiation by URI and Accept HTTP header to determine which representation to return via the ContentNegotiatingViewResolver, which is a elegant way to support multiple data representations(JSON, XML, RSS, Atom...). But to keep things simple I assume we only want to render JSON and are using the XmlViewResolver. (You can find more on views and view resolving in spring mvc in the spring documenation).
This means your servlet application context might look like this:
<beans>
<!!-- Search for annotated controllers in the package net.mgroh.www.foo.ctrl -->
<context:annotation-config />
<context:component-scan base-package="net.mgroh.www.foo.ctrl" />
<!!-- Map handler methods on HTTP paths with RequestMapping etc -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<!!-- Use the XmlViewResolver -->
<bean name="viewResolver" class="org.springframework.web.servlet.view.XmlViewResolver"/>
</beans>
And you have the following in a file named views.xml:
<beans>
<bean name="jsonView" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
</beans>
You can then implement a Controller serving a JSON representation of an object Foo like this:
@Controller
public class FooController {
@RequestMapping(value = "/foo/{fooid}", method = RequestMethod.GET)
public ModelAndView findFoo(@PathVariable String fooid) {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("jsonView");
modelAndView.addObject(new Foo());
return modelAndView;
}
And that's all what you need to implement a RESTful Web Service with Spring MVC.
In Spring 3 there is a lot more which makes it a easy to use (if you know spring, obviously) and (relatively) lightweight framework for implementing RESTful Web Services in the Java world. A good starting point is this article I mentioned before and the Spring documentation of course.


