HHHHq ~ “Hack”

A blog about programming and…

Archive for the ‘java’ tag

Java and .Net SOAP interoperability

without comments

I came across a question on Stack Overflow today regarding SOAP interoperability between Java and .Net.  I posted this answer.  I don’t know if that solves the author’s problem, but it worked for me a few months ago.  So, if you are having problems consuming a Java SOAP service (running under Axis 1.x in particular) with .Net, check that post out.

Written by James Royalty

June 10th, 2009 at 7:12 pm

Posted in Programming

Tagged with , ,

FTP using Groovy and Ant

without comments

Lately, I’ve been writing a lot of scripts in Groovy. Frankly, I love it. It’s easy to augment the functionality of your Java classes — implement interfaces, extend classes etc. Another nice feature is that Groovy allows you to leverage the power of Ant in your scripts using the AntBuilder object. I find this incredibly useful when doing off-liney, scripty things I’d normally do using bash combined with other Unix tools.

One common scripting task is to transfer a bunch of files to an FTP server. Here’s how I would accomplish FTP’ing *.gz files in the current directory using bash and curl:

for f in *.gz ; do
  curl -s -S -P - -T $f ftp.foo.com
done

Hard to beat for compactness. But, if you’re already working in Groovy, you can use Ant’s FTP task to accomplish the same thing. Here’s the Groovy code:

ant = new AntBuilder()
ant.ftp( server:"ftp.foo.com",
    userid:"user",
    password:"passwd",
    passive:"yes",
    verbose:"yes",
    remotedir:"/pub/incoming",
    binary:"yes" ) {
        fileset( dir:"." ) {
        include( name:"**/*.gz" )
    }
}

The verbose setting is helpful because otherwise the command’s operation is silent. With verbose enabled, output will be sent to stdout. All options supported by Ant’s FTP task can be used in the Groovy context. Furthermore, nested XML elements in Ant become closures in Groovy. (The fileset and include statements above.)

FTP is an optional Ant task so if you want to use it in your scripts, you’ll need the following dependencies on your classpath:

  • ant.jar
  • ant-nodeps.jar
  • ant-apache-oro.jar
  • ant-commons-net.jar
  • jakarta-oro.jar (at least version 2.0.8)
  • commons-net.jar (at least version 1.4)

I’ve tested this with Ant 1.6.5 only.

Written by James Royalty

May 1st, 2009 at 1:36 pm

Posted in Programming

Tagged with , ,