Usability - Productivity - Business - The web - Singapore & Twins

Apache Axis and Sharepoint Webservices

In preparation for Lotusphere 2011 I had to deal with SharePoint web services. While SharePoint 2010 is transitioning to oData the bulk of APIs is still web services only as in SharePoint 2003 and 2007. Inspired by Stubby and Julian's excellent explanations I decided to use Apache Axis (It's a bit outdated and one probably would use Apache CXF for flexibility today, but for my use case Axis was sufficient and lean. Now SharePoint has a lot of web service end points (I always thought you have a few and distinguish by port and service, but who am I to challenge a Microsoft architecture) you might want to use in code. Axis comes with a nice little tool called WDSL2Java to generate all the Java classes you need. Unfortunately the ServiceLocator classes have the URL where the WSDL file was retrieved from hard coded as local variable in case you call the service locator without URL.
Now I don't like the idea to have an arbitrary URL in a Java file. So I considered 2 options: edit all generated classes and replace the static string with a call to a variable or an not-implemented error -or- find a way how all these classes can be generated for every instance where one wants to use them. Then the actual/current SharePoint server name would be in the variable. I decided for the later and wrote a little script. It's a Linux script and requires that you have downloaded AXIS and made it available on the Java classpath (easiest: copy the jars to the lib/ext directory of your jvm). I also used some Linux eye candy, so you might need to adjust that for Mac or Windows. The result is a JAR file you can use in your XPages, Agent or Java project(s). Here you go:
#/** ========================================================================= *
# * Copyright (C) 2010, 2011 IBM Singapore Pte Ltd          *
# *                            All rights reserved.                            *
# * ========================================================================== *
# *                                                                            *
# * Licensed under the  Apache License, Version 2.0  (the "License").  You may *
# * not use this file except in compliance with the License.  You may obtain a *
# * copy of the License at <http://www.apache.org/licenses/LICENSE-2.0>.       *
# *                                                                            *
# * Unless  required  by applicable  law or  agreed  to  in writing,  software *
# * distributed under the License is distributed on an  "AS IS" BASIS, WITHOUT *
# * WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied.  See the *
# * License for the  specific language  governing permissions  and limitations *
# * under the License.                                                         *
# *                                                                            *
# * ========================================================================== */
# Script to generate all Sharepoint 2010 web service sources on a Linux machine
# The script uses zenity, tree and notify-send which might not be part of
# your standard Linux installation (but are highly recommended)
loc=$ ( zenity --entry --text= "What is your Sharepoint servers URL (without / at end!)" --entry-text= "http://sharepoint" );
#if $? != 0, user click on cancel button, so exit
if [ "${loc}?" == "?" ] ; then
    notify-send -t 1000 -u low -i gtk-dialog-info "Operation has been canceled"
    exit 1
notify-send -t 1000 -u low -i gtk-dialog-info "Generating classes for ${loc}"

retrieve= "alerts|Authentication|Copy|DspSts|DWS|ExcelService|Forms|Imaging|Lists|Meetings|People|Permissions|sharepointemailws|sites|spsearch|UserGroup|versions|Views|webpartpages|Webs"

for item in ${retrieve//|/ };
  notify-send -t 100 -u low -i gtk-dialog-info "Retrieving ${loc}/_vit_bin/${item}.asmx?WSDL"
  wget $loc /_vti_bin / ${item}.asmx?WSDL -O ${item}.wsdl
  java org.apache.axis.wsdl.WSDL2Java $item.wsdl -o src
notify-send -t 2000 -u low -i gtk-dialog-info "Compiling Java"
tree -if src | grep .java > compilelist
mkdir bin -p
javac @compilelist -d bin
jar cf sp2010ws.jar -C src . -C bin .
notify-send -t 2000 -u low -i gtk-dialog-info "Retrieval completed for: ${loc}"
As usual YMMV

Posted by on 06 January 2011 | Comments (0) | categories: Show-N-Tell Thursday


  1. No comments yet, be the first to comment