maandag 4 maart 2013

First two weeks

I've just started my third week at Docbyte, so it's definitely time to write an update on this blog. Just like I wrote in the previous introduction post, I'm currently developing a web service for DocShifter. In the first few days I had to get the print service for DocShifter working but I stumbled upon some problems with this.

Docshifter

First things first, what is DocShifter? It's a Java-written product that allows users to convert a file of a certain type into a file of another type. For example, it can change a text file (.txt) into a Portable Document Format, better known as PDF. To do this, it uses the Java Message Service (JMS) API to send conversion tasks from one component to another. Let me illustrate this for you.


As you can see on the image above, there are three main components in the project. First of all, we have a sender that places new tasks on a queue. Next, there is a receiver component that collects these tasks and runs the needed conversion. These two parts are configured by the DocShifter beans.

The advantage of dividing the project into these three pieces is that the whole process can work asynchronously. This way, the sender can always accept new tasks and put them on the queue and the user doesn't have to wait for one file to get processed before he can request another conversion. This is very important when processing rather large files.

The sender describes the different input modules of DocShifter while the receiver manages the output modules. An example of such an input is simple file system module. The user configures what directory it has to poll from and the sender will create a new task for every file that it finds in this directory. This task is placed on the JMS queue and will be fetched by the receiver. In this case we could create an output module that puts the converted file into another directory. Once we've done this, we only have to initialize a new process with these input and output modules. It's also possible to use the file system input with a completely different output module. For example, one that places the converted file in a Dropbox folder.

Print service

My first assignment was to get the print service working. This would actually make it possible for the user to print from any program to DocShifter. A lot of the code was already written for this. After diving into the source code for two days, I couldn't really understand how it was supposed to work. The whole application should run like the Line Printer Daemon/Line Printer Remote protocol (LPD or LPR). This is a network protocol for submitting print jobs to a remote printer, in this case, DocShifter.
Because I've got stuck on this, I was assigned another task. Create web service integration for DocShifter.

Web service for DocShifter

Docbyte wants to provide DocShifter as an online service, therefore, I had to create a web service that places new tasks on the queue. It has been quite some time since I've developed a web service, so the first steps went rather slow. Eventually I've chosen to use JAX-WS (Java API for XML Web Services). 

After trying out some things, I've got a simple web service running. Next step was to get it implemented into DocShifter. This was easier said than done. After hours of trying to solve errors, I found out that an unused imported library was blocking my web service. Once I had removed that, everything was working fine.

Because the project converts the files asynchronously, it's not that easy to return a converted file to the user. First of all, I'd let the sender check every 0,5 seconds if the output file had been created. To make sure that it doesn't end up in an infinite loop, the sender would stop polling after 5 seconds. 
In some way this can be approach. It's a way to make it work synchronously and send the file back to the client side of the web service as quick as possible. But in another way, it's keeping your sender from putting new tasks on the queue, especially if the system has large files to process.

So now, the client side will decide if the converted file should be send back immediately or not. If the file(s) are to big for this, the server returns the location of the output files. The files can be collected by another web service that polls this location.


1 opmerking:

  1. Why did you choose JAX-WS over other options like REST or the ancient SOAP?

    BeantwoordenVerwijderen