Consuming Web Services from Service Manager

Consuming Web Services from Service Manager Is it possible to consume Web Services in Service Manager through a proxy server? It is possible to consum...
Author: Harvey Hubbard
17 downloads 1 Views 485KB Size
Consuming Web Services from Service Manager Is it possible to consume Web Services in Service Manager through a proxy server? It is possible to consume Web Services through a proxy server in Service Manager 7. The following parameters have to be added to the sm.ini file for the Web Service to be able to connect through a proxy. JVMOptionX:-Dhttp.proxyHost=proxyserver.domain.company.com JVMOptionY:-Dhttp.proxyPort= you can also specify a list of hosts to bypass the proxy: JVMOptionZ:-Dhttp.nonProxyHosts="*.americas.hpqcorp.net|localhost"

The http.nonProxyHosts property indicates the hosts which should be connected to directly and not through the proxy server. The value can be a list of hosts, each separated by a |, and in addition a wildcard character (*) can be used for matching. The X, Y and Z represent three consecutive numbers. The first JVMOption in the sm.ini will be number 1, the next will be number 2 and 3 etc. If these three are the only JVMOptions in your sm.ini, they will be: JVMOption1:-Dhttp.proxyHost=proxyserver.domain.company.com JVMOption2:-Dhttp.proxyPort= JVMOption3:-Dhttp.nonProxyHosts="*.domain.company.com|localhost"

Sample sm.ini: JVMOption0:-DproxySet=true JVMOption1:-DproxyHost=web-proxy.corp.hp.com JVMOption2:-DproxyPort=8088

Demo 1 Creating the generated JavaScript

Go to Tailoring > Web Services > WSDL 2 JS Enter URL: http://ws.cdyne.com/WeatherWS/Weather.asmx?wsdl (no userID or password required) Click Execute and then click on Add to add the generated JavaScript to the ScriptLibrary. Note the name of the new ScriptLibrary record for later reference.

Demo 2 Create the calling JavaScript as a new record in the ScriptLibrary with the following code:

function getForecastforZIP(ZIP) { var ForecastSvc = new system.library.Weather.Weather(); var ForecastReq = new system.library.Weather.GetCityForecastByZIP(); ForecastReq.ZIP.setValue(ZIP); try { var ForecastResp = ForecastSvc.invoke(ForecastReq); if ( ForecastResp.isFault() ) { throw( "SOAP Fault: " + ForecastResp.faultstring.getValue() ); } print(ForecastResp.GetCityForecastByZIPResult.ResponseText.getValue()) return ForecastResp; } catch( err ) {

print( "Error! " + err ); return( "Error! " + err ); } } The following 2 lines test the calling JavaScript by printing out today’s forecast: ret_val=getForecastforZIP("92124") print(ret_val.GetCityForecastByZIPResult.ForecastResult.Forecast[0].Desciption.getValue())

Bonus: Getting the current weather for the zip code: function getWeatherForZIP(ZIP) { var WeatherSvc = new system.library.Weather.Weather(); var WeatherReq = new system.library.Weather.GetCityWeatherByZIP(); WeatherReq.ZIP.setValue(ZIP); try { var WeatherResp = WeatherSvc.invoke(WeatherReq); if ( WeatherResp.isFault() ) { throw( "SOAP Fault: " + WeatherResp.faultstring.getValue() ); } print(WeatherResp.GetCityWeatherByZIPResult.ResponseText.getValue()) return WeatherResp; } catch( err ) {

print( "Error! " + err ); return( "Error! " + err ); } } The following two lines test this calling JavaScript by printing out the current weather: ret_val=getWeatherForZIP("92124") print(ret_val.GetCityWeatherByZIPResult.Description.getValue())

Create the button to execute the calling JavaScript Go to Displayoption for screen apm.edit.problem, create a new option with GUI option 15, condition true, action: do nothing and the following preJavaScript code: var Location = new SCFile("location"); var SuccessFlag=Location.doSelect("location.full.name= \"" + system.vars.$L_filed.location_full_name + "\""); if (SuccessFlag == RC_SUCCESS) { var retVal=system.library.TestWeather.getWeatherForZIP(Location.zip); print(ret_val.GetCityWeatherByZIPResult.Description.getValue()) } else { print("Location not found") } Click Add to add the record to the displayoption table.

Bonus Demo: Consuming an SM Web Service from SM: function AssociateChange(incident_id) { var IncMgmtSvc = new system.library.IncidentManagement.IncidentManagement(); IncMgmtSvc.user="falcon" var assocReq = new system.library.IncidentManagement.ChangeIncidentRequest(); assocReq.model.keys.IncidentID.setValue(incident_id); assocReq.model.instance.ChangeNumber.setValue("C10001"); var JournalUpdate = assocReq.model.instance.JournalUpdates.JournalUpdates_newInstance(); JournalUpdate.setValue("Associating to change C10001"); try { var assocResp = IncMgmtSvc.invoke(assocReq); if ( assocResp.isFault() )

{ throw( "SOAP Fault: " + retrieveResp.faultstring.getValue() ); } return assocResp.model.instance; } catch( err ) { return( "Error! " + err ); } } The following two lines test the calling JavaScript: retVal=AssociateChange("IM10001"); print("Testing the result " + retVal.IncidentID.getValue())

Setting up .Net and AXIS2 README FOR WEB SERVICES .NET SAMPLE APPLICATION

REQUIREMENTS

Microsoft Visual Studio .NET 2003 or Visual C#.NET 2003 Microsoft .NET Framework 1.1 SP1 SDK (included with Visual Studio .NET) Microsoft Web Services Enhancements (WSE) 2.0SP2 http://www.microsoft.com/downloads/details.aspx?FamilyId=FC5F06C5-821F-41D3-A4FE6C7B56423841&displaylang=en Select the VS Developer option when installing WSE.

STEPS TO BUILD .NET SAMPLE APPLICATION

Start ServiceManager 7.00 server. Open the file DotNetSample.sln from Visual Studio or Visual C#. By default, this file is located in: C:\Program Files\HP\Service Manager 7.00\Server\webservices\sample\sc6webservices\DotNetSample. Open Web References from the SolutionExplorer. For each of the Web References listed, open the properties and update the “Web Reference URL” to point to the hostname and port number of the ServiceManager instance you started in step 1. Once all the URLs have been updated, right-click each web reference and select “Update Web Reference”. Rebuild the project file.

BUILD ERRORS:

You may see the following error messages the first time you build the .NET samples:

The type or namespace name 'ConfigurationManagementWse' could not be found (are you missing a using directive or an assembly reference?) The type or namespace name 'IncidentManagementWse' could not be found (are you missing a using directive or an assembly reference?) If these errors occur, repeat build steps 5 and 6. This error occurs because Visual Studio .NET sometimes uses older versions of the Web Services base classes when creating the C# stub classes from the WSDL files. The “Update Web Reference” operation should cause the stubs to be re-created using the WSE2.0 base classes. COMMAND LINE ARGUMENTS FOR THE .NET SAMPLE APPLICATION: The .NET sample application runs from the Windows command prompt. After you have compiled the .NET sample into an executable, you can perform configuration and incident management tasks with the following arguments. Note: To see the usage information for the .NET sample application, type: dotNetSample -example ClassName

where ClassName is the name of a sample application class. Configuration Management Example: The following commands invoke Configuration Management functionality. Operation Command-line example Create contact dotNetSample -example CreateContact -name sneveau -lastName Neveau -firstName Sophie workPhone "(858) 481-5000" -extension 3573 –fullname “Sophie Neveau” Delete contact dotNetSample -example DeleteContact -name sneveau -lastName Neveau -firstName Sophie Retrieve contact dotNetSample -example RetrieveContact -name "FALCON, JENNIFER" Update contact dotNetSample -example UpdateContact -name "FALCON, JENNIFER" -workPhone "(858) 481-5000" extension 3573 Incident Management Example: The following commands invoke Incident Management functionality. Operation Command-line example Close incident dotNetSample -example CloseIncident -incidentId IM10001 -closeCode "User Closer" -resolution "Problem disappeared" Create incident dotNetSample -example CreateIncident -title ".NET sample brief description" -category incident problemType "not specified" -description ".NET sample incident" -severity 1 -subCategory data productType " storage limit exceeded " -initialImpact 1 -primaryAssignmentGroup "Operating System Support (South America)" -service "Printing (Africa)" Resolve incident

dotNetSample -example ResolveIncident -incidentId IM10006 -resolution "Problem disappeared" Retrieve incident list dotNetSample -example RetrieveIncidentList -incidentId IM10001:IM10002 Retrieve incident dotNetSample -example RetrieveIncident -incidentId IM10001 Update incident dotNetSample -example UpdateIncident -incidentId IM10007 -journalUpdates "User provided more information"

