Archive for the ‘java’ Category.

problem with multiple tiles configuration files

This is an interesting problem for this newbie. I have one common tiles configuration file tiles.xml. I decided to split it into pieces based on modules. The syntax allows me to do it. the web.xml entry changed from

<context-param>
 <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
 <param-value>/WEB-INF/tiles.xml</param-value>
 </context-param>

to

<context-param>
 <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
 <param-value>/WEB-INF/tiles-license.xml,/WEB-INF/tiles-common.xml</param-value>
 </context-param>

Fortunately/Unfortunately, I declared all my basic templates in tiles-common.xml which is reused by tiles-license.xml. Pathetic. I ended up with annoying exception

org.apache.tiles.definition.NoSuchDefinitionException: licenseExpiryList
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:578)
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:246)
    org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:105)
    org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)

We need to specify the tiles config files in ‘correct’ order. base definitions at first, children at the last.

Ref: http://old.nabble.com/How-can-I-separate-tiles.xml-in-several-files—td13216254.html

org.apache.tiles.definition.NoSuchDefinitionException: licenseExpiryList
	org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:578)
	org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:246)
	org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:105)
	org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)

java.net.ProtocolException: Server redirected too many times

This is another nasty exception I came across today. I was developing a core java application that connects to internet via proxy. It was working fine with hardcoded values for username (domain\\myname as username and secret as password). When I accepted the same strings as command line arguments, the process did quit with this.

java.net.ProtocolException: Server redirected too many times (20)

Finally I came to know that I made a mistake with the username. Double slash is wrong when we give the string as command line argument. So, the server is keep on asking the username and password, which broke the process once the threshold 20 exceeded.

Connecting Sony Ericsson W810i to Mandriva and executing AT commands with Java

projects

Hi,

This post is to document the steps I overcome to connect my sony ericsson W810 as a serial modem with windows and linux and passing AT commands to it. My ultimate aim is to operate the phone in command line.

My Windows experience is sour, since sun doesnt offer its javax.comm version of jar for windows. From the googling I found sun issued it before and stopped as of now. I found the old version of comm.jar from the net from an unauthenticated website which resolved all issues. My phone is found to be a serial modem connected to COM7 port. Then passing AT commands reached the phone and I got the reply.

My Linux experience is time consuming, may be because of my ignorance. I am not at all able to mount the phone to any ports such as /dev/tty0, 1, 2. Usually USB mobile phones to be mounted in /dev/ttyACM0 or /dev/ttyACM1 in linux. From the googling I found I need to install the PCMCIA package, http://kernel.org/pub/linux/utils/kernel/pcmcia/pcmcia.html , luckily my Mandriva 2009 (again a FREEdom OS) bundle it by default. Then I found my phone got detected in /dev/ttyACM0.

When I connected the phone I found the following in the kernel logs. Use dmesg | tail -5 to do this.

Feb 22 11:58:32 pallava kernel: usb 3-1: new full speed USB device using ohci_hcd and address 5
Feb 22 11:58:32 pallava kernel: usb 3-1: configuration #1 chosen from 1 choice
Feb 22 11:58:32 pallava kernel: cdc_acm 3-1:1.1: ttyACM0: USB ACM device
Feb 22 11:58:32 pallava kernel: cdc_acm 3-1:1.3: ttyACM1: USB ACM device
Feb 22 11:58:32 pallava kernel: usb 3-1: New USB device found, idVendor=0fce, idProduct=d042
Feb 22 11:58:32 pallava kernel: usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Feb 22 11:58:32 pallava kernel: usb 3-1: Product: Sony Ericsson W810
Feb 22 11:58:32 pallava kernel: usb 3-1: Manufacturer: Sony Ericsson
Feb 22 11:58:32 pallava kernel: usb 3-1: SerialNumber: 352337019712611_0

But my java is not able to understand the port it was listing only the default ports as

SessionIndependent_/dev/ttyS0 1 Port currently unowned
SessionIndependent_/dev/ttyS1 1 Port currently unowned

Later I found the issue is with the java io config file javax.comm. It doesnt contain the entries for ACM ports. I am not sure they will be detected automatically, that doesnt happen to me.

# Paths to server-side serial port devices
serpath0 = /dev/ttyS0
serpath1 = /dev/ttyS1

I need to add ACM ports manually, which resolved all issues.

serpath2 = /dev/ttyACM0
serpath3 = /dev/ttyACM1

As of now its working fine, but now and then I am getting the following exception when I try to open the com port.

java.io.IOException: Not all params are supported by kernel
at com.sun.comm.LinuxSerial.nativeSetSerialPortParams(Native Method)
at com.sun.comm.LinuxSerial.setSerialPortParams(LinuxSerial.java:346)
at gf.sms.pack.Port.open(Port.java:46)
at gf.sms.pack.SendSMS.run(SendSMS.java:21)
at java.lang.Thread.run(Thread.java:619)

Will find why I am getting the error and document it as well.

I got immediate response from ILUGC Chennai Linux User Group, http://chennailug.org/ ,  regarding this. My sincere thanks to them.

Filename in response

folder

I was writing a servlet whose response is PDF, CSV, XLS etc. This works fine, but when I tried to save it HDD the url is given as the filename. I was wondering how to explicitly specify the filename. Here is the solution.

response.setHeader("Content-Disposition", "inline; filename=xyz.pdf" );

When we set this header property in the response, The filename will be xyz.pdf. Nice na!

Live internet radio stream extractor

radio.jpg

Friends,

This is to give you a code pack I wrote today. I was listening to one of the internet radios in Tamil. I want to store it on my hdd, the tools I searched dint helped me much. I want a simple tool, that saves my time. And It should be able to work in my absence. I wrote couple of classes, which I am going to test it now.

Why dont you test it youself :)
It doesnt require any installation. you need only three files.

mp3_stream_extractor.jar, The execution binary,
RUN.CMD, the invoking script
radio.properties, where you configure the radios

run the run.cmd, The audio is extracted to your home folder automatically.

Enjoy.

Download MP3 stream extractor

radio properties