Search in sources :

Example 1 with IJIComObject

use of org.jinterop.dcom.core.IJIComObject in project opennms by OpenNMS.

the class WmiClient method connect.

/** {@inheritDoc} */
@Override
public void connect(final String domain, final String username, final String password, final String namespace) throws WmiException {
    try {
        m_Session = JISession.createSession(domain, username, password);
        m_Session.useSessionSecurity(true);
        m_Session.setGlobalSocketTimeout(5000);
        JIComServer m_ComStub = new JIComServer(JIProgId.valueOf(WMI_PROGID), m_Address, m_Session);
        final IJIComObject unknown = m_ComStub.createInstance();
        IJIComObject m_ComObject = unknown.queryInterface(WMI_CLSID);
        // This will obtain the dispatch interface
        IJIDispatch m_Dispatch = (IJIDispatch) JIObjectFactory.narrowObject(m_ComObject.queryInterface(IJIDispatch.IID));
        final JIVariant[] results = m_Dispatch.callMethodA("ConnectServer", new Object[] { new JIString(m_Address), new JIString(namespace), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), 0, JIVariant.OPTIONAL_PARAM() });
        m_WbemServices = (IJIDispatch) JIObjectFactory.narrowObject((results[0]).getObjectAsComObject());
    } catch (final JIException e) {
        if (m_Session != null) {
            try {
                JISession.destroySession(m_Session);
            } catch (JIException e1) {
                LOG.error("Failed to destroy session after incomplete connect with host '{}'.", m_Address, e1);
            }
        }
        throw new WmiException("Failed to establish COM session with host '" + m_Address + "': " + e.getMessage(), e);
    } catch (final UnknownHostException e) {
        if (m_Session != null) {
            try {
                JISession.destroySession(m_Session);
            } catch (JIException e1) {
                LOG.error("Failed to destroy session after unknown host '{}'.", m_Address, e1);
            }
        }
        throw new WmiException("Unknown host '" + m_Address + "'. Failed to connect to WMI agent.", e);
    }
}
Also used : JIComServer(org.jinterop.dcom.core.JIComServer) UnknownHostException(java.net.UnknownHostException) IJIComObject(org.jinterop.dcom.core.IJIComObject) JIVariant(org.jinterop.dcom.core.JIVariant) JIString(org.jinterop.dcom.core.JIString) IJIDispatch(org.jinterop.dcom.impls.automation.IJIDispatch) JIException(org.jinterop.dcom.common.JIException)

Example 2 with IJIComObject

use of org.jinterop.dcom.core.IJIComObject in project opennms by OpenNMS.

the class OnmsWbemMethodSetImpl method get.

/** {@inheritDoc} */
@Override
public OnmsWbemMethod get(final Integer idx) throws WmiException {
    try {
        final IJIComObject enumComObject = wbemMethodSetDispatch.get("_NewEnum").getObjectAsComObject();
        final IJIEnumVariant enumVariant = (IJIEnumVariant) JIObjectFactory.narrowObject(enumComObject.queryInterface(IJIEnumVariant.IID));
        OnmsWbemMethod wbemMethod;
        IJIDispatch wbemMethod_dispatch = null;
        for (int i = 0; i < (idx + 1); i++) {
            final Object[] values = enumVariant.next(1);
            final JIArray array = (JIArray) values[0];
            final Object[] arrayObj = (Object[]) array.getArrayInstance();
            for (int j = 0; j < arrayObj.length; j++) {
                wbemMethod_dispatch = (IJIDispatch) JIObjectFactory.narrowObject(((JIVariant) arrayObj[j]).getObjectAsComObject());
            }
        }
        wbemMethod = new OnmsWbemMethodImpl(wbemMethod_dispatch);
        return wbemMethod;
    } catch (final JIException e) {
        throw new WmiException("Failed to enumerate WbemObject variant: " + e.getMessage(), e);
    }
}
Also used : JIArray(org.jinterop.dcom.core.JIArray) IJIComObject(org.jinterop.dcom.core.IJIComObject) OnmsWbemMethod(org.opennms.protocols.wmi.wbem.OnmsWbemMethod) IJIEnumVariant(org.jinterop.dcom.impls.automation.IJIEnumVariant) IJIDispatch(org.jinterop.dcom.impls.automation.IJIDispatch) IJIComObject(org.jinterop.dcom.core.IJIComObject) WmiException(org.opennms.protocols.wmi.WmiException) JIException(org.jinterop.dcom.common.JIException)

Example 3 with IJIComObject

use of org.jinterop.dcom.core.IJIComObject in project opennms by OpenNMS.

the class OnmsWbemObjectImpl method getWmiMethods.

