<document>

Resin uses the Apache Axis library to provide support for SOAP. You can download the axis distribution. To make the axis libraries available to the application, the necessary jar files are installed in the directory `WEB-INF/lib`:

- WEB-INF/lib/axis.jar
- WEB-INF/lib/commons-discovery.jar
- WEB-INF/lib/commons-logging.jar
- WEB-INF/lib/jaxrpc.jar
- WEB-INF/lib/log4j-1.2.8.jar
- WEB-INF/lib/saaj.jar
- WEB-INF/lib/wsdl4j.jar

The simplest way to provide a SOAP service with Resin is to implement a Servlet that extends .

package example; import com.caucho.soap.SoapServlet; import java.util.logging.Logger; import java.util.logging.Level; /** * A simple SOAP service, implemented by extending SoapServlet. */ public class StringServiceServlet extends SoapServlet { static protected final Logger log = Logger.getLogger(StringServiceServlet.class.getName()); public String reverse(String arg) { int l = arg.length(); StringBuffer b = new StringBuffer(l); for (int i = l - 1; i >= 0; i--) { b.append(arg.charAt(i)); } return b.toString(); } public String toUpperCase(String arg) { return arg.toUpperCase(); } } <servlet> <servlet-name>StringServiceServlet</servlet-name> <servlet-class>example.StringServiceServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>StringServiceServlet</servlet-name> <url-pattern>/soap/String/1.0</url-pattern> </servlet-mapping>

You can test the SOAP service by using a SOAP client, or with a simple HTTP get query from a browser:

http://localhost:8080/testsoap/soap/String/1.0?method=reverse&arg0=hello ==> elloh

SOAP uses a complicated descriptor file format called a WSDL to describe services. Resin will generate a WSDL for a service if the `?WSDL` query parameter is used:

http://localhost:8080/testsoap/soap/String/1.0?WSDL ==> the result is too long to show here

More advanced requirements for providing soap services may require the use of the SoapDeployerServlet. The `SoapDeployerServlet` allows the usage of any java class to provide the service.

package example; /** * A class that provides a simple add and a simple subtract. */ public class Calculator { public int add(int i1, int i2) { return i1 + i2; } public int subtract(int i1, int i2) { return i1 - i2; } } <servlet> <servlet-name>SoapDeployerServlet</servlet-name> <servlet-class>com.caucho.soap.SoapDeployerServlet</servlet-class> <init> <soap> <web-service name="Calculator/1.0" class-name="example.Calculator"/> </soap> </init> </servlet> <servlet-mapping> <servlet-name>SoapDeployerServlet</servlet-name> <url-pattern>/soap/*</url-pattern> </servlet-mapping> http://localhost:8080/testsoap/soap/Calculator/1.0?method=add&arg0=12&arg1=14 ==> 26

SOAP uses a complicated descriptor file format called a WSDL to describe services. Resin will generate a WSDL for a service if the `?WSDL` query parameter is used:

http://localhost:8080/testsoap/soap/String/1.0?WSDL ==> the result is too long to show here

Global configuration options configure the SOAP engine that Resin is using.

The global configuration options are shared between all instances of `SoapDeployerServlet`. If you use more than one instance of `SoapDeployerServlet` and have conflicting configuration options, the last ones specified win.

<servlet> <servlet-name>SoapDeployerServlet</servlet-name> <servlet-class>com.caucho.soap.SoapDeployerServlet</servlet-class> <init> <web-services> <attachments-directory>an example</attachments-directory> <web-service ...> <web-service ...> </web-services> </init> </servlet>

Configure web services.

attachments-directory the path of a directory to store attachments in WEB-INF/attachments/

The configuration options for a service are placed in a slightly different place depending on whether the service is a `SoapServlet` or specified with the `SoapDeployerServlet`. The following examples use the soap-style configuration option.

<servlet> <servlet-name>StringServiceServlet</servlet-name> <servlet-class>example.StringServiceServlet</servlet-class> <init> <soap-service> <soap-style>message</soap-style> </soap-service> </init> </servlet> <servlet> <servlet-name>SoapDeployerServlet</servlet-name> <servlet-class>com.caucho.soap.SoapDeployerServlet</servlet-class> <init> <web-services> <web-service name="Calculator/1.0" class-name="example.Calculator"> <soap-style>message</soap-style> </web-service> </web-services> </init> </servlet> <parents>web-services</parents>

Configure a web service.

name the name of the service required for services deployed with SoapDeployerServlet
class-name the name of the class that implements the service required for services deployed with SoapDeployerServlet
soap-namespace the namespace to use for the soap service value of the url used to access the service
soap-style`rpc', `document', `wrapped', or `message'rpc
Java type SOAP type
byte[]xsd:base64Binary
boolean xsd:boolean
byte xsd:byte
java.util.Calendar xsd:dateTime
java.math.BigDecimal xsd:decimal
double xsd:double
float xsd:float
byte[]xsd:hexBinary
int xsd:int
java.math.BigInteger xsd:integer
long xsd:long
javax.xml.namespace.QName xsd:QName
short xsd:short
java.lang.String xsd:string
</document>