Posts

Showing posts from 2013

Access jasper reports with URL authentication and remove jasper decoration for better integration

To give you some context recently while working on a new small project I needed to include a few Jasper Reports that where hosted in a Jasper Serverrepository. The main requirement was to include these reports in a lightweight application without the JAVA stack but using only HTML+JavaScript To my knowledge there are 3 ways to accomplish this : Allow anonymous access to a given URL pattern (I had some troubles working with this approach) Use Jasper's REST APIand authenticate through it (probably the cleaner way) Provide credentials in the URL (quick and dirty) :) For reasons outside the scope of this article I had to use the 3rd option and provide the credentials in the URL. Note : This is not a clean way to access the repository (especially as you may see the username and password are clear text) but sometimes there no way around it Jasper server uses spring under the hood to provide authentication/authorization so you can use the standard Java authentication mechanism, which b…

Create a runnable war with embedded tomcat or run a maven tomcat war project without maven and a tomcat installation

I know the title of this post is a bit of a contradiction, running a maven tomcat webapp without maven and a tomcat installation WTF?.So before we begin let me clarify what I mean. You will need maven on your development environment and you will be using the tomcat7 maven plugin to deploy and run your application-. When delivering a small to medium sized java web application it could be nice to have it as a self contained application allowing you to just drop-it anywhere and just run it without having to install/upgrade Maven, Apache Tomcat, etc. (of course you'll still need java :p )What I would like to accomplish is to develop a web application using my usual tools and stack and then deliver the application in it's most simple way, without having to install and configure tomcat and maven on the target system.Running a WAR project without a Tomcat installation is not very complicated you just use the maven tomcat plugin and run the appropriate goal (ex: tomcat7:run). But runn…

Multi-hop ssh tunnel - howto : Creating a SSH tunnel with port forwarding between multiple hosts

Image
How to create a multi-hop ssh tunnel or how to chain multiple ssh tunnels. (or SSH inception)For security reasons sometimes you need to jump through hoops in order to connect to a server in SSH and from that server SSH to another server and so on Consider the following scenario : An application is deployed on a tomcat server on the host3 and listens on the port 8080From my local machine I need to access the tomcat server on the machine host3 but it's not reachable from my machine I need to carry out some tests that need a graphical browser (Firefox, Chrome, etc.) host3 is only accessible from host2which is only accessible from host1SSH tunneling can help you in this scenario; you can find more information regarding here by forwarding requests on a given port to another port on another machine all through a (or in our case multiple)SSH connection(s) Below is a graphical representation of what I'm trying to accomplish : So without anymore delay let's get to it : All of th…

Devops mode - first steps using puppet to automate environment configuration and installation

So it has been some time since I was at the DevoxxFR 2 years ago and had the chance to assist a few presentations regarding this "obscure movement" called DevOps and even tough I'm always interested in new stuff to play around with, coming out of the conference my feeling was "meh, I'll try it out sometime later"... and I never did... But recently I got a task assigned : "install and configure a development and integration server" The requirements were the following : Java JDK7Apache MAVENApache ANTGITSubversion (SVN)Jenkins with the following plugins :Git plugin Apache MAVEN pluginApache ANT plugin Jenkins should run on a custom port namely port 9999Now I've done this several times and there's nothing really complicated about it. But usually when I do something more than a few times I try to find a way to automate things (apparently we developers are lazy by nature) As I'm no sysadmin or Linux expert and installing and configuring the…

Intellij change default encoding for properties and message bundle files to utf-8

Image
By default IntelliJ IDEA encodes Properties and Message bundle files using the System's default encoding (e.g. ISO-8859-1)

In my experience this is problematic since most frameworks out there use UTF-8 and most of the time you work in multi-platform environments.

If you are not careful and start writing say your i18n files with the default setting you'll be in hell when you realize that you have to save your files in UTF-8 for your favorite framework all your Properties files will probably become corrupt during the file-encoding conversion process.

This setting can be change either on the project level (this will affect only the current project) or on the IDE level (this will affect all new projects)

To change this setting on the IDE level just follow these easy steps :

File --> Other Settings --> Default Settings --> File Encodings Change the value of Default encoding for properties file to UTF-8 (or another one of your choice)
Now the default encoding for all y…

Intellij scala and SBT dependencies - enhancing the development experience

Image
I'm the happy owner of an Intellij Idea licence which I love, and as stated on a recent article I started learning Scala not long ago and I'm having some trouble to feel the SBT loveWhile playing a bit with Scala/SBT and IntelliJ I realized that the support for it is not great there are a few plugins bundled such as the SBT executor which adds some functionality, but no syntax highlighting for the .sbt files and more importantly no dependency management inside the IDE which for me is a deal breaker (Albeit since I'm pretty new to the Scala world I might be doing it wrong...)Luckily a few day ago I found this sbt plugin nightly builds which is a new IntelliJ plugin that will add some sugar to your Scala/SBT development such as dependency management.You will find all the installation instructions in the link above as well as information on the plugin features Now as stated on the website this plugin is still Alpha so there are still some rough edges and quircks. I for exampl…

Maven build number, versioning your projects builds automatically

By default all maven projects have a version number that you increase upon releases whether it's a minor or major release. When you are in a scenario in which you continuously deliver application (for example on a staging server) it's probably a good idea to have some unique build identifier so as to know the exact version that is deployed on the serverLuckily the guys over at codehaus have an app plugin just for that . I'm talking about the buildnumber-maven-plugin This plugins will generate a build identifier each time you compile your maven project and make this identifier available through a maven variable ${buildNumber}The plugin can generate build numbers in 3 ways : SCM (my personal favorite)Sequential build numberTimestampPersonally I prefer the SCM approach since it's coupled with your commits, and I will here I will be showing how to do that First you will have to configure the maven scm plugin with your details, otherwise you'll end up with error message…

Maven filtering test resources

When running tests in maven it's common usage to have configuration files that should be filtered.When filtering "normal" resources the syntax is the following : ... ${project.basedir}/src/main/resourcestrue ... Whereas when filtering test resources the syntax is following : ... ${project.basedir}/src/test/resourcestrue ... Otherwise your test resources will not be filtered

Scala sbt and np plugin type error in expression

I started learning scala a month or so ago, and I must say SBT is a bit of a pain to use to me ( Maven I miss you!!). I know you can use Maven to build your scala projects instead of SBT but I was trying to do it the "scala" way While trying to get started with a simple Hello World and I was having some issues while getting started using SBTWhen using SBT apparently it's a defacto standard to use the sbt np plugin to create a scala project skeleton. But after following the instructions on how to set-up SBT and the NP plugin I stumbled upon the following error when running sbt np: /home/ufasoli/.sbt/0.13/_settings.sbt:1: error: not found: value npSettings seq(npSettings:_*) ^ [error] Type error in expression From what I could read there were changes introduced in the sbt version 0.13 that changed the way plugins are configured. SBT's global configuration is now versioned which, from my understading means than instead of putting your global config files under …

Debugging a maven failsaife selenium build in intellij

Image
Recently I had to debug a set of Selenium tests using the failsafe plugin and the embedded tomcat7 plugin using Intellij Idea Usually you can just click on IDE's the debug button and Intellij will take care to launch the build and attach a debugger to the appropriate debug port: However this time it wasn't working I had 2 issues with my build : My breakpoints where completely ignored The maven build just kept waiting without exiting the project even once the integration tests where finished So I looked into the possible XML configuration tags for the failsafe plugin and thought that the <debugForkedProcess>true</debugForkedProcess> would be my salvation however I was wrong... So what's happening here ? By default, maven runs your tests in a separate ("forked") process. So when you set this property to true, the tests will automatically pause and await a remote debugger on port 5005 However this was not going happen since when you click on the IDE&…

Glassfish Cluster SSH - Tutorial : How to create and configure a glassfish cluster with SSH (Part 2)

3. Glassfish cluster configuration With our pre-requirements covered it's time to start configuring our cluster A. Enabling remote access on the glassfish servers By default the remote administration feature is disabled on the GlassFishServer This is to reduce your exposure to an attack from elsewhere in the network.So if you attempt to administer the server remotely you will get a 403 - Forbidden HTTP status as the response. This is true regardless of whether you use the asadmin command, an IDE, or the REST interface.You will need to start up the glassfish server on each one of your servers by executing the following command $GFISH_HOME/bin/asadmin start-domain domain1 Once the servers are up you can turn remote administration on running the following command locally in each one of the servers (please ensure the glassfish instance is running when you execute the command) and when prompted enter the appropriate user/password : $GFISH_HOME/bin/asadmin enable-secure-admin This c…

Glassfish Cluster SSH - Tutorial : How to create and configure a glassfish cluster with SSH (Part 1)

Image
0. Presentation A cluster is a named collection of GlassFish Server instances that share the same applications, resources, and configuration information. GlassFish Server enables you to administer all the instances in a cluster as a single unit from a single host, regardless of whether the instances reside on the same host or different hosts. You can perform the same operations on a cluster that you can perform on an unclustered instance, for example, deploying applications and creating resources. In this we will configure a 3 node Glassfish cluster using SSH and using only the command-line util asadmin. Below is a global picture of the target cluster structure : The following are the conventions/assumptions that will be used throughout this tutorial linux user : gfish glassfish domain : domain1 glassfish cluster name : myCluster 1. Pre-requirements A. SSH key configuration (Optional but used in this tutorial)In order for the different instances of glassfish to communicate easily…

Fix Did not receive a signal within 15.000000 seconds. Exiting... error message

Image
I have installed in my macbook pro OSXFuse with the NTFS-3G add-on and up until the MacOS Lion update I had no particular issues with itWith the Lion update I started getting the following error when mounting NTFS drives : Did not receive a signal within 15.000000 seconds. Exiting... This is a known issue and the NTFS drive was properly mounted and working despite the error message, but I found the error message pretty annoying.. luckily there's a solution to it. Head over to bfleischer's github fuse wait repo and follow the instructions to either install the patch manually (you'll need XCode to build the source file) or via a script that he has provided

ViewResolver vs MessageConverter Spring MVC when to use

Spring has lots of ways of handling view and content resolution, which is probably a good thing since it gives you flexibility but sometimes it can be a bit problematic. Full disclosure here I must admit I had never given much attention to all of the ways views could be resolved, usually I went with a ViewResolver for handling my views and that was it; until recently though... For one of my projects I needed some custom JSON handling so I had defined a custom ViewResolver by extending spring's org.springframework.web.servlet.view.json.MappingJackson2JsonView and defined as the default implementation for handling JSON views like so : Everything was working as expected until I had to annotate some methods with @ResponseBody and now every method with this annotation was not being processed by my custom ViewResolver and I couldn't understand why..As it turns out it's pretty simple (once you read the documentation again) when you annotate a method @ResponseBody spring will dele…

MongoDB spring data $elemMatch in field projection

Sometimes when querying a MongoDB document what you will actually need is an item of a given document's embedded collections The issue with MongoDB is that mongo will filter out only first level documents that correspond to your query but it will not filter out embedded documents that do not correspond to your query criteria (i.e. If you are trying to find a specific book in a book saga) you will get the complete 'parent' documents with the entire sub collection you were trying to filter So what can you do when you wish to filter a sub-collection to extract 1 subdocument ? Enter the $elementMatch operator. Introduced in the 2.1 version the $elemMatch projection operator limits the contents of an array field that is included in the query results to contain only the array element that matches the predicate expressed by the operator. Let's say I have a model like the following : { "id": "1", "series": "A song of ice and F…

Glassfish changing master password and saving it to a file

Saving the master password when creating a domain is pretty straight forward just pass the --savemasterpassword flag when executing the create-domain command ${glassfish_install}/bin/asadmin create-domain --savemasterpassword mydomain Enter admin user name [Enter to accept default "admin" / no password]> admin Enter the admin password [Enter to accept default of no password]> Enter the admin password again> Enter the master password [Enter to accept default password "changeit"]> Enter the master password again> Default port 4848 for Admin is in use. Using 55187 Default port 8080 for HTTP Instance is in use. Using 55188 Default port 7676 for JMS is in use. Using 55189 Default port 3700 for IIOP is in use. Using 55190 Default port 8181 for HTTP_SSL is in use. Using 55191 Using default port 3820 for IIOP_SSL. Using default port 3920 for IIOP_MUTUALAUTH. Default port 8686 for JMX_ADMIN is in use. Using 55192 Using default port 6666 for OSGI_SHELL. Using…

Glassfish asadmin without password

If like me you hate having to type your user/password combination every-time that you run the asadmin utility command you have 2 options Creating a password file and then using the --user --passwordfile options everytime you execute an asadmin command (ugh...)Using the asadmin login command and never think about your password againHere's how you could implement both solutions : 1.- Creating the password fileFirst you will need to create a file following the directives that can be found here AS_ADMIN_MASTERPASSWORD=mypassword AS_ADMIN_USERPASSWORD=mypassword AS_ADMIN_ALIASPASSWORD=mypassword ${glassfish_install}/glassfish/bin/asadmin --user admin --passwordfile ${glassfish_install}/glassfish-password.txt list-applications mydomain Now even though this works perfectly I find it a bit of a nag to have to write all this every-time I want to execute an asadmin command and sure I could write a bash script that wraps the underlying asadmin tool with the --user and --passwordfile opti…

Glassfish cluster ssh node. Subsystem request failed error when creating a ssh node

Recently I stumbled upon a nasty and obscure error while configuring a glassfish 3.x cluster I had all my ssh configuration properly in place with all my ssh keys between my nodes I could connect with no issues between the different machines by executing the ssh command : [user@das~]$ssh machine1.com Even when I executed the asadmin command to setup the ssh configuration on the remote server everything comes up normally : [user@das~]$ ./asadmin setup-ssh machine1.com Successfully connected to user@achine1.com using keyfile /home/user/.ssh/id_rsa SSH public key authentication is already configured for user@achine1.com Command setup-ssh executed successfully. But every-time I wanted to add a ssh node either by using the asadmin tool or the glassfish administration console I kept getting the following error message : [user@das~]$ asadmin create-node-ssh --nodehost=machine1.com node1 remote failure: Warning: some parameters appear to be invalid. SSH node not created. To force cre…

Context menu disappears in Intellij idea when right clicking and using eclipse keymap

Image
As a former user of Eclipse I switched to the Eclipse keymap (the mac version can be found here) on Intellij Idea, but there was a bug that was pretty annoying, every-time i right clicked somewhere the context menu will quickly disappear unless I moved the mouse while clicking... This was actually caused by a bug that was filled sometime ago and the workaround is pretty easy as stated in the bug page just remove the 'button3' mouse shortcut from the "show context menu" action in your IDE preferences I made the small change to the XML file and filled a pull request with the author, so if it gets accepted it should take care of the bugIn any case you can either download the xml file once the pull request gets accepted or do it yourself from your IDE preferences as explained in the bug page : Open Settings | Keymap, press Copy button to create an editable copy of the Eclipse keymap, in the copy find "Show Context Menu" action in the Other group, it has mu…

Redeploying to a remote glassfish with cargo (previous blog post follow up) - Solving the "application already registered error"

Sometimes right after you spent a whole day working on something (and blogging about it) you realize that there's actually an easier and faster way to accomplish the something.. d'oh (thank you very much brain In my previous post here I was talking about an issue that I was having while trying to redeploy different versions of my application on the same glassfish context To sum things up, the first time I deployed the application everything will work as expected but subsequent deployments will throw an error telling me that an application already exists for that context root (see message below) : Caused by: org.codehaus.cargo.util.CargoException: Deployment has failed: Action failed Deploying application to target server failed; Error occurred during deployment: Application with name myapp-1.4.8 is already registered. Either specify that redeployment must be forced, or redeploy the application. Or if this is a new deployment, pick a different name. Please see server.log …

Glassfish remote redeploy with maven and the mojo exec plugin

So a few days ago I run into a bug that took me almost a whole day to sort out.. I usually use cargo when I want to deploy an app to a running container but today I've spent several hours trying to make my app redeploy on a remote glassfish web profile server while working within my development/integration environment. Just to give you some context in this environment I needed to continually deploy the same application on the same server but with different versions. The first time I deployed the application everything will work as expected but subsequent deployments will throw an error telling me that an application already exists for that context root (see message below) : Caused by: org.codehaus.cargo.util.CargoException: Deployment has failed: Action failed Deploying application to target server failed; Error occurred during deployment: Application with name myapp-1.4.8 is already registered. Either specify that redeployment must be forced, or redeploy the application. Or if …

Enabling reading stats on kobo devices with side loaded epubs

I'm a big fan of ereaders and I've own several of them, I currently own a Kobo Aura HD and I'm really happy with it, but there was something missing, something from the Kindle world that I really liked the "time remaining" feature Kobo firmware 2.3 introduced some nice utilities, similar to what amazon brought with their Kindle Paperwhite, to enhance the reading experience, among them chapter pagination and "remaining time" for book and chapter The issue with these features is that by default they are only available for EPUBs that you bought directly from Kobo since these are actually no longer EPUBs but KEPUBs (Kobo epubs) so that they can add these new gimmicks But as usual Calibre comes to the rescue since someone has developed a plugin (which is actually an extended Kobo driver for calibre) that enables the Kobo specific stuff to side-loaded epubs You can find it here and the mobileread thread where you can get more infos regarding this pluginThe …

Maven resource filtering not working on spring configuration xml file

I recently run on a weird problem while running property filtering on tutorial project that I'm writing.One of my configuration files (spring XML config files) was being partially filtered (only the first 2 variables were properly "filtered" while the rest was left as they were )Below is my configuration file. Only the first 2 variables where filtered (mongo.host & mongo.port) : I've tried a few things and realized that if I moved them around then suddenly it would work but I couldn't put my finger on what was causing the problem So I decided to remove line by line from the bottom up and check if something will fix the problem As it turns out what was causing the problem was the '@' in my comment right before the repository configuration. This actually was a maven bug in the maven-resources-plugin but fear not the bug was corrected in the 2.6 versionSo if you come up by this behavior check your pom.xml configuration as by default my maven was using …

Spring MVC and Swagger. Generating documentation for your RESTful web services - PART 2

Image
Automating your RESTful web services documentation Using Spring MVC with Swagger for generating it
Part 2 - Implementing some business logic and configuring Swagger
1.- Configuring swagger and swagger-ui1.1.- What is swagger ? Swagger is a specification and complete framework implementation for describing, producing, consuming, and visualizing RESTful web services as stated by their official website Personally I find Swagger to be a pretty nice way to generate my web services documentation instead of having to rewrite everything again (I already comment my code so it should be enough!) However at the moment swagger does not support Spring MVC natively but there is an implementation over at github here As stated by the developer not all the Swagger annotations are currently supported but the implementation works mainly with the Spring MVC annotations(@Controller, @RequestMapping , etc.) which I just what I needed. 1.2.- Integrating swagger into spring First thing to do is to create…