AXIS2: REQUIREMENTS 1) Sun Java JDK 1.5.0 or later (A JRE is sufficient if it includes tools.jar) 2) Apache Ant (See http://ant.apache.org/) STEPS TO BUILD 1) Install Apache Ant. a. Preserve folder names when unzipping the Ant distribution. b. Set the ANT_HOME environment variable to the directory where you extracted the Ant archive. c. Set the PATH environment variable to the \bin subdirectory of the ANT_HOME variable. d. After updating your environment variables, start a new command window to set the environment variables. 2) Navigate to the Axis2Sample directory containing build.xml (where this README was found) 3) Edit the build.xml file to set the URL of your ServiceManager server. By default, the build.xml file assumes you have a ServiceManager 7.10 server running on the localhost and listening on port 13080. To change the ServiceManager host name and port, find the following lines in build.xml: Set the "value" attribute to the URL of your ServiceManager server host name and port number.

To get the service wsdl you may need to establish the connection through a proxy server. You can set the proxy host and port in the following lines in the build.xml:



4) From the command line in the Axis2Sample directory, type: ant You should get the following output: Buildfile: build.xml init: [echo] Project:

Axis SM7 Sample

[echo] Date/Time: 22 May 2008 11:23:44 PM [echo] Ant version: Apache Ant version 1.7.0 compiled on December 13 2006 [echo] Java version: 1.5 generate_stubs: generate_stubs.source: [mkdir] Created dir: C:\ServiceManager\7.10\main\examples\sm7webservices\Axis2Sample\stubs\IncidentManagement\src [java] Retrieving document at 'http://localhost:13080/SM/7/IncidentManagement.wsdl'. [java] Retrieving schema at 'http://www.w3.org/2005/05/xmlmime', relative to 'http://localhost:13080/SM/7/IncidentManagement.wsdl'. [java] Retrieving schema at 'http://localhost:13080/SM/7/Common.xsd', relative to 'http://localhost:13080/SM/7/IncidentManagement.wsdl'.

[java] Retrieving schema at 'http://www.w3.org/2005/05/xmlmime', relative to 'http://localhost:13080/SM/7/Common.xsd'. generate_stubs.source: [mkdir] Created dir: C:\ServiceManager\7.10\main\examples\sm7webservices\Axis2Sample\stubs\ConfigurationManageme nt\src [java] Retrieving document at 'http://localhost:13080/SM/7/ConfigurationManagement.wsdl'. [java] Retrieving schema at 'http://www.w3.org/2005/05/xmlmime', relative to 'http://localhost:13080/SM/7/ConfigurationManagement.wsdl'. [java] Retrieving schema at 'http://localhost:13080/SM/7/Common.xsd', relative to 'http://localhost:13080/SM/7/ConfigurationManagement.wsdl'. [java] Retrieving schema at 'http://www.w3.org/2005/05/xmlmime', relative to 'http://localhost:13080/SM/7/Common.xsd'. generate_Proxy_classes: build_stubs_classes: [mkdir] Created dir: C:\ServiceManager\7.10\main\examples\sm7webservices\Axis2Sample\stubs\IncidentManagement\bui ld [javac] Compiling 47 source files to C:\ServiceManager\7.10\main\examples\sm7webservices\Axis2Sample\stubs\IncidentManagement\bui ld [javac] Note: Some input files use unchecked or unsafe operations. [javac] Note: Recompile with -Xlint:unchecked for details. build_stubs_classes: [mkdir] Created dir: C:\ServiceManager\7.10\main\examples\sm7webservices\Axis2Sample\stubs\ConfigurationManageme nt\build [javac] Compiling 449 source files to C:\ServiceManager\7.10\main\examples\sm7webservices\Axis2Sample\stubs\ConfigurationManageme nt\build [javac] Note: Some input files use unchecked or unsafe operations.

[javac] Note: Recompile with -Xlint:unchecked for details. package_IM_ws_classes: [jar] Building jar: C:\ServiceManager\7.10\main\examples\sm7webservices\Axis2Sample\lib\sm7imws-proxy.jar package_CM_ws_classes: [jar] Building jar: C:\ServiceManager\7.10\main\examples\sm7webservices\Axis2Sample\lib\sm7cmws-proxy.jar build_sample: package_sample_classes: all: BUILD SUCCESSFUL Total time: 51 seconds C:\ServiceManager\7.10\main\examples\sm7webservices\Axis2Sample> **Note** There are hardcoded incident's values in the CreateIncidentSample.java. To change the hardcoded values of contact name and others, you can modify the CreateIncidentSample.java file and rebuild the java classes. RUNNING THE SAMPLE APPLICATIONS The Axis2Sample\bin directory contains a series of .bat files which you can use to invoke the various samples. For example, CreateIncidentSample.bat will create an incident. Note, you must supply a number of command line parameters (arguments) to successfully run these samples. To see the list of necessary command line arguments for each sample, invoke the .bat files with no arguments. Note that even if you updated the build.xml to point to your server, the generated sample code still uses the hard-coded values of "localhost" for the server and 13080 for the port. You must use the command line arguments to override these values when you invoke one of the samples. Here is some sample ouput showing explanations of the various parameters for the "CreateIncident" sample: C:\ServiceManager\7.10\main\examples\sm7webservices\Axis2Sample\bin>CreateIncidentSample

