Child pages
  • Using Envjs to call a SOAP WebService from within a Custom Endpoint
Skip to end of metadata
Go to start of metadata

Very simple example sample which demonstrates how to use Envjs 1.0 to call a SOAP WebService via a custom endpoint and perform a spellcheck against a provided string of text.

Pre-requisites

  1. Download and install OpenIDM 2.1.
  2. Download the env.rhino.1.0.js and copy it to the openidm/script directory.
  3. Shutdown OpenIDM if it is currently running.

Create the Custom Endpoint

Create a new custom endpoint configuration for the 'endpoint/spellcheck' context:

conf/endpoint-spellcheck.js
{
    "context" : "endpoint/spellcheck",
    "type" : "text/javascript",
    "file" : "script/spellcheck.js"
}

Create the script that will load the env.rhino.1.0.js file and invoke the webservice:

script/spellcheck.js
load('script/env.rhino.1.0.js');
 
if (request.params === undefined || request.params.text === undefined) {
    throw {
        "openidmCode" : 500,
        "message" : "Required parameter 'text' was not found"
    };
}


var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'http://wsf.cdyne.com/SpellChecker/check.asmx?WSDL', false);
 
var req =
'<?xml version="1.0" encoding="utf-8"?>' +
'<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">' +
' <soap12:Body>' +
' <CheckTextBody xmlns="http://ws.cdyne.com/">' +
' <BodyText>' + request.params.text + '</BodyText>' +
' <LicenseKey></LicenseKey>' +
' </CheckTextBody>' +
' </soap12:Body>' +
'</soap12:Envelope>';
 
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(req);
xmlhttp.responseText;

Invoke the Custom Endpoint

  1. Start OpenIDM

  2. Invoke the spellcheck endpoint with the text parameter 'Thi is spealt wrong!' via curl or your favourite REST client:

curl --header "X-OpenIDM-Username: openidm-admin" --header "X-OpenIDM-Password: openidm-admin" --request GET "http://localhost:8080/openidm/endpoint/spellcheck?text=%22Thi%20is%20spealt%20wrong%21%22"

 

Expected Result

"
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<soap:Envelope 
    xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" 
    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 
    xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">
    <soap:Body>
        <CheckTextBodyResponse 
            xmlns=\"http://ws.cdyne.com/\">
            <DocumentSummary>
                <MisspelledWord>
                    <Suggestions>thai</Suggestions>
                    <Suggestions>ti</Suggestions>
                    <Suggestions>Thai</Suggestions>
                    <Suggestions>t hi</Suggestions>
                    <Suggestions>the</Suggestions>
                    <Suggestions>thy</Suggestions>
                    <Suggestions>thu</Suggestions>
                    <Suggestions>tho</Suggestions>
                    <Suggestions>phi</Suggestions>
                    <Suggestions>chi</Suggestions>
                    <Suggestions>Thia</Suggestions>
                    <Suggestions>Th</Suggestions>
                    <Suggestions>thia</Suggestions>
                    <Suggestions>this</Suggestions>
                    <Suggestions>thin</Suggestions>
                    <Suggestions>th</Suggestions>
                    <Suggestions>Thu</Suggestions>
                    <Suggestions>hi</Suggestions>
                    <Suggestions>Th's</Suggestions>
                    <Suggestions>thigh</Suggestions>
                    <Suggestions>Thieu</Suggestions>
                    <Suggestions>Thais</Suggestions>
                    <Suggestions>thee</Suggestions>
                    <Suggestions>Theo</Suggestions>
                    <Suggestions>Thur</Suggestions>
                    <word>Thi</word>
                    <SuggestionCount>25</SuggestionCount>
                </MisspelledWord>
                <MisspelledWord>
                    <Suggestions>splat</Suggestions>
                    <Suggestions>split</Suggestions>
                    <Suggestions>spelled</Suggestions>
                    <Suggestions>splats</Suggestions>
                    <Suggestions>spoiled</Suggestions>
                    <Suggestions>splatter</Suggestions>
                    <Suggestions>splits</Suggestions>
                    <Suggestions>splat's</Suggestions>
                    <Suggestions>splatters</Suggestions>
                    <Suggestions>splutter</Suggestions>
                    <Suggestions>splitter</Suggestions>
                    <Suggestions>split's</Suggestions>
                    <Suggestions>splattered</Suggestions>
                    <Suggestions>respelled</Suggestions>
                    <Suggestions>splitters</Suggestions>
                    <Suggestions>splutters</Suggestions>
                    <Suggestions>splutterer</Suggestions>
                    <Suggestions>splattering</Suggestions>
                    <Suggestions>splitter's</Suggestions>
                    <Suggestions>unspoiled</Suggestions>
                    <Suggestions>spluttered</Suggestions>
                    <Suggestions>spluttering</Suggestions>
                    <word>spealt</word>
                    <SuggestionCount>22</SuggestionCount>
                </MisspelledWord>
                <ver>2.0</ver>
                <body>\"Thi is spealt wrong!\"</body>
                <MisspelledWordCount>2</MisspelledWordCount>
            </DocumentSummary>
        </CheckTextBodyResponse>
    </soap:Body>
</soap:Envelope>"
  • No labels