Possible to use ADODB.Stream to upload file?

jay
2011-06-23
2014-01-23
  • jay

    jay - 2011-06-23

    I'm a total DCOM newbie.  I have successfully used the WMI examples.   But I get an exception where calling xxxx.callMethodA("Open", params) after creating a JIComServer to ADODB.Stream.

    Can someone please post a working example, or confirmation of another method to upload a binary file to the client?

    I see another post asked about this, but it was never responded to.   Responses are much appreciated!

     
  • Vikram Roopchand

    Hi,
          Can you post the exception ?

    thanks,
    best regards,
    Vikram

     
  • jay

    jay - 2011-06-24

    Wow, thanks for the super fast response!

    I'm currently reading as much as I can about this great library.  I'm hoping I didn't make some kind of stupid and simple mistake. 

    Nevertheless, I sure hope you can point me in the right direction to get this code working properly.  Thanks a lot!

    Here is my code and the exception output.  I'm getting a VariantBody$EMPTY as a return from calling "Open" on the ADODB.Stream object.

    Here's the relevant code:

    private String username = null;
    private String password = null;
    private String domain = null;
    private String hostname = null;
    private JISession dcomSession = null;
    private IJIDispatch servicesDispatch = null;
    public static final String ADO_STREAM_INTERFACE_NAME = "ADODB.Stream";  // ActiveX Data Objects
    private final String BINARY_CRYPTO_FILE_NAME = "testCrytpo.bin";
        private boolean openADOSession()
        {
            try
            {
                JISystem.setAutoRegisteration(true);
                //
                // Create a DCOM session.
                //
                dcomSession = JISession.createSession(domain, username, password);
                dcomSession.useSessionSecurity(true);
                //
                // Now create the COM server connected to the target machine.
                //
                JIComServer comServer = new JIComServer(JIProgId.valueOf(ADO_STREAM_INTERFACE_NAME), hostname, dcomSession);
                //
                // Get a handle to the main interface.
                //
                servicesDispatch = (IJIDispatch) JIObjectFactory.narrowObject(comServer.createInstance().queryInterface(IID));
            }
            catch (Exception e)
            {
                dcomSession = null;
                Logger.getLogger("TestLog").log(Level.SEVERE, "{WMIController::openADOSession} Exception caught: " + hostname, e);
            }
            return dcomSession != null;
        }
        public void remoteTest_CreateNewBinaryFile()
        {
            if (openADOSession() == false)
            {
                return;
            }
            final String REMOTE_BINARY_FILEPATH = "c:/" + BINARY_CRYPTO_FILE_NAME;
            try
            {
                Object[] params = new Object[]
                {
                    JIVariant.OPTIONAL_PARAM(),  // Source
                    JIVariant.OPTIONAL_PARAM(),  // Mode (ConnectModeEnum) default is adModeUnknown
                    JIVariant.OPTIONAL_PARAM(),  // OpenOptions (StreamOpenOptionsEnum) default is adOpenStreamUnspecified
                    JIVariant.OPTIONAL_PARAM(),  // UserName
                    JIVariant.OPTIONAL_PARAM()  // Password
                };
                Logger.getLogger("TestLog").log(Level.INFO, "{WMIController::remoteTest_CreateNewBinaryFile} Calling ADODB.Stream Open()...");
                JIVariant[] results = servicesDispatch.callMethodA("Open", params);
                IJIDispatch binaryStreamObject = (IJIDispatch) JIObjectFactory.narrowObject(results[0].getObjectAsComObject());
                byte[] bytesToWrite = new byte[1024];
                
                params = new Object[]
                {
                    new JIArray(bytesToWrite)  // Buffer
                };
                Logger.getLogger("TestLog").log(Level.INFO, "{WMIController::remoteTest_CreateNewBinaryFile} Calling ADODB.Stream Write()...");
                binaryStreamObject.callMethodA("Write", params);
                params = new Object[]
                {
                    new JIString(REMOTE_BINARY_FILEPATH),  // FileName
                    new JIVariant(new Integer(2))  // SaveOptions adSaveCreateOverWrite
                };
                Logger.getLogger("TestLog").log(Level.INFO, "{WMIController::remoteTest_CreateNewBinaryFile} Calling ADODB.Stream SaveToFile()...");
                binaryStreamObject.callMethodA("SaveToFile", params);
            }
            catch (Exception e)
            {
                lastCommandSuccessful = false;
                Logger.getLogger("TestLog").log(Level.SEVERE, "{WMIController::remoteTest_CreateNewBinaryFile} Exception caught\n", e);
            }
            closeSession();
        }
    

    And here's the output:

    INFO [org.jinterop]: Running ClientPingTimerTask !
    INFO [org.jinterop]: Running ServerPingTimerTask !
    INFO [org.jinterop]: Created Session: -1152323274
    INFO [org.jinterop]: Release_References_TimerTask:[RUN] Session:  -1152323274 , listOfDeferencedIpids.size(): 0
    INFO [org.jinterop]: progIdVsClsidDB: {}
     Sending BIND
     Recieved BIND_ACK
     Sending REQUEST
     Recieved RESPONSE
     Sending REQUEST
     Recieved RESPONSE
     Sending REQUEST
     Recieved RESPONSE
     Sending REQUEST
     Recieved RESPONSE
     Sending REQUEST
     Recieved RESPONSE
    INFO [org.jinterop]: mapOfHostnamesVsIPs: {}
     Sending BIND
     Recieved BIND_ACK
     Sending AUTH3
     Sending ALTER_CTX
     Recieved ALTER_CTX_RESP
     Sending REQUEST
     Recieved RESPONSE
    addUpdateOXIDs: finally this oid is { IPID ref count is 1 } and OID in bytes[] 00000: 26 8A 7F 6E 42 C3 85 60                          |&..nBÃ.`        |
     , hasExpired false } 
    INFO [org.jinterop]: [addToSession] Adding IPID: 00000008-154c-ffff-2577-1278c0266b7d to session: -1152323274
    INFO [org.jinterop]:  for IID: 00000000-0000-0000-c000-000000000046
    INFO [org.jinterop]: releaseRef:Reclaiming from Session: -1152323274 , the IPID: 0000bc09-154c-ffff-6a64-956593b9e416, numinstances is 5
    WARNING [org.jinterop]: releaseRef: Releasing numinstances 5 references of IPID: 0000bc09-154c-ffff-6a64-956593b9e416 session: -1152323274
     Sending BIND
     Recieved BIND_ACK
     Sending AUTH3
     Sending REQUEST
     Recieved RESPONSE
    WARNING [org.jinterop]: addRef: Adding 5 references for 00000008-154c-ffff-2577-1278c0266b7d session: -1152323274
     Sending REQUEST
     Recieved RESPONSE
     Sending REQUEST
     Recieved RESPONSE
    addUpdateOXIDs: finally this oid is { IPID ref count is 2 } and OID in bytes[] 00000: 26 8A 7F 6E 42 C3 85 60                          |&..nBÃ.`        |
     , hasExpired false } 
    INFO [org.jinterop]: [addToSession] Adding IPID: 0000bc09-154c-ffff-6a64-956593b9e416 to session: -1152323274
    INFO [org.jinterop]:  for IID: 00020400-0000-0000-c000-000000000046
    WARNING [org.jinterop]: addRef: Adding 5 references for 0000bc09-154c-ffff-6a64-956593b9e416 session: -1152323274
     Sending REQUEST
     Recieved RESPONSE
    INFO [TestLog]: {WMIController::remoteTest_CreateNewBinaryFile} Calling ADODB.Stream Open()...
     Sending BIND
     Recieved BIND_ACK
     Sending AUTH3
     Sending REQUEST
     Recieved RESPONSE
     Sending REQUEST
     Recieved RESPONSE
    SEVERE [TestLog]: {WMIController::remoteTest_CreateNewBinaryFile} Exception caught
    java.lang.IllegalStateException: org.jinterop.dcom.core.VariantBody$EMPTY cannot be cast to org.jinterop.dcom.core.IJIComObject
        at org.jinterop.dcom.core.VariantBody.getObjectAsComObject(JIVariant.java:1948)
        at org.jinterop.dcom.core.JIVariant.getObjectAsComObject(JIVariant.java:1373)
    [catch] at org.rcert.wmi.WMIController.remoteTest_CreateNewBinaryFile(WMIController.java:863)
        at org.rcert.wmi.WMIController.remoteTest_Harness(WMIController.java:734)
        at org.rcert.nodeobjects.Device.runRemoteScriptTest(Device.java:475)
        at org.rcert.devicedataview.ScanProfileForm.testWScriptButtonActionPerformed(ScanProfileForm.java:216)
        at org.rcert.devicedataview.ScanProfileForm.access$000(ScanProfileForm.java:19)
        at org.rcert.devicedataview.ScanProfileForm$1.actionPerformed(ScanProfileForm.java:180)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6289)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
        at java.awt.Component.processEvent(Component.java:6054)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4652)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4482)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Window.dispatchEventImpl(Window.java:2478)
        at java.awt.Component.dispatchEvent(Component.java:4482)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
        at java.awt.EventQueue.access$000(EventQueue.java:85)
        at java.awt.EventQueue$1.run(EventQueue.java:603)
        at java.awt.EventQueue$1.run(EventQueue.java:601)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
        at java.awt.EventQueue$2.run(EventQueue.java:617)
        at java.awt.EventQueue$2.run(EventQueue.java:615)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
        at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:148)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    WARNING [org.jinterop]: prepareForReleaseRef: Releasing numInstancesfirsttime + 5 references of IPID: 00000008-154c-ffff-2577-1278c0266b7d session: -1152323274 , numInstancesfirsttime is 5
    WARNING [org.jinterop]: prepareForReleaseRef: Releasing numInstancesfirsttime + 5 references of IPID: 0000bc09-154c-ffff-6a64-956593b9e416 session: -1152323274 , numInstancesfirsttime is 5
    INFO [org.jinterop]: In releaseRefs for session : -1152323274 , array length is: 2
     Sending REQUEST
     Recieved RESPONSE
    INFO [org.jinterop]: clearIPIDsforSession: holder.currentSetOIDs's size is 1
    INFO [org.jinterop]: Destroyed Session: -1152323274
    INFO [org.jinterop]: About to destroy links for Session: -1152323274 , size of which is 0
    INFO [org.jinterop]: destroySessionOIDs for session: -1152323274
    INFO [org.jinterop]: About to destroy links for Session: -1152323274 , size of which is 0
    INFO [org.jinterop]: destroySessionOIDs for session: -1152323274
    INFO [org.jinterop]: Running ClientPingTimerTask !
    INFO [org.jinterop]: Running ClientPingTimerTask !
    INFO [org.jinterop]: Running ServerPingTimerTask !
    INFO [org.jinterop]: Running ClientPingTimerTask !
    INFO [org.jinterop]: Running ClientPingTimerTask !
    INFO [org.jinterop]: Running ServerPingTimerTask !
    INFO [org.jinterop]: Running ClientPingTimerTask !
    
     
  • Vikram Roopchand

    Hi,
         Is "Open" with optional params supposed to return anything ? It would open the default stream right ? I haven't worked with this interface so could be wrong. Nothing incorrect in your implementation though.

    thanks,
    best regards,
    Vikram

     
  • jay

    jay - 2011-06-24

    Yes, you are totally correct!  I've since changed the code to account for that fact, and I did get the ADODB.Stream to successfully write a text file. 

    I'm still having problems with writing an actual binary file and placing the stream in Binary mode.  But that seems like it is related to other issues which I'm yet unclear on.  Like, setting the "Mode" of the stream, whereas there's no method call to do so from the ADODB.Stream interface.  But I suppose I'll have to use the GetIDsOfNames() method and Set() method as a start for doing that. 

    Nevertheless, I think I'm on the right track now.  Thanks a lot for your time and assistance!  Cheers.

     
  • danilop

    danilop - 2011-06-24

    Hi skorpioz,

    Please post the code if you are able to get this to work. I'm interested in doing the same thing but having issues with the ADODB.Stream "Write" method call. I too experienced that I can push a text file with "WriteText" but I'm having issues with writing a binary file.

    Thanks.

     
  • jay

    jay - 2011-06-27

    Well, I think I'm at my end working with the ADODB.Stream interface for writing binary files.  It simply does not work.  I believe it's being blocked on the Windows side via the registry, but I wouldn't know how to confirm this.

    The bottom line is that the "Write" function, when executed, will always throw up a 0x80020009 exception.  I highly doubt this has anything to do with J-Interop.

    Writing a text file is simple and straightforward.
    servicesDispatch.callMethodA("Open", params);
    servicesDispatch.callMethodA("WriteText", params);
    servicesDispatch.callMethodA("SaveToFile", params);

    And then we're done, and it works very well.  However, replacing "WriteText" with "Write", including the appropriate arguments, will always yield an exception.

    If anyone finds this to be untrue, please post your findings.  Also, if anyone knows of a workaround or a replacement for ADODB.Stream for writing binary files, please post that information as well.

    Cheers

     
  • Vikram Roopchand

    Hi,
         Can you tell me the detailed message in getExcepInfo in JIAutomationException ?

    thanks,
    best regards,
    Vikram

     
  • jay

    jay - 2011-06-27

    Absolutely.  Please let me know if any further info is needed.
    I hope this is what you're looking for.  Here is the log from just before calling the "Write" method:

    {WMIController} Calling Write()…

    Sending REQUEST

    Recieved RESPONSE

    Sending REQUEST

    Recieved RESPONSE

    {WMIController} JIAutomationException caught

    WARNING : prepareForReleaseRef: Releasing numInstancesfirsttime + 5 references of IPID: 00006009-1200-ffff-7171-9c2606b5f1bb session: 255009370 , numInstancesfirsttime is 5
    WARNING : prepareForReleaseRef: Releasing numInstancesfirsttime + 5 references of IPID: 0000f808-1200-ffff-6abd-ecca02f2c56a session: 255009370 , numInstancesfirsttime is 5
    INFO : In releaseRefs for session : 255009370 , array length is: 2

    Sending REQUEST

    Recieved RESPONSE
    INFO : clearIPIDsforSession: holder.currentSetOIDs's size is 1
    INFO : Destroyed Session: 255009370
    INFO : About to destroy links for Session: 255009370 , size of which is 0
    INFO : destroySessionOIDs for session: 255009370
    INFO : About to destroy links for Session: 255009370 , size of which is 0
    INFO : destroySessionOIDs for session: 255009370

     
  • jay

    jay - 2011-06-27

    Jeez…Sorry, but I didn't realize your Exception class had multiple methods!  Which are now VERY helpful to me  :)
    Here's the data you're looking for:

    {WMIController::remoteTest_CreateNewBinaryFileWithADODBStream} JIAutomationException
    getErrorCode(): -2146825287
    getExcepDesc(): Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. [ 
    getExcepSource(): ADODB.Stream 
    getHelpFilePath(): C:\Windows\HELP\ADO270.CHM ] 
    WARNING [org.jinterop]: prepareForReleaseRef: Releasing numInstancesfirsttime + 5 references of IPID: 0000600c-1394-ffff-3821-5418ab491b4f session: -1090992537 , numInstancesfirsttime is 5
    WARNING [org.jinterop]: prepareForReleaseRef: Releasing numInstancesfirsttime + 5 references of IPID: 00000c08-1394-ffff-78d9-b061bb60feee session: -1090992537 , numInstancesfirsttime is 5
    INFO [org.jinterop]: In releaseRefs for session : -1090992537 , array length is: 2
    

    Odd that I get that wrong type exception.  Here's the argument code I'm using:

    Byte[] bytesToWrite = new Byte[]
                {
                    new Byte(Byte.MIN_VALUE), new Byte(Byte.MIN_VALUE), new Byte(Byte.MAX_VALUE), new Byte(Byte.MAX_VALUE)
                };
                params = new Object[]
                {
                    new JIArray(bytesToWrite)  // Buffer
                };
    

    Can you see something wrong from that argument?

    Thanks

     
  • jay

    jay - 2011-06-28

    I've tried an exhaustive permutation of argument combinations and Types.  Unfortunately, it seems that no matter the derivation of arguments, I get that same exception message:

    "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another."

    Obviously, I'm missing the "correct" combination of Types.  If anyone is able to figure this out, please post your solution.

    Cheers

     
  • danilop

    danilop - 2011-07-05

    Skorpioz,

    I finally gave up. I now made it a requirement to have Admin shares enabled and use JCIF to move the files across windows systems. If you are not transferring files across 2 windows systems then JCIF will not work for you.

     
  • Vikram Roopchand

    Hi,
         Actually one of the users has implemented this specification. Satwik Hebbar (https://sourceforge.net/users/satwikhebbar/), I think. Maybe he can share his code/insights.

    thanks,
    best regards,
    Vikram

     
  • Deependra

    Deependra - 2014-01-23

    Hi,

    Have you find any way around to copy binary file in remote window machine.

    Thanks in advance.

     

Log in to post a comment.