Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • ServiceMode indicates whether the specified service handles SOAP payload documents or full SOAP message documents. This property mimics the JAX-WS ServiceMode annotation. The default value is PAYLOAD.
  • BindingMode indicates the service binding ID URL. The default is the SOAP 1.1/HTTP binding.
  • EndpointAddress indicates the URL consumer applications use to communicate with this service. The property is optional but has no default.

Example 1 shows a metadata description for a JavaScript service implementation.Javascript service implementation.

Anchor
ex1
ex1

Code Block
titleExample 1:Javascript Metadata

var WebServiceProvider1 = {
    'wsdlLocation': 'file:./wsdl/hello_world.wsdl',
    'serviceName': 'SOAPService1',
    'portName': 'SoapPort1',
    'targetNamespace': 'http://apache.org/hello_world_soap_http',
};

Implementing the Service Logic

You implement the service's logic using the required invoke property of the WebServiceProvider variable. This variable is a function that accepts one input argument, a javax.xml.transform.dom.DOMSource node, and returns a document of the same type. The invoke function can manipulate either the input or output documents using the regular Java DOMSource class interface just as a Java application would.

Example 2 shows an invoke property for a simple Javascript service implementation.

Anchor
ex2
ex2

Code Block
titleExample 2:Javascript Service Implementation

WebServiceProvider.invoke = function(document) {
    var ns4 = "http://apache.org/hello_world_soap_http/types";
    var list = document.getElementsByTagNameNS(ns4, "requestType");
    var name = list.item(0).getFirstChild().getNodeValue();
    var newDoc = document.getImplementation().createDocument(ns4, "ns4:greetMeResponse", null);
    var el = newDoc.createElementNS(ns4, "ns4:responseType");
    var txt = newDoc.createTextNode("Hi " + name);
    el.insertBefore(txt, null);
    newDoc.getDocumentElement().insertBefore(el, null);
    return newDoc;
}

Implementing a Service in ECMAScript for XML(E4X)

...

The only difference between the two approaches is the type of document the implementation manipulates. When working with E4X, the implementation receives requests as an E4X XML document and returns a document of the same type. These documents are manipulated using built-in E4X XML features.

Example 3 shows an invoke property for a simple E4X service implementation.

Anchor
ex3
ex3

Code Block
titleExample 3:E4X Service Implementation

var SOAP_ENV = new Namespace('SOAP-ENV',
                             'http://schemas.xmlsoap.org/soap/envelope/');
var xs = new Namespace('xs', 'http://www.w3.org/2001/XMLSchema');
var xsi = new Namespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance');
var ns = new Namespace('ns', 'http://apache.org/hello_world_soap_http/types');

WebServiceProvider1.invoke = function(req) {
    default xml namespace = ns;
    var name = (req..requestType)[0];
    default xml namespace = SOAP_ENV;
    var resp = <SOAP-ENV:Envelope xmlns:SOAP-ENV={SOAP_ENV} xmlns:xs={xs} xmlns:xsi={xsi}/>;
    resp.Body = <Body/>;
    resp.Body.ns::greetMeResponse = <ns:greetMeResponse xmlns:ns={ns}/>;
    resp.Body.ns::greetMeResponse.ns::responseType = 'Hi ' + name;
    return resp;
}

Deploying Scripted Services

...

Argument

Description

-a addressURL

Specifies the address at which ServerApp publishes the service endpoint implementation found in the script file following the URL.

-b baseAddressURL

Specifies the base address used by ServerApp when publishing the service endpoints defined by the script files. The full address for the service endpoints is formed by appending the service's port name to the base address.

-v

Specifies that {ServerApp is to run in verbose mode.

Table 1.: Optional Arguments

The optional arguments take precedence over any addressing information provided in {{EndpointAddress}}properties that appear in the JAX-WS metadata.

For example, if you deployed a Javascript service using the command shown in Example 4, your service would be deployed at http://cxf.apache.org/goodnessImage Added.

Anchor
ex4
ex4
Panel
titleExample 4:Deploying a Service at a Specified Address

java org.apache.cxf.js.rhino.ServerApp -a http://cxf.apache.org/goodnessImage Modified hello_world.jsx

To deploy a number of services using a common base URL you could use the command shown in Example 5. If the service defined by hello_world.jsx had port name of helloWorld, ServerApp would publish it at http://cxf.apache.org/helloWorld. If the service defined by goodbye_moon.js had a port name of blue, ServerApp would publish at http://cxf.apache.org/blue.

Anchor
ex5
ex5
Panel
titleExample 5:Deploying a Group of Services to a Base Address

java org.apache.cxf.js.rhino.ServerApp -b http://cxf.apache.orgImage Added hello_world.jsx goodbye_moon.js

You can also combine the arguments as shown in Example 6., and your service would be deployed at http://cxf.apache.org/goodness. ServerApp would publish three service endpoints: