Thoughts on technology Thoughtology

Monday Nov 10, 2008

You plan to run the M2 Demo of Fuji and wish to use your Mac OS X's in-built FTP server or wish to enable different Logging levels at runtime in Fuji, then check out this article.

The first step is to have your environment set up as detailed at M2 Demo. Once you have the projects imported, Felix installed (or the archive unzipped) and are ready to build and deploy, stop. Using Mac's FTP server - you need to enable the service if not enabled,  probably create a new user for FTP access, create the required directory structure, and must modify the default FTP's service.properties.  We set the up the FTP and then jump to how we can enable different logging levels. If all you care is about the Logging levels, jump to the next section.

FTP server on Mac (Tiger OS):

- Ensure you re-index your Maven as stated at the above URL.

- Enable the FTP server on your Mac OS X, if not enabled yet. You can do this by going to 'System Preferences --> Under Internet & Network section --> Sharing'. In the Services tab, ensure the FTP Access is selected and the service started to enable external computers to exchange files with the FTP server. At the bottom of the window, the IP address to access this FTP server should be provided.

- Create a new user for FTP access. Eg: remoteftp. To do so, go to 'System Preferences --> System --> Accounts --> create a new user'. In my case I created the user as a standard user with no admin rights. You need to have the necessary permissions to create a new user.

- In your NetBeans --> in the Projects tab --> the M2 Demo project, 'Integration Application (m2app)', open the properties file at Service Config Files --> ftp --> receive-manifest --> service.properties. By default the property 'ftp.messageRepository=/tmp'. To use the Mac FTP server, change this to

ftp.messageRepository=tmp

Notice that the path is not prefixed with '/'.

- In your FTP home directory create the directory 'tmp/inbox'. You can do this by logging into the FTP server and using mkdir command. Please note the 'inbox' directory MUST exist, although in the service.properties for FTP you only specify 'tmp'.

- Drop the input file req.in.xml as provided in the demo tutorial at the above created directory. Please note that although the file name is req.in.xml, the file name specified in FTP's service.properties would be

ftp.messageName=in.xml 

- With these changes, do a clean build of your m2app project. Start the Fuji server, install the generated bundle from the build. Ensure you explicitly start the bundle if not started by default. Otherwise the file will never get picked up. For details on how to build, install the bundle and start the Fuji server, please refer to the above mentioned M2 Demo URL.

With this you are all set to run your M2 Demo using Mac FTP server.

Log Level:

For various reasons, you need a detailed log to analyze your code or understand what exactly is happening internally. In my case, I needed this to overcome the FTP config problem with Mac FTP server.

Felix itself has a single property that can be used to configure different log level. Go to  <FUJI_FELIX_HOME>\conf\config.properties and edit the property felix.log.level  as required. But unfortunately, this log level is specific to Felix code only and in most of the cases,  we  are looking for logs from user bundles that we create. There is no single point of change to achieve this. Fortunately, a third party bundle is available that enables us overcome this short coming. This third party bundle is available at http://wiki.ops4j.org/confluence/display/ops4j/Pax+Logging. The link provides enough documentation on how to use the bundle while below are the details on how I used it for your reference.

- Get the required bundles from : API (http://repository.ops4j.org/maven2/org/ops4j/pax/logging/pax-logging-api/), Service (http://repository.ops4j.org/maven2/org/ops4j/pax/logging/pax-logging-service/). I used the 1.1.1 version. I downloaded the files on to a temp directory in my local file system.

- Open a cmd prompt. 'cd' to the directory where Felix zip file is extracted. On the cmd prompt I start felix using

java -jar bin/felix.jar

- Then installed the two bundles using the commands -

install file:/tmp/felix/bundle/pax-logging-api-1.1.1.jar
install file:/tmp/felix/bundle/pax-logging-service-1.1.1.jar
ps - to get the bundle ID's if you could not get at the end of above commands.
start <bundle_id>

More details on the commands are available at http://felix.apache.org/site/apache-felix-usage-documentation.html. To enable different Log level's you need to download Pax Runner. Extract the Zip / tar file. In the terminal window, modify your PATH variable to include the Pax Runner bin directory. 'cd' to the <FUJI_FELIX_HOME>\bundle directory and run the below commands.

pax-run "--log=TRACE" 

The above is since Fuji uses JDK logging and the mapping from JDK FINEST to DEBUG is Trace. For further details you can refer to http://www.ops4j.org/projects/pax/logging/apis/jdk.html.

Now kick start your Felix / Fuji server. Ensure all the bundles are installed and started (bundles are not started by default). You should see log that contains more output than before and includes the DEBUG level since we requested for DEBUG level in the above command.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed