Doorgaan naar hoofdcontent

Posts

UTF codepoints in Java

So, we needed to do some UTF-8 code matchings. And someone grabbed the proper UTF-8 document and was talking code points. And then you notice that java 7 has no nice way to determine code points... *really*, it's only been 7 versions and it's still not well. At least, a snippet to show the proper code point:     public static String printCharacters(final String s) {         for (final int codepoint : codePoints(s)) {             // we need Character.toChars and new String since we cannot call back to the specific character from the string from the iterator.              System.out.println(new String(Character.toChars(codepoint)) + "is of type: "+ typeToString(Character.getType(codepoint));         }     }     /** java 7 doesn't have a nice support for determining code points. Java 8 does... */     publ...

Spring-ws and spring-mvc combined

Sometimes we want to use both spring-ws and spring-mvc in one application. However, these are two different stacks. To use them combined is a bit of a hassle, and... lest I forget, this post. The following needs to be set in the applicationcontext: <!-- To nicely support webservices from httprequests, we use the WebServiceMessageReceiverHandlerAdapter (which needs a messagefactory) --> <!-- Because we declare this, the dispatcherservlet automatically uses it... instead of the normal mvc adapter! --> <!-- To ensure that the normal mvc adapter is also loaded, we need to define it (the SimpleControllerHandlerAdapter) as well. --> <!-- Requires a message factory so we declare one --> <bean class="org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter">   <property name="messageFactory" ref="messageFactory" /> </bean> <bean id="messageFactory" class="org.springframework.ws....

Pure java browser

Since I'm going to forget this if I don't write it down, in some cases you really want to test 'as if you're using a browser'. I.e. open a webpage, click on this link... The project you're looking for is HtmlUnit Haven't played around with it too much, but it's pure java - no browser necessary. If you want to use a browser, and 'drive' around with it, use selenium (it can spawn a Firefox/chrome browser, let it open pages, etc.)

Git undo commit

As always, I commit way too quickly to my local repository, and then automatically push it, only to find out that i've done it wrong... There are two commands to know: git reset --hard [commit id] Returns your local repository to the specified commit id (assuming you're using the current branch) git push [repository] +[commit id]:[branchname] Returns the remote repository to the commit id. When executing both, you both reset the remote, and local repository to the specified commit... as if the rest never happened (well, it's there, but you don't see it... that's a different story)

Annotation scanning done easy

We all love annotations. Really, they're nice markers for your pointcuts, create the option to have cross cutting concerns easily (i.e. only log these marked fields, or mask these annotated fields when logging). However, we do need to be able to *get* to those annotations at runtime to inject those fancy tricks we have up our sleeve. In comes the beautiful google reflections library which allows us to scan the class files for annotations. Of course, we made those annotations available at runtime, right? If not, add @Retention(RetentionPolicy.RUNTIME) to the annotation ;) So, scanning at runtime done easy: Collection<URL> urls = ClasspathHelper.forPackage("nl.shopname.location.domain");   Reflections reflections =                 new Reflections(new ConfigurationBuilder().setUrls(urls).setScanners(new FieldAnnotationsScanner())); Set<Field> fieldsWithAnnotation = <reflections.getF...

Proper Ctrl-tabbing in Eclipse

I'm one of those guys who uses TabMixPlus for my Firefox, since I like the behaviour of Ctrl-Tab to be like Windows-Tab, i.e. jump to previously opened tab. You also want this in eclipse, right? So, modify the key bindings in Window->preferences->keys and modify the 'next editor' to Ctrl-Tab ... and 'previous editor to Ctrl-Shift-Tab. Voila! (it'll also show a small window in the order of which the tabs were opened... that's just gravy ;) )