// This shows how the echoService can be invoked using the JMS transport.
// Use the WSRequest host onject to invoke the echoService
function invokeEchoViaJMS(){
var request = new WSRequest();
var options = new Array();
// Specify the soap action so that the request can be dispatched to the correct operation
options.action="http://services.mashup.wso2.org/echoService/ServiceInterface/echoRequest";
// The payload that the service will be invoked with
var payload = JMS;
var result;
try {
request.open(options,"jms:/keith-echoService?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616", false);
request.send(payload);
result = request.responseXML;
} catch (e) {
system.log("Received an error" + e.toString());
result = e.toString();
}
return result;
}
function invokeEchoViaJMSOneWay(){
var request = new WSRequest();
var options = new Array();
// Specify the soap action so that the request can be dispatched to the correct operation
options.action="http://services.mashup.wso2.org/echoService/ServiceInterface/echoRequest";
// Specify that I dont care about the responce
options.mep="in-only";
// The payload that the service will be invoked with
var payload = JMS;
request.open(options,"jms:/keith-echoService?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616", false);
// As we are using a in-only mep there wont be a responce
request.send(payload);
return "Message sent";
}
function invokeEchoViaJMSUsingWSDL(){
var request = new WSRequest();
// The payload that the service will be invoked with
var payload = JMS;
// Need to specify the service that we need to invoke. The WSDL may have multiple services in it
var service = new QName("http://services.mashup.wso2.org/echoService","echoService");
var result;
try {
// We instruct that we want to invoke this operation using details in the JMSSOAP12Endpoint
request.openWSDL("http://localhost:7762/services/keith/echoService?wsdl",false, new Array(), service, "JMSSOAP12Endpoint");
request.send("echo",payload);
result = request.responseXML;
} catch (e) {
system.log("Received an error" + e.toString());
result = e.toString();
}
return result;
}
// Include the stub of the echoService mashup that we hope to invoke
system.include("stub.js");
function invokeEchoViaStub(){
var result;
try {
// Specify that we need to use one of the JMS endpoints
echoService.endpoint = "JMSSOAP12Endpoint";
// Call the echo operation with the parameter as JMS
result = echoService.echo("JMS");
} catch (e) {
system.log("Received an error" + e.toString());
result = e.toString();
}
return result;
}
function invokeEchoViaJMSWithSecurityUsingWSDL(){
var request = new WSRequest();
// The payload that the service will be invoked with
var payload = JMS;
// Need to specify the service that we need to invoke. The WSDL may have multiple services in it
var service = new QName("http://services.mashup.wso2.org/echoService","echoService");
var options = new Array()
// Set the details needed by the security policy.
options["username"] = "keith";
options["password"] = "keith";
options["encryptionUser"] = "keith";
var result;
try {
// We instruct that we want to invoke this operation using details in the JMSSOAP12Endpoint
request.openWSDL("http://localhost:7762/services/keith/echoService?wsdl",false, options, service, "JMSSOAP12Endpoint");
request.send("echo",payload);
result = request.responseXML;
} catch (e) {
system.log("Received an error" + e.toString());
result = e.toString();
}
return result;
}