TinyWS
TinyWS is a Java servlet which gives access to methods via SOAP over HTTP. Function signatures and data structures are exported via WSDL (hence the name TinyWS which stands for a Tiny WebService).
Howto
- Download the latest TinyWS release
- Deploy the TinyWS-X.Y.war file at your servlet container (e.g. Tomcat)
- Download Codec from the Apache Commons Project into your $CATALINA_HOME/lib folder (only for TinyWS >= 2.0)
- Download FileUpload from the Apache Commons Project into your $CATALINA_HOME/lib folder (only for TinyWS >= 2.0)
- Put a JDBC connector for your database into your $CATALINA_HOME/lib folder, eg. for MySQL (only for TinyWS >= 2.0)
- Create a JNDI datasource called TinyWSDB within
your servlet container. Have a look at my
$CATALINA_HOME/conf/Catalina/localhost/TinyWS.xml:
<?xml version="1.0" encoding="UTF-8"?> <Context path="/TinyWS"> <Resource name="/jdbc/TinyWSDB" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" username="tinyws" password="verysecret" url="jdbc:mysql://localhost:3306/TinyWSDB" /> </Context>
(only for TinyWS >= 2.0) - Ensure that you can connect to the database specified by those credentials (only for TinyWS >= 2.0)
- Either:
- Write a small application that allows you to upload and delete applications within TinyWS
- Download or reference the url http://your.servlet.container/TinyWS/servlet/net.ogris.tinyws?wsdl in that application
- Call the (remote) methods TinyWSUploader.uploadApplication and TinyWSUploader.deleteApplication where appropriate
- Start a new Java project in your IDE, and import the file http://your.servlet.container/TinyWS/net.ogris.tinyws.annotation.jar
- Write the methods that you want to make accessible via SOAP; prefix each exported method with an net.ogris.tinyws.annotation.TinyWSParams annotation, which should contain an array of strings stating the method's parameter names
- Copy your Java classes into a new jar file as if you were building an ordinary application
- Upload that jar file to TinyWS by using your small application from #8.1 to #8.3
- Alternatively, upload your jar file through the TinyWS web interface
- Now you can start writing SOAP clients for Java classes by referencing http://your.servlet.container/TinyWS/servlet/your.name.space?wsdl
- For logging all TinyWS errors and warnings to a separate
file, edit $CATALINA_HOME/conf/logging.properties. Add a new handler
called 6TinyWS.org.apache.juli.FileHandler. Configure this handler:
6TinyWS.org.apache.juli.FileHandler.level = ALL 6TinyWS.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 6TinyWS.org.apache.juli.FileHandler.prefix = TinyWS.
Finally send all TinyWS logs to this handler:org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/TinyWS].level = ALL org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/TinyWS].handlers = 6TinyWS.org.apache.juli.FileHandler
About
TinyWS is a Java servlet that acts as a SOAP container. You upload compiled class files bundled into JAR archives (I call these applications although there is no need for a public static main(String[]) method). Every method within those class files will be accessible by SOAP (and WSDL) if all of the following requirements are met:
- it is annotated with a TinyWSParams interface
- its parameter count matches the amount of strings within its TinyWSParams annotation
- it is a public method
- it is not an abstract method
- its class is not abstract
- its class is not an interface
- its class is public
- it is either a static method or its class has a public nullary constructor (a constructor without any parameters)
- its return type and parameter types are either
resolvable within all currently uploaded application or one of the
following types:
- boolean
- byte
- float
- double
- int
- long
- short
- Boolean
- Byte
- Float
- Double
- Integer
- Long
- Short
- String
- void
- URI
- byte[]
- java.util.Date
- UUID
- InetAddress
- Inet4Address
- Inet6Address
public String foobar(Integer a, String b) { return b + a; }The Java compiler removes the name of all parameters. In byte code the method's signature looks like public String foobar(Integer, String). To keep the name of all parameters, you have to use a TinyWSParams annotation:
@TinyWSParams({"a", "b"}) public String foobar(Integer a, String b) { return b + a; }So TinyWS can generate method descriptions using named method parameters. Another annotation type (TinyWSDoc) could be used to export your inline documentation:
package net.ogris.tinyws.test; @TinyWSDoc("This class provides some services") public class Test { @TinyWSDoc("This method does something.\n" + "And has a multiline documentation.\n" + "Cool!") @TinyWSParams({"a", "b"}) public static int blabla(int a, int b) { return a + b; } }These TinyWSDoc annotations are put into the WSDL description and generated stubs. Keep in mind that all classes and types must be resolvable. If you are using non-base Java types:
@TinyWSParams({"a", "b"}) public Snafu foobar(Integer a, String b) { return new Snafu(b + a); }Then the class Snafu must be resolvable, which means that
- it must reside in one of the currently uploaded applications (JAR files)
- it is not abstract
- it is not an interface
- it is public
- it has a nullary constructor
- its fields are either public or have public getters and setters, so that a private boolean field called foo is accessible through a public boolean isFoo() and a public void setFoo(boolean) and any non-boolean field is accessible through a public whatever getBar() and a public void setBar(whatever).
Features
- on-the-fly server side creation of WSDL descriptions by just using TinyWS annotations in the source code
- RPC like access to uploaded methods through SOAP over HTTP (document/literal encoded style only)
- on-the-fly server side creation of PHP stubs as there are currently no WSDL-to-PHP code generators for Eclipse, NetBeans, etc.
- servlet status page
- human readable list of all accessible methods
- small code size (2k lines of Java code as of TinyWS 2.0!)
- list, upload and delete applications through included SOAP functions
- list, upload and delete applications through web page (TinyWS >= 2.0 only)
- storage of applications in the local filesystem (TinyWS 1.0 only)
- storage of applications in a SQL database (TinyWS >= 2.0 only)
- cluster-aware by using a central SQL database (which could by clustered itself) and sending multicast helo- and reconfiguration-packets (TinyWS >= 2.0 only)
Wishlist
let TinyWSUploader cache all applications like TinyWSConfig caches all config options(fixed as of TinyWS 2.1)database setup through web page(fixed as of TinyWS 2.1)create an internal (error) logging and make it viewable on the web page(no, use Tomcat's logging facilities instead)- authentication for TinyWSUploader or maybe a flexible ip address restriction for any SOAP access
- provide more stub generators, eg. for Perl, C, bash, etc.
- support the whole bunch of SOAP variants, WS-I sermon, and so on
- hear some success stories from you outside there about using TinyWS, send mail to www@ogris.de
Download
TinyWS is licensed under the LGPL Version 3. See the file web/License.txt in the source distribution, which is available as http://your.servlet.container/TinyWS/License.txt on a TinyWS equipped site or read it online at http://www.gnu.org/licenses/lgpl.txt (local copy).
- TinyWS-2.4.war (released 2010-04-11)
- TinyWS-2.3.war (released 2009-07-18)
- TinyWS-2.2.war (released 2008-12-21)
- TinyWS-2.1.war (released 2008-12-04)
- TinyWS-2.0.war (released 2008-12-03)
- TinyWS-1.0.war (released 2008-07-27)
Source
Source code is available in SVN:
- https://ogris.net/svn/TinyWS/TinyWS (Head)
- https://ogris.net/svn/TinyWS/tags (Releases), eg. https://ogris.net/svn/TinyWS/tags/TinyWS-1.0
Username: svn, Password: svn