0.1.1 • Published 8 years ago

soap-connector v0.1.1

Weekly downloads
5
License
-
Repository
-
Last release
8 years ago

Mad Oracle CDI Connector

This module manipulates requests to bring the ability to do SOAP requests with connection configuration.

Install

npm install bitbucket:core-service/oracle-orce-connector

Initialize

let soapConnector = require('soap-connector');

soapConnector.getInstance(config).then((client)=>{
    client[method](data).then(function(res){
      // do something with the response
    }).catch(function(err){
      // do something with the error
    });
})

Config object options for the init connector

Is necessary the object have this properties:

  • wsdl: the url, it can be a http://, http:// or file://
  • auth: authorization configuration object
  • wsdlOptions: an object with the WSDL options defined in detail below in the document
  • responseParser: a function as like handler of the document, the default format is like this:
    res = {
      response: {
        status: '',
        payload: response
      }
    };

Example

let config = {
  wsdl: 'http://mad-test.com?wsdl',
  auth : {
    type:'basic'
    username: 'Bruce',
    password: 'Wayne'
  },
  wsdlOptions: {
    ignoredNamespaces: {
      namespaces: [],
      override: true
    }
  },
  responseParser : function(){}
}

auth object configuration:

  • type: the type of the Security strategy. The library supports: basic, ssl, ws,barear, none
  • username: the service name of the endpoint to execute, example myService
  • password: the port name of the service to execute, example myPort
  • key: the key value if the configuration type needs
  • certificate: the certificate if the configuration type needs
  • token: the token string if the configuration type needs

BASIC security config needs :

  • username
  • password

SSL security config needs :

  • username
  • password
  • key
  • certificate

WS security config needs :

  • username
  • password

Barear security config needs :

  • token

Example

auth:{
  type: "basic"
  username: "Bruce",
  password: "Wayne"
},

WSDL options configuration:

Sometimes it is necessary to override the default behaviour of the connector in order to deal with the special requirements of your code base or a third library you use. Therefore you can use the wsdlOptions Object, which is passed in the options, and could have any (or all) of the following contents:

let wsdlOptions = {
  attributesKey: 'theAttrs',
  valueKey: 'theVal',
  xmlKey: 'theXml'
}

Handling "ignored" namespaces

If an Element in a schema definition depends on an Element which is present in the same namespace, normally the tns: namespace prefix is used to identify this Element. This is not much of a problem as long as you have just one schema defined (inline or in a separate file). If there are more schema files, the tns: in the generated soap file resolved mostly to the parent wsdl file, which was obviously wrong.

The submodule handles namespace prefixes which shouldn't be resolved (because it's not necessary) as so called ignoredNamespaces which default to an Array of 3 Strings (['tns', 'targetNamespace', 'typedNamespace']).

If this is not sufficient for your purpose you can easily add more namespace prefixes to this Array, or override it in its entirety by passing an ignoredNamespaces object within the options you pass in soap.createClient() method.

A simple ignoredNamespaces object, which only adds certain namespaces could look like this:

var wsdlOptions = {
  ignoredNamespaces: {
    namespaces: ['namespaceToIgnore', 'someOtherNamespace']
  }
}

This would extend the ignoredNamespaces of the WSDL processor to ['tns', 'targetNamespace', 'typedNamespace', 'namespaceToIgnore', 'someOtherNamespace'].

If you want to override the default ignored namespaces you would simply pass the following ignoredNamespaces object within the options:

var wsdlOptions = {
    ignoredNamespaces: {
      namespaces: ['namespaceToIgnore', 'someOtherNamespace'],
      override: true
    }
  }

This would override the default ignoredNamespaces of the WSDL processor to ['namespaceToIgnore', 'someOtherNamespace']. (This shouldn't be necessary, anyways).

If you want to override the default ignored namespaces you would simply pass the following ignoredNamespaces object within the options:

var wsdlOptions = {
    ignoredNamespaces: {
      namespaces: ['namespaceToIgnore', 'someOtherNamespace'],
      override: true
    }
  }

This would override the default ignoredNamespaces of the WSDL processor to ['namespaceToIgnore', 'someOtherNamespace']. (This shouldn't be necessary, anyways).

Handling "ignoreBaseNameSpaces" attribute

If an Element in a schema definition depends has a basenamespace defined but the request does not need that value, for example you have a "sentJob" with basenamespace "v20" but the request need only: set in the tree structure, you need to set the ignoreBaseNameSpaces to true. This is set because in a lot of workaround the wsdl structure is not correctly set or the webservice bring errors.

By default the attribute is set to true. An example to use:

A simple ignoredNamespaces object, which only adds certain namespaces could look like this:

var wsdlOptions = {
ignoredNamespaces: true
}

Client Object:

In the client data object, you can give a specific auth information and parameters. Remember, the auth property overrides the setting set in the connection config, and uses the same settings of auth definition in buildClient().

let data = {
  params: {},
  auth: {},
  headers: []
}

Array of Header objects configuration:

Every object need:

  • header: soapHeader Object({rootName: {name: "value"}}) or strict xml-string
  • name: unknown parameter (it could just a empty string)
  • namespace: prefix of xml namespace
  • xmlns: URI