Failed to execute sample java.lang.IllegalArgumentException: No arguments given. at com.hp.sm.webservice.sample.ArgumentUtility.parseArguments(Unknown Source) at com.hp.sm.webservice.sample.incident.CreateIncidentSample.main(Unknown Source) Usage: com.hp.sm.webservice.sample.incident.CreateIncidentSample -host IP|name Web Service host IP or name. (Default: 'localhost') -port number Web Service port number (Default: '13080') -username username -password password

Web Service user's name (Default: 'falcon') Web Service user's password (Default: '')

-briefDescription description Incident's brief description (i.e. "Program crashes") -category category

Incident's category (i.e. "telecoms")

-subCategory subcategory

Incident's subcategory (i.e. "fixed infrastructure")

-productType productType

Incident's product type (i.e. "fixed infrastructure")

-problemType type

Incident's problem type (i.e. "not specified")

-incidentDescription description

Incident's description (i.e. "Customer reports...")

-severity level Incident's severity level (i.e. 1) -initialImpact level Incident's initial impact assessment (i.e. 1) C:\ServiceManager\7.10\main\examples\sm7webservices\Axis2Sample\bin> Here is an example of a successful execution of CreateIncidentSample: C:\ServiceManager\7.10\main\examples\sm7webservices\Axis2Sample\bin>CreateIncidentSample host localhost -port 13080 -briefDescription "Java sample brief description" -category incident incidentDescription "This is a description" -severity 1 -subCategory hardware -productType "missing or stolen" -initialImpact 1 -service Applications -primaryAssignmentGroup Network Create SUCCESS Messages: US/Pacific 05/23/08 09:31:50: Incident IM10119 has been opened by falcon Incident ID: IM10119

Status: Open Severity: 1 Brief Description: Java sample brief description Opened by: falcon Opened time: May 23, 2008 8:31:50 AM PDT You can also create/update a incident with attachments: C:\ServiceManager\7.10\main\examples\sc6webservices\AxisSample\bin>CreateIncidentSample -host localhost -port 13080 -briefDescription "Java sample brief description" -category incident incidentDescription "This is a description" -severity 1 -subCategory hardware -productType "missing or stolen" -initialImpact 1 -service Applications -primaryAssignmentGroup Network -attachment 101.jpg:README.txt You can send more than one attachments in a request. All the attachments should be placed under the "resources" folder. The command line option is -attachment file01:file02. The attachment files are separated by ":'. TROUBLESHOOTING 1. If the "ant" command cannot be found, check your ANT_HOME environment variable setting. It should not have a trailing slash. An example of a correct value (for Windows) would be: ANT_HOME=c:\apache-ant-1.7.0 Issue the appropriate command (for example, "set" or "env") to inspect your environment variables 2. If Ant complains about tools.jar, it is usually because you have a JRE installed without tools.jar, and not a JDK. Install a JDK ( or obtain the correct version of tools.jar and place it in the lib directory of your JRE directory) 3. If you can build successfully but you get errors trying to execute a sample, either your server is not up or you need to explicity set the host and port command line parameters to point to the correct server host and port. The samples use a hard-coded location of localhost:13080 despite any value you specify in build.xml. The URL in build.xml is only used by WSDL2Java to build the sample applications. C:\ServiceManager\7.10\main\examples\sm7webservices\Axis2Sample\bin>CreateIncidentSample briefDescription "This is a test" -category telecoms -problemType "not specified" -incidentDescription "This is a description" -severity 1 -subCategory "fixed infrastructure" -productType "fixed infrastructure" -initialImpact 1

