Web4Math

Dr. Olga Caprotti

caprottio@acm.org H.Ö. Möllersväg 5 SE–24471 Dösjebro voice: +46 46 772163

Maxima Web Service in Axis

Tender: FP6-LeAM/2004/004 Project: LeActiveMath Date: May 20, 2005 CONTENTS 1

Contents

1 Introduction 2 2 Maxima Phrasebook 2 3 Axis 2 4 System Requirements 3 5 Compilation 3 6 Client for WebMaxima 3

6.1 Service Styles in Axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 7 Using WebMaxima in Exercises 5

1 Introduction

This document is part of tender FP6-LeAM/2004/004 issued by the European FP6 project ”LeActiveMath” (IST-507826) concerning the development of the LeAM Phrasebook, technically an OpenMath interface to the computational software system Maxima. It describes the Axis web service which exports the phrasebook functionality. This web service is a generic wrapper and does not specifically do a particular mathematical web service as intended by the MONET definition. It is possible however, to use it in order to implement well defined mathematical web services as specified by the MSDL MONET definitions.

2 Maxima Phrasebook

The computer algebra system Maxima is a lisp based system which is loaded and then interpred in a Lisp environment. The Maxima Phrasebook communicates to the Maxima process via a custom built socket connection since we have not succeeded in using the Maxima native server mode. According to the Maxima documentation, Maxima can be started as a server by using the command line switch -s <port>. In all our experiments, this however has always returned an error message and we decided to write a Java socket connection. In what follows, when we refer to the Maxima service, we mean the custom built class,

com.web4math.maxima.service.MaximaSocketService, which exports the Maxima process in

a socket connection.

3 Axis

Apache Axis(Apache eXtensible Interaction System), http://ws.apache.org/axis/, is an implementation of the SOAP ”Simple Object Access Protocol” submission to W3C. Axis is essentially a SOAP engine – a framework for constructing SOAP processors such as clients, servers, gateways, etc. For the Maxima Web Service we have used the Java version of Axis (Final 1.2 was released on May 4, 2005). This choice is motivated by compatibility with the mathematical services developed within MONET, e.g. the Maple Symbolic Service is also written using Axis and so is the ORCCA broker.

Axis includes several additional features that are very useful when developing, deploying and debugging web services, in particularand administration servlet which allows to register/deregister web services, an emitter tool that generates Java classes from the Web Service Description Language (WSDL) definition of the service interface, and the SOAP Monitor to monitor TCP/IP packets and the format of the SOAP messages. All these feature are well documented on the Axis webpage so we will not describe here the installation procedure for Axis. It is however recommended that all steps are followed to make sure that all required jar files are available to the Axis engine.

The Ant buildfile in the distribution contains a target called soapmonitor and the deploy file for installing the SOAP Monitor on the Axis engine.

4 System Requirements

Apache Axis version at least 1.2RC, requires activation.jar, see http://java.sun.com/

products/javabeans/glasgow/jaf.html.

Maxima service running on the localhost on port 1239 (default port chosen by the distribution). (It would be possible to modify the Maxima web service so that Maxima could be running on an arbitrary remote host, but at present localhost is the default).

We tested it on the Java jdk1.5.0 01 distribution on a Linux Fedora Core 3 platform.

Set the environment variable AXIS HOME to the WEB-INF directory of the Axis installation so that AXIS HOME/lib points to Axis jar files. This environment variable is used during compilation. Set the environment variable TOMCAT HOME to the directory of the JSP container, in our case we tested on Apache Tomcat/5.5.7.

5 Compilation

