Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Apache Axis2 Stubs & Skeletons With Axis2 Agenda Introducing the Axis2 code generator Client Side-Stubs with Axis2 − − − Server Side-Skeletons with Axis2 − − − Default options Different data bindings Tweaks and options Default options Different data bindings More tweaks Exercises Command Line Codegen Tool • Two Formats − − wsdl2java java2wsdl • Available in .bat and .sh formats in <Axis2_home>/bin directory • wsdl2java - generate Java helper classes from WSDL • java2wsdl – generate a WSDL from a Java Class or Interface Main tooling functions Stub <wsdl/> Interface Or class java2wsdl wsdl2java document Skeleton Tooling in real life WSDL Enhance WSDL Axis2 client stub 1 POJO 2 Axis2 server SOAP (at runtime) WSDL2Java Java2WSDL (automatic) WSDL2Java WSDL + (filled-in) Skeleton WSDL Where is the Code Generator? Command line version − − Available in the Axis2 standard distribution Accompanied with Batch and Shell scripts Eclipse plug-in IntelliJ IDEA plug-in Maven2 plug-in Ant task Details: http://ws.apache.org/axis2/tools/index.html Note: All the examples use the command line tool Options for the Code Generator Long list of options! − − Complete reference at http://ws.apache.org/axis2/tools/1_4/CodegenToolReference.html Also look at http://ws.apache.org/axis2/1_4/reference.html Important ones − − − − -uri – WSDL file (required) -o – output folder -d – data binding framework -s – sync interfaces o Agenda Introducing the Axis2 code generator Client Side-Stubs with Axis2 − − − Default options Different data bindings Tweaks Server Side-Skeletons with Axis2 − − − Default options Different data bindings More tweaks Stubs - Case 1 - Default Options Try the -uri option only wsdl2java -uri currencyConvert.wsdl Applied default options − − − − − Output directory is the current directory Data binding is ADB Language is Java Both sync and async methods Client side code generation only Stubs - Case 1 Cont... Generated Artifacts − src directory Stub source file − Callback source file − − The call back class to be used when invoking the async methods build.xml − Contains both the sync and async methods Ant build file All data binding classes are generated as inner classes inside the stub Stubs – Case 1 - sync Method Returns the relevant response directly //instantiate the stub CurrencyConverterServiceStub stub = new CurrencyConverterServiceStub(); CurrencyConverterServiceStub.ConversionRequest request = new CurrencyConverterServiceStub.ConversionRequest(); //fill up the request object request.setAmount(100f); request.setFromCurrency("USD"); request.setToCurrency("SLR"); //send and get the response CurrencyConverterServiceStub.ConversionResponse response = stub.convert(request); Data binding How to go from Java objects to XML and back again Axis2 was designed to be flexible with respect to the Data Binding approach wsdl2java supports − − − − − XMLBeans – an Apache project ADB – Axis Data Binding (built-in) JIBX – http://jibx.sourceforge.net JAXBRI – Java API for XML Binding Reference Implementation None – A stub/skeleton with AXIOM-typed interface Data binding compared XMLBeans has 100% schema coverage − But generates many many classes! ADB does not support 100% schema coverage and hence has limitations. But the number of classes are significantly reduced improving performance. JiBX is a third party binding framework JAXB is the Java Standard Stubs - Case2 - Switch Data Binding Use the -d option Other options are defaults − Similar to case 1 wsdl2java -uri currencyConvert.wsdl -d xmlbeans Stubs – Case2 Cont... Generated Artifacts − src directory Stub source file − Callback source file − − The call back class to be used when invoking the async methods XMLBeans specific data binding classes resources directory − Contains both the sync and async methods XMLBeans specific xsb files build.xml Ant build file Stubs - Case 2 – sync Method Method signatures are slightly different − Uses XMLBeans classes now! CurrencyConverterServiceStub stub = new CurrencyConverterServiceStub(); ConversionRequestDocument requestDoc = ConversionRequestDocument.Factory.newInstance(); ConversionRequest request = requestDoc.addNewConversionRequest(); //fill up the request object request.setAmount(100f); request.setFromCurreCncy("USD"); request.setToCurrency("SLR"); //call the method ConversionResponseDocument response = stub.convert(requestDoc); Stubs – Case 3 - Tweaks Switch on/off sync and async − − -a generates only async methods -s generates only sync methods Generate a test case − -t generates a Junit test case Needs filling in before usage Read the todo's before running! Unpack ADB classes − -u expands the generated data binding classes See next page Unpacking Unpacked stubs have separate classes for the top-level types Works well for a real SOA application where the data types will be used across several different services Always used for server side Otherwise all the classes are inner types of the stub Gives a single class to use a service and works well for building a client to a single service Stubs – Case 3 Cont... Package name control − − − Derives package names from the target namespace by default -p overrides the main package -ns2p helps to provide different packages to different namespac Unwrapping Remember the discussion of “wrapping” in WSDL? -uw performs an unwrapping if your WSDL uses a wrapped style Instead of − − submit(PORequest po) submit(String,String,int, double,…) Agenda Introducing the Axis2 code generator Client Side-Stubs with Axis2 − − − Default options Different data bindings Tweaks and options Server Side-Skeletons with Axis2 − − − Default options Different data bindings More tweaks Skeletons – Case 1 - Defaults Try the -uri option with -ss and -sd -ss stands for server side -sd stands for service descriptor Default options used are similar to stub case 1 wsdl2java -uri currencyConvert.wsdl -ss -sd Skeletons – Case 1 Cont... Generated Artifacts − src directory Skeleton source file Message receiver source file ADB specific data binding classes − resources directory WSDL file services.xml file − build.xml Ant build fil Skeletons – Case 1 Cont... Just fill in the skeleton Example code: public class MyServiceSkeleton { public MyReturnObject myOperation(MyReqObj param0) { // fill in code here return null; } } Skeletons – Case 1 Cont... Making the service archive − Use the build script! Deploy the service archive − − Copy the archive to the services folder of the repository. Upload it using the web admin tool. Skeletons - Case 2 - Switch Data Binding Use the -d xmlbeans switch Default options used are similar to case1 wsdl2java -uri currencyConvert.wsdl -ss –sd -d xmlbeans Skeletons – Case 2 Cont... Generated Artifacts − src directory Skeleton source file Message receiver source file XMLBeans specific data binding classes − resources directory WSDL file services.xml file XMLBeans specific .xsb files − build.xml Ant build file Skeletons – Case 3 - Tweaks -ssi generates an interface − useful when multiple implementations are present -g generates both client and server code Summary Axis2 offers a rich set of code generation options − − − Stubs and skeletons Multiple data bindings Auto creation of WSDL, services.xml and Ant build file Also plug-in versions of the command line tools are available for several IDEs Exercises In the beginner section of this training, we have used wsdl2java command both to generate server side and client side code. How about java2wsdl? Find the options that can be used with this command. Given the Java interface “TemperatureConverter.java” (see the resources section), − − Use java2wsdl to generate the WSDL file and then wsdl2java to generate client and server side code Complete both client and server, deploy the service and test