Monday, November 30, 2009

JCIFS rocks!

Actually, JCIFS works, the way I excpected.

Look at this:

import java.io.*;
import jcifs.smb.*;
public class t_getfile {
    public static void main(String[] args) {
        jcifs.Config.setProperty("jcifs.smb.client.username", "administrator");
        jcifs.Config.setProperty("jcifs.smb.client.password", "password");     
        try {
        SmbFileInputStream in = new SmbFileInputStream("smb://10.112.27.31/c$/Program files/Avaya/IC71/MessageCenter/Messages/9698.msg");
        byte[] b = new byte[8192];
        int n;
        while(( n = in.read( b )) > 0 ) {
            System.out.write( b, 0, n );
        }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}


What I want to achieve: from a servlet, I want to connect to a Samba (Windows) "share" and read the contents of the file.

Update:

This is even cleaner, supports multiple authentication sessions:


import jcifs.smb.*;
import java.io.*;
public class t_getfile2 {
    public static void main(String[] args) {   
        /* NtlmPasswordAuthentication object from the userinfo
         * component of an SMB URL like "domain;user:pass".
         * This constructor is used internally be jCIFS
         * when parsing SMB URLs.
         */
        NtlmPasswordAuthentication auth =  new NtlmPasswordAuthentication("administrator:password");
        try {
        SmbFile file = new SmbFile( "smb://10.112.27.31/c$/Program files/Avaya/IC71/MessageCenter/Messages/9698.msg", auth );
        InputStream in = file.getInputStream();
        byte[] b = new byte[8192];
        int n;
        while(( n = in.read( b )) > 0 ) {
            System.out.write( b, 0, n );
        } //while
        } catch (Exception e) {
            e.printStackTrace();
        } //try..catch
    }
}

Thursday, November 26, 2009

My First Script in BIRT

Yeah, I got it finally. I added a piece of ECMAScript to a BIRT report. Actually, it just does one very simple thing: highlighting one row if the value of a column fulfills a condition.

Created a datasource (MySQL database on my computer) and a dataset. Business as usual, nothing fancy. The dataset is actually a table consisting of two columns, one is the primary key, the second is the value.
On the Layout tab, I clicked the value column's value row, and just added this code to the onRender method (the Help says: "Script executed when the element is prepared for rendering in the Presentation engine"):

var val = this.getValue();
if (val == "boo") {
this.getStyle().backgroundColor = "#AAAAAA";
}

And voilá:




This BIRT thing is not bad, after all.

Tuesday, November 24, 2009

Java going CORBA

JacORB - will give it a shot if time > 0.

Java going Samba share

JCIFS that is. Will try it out.

Just another day

In Vienna. Schwarzenbergplatz, that is.
It's going to be a nice little project. Actually, there are some challenges, like web services, but remember, the stuff I work with, is capable doing anything, using Java. So I don't expect any problems. Apart from one: no time.

First

This is my first blog entry.
Sure, I don't really know what to write now. I was full of ideas yesterday, driving home, but not now. I am kind of slow. Tired, maybe.
Actually, it's 7:36 in the morning, CET, I am sitting at my desk at work, thinking about my life. After all, I am planning a change. And it's going to be documented.
So for now, I am just going to explore this blog thing.