Environment
NetIQ Operations Center
NetIQ AppManager Operations Portal
NetIQ AppManager Operations Portal
Situation
This sample code demonstrates how to use the JAX-WS client-side library from NOC/BSM Web 2.0 Connect, to access NOC/BSM server via SOAP technology using Java "light" client.
Resolution
Please do the following:
1. Install Web2Connect package on your dashboard server, please see documentation for details.
2. Make sure your Web2Connect is up and running correctly
3. Download moweb2cn.jar and moweb2cn-src.jar from the following link (your web2connect server):
http://<server>:<port>/moweb2cn/doc/downloads.html
4. Read the documentation and study provided library source code
5. Modify the sample code below according to your environment - change or remove hard-coded IP address, port, userID, and password
6. Compile the code using Java compiler
7. Run compiled application in console/DosBox window
That's all folks!
1. Install Web2Connect package on your dashboard server, please see documentation for details.
2. Make sure your Web2Connect is up and running correctly
3. Download moweb2cn.jar and moweb2cn-src.jar from the following link (your web2connect server):
http://<server>:<port>/moweb2cn/doc/downloads.html
4. Read the documentation and study provided library source code
5. Modify the sample code below according to your environment - change or remove hard-coded IP address, port, userID, and password
6. Compile the code using Java compiler
7. Run compiled application in console/DosBox window
// Copyright (c) 2011 Novell, Inc. All Rights Reserved. // USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE DEVELOPER LICENSE // AGREEMENT OR OTHER AGREEMENT THROUGH WHICH NOVELL, INC. MAKES THE WORK AVAILABLE. // THIS WORK MAY NOT BE ADAPTED WITHOUT NOVELL'S PRIOR WRITTEN CONSENT. // NOVELL PROVIDES THE WORK "AS IS," WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, // INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. NOVELL, THE AUTHORS OF THE WORK, // AND THE OWNERS OF COPYRIGHT IN THE WORK ARE NOT LIABLE FOR ANY CLAIM, DAMAGES, // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, // OUT OF, OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS IN THE WORK. //======================================================================================== // File: jaxwstest.java // Version: 1.0 // Date: 10/28/2011 // Author: RLE, Novell NOC/BSM Support // Description: This sample code demonstrates how to use the JAX-WS client-side library // from NOC/BSM Web 2.0 Connect to access NOC/BSM server via SOAP technology using Java "light" client. //HowTo: - Install Web2Connect package on your myMO server, please see documentation for details. // - Make sure your Web2Connect is up and running // - Download moweb2cn.jar and moweb2cn-src.jar from your http://server:port/moweb2cn/doc/downloads.html // - Read the documentation and study provided library source code // - Modify this sample code below according to your environment ( hard-coded ip, port, user, password ) // - Compile the code // - Run it in console/dosbox window //================================================================================= import javax.xml.ws.WebServiceFeature; import javax.xml.ws.soap.AddressingFeature; import javax.xml.ws.soap.MTOMFeature; import javax.xml.ws.RespectBindingFeature; import javax.xml.ws.BindingProvider; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import java.io.IOException; import java.util.Map; import com.mosol.moweb2cn.ElementValue; import com.mosol.moweb2cn.ElementValueList; import com.mosol.moweb2cn.AttributesValue; import com.mosol.moweb2cn.AttributeValue; import com.mosol.moweb2cn.AttributesMap; import com.mosol.moweb2cn.AttributeMapValue; import com.mosol.moweb2cn.AttributeType; import com.mosol.moweb2cn.UserValue; import com.mosol.moweb2cn.ResponseValue; import com.mosol.moweb2cn.ModelException; import com.mosol.moweb2cn.Web2Connect; import com.mosol.moweb2cn.impl.Web2ConnectImpl; import com.mosol.util.Util; public class jaxwstest { public static WebServiceFeature feature; public static Web2Connect service; public static Web2ConnectImpl proxy; public static void main( String args[] ) { // First we have to create new service object System.out.print("\nNow creating service object.. "); try { service = new Web2ConnectImpl( "192.168.163.118", 8087, new MTOMFeature(true)); } catch( IllegalStateException e ) { System.out.print("got exception: " + e.getMessage()); } // Next we have set SESSION_MAINTAIN_PROPERTY to TRUE, // We do it over proxy, as the Web2Connect class does not provide the function we need System.out.print("\nNow playing with proxy.. "); try { proxy = (Web2ConnectImpl)service; proxy._getBindingProvider().getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY,true); } catch( IllegalStateException e ) { System.out.print("got exception: " + e.getMessage()); } // In this step we create session System.out.print("\nNow creating session.. "); try { ResponseValue res = service.createSession( "admin", "formula" ); System.out.print(res.getValue()); } catch( ModelException e ) { System.out.print("got exception: " + e.getMessage()); } // Our service object is logged and active, so we can now use all provided functionality // in order to get elements, their properties, alarms, and also to set various information System.out.print("\nNow querying logged-in user info.. "); try { UserValue user = service.getUser(); System.out.print("received: " + user.getFullName()); } catch( ModelException e ) { System.out.print("got exception: " + e.getMessage()); } // System.out.print("\nNow calling ping.. "); try { ResponseValue res = service.ping(); System.out.print(res.getValue()); } catch( ModelException e ) { System.out.print("got exception: " + e.getMessage()); } // String identity = "root=Organizations"; // String identity = "root=Administration"; String identity = "formulaServer=Server/root=Administration"; String encodedName = Util.tob64(identity); System.out.print("\nNow encoding for fun: " + encodedName); System.out.print("\nNow reading attributes and its values for element '" + identity + "'"); try { System.out.print("\n Calling getElementAttributes().. "); AttributesValue aValue = new AttributesValue(); try { String[] aList = {"*"}; aValue = service.getElementAttributes(identity,aList); } catch( ModelException e ) { System.out.print("got exception: " + e.getMessage()); } System.out.print("\n Retrieving received data.. "); identity = aValue.getIdentity(); System.out.print("\n Identity: " + identity); AttributesMap aMap = aValue.getAttributes(); AttributeMapValue[] aMapValues = aMap.getAttributeMapValues(); for (int i=0; i<aMapValues.length; i++) { System.out.print("\n\n Attribute: " + aMapValues[i].getName()); AttributeValue value = aMapValues[i].getValue(); AttributeType valueType = value.getType(); System.out.print("\n Type: " + valueType.toString()); System.out.print("\n Value: "); if (valueType.toString().equals("StringType")) { System.out.print(value.getStringValue()); } else { if (valueType.toString().equals("BooleanType")) { System.out.print(value.getBooleanValue()); } else { if (valueType.toString().equals("IntegerType")) { System.out.print(value.getIntegerValue()); } else { if (valueType.toString().equals("LongType")) { System.out.print(value.getLongValue()); } else { System.out.print("[Oops.. not implemented yet for this type!]"); } } } } } } catch( Exception e ) { System.out.print("got exception: " + e.getMessage()); } // Finally, we close our session System.out.print("\nNow closing session.. "); try { ResponseValue res = service.closeSession(); System.out.print(res.getValue()); } catch( ModelException e ) { System.out.print("got exception: " + e.getMessage()); } System.out.println(); } } |
That's all folks!