|
Page Edited :
CXF20DOC :
_javascript_ Client Code
_javascript_ Client Code has been edited by Benson Margulies (Dec 24, 2007). Content:Structure of the CodeThere are three types of _javascript_ code:
UtilitiesThe utilities code is a fixed set of _javascript_ that provides some browser compatibility and XML management. This code is delivered in the distribution in the file etc/cxf-utils.js. If you are using the ?js URL handler, it is delivered at the beginning of the response (unless you add ?nojsutils to the URL). If you are generating _javascript_ using the tools, it is up to you to copy this file use it. Schema CodeThe Schema code generates one object for each 'bean' used in your service. This code is organized by XML Schema. The code for each schema starts with a comment like: //
// Definitions for schema: http://apache.org/hello_world_soap_http/types
// file:/home/benson/cxf/trunk/distribution/src/main/release/samples/js_browser_client/wsdl/hello_world.wsdl#types1
//
Synchronous and Asynchronous processingThe CXF _javascript_ code generator is designed to facilitate typical, AJAX, asynchronous processing. As described below, the per-operation functions take callbacks as parameters, and call them back when the server responds. If you want to use synchronous communications, you can set the 'synchronous' property to 'true'. That does not change the API, but rather changes the behavior. With this setting, the operation functions do not return until after the server has responded and the callbacks have been called back. Per-Operation FunctionsThe code generator generates a function for each operation. Unless the operation is one way, the function will take two callback parameters plus the parameters for the operation itself. The first two parameters are the success callback and the error callback. OneWay operations have no callbacks, they are "fire and forget." The success callback is called back with one parameter: the _javascript_ object corresponding to the response. What is that object? Well, that depends on the schema of the operation. If you are using Document/Literal/Wrapped, it will be a _javascript_ object corresponding to the wrapper object for the output part. If you are using Document/Literal/Bare, it will correspond to the output part. If the output part has a simple type, such as String, the response callback will be called with a simple _javascript_ object. The error callback will be called only when the server responds with an HTTP error status. It will be called with two parameters: the HTTP status number and the HTTP status text. When/if the client _javascript_ generator is improved to have more comprehensive support for faults, the protocol will change to pass Understanding the Parameters of Operation FunctionsIf you have a choice in the matter, and you are using Document/Literal, the present author recommends bare as opposed to wrapped methods. This pushes all the type management from the front end (JAX-WS or Simple) to the data binding (JAXB or Aegis). The data bindings offer much clearer configuration control over namespaces and such than the frontends. In general, you will probably feel the need to read the _javascript_ code to understand the binding in complex cases. One possible future enhancement of the generator is to generate more comments, or perhaps even an HTML explanation, to assist in this process. Examples of Calling ServicesHere are some snippets of calls to services. You should expect to inspect the generated _javascript_ to learn the names of classes and functions. A Document/Literal/Bare ServiceThe present author finds that, at least for JAX-WS, BARE has a lot to recommend it, as it avoids surprising interactions between JAX-WS and JAXB. function errorCallback(httpStatus, httpStatusText) { globalErrorStatus = httpStatus; // integer HTTP status globalStatusText = httpStatusText; // Textual HTTP status } function successCallback(responseObject) { // the parameter is an object of the type declared for the // method. globalResponseObject = responseObject; } function compliantTest(url) { var intf; // class for the service. intf = new org_apache_cxf_javascript_fortest_SimpleDocLitBare(); intf.url = "" var bareParam = new my_param_class_object(); bareParam.setWhatever(someValue); // ... intf.compliant(successCallback, errorCallback, bareParam); } |
Unsubscribe or edit your notifications preferences