The distribution provides a buildfile for Apache Ant (http://ant.apache.org/). The default target will compile the Java class that wraps the Maxima Phrasebook in a web service

com.web4math.maxima.axis.WebMaxima and produce the class file in the build/webapp/axis

directory. These files are deployed to the installed Axis engine by calling the Ant target deploy. This target will copy the compiled files to the default Axis web application and will inform the Axis servlet of the new web service. After this is done, by loading the page

http://localhost:8080/axis/servlet/AxisServlet it is possible to view the list of available

web services, in particular WebMaxima should appear in the list.

To remove the WebMaxima web service from the Axis engine use the target undeploy.

6 Client for WebMaxima

A web service is specified in terms of an XML description file in a format called WSDL. From this specification of the web service interface, it is possible to automatically generate a client to the web service. We have included such a test client in the distribution, however, a more convenient generic client for the WebMaxima web service can be accessed online by providing the

WSDL of WebMaxima, e.g. http://soapclient.com/soaptest.html.

****mark, possibly you can make a screenshot of the generic soap client calling WebMaxima and include it here

The Axis engine returns the WSDL of any web service it hosts by appending ?wsdl to the URL of

the service, in this case, http://localhost:8080/axis/services/WebMaxima?wsdl will return

the XML document of Figure1. From it, one notices that the operation Phrasebook takes as input 2 strings and returns a string as result. Knowing the API of the Maxima Phrasebook Java class, one can deduce that the first string is the directive type, one among “EVAL NATIVE NATIVE”, “EVAL NATIVE OPENMATH” , “EVAL OPENMATH NATIVE”, and “EVAL”, whereas the second represents the XML encoding of the OpenMath object to be evaluated.

6 CLIENT FOR WEBMAXIMA 4

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://localhost:8080/axis/services/WebMaxima"
               xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="http://localhost:8080/axis/services/WebMaxima"
               xmlns:intf="http://localhost:8080/axis/services/WebMaxima"
               xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
               xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
               xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.2 Built on May 03, 2005 (02:20:24 EDT)-->
<wsdl:message name="PhrasebookResponse">
   <wsdl:part name="PhrasebookReturn" type="soapenc:string"/>
</wsdl:message>
<wsdl:message name="PhrasebookRequest">
   <wsdl:part name="in0" type="soapenc:string"/>
   <wsdl:part name="in1" type="soapenc:string"/>
</wsdl:message>
<wsdl:portType name="WebMaxima">
   <wsdl:operation name="Phrasebook" parameterOrder="in0 in1">
      <wsdl:input message="impl:PhrasebookRequest" name="PhrasebookRequest"/>
      <wsdl:output message="impl:PhrasebookResponse" name="PhrasebookResponse"/>
   </wsdl:operation>
</wsdl:portType>
<wsdl:binding name="WebMaximaSoapBinding" type="impl:WebMaxima">
   <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
   <wsdl:operation name="Phrasebook">
      <wsdlsoap:operation soapAction=""/>
      <wsdl:input name="PhrasebookRequest">
         <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                        namespace="http://axis.maxima.web4math.com" use="encoded"/>
      </wsdl:input>
      <wsdl:output name="PhrasebookResponse">
         <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                        namespace="http://localhost:8080/axis/services/WebMaxima" use="encoded"/>
      </wsdl:output>
   </wsdl:operation>
</wsdl:binding>
<wsdl:service name="WebMaximaService">
   <wsdl:port binding="impl:WebMaximaSoapBinding" name="WebMaxima">
      <wsdlsoap:address location="http://localhost:8080/axis/services/WebMaxima"/>
   </wsdl:port>
</wsdl:service>
</wsdl:definitions>

Figure 1: WebMaxima WSDL

6.1 Service Styles in Axis

There are four ”styles” of service in Axis: RPC, document, wrapped and message. RPC services use the SOAP RPC conventions and are the default in Axis. Axis deserializes the SOAP XML into Java objects which can be fed to the service, and serializes the returned Java object(s) from the service back into XML. This is the style used currently on simple string types. Document services do not use any encoding but do still do XML-Java databinding. Wrapped services are just like document services, except that rather than binding the entire SOAP body into one big structure, they ”unwrap” it into individual parameters. Message services receive and return arbitrary XML in the SOAP Envelope without any type mapping / data binding. This is the style to be used in order to work directly with the raw XML of the incoming and outgoing SOAP Envelopes, write a message service. There are four valid signatures for your message-style service methods:

public Element [] Phrasebook(Element [] bodies);
public SOAPBodyElement [] Phrasebook (SOAPBodyElement [] bodies);
public Document Phrasebook(Document body);
public void Phrasebook(SOAPEnvelope req, SOAPEnvelope resp);

*****Decide/Motivate whether this is what we want (e.g. include the fragment call from the exercise XML to show that it could take the XML directly?).

7 Using WebMaxima in Exercises

Just like the generic SOAP client mentioned above, more and more third party tools and software now provide the support to invoke web services by simply specifying the WSDL and the arguments to the call.

One example of thse emerging technologs is the Gomba tag library http://gomba.sourceforge. net/. It promises to provide utilities for invoking web services in a practical way, for parsing the XML result from the service and for displaying data in the web page.

***Mark please add a small fragment of the example in which you called the web service.