CISCO CONFIDENTIAL
A P P E N D I X
A
Sample Codes
This section contains sample codes for:
•
EventObject
•
EventHandler
•
Remote Listener Service
•
WSDL of Listener Service
•
WSDD File of the Listener Service
•
Sample Code for Obtaining Cookie
EventObject
This section contains sample code for Event Object.
/**
* @author vechandr
*
*/
package com.cisco.nm.dcr;
public class DCREventObject extends EventObject {
String deviceName;
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
}
EventHandler
This section contains sample code for Event Handler.
package com.cisco.nm.dcr;
import javax.jms.Message;
import javax.jms.TextMessage;
import com.cisco.nm.nbi.cwcs.nbifw.efw.handler.EventHandler;
import com.cisco.nm.nbi.cwcs.nbifw.efw.event.EventObject;
import com.cisco.nm.nbi.cwcs.nbifw.efw.util.EventFrameworkHelpers;
/**
* @author vechandr
SDK Developers Guide for CiscoWorks Common Services 3.2 Northbound API 1.1
OL-16255-01
A-1
Appendix A
Sample Codes
CISCO CONFIDENTIAL
*
*/
public class DCREventHandler extends EventHandler {
protected EventObject convertEvent(Message msg) {
TextMessage text;
try {
if (!(msg instanceof javax.jms.TextMessage)) {
System.out.println("UnExpected Type!");
return null;
}
text = (TextMessage) msg;
// Building customized event object.
DCREventObject eo = new DCREventObject();
// preprocess eventobject.
EventFrameworkHelpers.preprocessEventObject(eo,msg,handler);
eo.setSourceApplication("cmf");
eo.setSourceApplicationVersion("3.0");
eo.setDeviceName(text.getText());
return eo;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
}
Remote Listener Service
This section contains sample code for Remote Listener Service
import com.cisco.nm.dcr.DCREventObject;
public class EventReceiver
{
public boolean ProcessDCREvent(DCREventObject event)
{
System.out.println ("Retrieved Messsage "+ event.getDeviceName() );
// other processing logics goes here.
return true;
}
}
WSDL of Listener Service
This section contains sample WSDL of Listener Service.
<wsdl:definitions targetNamespace="http://localhost:8080/axis/services/EventReceiver">
<!-WSDL created by Apache Axis version: 1.4
Built on May 03, 2005 (02:20:24 EDT)
-->
<wsdl:types>
<schema targetNamespace="http://dcr.nm.cisco.com ">
<import namespace="urn:EventReceiver"/>
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
-
SDK Developers Guide for CiscoWorks Common Services 3.2 Northbound API 1.1
A-2
OL-16255-01
Appendix A
Sample Codes
CISCO CONFIDENTIAL
<complexType name="EventObject">
<sequence>
<element name="eventID" nillable="true" type="soapenc:string"/>
<element name="eventType" nillable="true" type="soapenc:string"/>
<element name="sourceApplication" nillable="true" type="soapenc:string"/>
<element name="sourceApplicationVersion" nillable="true" type="soapenc:string"/>
<element name="sourceMachineName" nillable="true" type="soapenc:string"/>
<element name="topic" nillable="true" type="soapenc:string"/>
</sequence>
</complexType>
</schema>
<schema targetNamespace="urn:EventReceiver">
<import namespace="http://dcr"/>
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="EventObject">
<complexContent>
<extension base="tns2:EventObject">
<sequence>
<element name="deviceName" nillable="true" type="soapenc:string"/>
</sequence>
</extension>
</complexContent>
</complexType>
</schema>
</wsdl:types>
<wsdl:message name="ProcessDCREventResponse">
<wsdl:part name="ProcessDCREventReturn" type="soapenc:string"/>
</wsdl:message>
<wsdl:message name="ProcessDCREventRequest">
<wsdl:part name="in0" type="tns1:EventObject"/>
</wsdl:message>
<wsdl:portType name="EventReceiver">
<wsdl:operation name="ProcessDCREvent" parameterOrder="in0">
<wsdl:input message="impl:ProcessDCREventRequest" name="ProcessDCREventRequest"/>
<wsdl:output message="impl:ProcessDCREventResponse" name="ProcessDCREventResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="EventReceiverSoapBinding" type="impl:EventReceiver">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ProcessDCREvent">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="ProcessDCREventRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://DefaultNamespace" use="encoded"/>
</wsdl:input>
<wsdl:output name="ProcessDCREventResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://localhost:8080/axis/services/EventReceiver" use="encoded"/>
</wsdl:output>
</wsdl:operation>
SDK Developers Guide for CiscoWorks Common Services 3.2 Northbound API 1.1
OL-16255-01
A-3
Appendix A
Sample Codes
CISCO CONFIDENTIAL
</wsdl:binding>
<wsdl:service name="EventReceiverService">
<wsdl:port binding="impl:EventReceiverSoapBinding" name="EventReceiver">
<wsdlsoap:address location="http://localhost:8080/axis/services/EventReceiver"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
WSDL for DCREventObject, JOBEventObject and JOBEventObject:
OGSEventObject:
<complexType name="OGSEventObject">
<complexContent>
<extension base="tns2:EventObject">
<sequence>
<element name="eventAction" nillable="true" type="soapenc:string"/>
<element name="groupName" nillable="true" type="soapenc:string"/>
<element name="oldGroupName" nillable="true" type="soapenc:string"/>
<element name="subGroupNames" nillable="true" type="impl:ArrayOf_soapenc_string"/>
</sequence>
</extension>
</complexContent>
</complexType>
DCREventObject:
<complexContent>
<extension base="tns2:EventObject">
<sequence>
<element name="dcrDomainId" nillable="true" type="soapenc:string"/>
<element name="dcrTransactionId" type="xsd:long"/>
<element name="udfName" nillable="true" type="soapenc:string"/>
</sequence>
</extension>
</complexContent>
</complexType>
JOBEventObject:
<complexType name="JobEventObject">
<complexContent>
<extension base="tns2:EventObject">
<sequence>
<element name="jobAction" nillable="true" type="soapenc:string"/>
<element name="jobId" type="xsd:int"/>
<element name="runState" type="xsd:int"/>
</sequence>
</extension>
</complexContent>
WSDD File of the Listener Service
This section contains sample WSDD of Listener Service
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="EventReceiver" provider="java:RPC">
<parameter name="className" value="EventReceiver"/>
<parameter name="allowedMethods" value="*"/>
<beanMapping qname="myNS:EventObject" xmlns:myNS="urn:EventReceiver"
languageSpecificType="java: com.cisco.nm.dcr.DCREventObject"/>
</service>
</deployment>
SDK Developers Guide for CiscoWorks Common Services 3.2 Northbound API 1.1
A-4
OL-16255-01
Appendix A
Sample Codes
CISCO CONFIDENTIAL
Sample XML File for Accounting
This section contains sample XML file for Accounting.
<?xml version="1.0"?>
<Product NAME="CiscoWorks Web Services" SERVICE="cwhp" VERSION="1.0">
<!-- Method Description For Security Web Service -->
<Method>
<Name>addUser</Name>
<Description>Adds an user </Description>
<Authentication>YES</Authentication>
<Tasks>
<TaskId>sec_um_add</TaskId>
</Tasks>
</Method>
<Method>
<Name>deleteUser</Name>
<Description>Deletes an user </Description>
<Authentication>YES</Authentication>
<Tasks>
<TaskId>sec_um_del</TaskId>
</Tasks>
</Method>
<Method>
<Name>modifyUser</Name>
<Description>Modifies an user </Description>
<Authentication>YES</Authentication>
<Tasks>
<TaskId>sec_um_edit</TaskId>
</Tasks>
</Method>
<Method>
<Name>login</Name>
<Description>Method used for login </Description>
<Authentication>NO</Authentication>
<Tasks/>
</Method>
</Product>
Sample Code for Obtaining Cookie
This section contains sample code for obtaining Cookie.
SecurityServiceServiceLocator seLoc;
AxisServletSoapBindingStub _secService ;
SessionHandle cookie;
seLoc = new SecurityServiceServiceLocator();
_secService = (AxisServletSoapBindingStub) seLoc.getAxisServlet();
cookie = _secService.initiateSession(csUser,srcContext);
System.out.println("step 2 ......");
if ( cookie == null) {
System.out.println("Login Failed ... ");
System.exit(1);
SDK Developers Guide for CiscoWorks Common Services 3.2 Northbound API 1.1
OL-16255-01
A-5
Appendix A
Sample Codes
CISCO CONFIDENTIAL
}
System.out.println("The Cookie value is = " + cookie.getCookie() );
StringTokenizer strTok = new StringTokenizer(cookie.getCookie(), "=");
String coreId = strTok.nextToken();
coreId = strTok.nextToken();
System.out.println("core Id = " + coreId);
System.out.println("step 3 ......");
((javax.xml.rpc.Stub)_secService)._setProperty( "javax.xml.rpc.session.maintain",
Boolean.TRUE);
((javax.xml.rpc.Stub)_secService)._setProperty( HTTPConstants.HEADER_COOKIE,
"JSESSIONID="+coreId +","+cookie.getCookie());
SDK Developers Guide for CiscoWorks Common Services 3.2 Northbound API 1.1
A-6
OL-16255-01
© Copyright 2026 Paperzz