Categories
Java Web Development

Axis nsmap.properties

Trying to generate classes from a SOAP WSDL is pretty easy, especially if you are using Ant. You simply run the axis-wsdl2java task and you get the stub classes. The problem is that if your WSDL file looks like this:


<wsdl :definitions
targetNamespace="http://localhost/axis/services/MyService">
</wsdl>
<schema targetNamespace="http://myservice.yzukerman.cscie162.harvard">

The classes will be generated into two directories:

  • The Axis infrastructure classes will be generated into:

    localhost/axis/services/MyService

    Which corresponds to the WSDL URL

  • The service stubs will be generated into:
    harvard/cscie162/yzukerman/myservice

    which is in the reverse order of the namespace URL

To overcome that, Axis can use a namespace mapping file, nsmap.properties which maps the namespace names into the package names you want each of the remote namespaces (Axis classes, stub classes) to be generated into. So, for the above files to both be mapped under a package called com.enavigo.myservice, the nsmap will look like this:

http\://myservice.yzukerman.cscie162.harvard=
com.enavigo.myservice

http\://localhost/axis/services/MyService=com.enavigo.myservice

My co-worker Nate Pickett helped me with this ‘discovery’.

Look at this JavaWorld article to more.

Share
Categories
Java Web Development

Axis and Java 1.5 Problem

If you use Java 1.5 and try to use Axis 1.1’s WSDL2Java utility to read a WSDL file and generate Java stubs, you will notice that when the utility generates Enumeration objects which it names enum. Enum is a keyword in Java 1.5 (whoopie!) – so your code will not compile. This sucks.

Update: April 19, 2005
To make the compilation work, use the -source 1.4 switch. In the Ant javac task, add the source attribute and set it to 1.4.

Share
Categories
Java SQL Server

Counting how many rows were returned by a JDBC ResultSet

After executing a JDBC query, you often want to know if anything was returned and if so how many rows exist in the ResultSet. To do that, use this snippet of code:


ResultSet rs = st.exeuteQuery();
rs.last();
int rsRowCount = rs.getRow();
rs.beforeFirst();

The rsRowCount variable will have the answer.
Make sure that your Statement or PreparedStatenent are created using the three parameter version of the Connection object methods createStatement() and PrepareStatement() like:
Statement statement =
conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

OR

PreparedStatement ps = conn.prepareStatement([SQL EXPRESSION],
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);

Look at
the JavaDoc entry for this method.

Share
Share