@PostConstruct method called twice for the same request

December 17, 2013 Leave a comment

Hi there,

for those of you fighting with CDI and JSF when getting this error:  http://stackoverflow.com/questions/9077966/postconstruct-method-called-twice-for-the-same-request

Be sure that you did not import javax.enterprise.context.SessionScoped instead of javax.faces.bean.SessionScoped.

Both compile, but only the latest is the one you want for dealing with session scope bean in JSF.

cdi

Advertisements
Categories: java, JSF

Working with c9.io and Git (BitBucket)

September 18, 2012 Leave a comment

I have recently discovered c9.io, an online editor + runtime that allow you to work remotely and share with your team. Not only does it allow you to write and test html+css, php, javascript code, you can also push on your git repository with it.

The documentation is not accurate enough for me, so I’ll add a more few lines here:

  • you need to copy your ssh key on your clipboard. you will find it on your c9i workspace

  • then copy it into your bitbucket account settings:

and now you can push into your bitbucket repository from c9.io

For instance:

my repo is     git@bitbucket.org:loictalbot/myrepo.git
git remote add origin git@bitbucket.org:loictalbot/myrepo.git
git add *
git commit - m 'initial revision'
git push -u origin master
Categories: Configuration Tags: , ,

Notes on running AIR apps on Blackberry playbook

January 11, 2012 Leave a comment

After several attempts to run my non-finished app on the playbook I find it usefull to save some notes on how to proceed step by step. So many examples that can be found over the web I know, I’ll add my contribution too because it took some time to deploy it the first time so one more described experience may not be useless.
Register for signing keys on Blackberry web site here:
[A]
It’s important to save somewhere the PIN that you enter here!

Signing Keys Order Form

Signing Keys Order Form

      Once ordered you will receive two signing keys by email

 

    They are called client-RDK-XXXXXXXXX.csj and client.PBDT-XXXXXXXXX.csj.
      signing with blackberry you CSJ file.

 

      If you did several unsuccessfull attempts before you need to delete your previous attempts with:

blackberry-signer -cskdelete

      For others fresh new developers register your RDK file like this:

blackberry-signer -cskpass YOUR_PASSWORD_HERE

      Now remember the step [A] where you entered y pin ? enter it again after csjpin here:

blackberry-signer -register -csjpin YOUR_PIN_HERE -cskpass YOUR_PASSWORD_HERE client-RDK-XXXXXXXXX.csj

    I have then received an email saying that my CSJ registration was ok.
    Them comes the P12 file creation:

blackberry-keytool -genkeypair -keystore YOUR_FILE_NAME.P12 -storepass ENTER_STOREPASS_HERE -dname "YOUR_APP_NAME" -alias author

To create a debug token I have executed the following commands:
blackberry-debugtokenrequest -register -cskpass YOUR_PASSWORD_HERE -csjpin YOUR_PIN_HERE client-RDK-XXXXXXXXX.csj

It said :

already registered

So I did:
blackberry-debugtokenrequest -register -cskpass YOUR_PASSWORD_HERE -csjpin YOUR_PIN_HERE client-PBDT-XXXXXXXXX.csj
It said :

successfully registered with server

The debug token is created with the following command: (replace 0x444444 with your device id)
blackberry-debugtokenrequest -register -cskpass YOUR_PASSWORD_HERE -keystore YOUR_FILE_NAME.P12 -storepass ENTER_STOREPASS_HERE -deviceid 0x444444 NAME_OF_YOUR_DEBUG_TOKEN_FILE.bar

debug token created

To upload the debug token on your device, press upload debug token and then execute the following command: (replace 192.168.0.14 with your device ip address)

blackberry-deploy -installDebugToken NAME_OF_YOUR_DEBUG_TOKEN_FILE.bar -device 192.168.0.14 -password YOUR_DEVICE_PASSWORD

Now you can install unsigned apps on your device. theoretically … you need to ensure that your bar file (the one for your app) contains the same info as the debug token:
List the debug token info like this:

blackberry-airpackager -listManifest NAME_OF_YOUR_DEBUG_TOKEN_FILE.bar
Copy Author and AuthorId in the appropriate fields in the blackberry-tablet.xml file, package your app as a bar file with these info:

blackberry-airpackager -package YOUR_APP.bar YOUR_APP.xml blackberry-tablet.xml YOUR_APP.swf -devMode

and deploy it on the device:
blackberry-deploy -installApp -device 192.168.0.14 -package YOUR_APP.bar -password YOUR_DEVICE_PASSWORD

That’s it. As I said it took time for me, especially the order of the commands and also to install the debug token. These are the commands which worked for me in the same order I runned them. I hope it helps!

File upload using REST Spring MVC

April 21, 2010 7 comments

A quick note on developing an HTTP POST based web service using Spring 3 MVC and its testing using curl command line program.

To me the most important resides in the configuration file:

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

<property name="maxUploadSize" value="300000"/><!-- Max size in bytes. -->

</bean>

The web service itself is configured like this:

@RequestMapping(value = "/fileUpload", method = RequestMethod.POST)
@ResponseBody
public myObject upload (
@RequestParam("file") MultipartFile multipartFile,
HttpServletRequest request) {...

and the curl command is:

curl -F "file=@file.jpg" http://localhost:8080/fileUpload

Edit 4/12/2011: just noticed there exists a nice working example at springsource dealing with this (and much more), here

Configuring a Java project with MS SQL Server 2000

March 29, 2010 Leave a comment

I was recently asked to configure an existing Java project (JSP/Spring/iBatis) to run on Microsoft SQL Server 2000. I have encountered some issues on this: the other team members already had the project configured and it was running fine, so I did not expect to spend so much time on it.

First of all the project was running on JDK 1.4. If you try to download such a JDK version, the Oracle web site now tells you that this version is in an EOSL state which means (End Of service Life). It was a bit surprising to me, things are going faster than I thought 🙂

Then if you try to find a MS SQL 2000 driver on the Internet you won’t find. You will need to download the MS SQL 2005 JDBC driver. On the download page Microsoft says it works for both 2000 and 2005 version of their product. I can now tell this is true.

True, for sure, but I also had to change the spring datasource configuration a bit:


property name="jndiName" value="java:comp/env/jdbc/wwdfvpDS"

instead of this one (which works for the other team members)

property name="jndiName" value="java:jdbc/wwdfvpDS"

Basically that’s just a syntactical change and to my opinion it’s due to the JDBC driver. That’s why I think it’s safe to keep a folder on SVN with all these drivers (actually the setup.exe file for the MSSQL driver for JDBC). Best would be to upgrade the project along with the technologies upgrade. For instance if the iBatis framework evolves from version 1 to version 3.0 then the most recent has to be used. The unitary tests should ensure there’s no regression.

SFTP on Amazon EC2

January 29, 2010 1 comment

Amazon Elastic Compute Cloud as well as Rackspacecloud (and many others) allows you to set up a remote server and deploy your web application (among other things).
I have setup my own account and run a small instance. For this I have used Amazon Web Toolkit plugin for Eclipse.
The documentation provided with this toolkit is fine. Unfortunately for me, as usual, it doesn’t work as expected: I have tried to run an instance located in the US but it seems that’s way too far ! I used to have this popup screen:

mmm… why did I do that ? Because I thought my fellows there would have a better time response and therefore a better user experience for the prototype that I did. I have changed the settings to point to a European instance.

This time it was starting up fine with AWS.

But running a simple dynamic web application as described in their tutorials (you don’t even need a tutorial though to create that) caused some trouble.

Another solution was to transfer the WAR file on the server and then put it into the webapps folder of tomcat. To do that why not use sftp, said Loïc to himself… 🙂
As the picture above shows you can right-click on the live server and select open shell. Your command is written at the top of the shell window. Here is what you should have:
Last login: Fri Jan 29 14:01:11 on ttys005
/usr/bin/ssh -o CheckHostIP=no -o TCPKeepAlive=yes -o StrictHostKeyChecking=no -o ServerAliveInterval=120 -o ServerAliveCountMax=100 -i /Users/loic/.ec2/eclipse-keypair.pem root@ec2-xxx-xxx-xxx-xxx.eu-west-1.compute.amazonaws.com
loic-talbots-macbook-pro:~ loic$ /usr/bin/ssh -o CheckHostIP=no -o TCPKeepAlive=yes -o StrictHostKeyChecking=no -o ServerAliveInterval=120 -o ServerAliveCountMax=100 -i /Users/loic/.ec2/eclipse-keypair.pem root@ec2-xxx-xxx-xxx-xxx.eu-west-1.compute.amazonaws.com

We have a pem file that manages the access keys to the server. In order to use them with sftp just type:
ssh-add ~/.ec2/eclipse-keypair.pem
and then you can use sftp to transfer your WAR file:
sftp root@ec2-xxx-xxx-xxx-xxx.eu-west-1.compute.amazonaws.com

Categories: Amazon web services Tags: , , , ,

Mule ESB set up with Maven under Eclipse (OSX)

January 22, 2010 2 comments

I have followed the Mule ESB tutorial and found that it did not work with Java5 on OSX. I have switched to Java6 and everything was back to normal.

Everything is explained very well on Mule web site, here is what I did to get it running with Maven 2 under Eclipse on OSX.

Firstly I have of course downloaded Mule (community edition) on their download page and expanded everything in /opt folder with the following command:

tar -xvzf mule-standalone-2.2.1.tar.gz

I’ve also downloaded the mule ide plugin for eclipse and followed the instructions here

To get it running with Maven, I used the command line in my project folder :
mvn mule-project-archetype:create -DartifactId=MMuleProject -DmuleVersion=2.2.0

and then I have the following command:
mvn eclipse:eclipse

to make it available as a project in eclipse.

Then I have launched Eclipse and imported the project:

File->import->Existing project into workspace

and I have selected the MMuleProject folder as root folder. Once the project was imported i have right-clicked on the project name MMProject in the package explorer and added Mule libraries:

project properties under eclipse

the project finally appears like the following inside the package explorer:

With Java 5 enabled I had this issue when trying to run the project : (right-click on mule-config.xml -> run as -> Mule Server)

INFO 2010-01-22 14:15:41,561 [main] org.mule.MuleServer: Mule Server initializing...
ERROR 2010-01-22 14:15:41,648 [main] org.mule.MuleServer: A Fatal error has occurred while the server was running: [[B
java.lang.ClassCastException: [[B
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1215)
at java.net.InetAddress.getLocalHost(InetAddress.java:1350)
at org.mule.config.DefaultMuleConfiguration.(DefaultMuleConfiguration.java:116)
at org.mule.context.DefaultMuleContextBuilder.getMuleConfiguration(DefaultMuleContextBuilder.java:125)
at org.mule.context.DefaultMuleContextBuilder.buildMuleContext(DefaultMuleContextBuilder.java:84)
at org.mule.context.DefaultMuleContextFactory.buildMuleContext(DefaultMuleContextFactory.java:197)
at org.mule.context.DefaultMuleContextFactory.doCreateMuleContext(DefaultMuleContextFactory.java:186)
at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:168)
at org.mule.MuleServer.initialize(MuleServer.java:351)
at org.mule.MuleServer.run(MuleServer.java:257)
at org.mule.MuleServer.start(MuleServer.java:244)
at org.mule.MuleServer.main(MuleServer.java:121)
ERROR 2010-01-22 14:15:41,671 [main] org.mule.MuleServer:

Switching to JDK 6 solved it :

INFO 2010-01-22 14:18:18,142 [main] org.mule.DefaultMuleContext:
**********************************************************************
* Mule ESB and Integration Platform *
* Version: 2.2.0 Build: 14110 *
* MuleSource, Inc. *
* For more information go to http://mule.mulesource.org *
* *
* Server started: 1/22/10 2:18 PM *
* Server ID: 999d182b-0758-11df-82a2-811cd9e5dabf *
* JDK: 1.6.0_15 (mixed mode) *
* OS encoding: UTF-8, Mule encoding: UTF-8 *
* OS: Mac OS X (10.5.8, x86_64) *
* Host: loic-talbots-macbook-pro.local (192.168.0.10) *
* *
* Agents Running: None *

pheeewww… it should have taken a few minutes, it took a few hours to figure out I should not use JDK5. Now I’ll experience this lightweight SOA architecture to expose SOAP web services. Something for a next post.

Categories: SOA Tags: , , ,