Sambuca Simple Web Service Framework - Simple Web Service Auto Mounting

Navigation

How to automatically "mount" your Java Facade class as a Web Service

  1. Create a java class with a public default constructor. (It makes sense if this class uses the Facade Design Pattern.)
  2. Add public methods to your java class. (If you are following the Facade Design Pattern, your methods should be nothing more than entry point wrapper methods.) Note that ALL public accessible methods in the class you provide to the WebServiceAutoMounter will be exposed via the Web Service Interface.
  3. Ensure that your Facade class that you have just created to expose as a web service and all of the classes it references are in the same classpath as the Sambuca Framework.
  4. From the command line run the class: com.roguelogic.sambuca.websrvcs.simple.WebServiceAutoMounter
  5. Usage of the Web Service Auto Mounter:
    java <-DSambucaLogger=[CLASS_NAME]> com.roguelogic.sambuca.websrvcs.simple.WebServiceAutoMounter [WEB_SERVICE_FACADE_CLASS_NAME] [PORT]
    Where [WEB_SERVICE_FACADE_CLASS_NAME] is the fully qualified class name of a java Facade, that the WebServiceAutoMounter will scan and make available ALL public methods of this class as Web Services via the supplied [PORT].
  6. Check out how simple the SimpleEchoWSFacade.java Facade Class really is...

How to obtain the Client Stubs for your Automatically Mounted Web Service

  1. Once your Java Facade Class is automatically mounted as a Web Service, all you need to do is pass the URL of the Web Service Inventory to the Client Stub Generator class.
  2. Since each instance of the WebServiceAutoMounter only hosts one Java Facade Class as a web service, the URL is always the same for the Web Service Inventory XML: http://localhost:8181/?action=GET-WS-INVENTORY (Note that the port may be different depending on which port you specific to your instance of WebServiceAutoMounter)
  3. Pass the Inventory URL as the first parameter to the Client Stub Generator. The second parameter is a package name you want the Generator to create the Client classes in. The final parameter is the root output directory, where you want the generator to create the package and write the class files to.
    Usage of the Client Stub Generator:
    java com.roguelogic.sambuca.websrvcs.simple.ClientStubGenerator [INVENTORY_URL] [OUTPUT_PACKAGE_NAME] [OUTPUT_DIR]

How to use the generated Client Stubs to make the remote web service method calls

  1. The generator will create a class "[MOUNTED_FACADE_CLASS_NAME]WSClient". This is the class you will invoke methods on locally, which will make the remote calls to the web service on your behalf.
  2. The WSClient class is generated with a constructor that takes a URL (string representation) of the Web Service Auto Mounter instance. If your server is listening on port 8181 on localhost, all you need to do is pass "http://localhost:8181/" to the constructor.
  3. Once you have an instance of the generated WSClient class, you can invoke the same methods on your remote Java Facade class, however you would be calling them on the instance of the WSClient client stub instance instead. The stub will remotely invoke the method on the server for you!
  4. Take a look at how easy it is to invoke the remote web service methods using the Generated Client Stubs, used by the test class TestSimpleWSEcho.java
  5. If you are interested in what the Client Stub Generator's generated code looks like, take a look at SimpleEchoWSFacadeWSClient.java


RogueLogic