Synchronous call to external SOAP Authentication Enabled Webservice from Maximo Automation Script

Synchronous call to external SOAP Authentication Enabled Webservice from Maximo





Maximo Out of the box Web service/ HTTP handler will support user name and password but it will use when external webservice using HTTP layer authentication.


Normal Webservice call:

Sometimes there can be a situation when you want to invoke a webservice on Mbo Save or update or delete or from a Work Flow action.


Following snippets to synchronous webservice from automation script.


from psdi.iface.mic import InvokeChannelCache
InvokeChannelCache.getInstance().getInvokeChannel("InvokeAsset").invoke(null,mbo,mbo,"<WebserviceEndPoint>")





Some times you want to call web service with out interacting with maximo integration layer. use below snippet.


Normal webservice call to bypass MIF:

package psdi.iface.webservices;


WSCallClient callClient = new WSCallClient();
callClient.invokeWebService(getPropertyValue("SERVICENAME"), getEndpointURL(), data, getHttpVersion(), getUserName(), getPassword(), getSoapAction(), getMsgExPtrn(), getSOAPVersion(), null, getTokenUserName(), getTokenPassword(), getHttpReadTimeout(), getHttpConnTimeout(), getCfgXmlPath(), null, headerElements);



Calling SOAP Authenticated Webservice from Maximo:

Some times there can be situation external system webservices are using webservice header level authentication.


1. Need to prepare OMElement based on External webservice.
2. Convert to OMElement to Byte Stream and Pass as SOAP header element.
3. Add this to List object with key "HEADERELEMENTS"
4. Add above list to new list with key "endpointprops"
5. Pass this list as first parameter to invocation channel method.
6. Add new system property "mxe.int.useaxiswsclient" as value 1.

Use below snippet.

from psdi.iface.mic import InvokeChannelCache
from psdi.iface.mic import InvokeChannel
from psdi.util import MXSystemException
from psdi.server import MXServer
from psdi.util import MXException
from java.net import ConnectException
from javax.xml.ws import WebServiceException
from javax.xml.ws.soap import SOAPFaultException
from org.apache.axis2 import AxisFault
from org.apache.axiom.om import OMAbstractFactory
from org.apache.axiom.om import OMElement
from org.apache.axiom.om import OMFactory
from org.apache.axiom.om import OMNamespace
from org.apache.axiom.om import OMText
from java.util import List
from java.util import Map
from java.util import Hashtable as headersmap
from java.util import Hashtable as oslistmap
from java.util import ArrayList as headerslist
from psdi.iface.webservices import WebServicesUtil  



#Creation of Factory
factory = OMAbstractFactory.getOMFactory();
#getting username and password from system properties
uname=service.getProperty("XXXXX.webservice.username")
pwd=service.getProperty("XXXXX.webservice.password")
namespace1  = factory.createOMNamespace("<NameSpace>", "wsse");
#Creating the Namespace
root = factory.createOMElement("Security", namespace1); #creating the root element
ns2  = root.declareNamespace("<NameSpace>", "wsu");
ns3  = root.declareNamespace("
http://schemas.xmlsoap.org/soap/envelope", "soapenv");
root.addAttribute("mustUnderstand", "1", ns3); #adding attribute to root element.
            
elt1 = factory.createOMElement("UsernameToken", namespace1);
elt1.addAttribute("Id", "UsernameToken-4", ns2);
            
elt2 = factory.createOMElement("Username", namespace1);
elt3 = factory.createOMElement("Password", namespace1);
elt3.addAttribute("Type", "<NameSpace>", ns2);
#passing username  and password
txt1 = factory.createOMText(elt2, uname);
txt2 = factory.createOMText(elt3, pwd);

#Adding elements to Header element.
elt2.addChild(txt1);
elt3.addChild(txt2);
elt1.addChild(elt2);
elt1.addChild(elt3);
root.addChild(elt1);
soapheaderbytearry= WebServicesUtil.convertToBytes(root) # converting OMElement to Byte array.
service.log("SOAP Headers:::"+ str(root))

metaoslistmap=oslistmap()
metaheadersmap=headersmap()
metaheaderslist=headerslist()
metaheaderslist.add(soapheaderbytearry)
metaheadersmap.put("HEADERELEMENTS",metaheaderslist) # Adding Byte Array to Headers Map.
metaoslistmap.put("endpointprops",metaheadersmap) # Adding Map to endpoint Properties.


#Getting the Invocation Channel. Assume In Invocation channel associative end point.
srInvokeChannel = InvokeChannelCache.getInstance().getInvokeChannel("<InvocationChannalName>")
#Invoking the GIS Web Service.
responsemessage = srInvokeChannel.invoke(metaoslistmap,mbo,mbo,"")




Note: "responsemessage" Message will came response if invocation channel don't have configured auto process check box is not flagged. If flagged always response message will came as None.

In above code I used so many list of import may be not required your case. In may case I handled exceptions my own way.





Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. This is genius! Sir you saved my life! This works also for the older versions of Maximo. Regarding the sixth item: "Add new system property 'mxe.int.useaxiswsclient' as value 1" if it doesn't exist in your system properties, just add it manually as an INTEGER value and set it to 1. It works like a charm.
    It solves a lot of problems regarding Maximo-BMC remedy integration.

    ReplyDelete

Post a Comment