Failed to execute sample org.apache.axis2.AxisFault: Connection refused: connect at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430) at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193) at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75) at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(Common sHTTPTransportSender.java:364) at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender .java:208) at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:448) at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:401) at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228) at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163) at com.hp.sm.webservice.IncidentManagementStub.CreateIncident(IncidentManagementStub.java:862) at com.hp.sm.webservice.sample.incident.CreateIncidentSample.createIncident(CreateIncidentSample.jav a:341) at com.hp.sm.webservice.sample.incident.CreateIncidentSample.main(CreateIncidentSample.java:364) (etc..) Followings are some command line examples for running the sample application. You can run these command from the Axis2Sample\bin directory. C:\ServiceManager\7.10\main\examples\sm7webservices\Axis2Sample\bin> CreateIncidentSample -host localhost -port 13080 -briefDescription "Java sample brief description" category incident -incidentDescription "This is a description" -severity 1 -subCategory hardware productType "missing or stolen" -initialImpact 1 -service Applications -primaryAssignmentGroup Network

CloseIncidentSample -host localhost -port 13080 -incidentId IM10003 -resolution "Developer fix problem" -closeCode "User Closure" ResolveIncidentSample -host localhost -port 13080 -incidentId IM10011 -resolution "Developer fix problem" RetrieveIncidentListSample -host localhost -port 13080 -incidentId IM10011:IM10021:IM10031 RetrieveIncidentSample -host localhost -port 13080 -incidentId IM10041 UpdateIncidentSample -host localhost -port 13080 -incidentId IM10060 -journalUpdates "this is a update from SM webservice sample" CreateContactSample -host localhost -port 13080 -name "FALCON, MERLINE2" -fullname "MERLINE2 FALCON" RetrieveContactSample -host localhost -port 13080 -name "FALCON, MERLINE2" UpdateContactSample -host localhost -port 13080 -name "FALCON, MERLINE2" -email "[email protected]" DeleteContactSample -host localhost -port 13080 -name "FALCON, MERLINE2"

Demo 3 Running AXIS2 sample from DOS prompt Set environment variables Edit build.xml: Run ant from the samples directory where build.xml resides Change to the bin directory and enter the following command: C:\scs\sm711\server\WEBSER~1\sample\SM7WEB~1\AXIS2S~1\bin>CreateIncidentSample -host localhost -port 15711 -briefDescription "Java sample brief description" -category incident incidentDescription "Testing the AXIS2 sample" -severity 1 -subCategory hardware -productType "missing or stolen" -initialImpact 1 -service Applications -primaryAssignmentGroup Network – changeNumber C10001 (section in RED added due to advanced bonus demo scripted below, not needed in OOB system)

Create SUCCESS Messages: US/Mountain 01/19/10 17:44:06: Incident IM10162 has been opened by falcon Incident ID: IM10162 Status: Open Severity: 1 Brief Description: Java sample brief description Opened by: falcon Opened time: January 19, 2010 4:44:03 PM PST

Advanced bonus Making the ChangeNumber a required field when executing the AXIS2 sample CreateIncidentSample.java: Add to public class createincidentsample() public static final String ARGUMENT_CHANGE_NUMBER = "-changeNumber"; Add to public CreateIncidentSample() validArguments.add(ARGUMENT_CHANGE_NUMBER); Add to public String getUsage() buffer.append("\t"); buffer.append(ARGUMENT_CHANGE_NUMBER); buffer.append(" change number"); buffer.append("\t"); buffer.append("Change Number to associate(i.e. C10001)"); buffer.append(ServiceUtility.LINE_SEPARATOR); Add to private IncidentInstanceType createIncidentInstance(Map arguments) throws IOException value = (String) arguments.get(ARGUMENT_CHANGE_NUMBER);

instance.setChangeNumber(IncidentManagementServiceUtility.GetStringType(value));

IncidentInstanceType.java Add to public class IncidentInstanceType implements org.apache.axis2.databinding.ADBBean /*Field for… .*/ section /** * field for ChangeNumber */

protected com.hp.sm.webservice.common.StringType localChangeNumber ;

/* This tracker boolean wil be used to detect whether the user called the set method * for this attribute. It will be used to determine whether to include this field * in the serialized XML */ protected boolean localChangeNumberTracker = false ;

/** * Auto generated getter method * @return com.hp.sm.webservice.common.StringType */ public com.hp.sm.webservice.common.StringType getChangeNumber(){ return localChangeNumber; }

/** * Auto generated setter method * @param param ChangeNumber */ public void setChangeNumber(com.hp.sm.webservice.common.StringType param){

if (param != null){ //update the setting tracker localChangeNumberTracker = true; } else { localChangeNumberTracker = true;

}

this.localChangeNumber=param;

}

Suggest Documents