/**
     * <p>getWmiMethods</p>
     *
     * @return a {@link org.opennms.protocols.wmi.wbem.OnmsWbemMethodSet} object.
     * @throws org.opennms.protocols.wmi.WmiException if any.
     */
@Override
public OnmsWbemMethodSet getWmiMethods() throws WmiException {
    try {
        // Get the WbemMethodSet dispatcher.
        final IJIComObject methodComObject = wbemObjectDispatch.get("Methods_").getObjectAsComObject();
        final IJIDispatch methodsSet_dispatch = (IJIDispatch) JIObjectFactory.narrowObject(methodComObject);
        return new OnmsWbemMethodSetImpl(methodsSet_dispatch);
    } catch (final JIException e) {
        throw new WmiException("Failed to retrieve list of methods: " + e.getMessage(), e);
    }
}
Also used : IJIComObject(org.jinterop.dcom.core.IJIComObject) IJIDispatch(org.jinterop.dcom.impls.automation.IJIDispatch) WmiException(org.opennms.protocols.wmi.WmiException) JIException(org.jinterop.dcom.common.JIException)

Example 4 with IJIComObject

use of org.jinterop.dcom.core.IJIComObject in project opennms by OpenNMS.

the class OnmsWbemObjectImpl method getWmiPath.

/**
     * <p>getWmiPath</p>
     *
     * @return a {@link org.opennms.protocols.wmi.wbem.OnmsWbemObjectPath} object.
     * @throws org.opennms.protocols.wmi.WmiException if any.
     */
@Override
public OnmsWbemObjectPath getWmiPath() throws WmiException {
    try {
        // Get the WbemMethodSet dispatcher.
        final IJIComObject pathComObject = wbemObjectDispatch.get("Path_").getObjectAsComObject();
        final IJIDispatch path_dispatch = (IJIDispatch) JIObjectFactory.narrowObject(pathComObject);
        return new OnmsWbemObjectPathImpl(path_dispatch);
    } catch (final JIException e) {
        throw new WmiException("Failed to retrieve object path: " + e.getMessage(), e);
    }
}
Also used : IJIComObject(org.jinterop.dcom.core.IJIComObject) IJIDispatch(org.jinterop.dcom.impls.automation.IJIDispatch) WmiException(org.opennms.protocols.wmi.WmiException) JIException(org.jinterop.dcom.common.JIException)

Example 5 with IJIComObject

use of org.jinterop.dcom.core.IJIComObject in project opennms by OpenNMS.

the class OnmsWbemObjectImpl method getWmiProperties.

/**
     * <p>getWmiProperties</p>
     *
     * @return a {@link org.opennms.protocols.wmi.wbem.OnmsWbemPropertySet} object.
     * @throws org.opennms.protocols.wmi.WmiException if any.
     */
@Override
public OnmsWbemPropertySet getWmiProperties() throws WmiException {
    try {
        // Get the WbemMethodSet dispatcher.
        final IJIComObject propsSetComObject = wbemObjectDispatch.get("Properties_").getObjectAsComObject();
        final IJIDispatch propSet_dispatch = (IJIDispatch) JIObjectFactory.narrowObject(propsSetComObject);
        return new OnmsWbemPropertySetImpl(propSet_dispatch);
    } catch (final JIException e) {
        throw new WmiException("Failed to retrieve object property set: " + e.getMessage(), e);
    }
}
Also used : IJIComObject(org.jinterop.dcom.core.IJIComObject) IJIDispatch(org.jinterop.dcom.impls.automation.IJIDispatch) WmiException(org.opennms.protocols.wmi.WmiException) JIException(org.jinterop.dcom.common.JIException)

Aggregations

JIException (org.jinterop.dcom.common.JIException)8 IJIComObject (org.jinterop.dcom.core.IJIComObject)8 IJIDispatch (org.jinterop.dcom.impls.automation.IJIDispatch)8 WmiException (org.opennms.protocols.wmi.WmiException)7 JIArray (org.jinterop.dcom.core.JIArray)4 IJIEnumVariant (org.jinterop.dcom.impls.automation.IJIEnumVariant)4 JIVariant (org.jinterop.dcom.core.JIVariant)2 UnknownHostException (java.net.UnknownHostException)1 JIComServer (org.jinterop.dcom.core.JIComServer)1 JIString (org.jinterop.dcom.core.JIString)1 OnmsWbemMethod (org.opennms.protocols.wmi.wbem.OnmsWbemMethod)1 OnmsWbemObject (org.opennms.protocols.wmi.wbem.OnmsWbemObject)1 OnmsWbemProperty (org.opennms.protocols.wmi.wbem.OnmsWbemProperty)1