Directory monitor in Java, help

Hey everyone,
I'm attempting to write a directory monitor in java but I'm stuck. I'm trying to find something in Java that is like FileSystemWatcher in .NET but I don't think java does. From what I read is that you have to continually poll the directory for changes. What I would like to know is that are there any events and/or signals raised when a changes are made so that one could catch and process them? If not, could someone explain how to simply poll the directory for changes?
Thanks
Barefoot

barefootsanders wrote:
This is exactly what I need to do. Now, i already have been working on the last modified time comparison which is relatively simple. What I was stuck on was finding what was different between the two file lists. Would I have to iterate through the entirety of the list and compare each item to find what was different or is there a more efficient way of doing this?The simplest thing to do would be to use Collection's removeAll method to get the difference between the two. This will show you which files have been added (using newList.removeAll(oldList)) and which have been removed (using oldList.removeAll(newList)).
A few notes:
* removeAll modifies the collection on which you call it, so you'll need to make copies.
* File's equals method docs say: Returns true if and only if the argument is not null and is an abstract pathname that denotes the same file or directory as this abstract pathname. Whether or not two abstract pathnames are equal depends upon the underlying system. On UNIX systems, alphabetic case is significant in comparing pathnames; on Microsoft Windows systems it is not.
So you'll need to decide if that's good enough, or if you want to implement your own comparison for files. Also, it's not clear from the above how shortcuts or symbolic links are handled--whether the shortcut and the original are considered equal or not.
* Based on the above, you may get different results with a List vs. a Set, so play around and see which one better suits your needs.
* I think a directory's mod time only changes if you add or remove or rename files, or explicitly change it, as with the touch command in unix. I don't think modifying the contents of an existing directory cause that directory's mod time to be updated. If you want to know when a file has changed, you'll probably have to poll that file's mod time explicitly.
In light of the above, I suggest you start by writing a small program that does nothing but poll a directory every, say, 5 or 10 or 30 seconds and print out whether it's changed or not. Then, while that program is running, do various things like add, delete, rename, rename with same letters but different case, etc. and see if the program gives you the results you want. If not, you'll have to tweak it based on your findings.

Similar Messages

  • How to bundle java help class into jar file ?

    Hi, all,
    I have some package in my project, with which I have a java help jar file as classpath, when I run my project, I need the jh.jar file in directory /jar/jh.jar.
    Now, I bundled all my class packages into a jar file, my.jar, together with the /jar directory. When i run my jar file with command:
    java -jar my.jar
    It tells me couldn't find javahelp class.
    What shall I do? How can I create my jar file with the jh.jar?
    Thanks in advance.

    I think you'd be better off just adding the jh.jar as
    a classpath argument and running it like that:
    java -classpath /myjavalibdir/jh.jar -jar myjar.jar
    ...otherwise you're stepping into redistribution of
    binary issues licensing-wise. That won't work either; when you run java with the -jar option, it ignores both the -classpath option and the CLASSPATH environment variable. However, it will see jh.jar automatically if you put it in the <path-to-java>/jre/lib/ext directory. But for distribution purposes, it might be simpler just to combime the contents of jh.jar into myjar.jar (if you use Ant, its <jar> task makes that very easy). Or, you can just run it this way:java -classpath myjar.jar;jar/jh.jar MyMainClassBTW, I don't think redistribution is a problem; otherwise how anyone even use JavaHelp?

  • Finding the directory path in java

    I need to check if a file exists or not before an action is taken. I used File class to get the handle of a file and and then used exist() function to check if it is there. But this function needs to full path to that file. I need to find a directory path at runtime as the application is deployed in different environment and wouldn't know the directory path in each environment. Could somebody help me on this. Thanks,

    fBut this function
    needs to full path to that file. I need to find a
    directory path at runtime as the application is
    deployed in different environment and wouldn't know
    the directory path in each environment. Well, that can only you know where this file is on the different platforms. So maybee you can provide it as a user-input, a parameter to the program or be set in a settings-file which the program reads.
    If you want the full path to the current directory where the java program runs, this works:
    File f=...;
    String absPath=f.getAbsolutePath();
    File absPathFile=new File(absPath);Gil

  • Java help

    hi ,
    i have a program browseexception which i call in all of my other prgms.
    i have compiled this and it is in the "ui" directory.
    BrowseException.java
    package ui;
    import javax.servlet.jsp.JspException;
    public class BrowseException extends JspException
         public BrowseException(String msg)
              super(msg);
    there is no compilation errors.
    the prg where i'm using this is :
    InvalidInputException.java
    package ui;
    public class InvalidInputException extends BrowseException
         private String retryURL;
         public InvalidInputException(String msg,String retryURL)
              super(msg);
              this.retryURL = retryURL;
         public String getRetryURL()
              return retryURL;
    this is also in the "ui" directory.
    but when i compile this it gives me an error message saying:
    " InvalidInputException.java:3: cannot resolve symbol
    symbol : class BrowseException
    location: class ui.InvalidInputException
    public class InvalidInputException extends BrowseException
    ^
    1 error ".
    can u help me out .have i made anything wrong while compiling or is there any problem in the code.
    Thanks

    Hi,
    set the classpath to point to the directory which contains the directory 'ui' or use the -classpath switch of javac to specify the location

  • Directory monitoring - unreadable directory?

    Hi,
    this may be related to my previous question.
    I want to use directory monitor to watch /var/core on all systems.
    I set up an Instance to do this in the appropriate module, but
    in fact it's not working because /var/core is unreadable under normal circumstances:
    # ls -la /var/core/
    total 13
    drwx------ 2 root root 2 Feb 21 10:19 .
    drwxr-xr-x 42 root sys 42 Feb 22 10:08 ..
    Without changing any permissions or ownership on /var/core, what is the procedure to allow SMC to watch this
    directory and read into it?
    Sorry for all the questions. We are doing a major deployment of SMC and relying on it for critical
    systems and need to come up to speed quickly - we are working through many of our issues and
    this forum has been extremely helpful.
    rachel

    Hi Rachel,
    virag064 wrote:
    I created an instance of Dirsize monitor with an Instance Name "core dumps".
    I set it to alarm me if the dirsize is greater than 8192kb (ie a core dump).
    I just ran gcore against a process to create a core dump and it exceeded the alarm rate.
    So then I saw the field light up in Yellow (it didn't do this before, so I must've mis-set something previously).
    But when I select the instance and do a Probe and select "Recursively list files" i(to return a file list) it
    returns with:
    /var/core:
    total 2
    /var/core: Permission deniedThat is why I am wondering if I have security not set properly - if it runs as root, it should be able to browse the directory
    from a probe?Ah... although SunMC runs as root... so it can monitor that directory properly and send alarms (as you have seen)... many of the probe commands are configured to run as "nobody". As a security feature lots of the probes that show directory/file listings don't run as root... so you can't go poking around and see things you're not supposed to as a SunMC admin.
    It probably wouldn't be hard to change that behavior (likely a single-line change in the Directory Monitor config file)... but be aware it would allow anybody in the SunMC "esadm" group to look at the contents of every directory on that Agent (i.e. you couldn't easily allow people to only look in /var/core... it would apply to any directory you were monitoring).
    [email protected]
    http://www.HalcyonInc.com
    New !! : http://forums.HalcyonInc.com !!

  • Can not open Integration Directory nor Integration Repository help please!

    Hi,
    I am not able to load the integration directory and repository java parts.
    The funny thing is that it worked yesterday for me, but I re-installed a newer version of Java and it crashed. I have tried to delete all the Java versions and install the version 1.6.0_03_b21 (this version works for my team mates), but I have only found version 1.6.0_03_b07, and it does not work.
    I am able to acces to the SAP PI 7.1 portal (http://proxy:port/dir/start/index.jsp), but when I enter here and try to access to the integration directory/repository, I get an error.
    Your help is much apreciated. Greetings from Spain!
    Edited by: Silvia Garcia Rua on Jul 7, 2011 6:09 PM

    Hi all,
    Thank you so much for the answers, but I am still not able to open them.
    Hope this error message helps:
    java.io.IOException: Server returned HTTP response code: 504 for URL: http://<<host>>:<<port>>/rep/repository/com.sap.xpi.ib.client.jar
         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
         at com.sun.deploy.net.DownloadEngine.getJarFileWithoutCache(Unknown Source)
         at com.sun.deploy.net.DownloadEngine.getCachedJarFile(Unknown Source)
         at com.sun.deploy.net.DownloadEngine.getCachedJarFile(Unknown Source)
         at com.sun.javaws.LaunchDownload.downloadEagerorAll(Unknown Source)
         at com.sun.javaws.Launcher.downloadResources(Unknown Source)
         at com.sun.javaws.Launcher.prepareLaunchFile(Unknown Source)
         at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
         at com.sun.javaws.Launcher.launch(Unknown Source)
         at com.sun.javaws.Main.launchApp(Unknown Source)
         at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
         at com.sun.javaws.Main$1.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)

  • Need to change the directory using the java program

    hi,
    can anyone give me the code to change the directory in the java program by using the system command.
    as in C where we use the system call system("cd");
    the same way how to do that in java. please help me with that!!!

    Please search the forums for "runtime.exec", there are dozens of examples posted.
    Although this may not do you any good, since changing the os's directory is not likely to change anything you're using in Java. What are you trying to do?

  • XSLT mapping with Java helper classes

    Hi,
    I'm trying to implement a XSLT mapping to convert my request to a specific soap request message format for this I'm calling some methods from a java helper class. I have imported the jar file into the archives. When I tried to test the interface it keeps complaing there is some exception but doesn't give me the exact error. Has any one called any java helper classes with in XSLT mapping, if so I would appreciate if you could help me with this. Here is the code from xsl.
    <wsse:Security soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext"   xmlns:UserToken="java:com.company.test.mapping.UserTokenMap">
    <wsse:UsernameToken>
        <wsse:Username xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
          <xsl:value-of select="UserToken:getUsername()"/>
        </wsse:Username>
        <wsse:Password wsse:Type="wsse:PasswordDigest" xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
        <xsl:value-of select="UserToken:getPasswordDigest()"/>
        </wsse:Password>
        <wsse:Nonce xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
        <xsl:value-of select="UserToken:getNonce()"/>
        </wsse:Nonce>
        <wsu:Created xsi:type="soapenc:string" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
        <xsl:value-of select="UserToken:getCreateDate()"/>
    </wsu:Created>
    </wsse:UsernameToken>
    </wsse:Security>
    Thanks,
    Joe

    Hi,
    I'm getting following exception when I refer to the java class with in my XSLT mapping. Any one encountered the same problem.
    com.sap.engine.services.ejb.exceptions.BaseRemoteException:
    Exception in method transform.
         at com.sap.aii.ibrep.sbeans.mapping.MapServiceRemoteObjectImpl0.transform(MapServiceRemoteObjectImpl0.java:218)
         at com.sap.aii.ibrep.sbeans.mapping.MapServiceRemoteObjectImpl0p4_Skel.dispatch(MapServiceRemoteObjectImpl0p4_Skel.java:104)
         at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java:320)
         at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java:198)
         at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java:129)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
         at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native
    Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
    Caused by: java.lang.UnsupportedClassVersionError:
    com/earthlink/xi/mapping/UserTokenMap (Unsupported
    major.minor version 49.0)
         at java.lang.ClassLoader.defineClass0(Native
    Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:448)
         at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingLoader.findClass(RepMappingLoader.java:175)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
         at com.sap.engine.lib.xsl.xpath.JLBLibrary.<init>(JLBLibrary.java:33)
         at com.sap.engine.lib.xsl.xpath.LibraryManager.getFunction(LibraryManager.java:69)
         at com.sap.engine.lib.xsl.xpath.ETFunction.evaluate(ETFunction.java:98)
         at com.sap.engine.lib.xsl.xpath.XPathProcessor.innerProcess(XPathProcessor.java:56)
         at com.sap.engine.lib.xsl.xpath.XPathProcessor.process(XPathProcessor.java:43)
         at com.sap.engine.lib.xsl.xpath.XPathProcessor.process(XPathProcessor.java:51)
         at com.sap.engine.lib.xsl.xslt.XSLValueOf.process(XSLValueOf.java:76)
         at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java:296)
         at com.sap.engine.lib.xsl.xslt.XSLElement.process(XSLElement.java:248)
         at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java:296)
         at com.sap.engine.lib.xsl.xslt.XSLElement.process(XSLElement.java:248)
         at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java:296)
         at com.sap.engine.lib.xsl.xslt.XSLElement.process(XSLElement.java:248)
         at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java:296)
         at com.sap.engine.lib.xsl.xslt.XSLElement.process(XSLElement.java:248)
         at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java:296)
         at com.sap.engine.lib.xsl.xslt.XSLElement.process(XSLElement.java:248)
         at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java:296)
         at com.sap.engine.lib.xsl.xslt.XSLTemplate.process(XSLTemplate.java:272)
         at com.sap.engine.lib.xsl.xslt.XSLStylesheet.process(XSLStylesheet.java:463)
         at com.sap.engine.lib.xsl.xslt.XSLStylesheet.process(XSLStylesheet.java:431)
         at com.sap.engine.lib.xsl.xslt.XSLStylesheet.process(XSLStylesheet.java:394)
         at com.sap.engine.lib.jaxp.TransformerImpl.transformWithStylesheet(TransformerImpl.java:398)
         at com.sap.engine.lib.jaxp.TransformerImpl.transform(TransformerImpl.java:240)
         at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingTransformer.transform(RepMappingTransformer.java:150)
         at com.sap.aii.ibrep.server.mapping.ibrun.RepXSLTMapping.execute(RepXSLTMapping.java:81)
         at com.sap.aii.ibrep.server.mapping.ibrun.RepSequenceMapping.execute(RepSequenceMapping.java:54)
         at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingHandler.run(RepMappingHandler.java:80)
         at com.sap.aii.ibrep.server.mapping.rt.MappingHandlerAdapter.run(MappingHandlerAdapter.java:107)
         at com.sap.aii.ibrep.server.mapping.ServerMapService.transformInterfaceMapping(ServerMapService.java:127)
         at com.sap.aii.ibrep.server.mapping.ServerMapService.transform(ServerMapService.java:104)
         at com.sap.aii.ibrep.sbeans.mapping.MapServiceBean.transform(MapServiceBean.java:40)
         at com.sap.aii.ibrep.sbeans.mapping.MapServiceRemoteObjectImpl0.transform(MapServiceRemoteObjectImpl0.java:167)
         ... 10 more
    ; nested exception is:
         java.lang.UnsupportedClassVersionError:
    com/earthlink/xi/mapping/UserTokenMap (Unsupported
    major.minor version 49.0)

  • Noob here, mac is always showing rainbow wheel for minutes at a time. Memory not an issue according to activity monitor. Please help.

    Oh here is my etre report, it takes forever when im browsing sites like reddit, youtube, etc...
    EtreCheck version: 1.9.12 (48)
    Report generated July 20, 2014 at 8:22:07 PM EDT
    Hardware Information:
        MacBook Pro (15-inch, Mid 2010) (Verified)
        MacBook Pro - model: MacBookPro6,2
        1 2.53 GHz Intel Core i5 CPU: 2 cores
        4 GB RAM
    Video Information:
        Intel HD Graphics - VRAM: 288 MB
            Color LCD 1440 x 900
        NVIDIA GeForce GT 330M - VRAM: 256 MB
    System Software:
        OS X 10.9.3 (13D65) - Uptime: 0 days 7:32:10
    Disk Information:
        TOSHIBA MK5055GSXF disk0 : (500.11 GB)
            EFI (disk0s1) <not mounted>: 209.7 MB
            Macintosh HD (disk0s2) / [Startup]: 441.71 GB (185.41 GB free)
            Recovery HD (disk0s3) <not mounted>: 650 MB
        MATSHITADVD-R   UJ-898 
    USB Information:
        Apple Internal Memory Card Reader
        Apple Inc. Apple Internal Keyboard / Trackpad
        Apple Inc. BRCM2070 Hub
            Apple Inc. Bluetooth USB Host Controller
        Apple Inc. Built-in iSight
        Apple Computer, Inc. IR Receiver
    Gatekeeper:
        Anywhere
    Kernel Extensions:
        [not loaded]    com.livescribe.kext.LivescribeSmartpen (1) Support
        [loaded]    com.rim.driver.BlackBerryUSBDriverInt (0.0.74) Support
        [not loaded]    com.rim.driver.BlackBerryUSBDriverVSP (0.0.74) Support
    Launch Daemons:
        [loaded]    com.adobe.fpsaud.plist Support
        [running]    com.examsoft.softest.service.plist Support
        [loaded]    com.google.keystone.daemon.plist Support
        [running]    com.livescribe.PenCommService.plist Support
        [loaded]    com.oracle.java.Helper-Tool.plist Support
        [loaded]    com.quark.quarkupdate.plist Support
        [running]    com.rim.BBDaemon.plist Support
        [not loaded]    org.eyebeam.SelfControl.plist Support
    Launch Agents:
        [loaded]    com.examsoft.softest.plist Support
        [loaded]    com.google.keystone.agent.plist Support
        [loaded]    com.oracle.java.Java-Updater.plist Support
        [running]    com.rim.BBAlbumArtCacher.plist Support
        [running]    com.rim.BBLaunchAgent.plist Support
    User Launch Agents:
        [not loaded]    com.adobe.ARM.[...].plist Support
        [not loaded]    com.spotify.webhelper.plist Support
    User Login Items:
        iTunesHelper
        PenAutoLaunch
        AutoLaunchForConnect
        Dropbox
        Spotify
    Internet Plug-ins:
        Flip4Mac WMV Plugin: Version: 3.2.0.16   - SDK 10.8 Support
        FlashPlayer-10.6: Version: 14.0.0.145 - SDK 10.6 Support
        JavaAppletPlugin: Version: Java 7 Update 45 Check version
        Flash Player: Version: 14.0.0.145 - SDK 10.6 Support
        Default Browser: Version: 537 - SDK 10.9
        o1dbrowserplugin: Version: 5.4.2.18903 Support
        QuickTime Plugin: Version: 7.7.3
        googletalkbrowserplugin: Version: 5.4.2.18903 Support
        Silverlight: Version: 5.1.20913.0 - SDK 10.6 Support
        iPhotoPhotocast: Version: 7.0 - SDK 10.8
    Safari Extensions:
        AdBlock: Version: 2.7.7
        Evernote Web Clipper: Version: 6.1.3
    Audio Plug-ins:
        BluetoothAudioPlugIn: Version: 1.0 - SDK 10.9
        AirPlay: Version: 2.0 - SDK 10.9
        AppleAVBAudio: Version: 203.2 - SDK 10.9
        iSightAudio: Version: 7.7.3 - SDK 10.9
    iTunes Plug-ins:
        Quartz Composer Visualizer: Version: 1.4 - SDK 10.9
    User iTunes Plug-ins:
        TuneUp Visualizer: Version: 2.4.0 - SDK 10.6 Support
    3rd Party Preference Panes:
        Flash Player  Support
        Flip4Mac WMV  Support
        Java  Support
        Quark Update Preferences  Support
    Time Machine:
        Skip System Files: NO
        Mobile backups: OFF
        Auto backup: NO - Auto backup turned off
        Volumes being backed up:
            Macintosh HD: Disk size: 411.38 GB Disk used: 238.71 GB
        Destinations:
            Seagate Backup Plus Drive [Local] (Last used)
            Total size: 931.19 GB
            Total number of backups: 5
            Oldest backup: 2012-07-30 07:55:56 +0000
            Last backup: 2014-07-10 09:04:08 +0000
            Size of backup disk: Adequate
                Backup size 931.19 GB > (Disk used 238.71 GB X 3)
        Time Machine details may not be accurate.
        All volumes being backed up may not be listed.
    Top Processes by CPU:
            35%    plugin-container
            30%    firefox
             7%    WindowServer
             4%    coreaudiod
             1%    hidd
    Top Processes by Memory:
        688 MB    firefox
        152 MB    plugin-container
        123 MB    mds_stores
        106 MB    Dropbox
        90 MB    mds
    Virtual Memory Information:
        321 MB    Free RAM
        1.74 GB    Active RAM
        1.03 GB    Inactive RAM
        807 MB    Wired RAM
        1.08 GB    Page-ins
        0 B    Page-outs

    System Software:
        OS X 10.9.3 (13D65) - Uptime: 0 days 7:32:10
    Gatekeeper:   Anywhere
    You need to update OS X.
    OS X Mavericks 10.9.4 Update (Combo)
    http://support.apple.com/kb/DL1755
    Post Date: Jun 30, 2014
    File Size: 958.2 MB
    Set System Preferences > Security & Privacy
    Set to Mac App Store and identified developers. Leaving it to Anywhere is not advised. You can always select to install if it's a legitimate app.
    I would disable all your plugins and extensions in your browsers. If the problem goes away, add back one at a time and make sure they are fully updated.
    Are you still using a Blackberry. Their software is still running.
    Make sure Flash is fully updated. Even with it set to automatic it often fails to update. I suggest you also turn it off and see if there is an improvement. many sites will use HTML5 if Flash is not installed. Install YouTube5 Safari extension

  • XSLT Mapping : RFC Lookup using java helper class

    Hi All,
    I am doing RFC Lookup in xslt mapping using java helper class. I have found blog for the same (http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/05a3d62e-0a01-0010-14bc-adc8efd4ee14) However this blog is very advanced.
    Can anybody help me with step by step approach for the same?
    My basic questions are not answered in the blog as:
    1) where to add the jar file of the java class used in xslt mapping.
    I have added zip file of XSLT mapping in imported archived and using that in mapping.
    Thanks in advace.
    Regards,
    Rohan

    Hi,
    Can u please have look at this in detail , u can easily point out yourself the problem...
    http://help.sap.com/saphelp_nw04/helpdata/en/55/7ef3003fc411d6b1f700508b5d5211/content.htm
    Please observe the line,
    xmlns:javamap="java:com.company.group.MappingClass
    in XSLT mapping..
    The packagename of class and class name and XSLT namespace should be matching...
    Babu
    Edited by: hlbabu123 on Sep 29, 2010 6:04 PM

  • Java Error in RFC Lookup in XSLT Mapping usinf Java helper class

    Hi All,
    I am doing RFC Lookup in XSLT Mapping using Java Helper class.
    The Lookup works fine when called one RFC at a time However my requirement is I want to do 2 Lookups.
    Both Lookups works when done individually however when I call both lookups in one mapping I get following error "javax.xml.transform.TransformerException: DOMSource whose Node is null."
    Following is the code I have written in XSLT for the lookup:
         <xsl:template name="Lookup_1">
              <xsl:param name="STDPN"/>
                   <rfc:RFC_READ_TABLE>
                        <QUERY_TABLE>KNA1</QUERY_TABLE>
                        <OPTIONS><item><TEXT>
                                  <xsl:value-of select="$STDPN"/>
                             </TEXT></item>
                        </OPTIONS>
                        <FIELDS>
                             <item>
                                  <FIELDNAME>KUNNR</FIELDNAME>
                             </item>
                        </FIELDS>
                   </rfc:RFC_READ_TABLE>
              </xsl:variable>
              <xsl:variable name="response" xmlns:lookup="java:urn.mt.pi" select="lookup:execute($request, 'BS_D, 'cc_RfcLookup', $inputparam)"/>
              <xsl:element name="STDPN">
                   <xsl:value-of select="$response//DATA/item/WA"/>
              </xsl:element>
         </xsl:template>
         <xsl:template name="Lookup_2">
              <xsl:param name="BELNR"/>
                   <xsl:variable name="Query">AGMNT = '<xsl:value-of select="$BELNR"/>'</xsl:variable>
                   <xsl:variable name="request1">
                        <rfc:RFC_READ_TABLE>
                             <QUERY_TABLE>ZTABLE</QUERY_TABLE>
                             <OPTIONS><item><TEXT>
                                  <xsl:value-of select="$Query"/>
                                  </TEXT></item>
                             </OPTIONS>
                             <FIELDS>
                                  <item>
                                       <FIELDNAME>KUNAG</FIELDNAME>
                                  </item>
                             </FIELDS>
                        </rfc:RFC_READ_TABLE>
                   </xsl:variable>
                   <xsl:variable name="response1" xmlns:lookup="java:urn.mt.pi" select="lookup:execute($request1, 'BS_D','cc_RfcLookup', $inputparam)"/>
                   <xsl:element name="BELNR">
                        <xsl:value-of select="$response1//DATA/item/WA"/>
                   </xsl:element>
         </xsl:template>
    My Question: Am I doing anything wrong? Or Is it possible to call multiple lookups in one XSLT?
    Thanks and Regards,
    Atul

    Hi Atul,
    I had the same problem like you had.
    The main Problem is that with the example code the request variable is created as NodeList object. In XSLT a variable is somekind of a constant and can't be changed. As the request object is empty after the first request the programm fails at the following line:
    Source source = new DOMSource(request.item(0));
    So I've created a workaround for this problem.
    In the call of the template I've put the request as a parameter object at the template call:
    <xsl:with-param name="req">
    <rfc:PLM_EXPLORE_BILL_OF_MATERIAL xmlns:rfc="urn:sap-com:document:sap:rfc:functions">
      <APPLICATION>Z001</APPLICATION>
      <FLAG_NEW_EXPLOSION>X</FLAG_NEW_EXPLOSION>
      <MATERIALNUMBER><xsl:value-of select="value"/></MATERIALNUMBER>
      <PLANT>FSD0</PLANT>
      <VALIDFROM><xsl:value-of select="//Recordset/Row[name='DTM-031']/value"/></VALIDFROM>
      <BOMITEM_DATA/>
    </rfc:PLM_EXPLORE_BILL_OF_MATERIAL>
    </xsl:with-param>
    With this change the request will be provided as a String object and not as a NodeList object.
    Afterwards the RfcLookup.java has to be changed to the following:
    package com.franke.mappings;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.PrintWriter;
    import java.io.StringWriter;
    import java.util.Map;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.Source;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Document;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import com.sap.aii.mapping.lookup.Channel;
    import com.sap.aii.mapping.api.StreamTransformationConstants;
    import com.sap.aii.mapping.api.AbstractTrace;
    import com.sap.aii.mapping.lookup.RfcAccessor;
    import com.sap.aii.mapping.lookup.LookupService;
    import com.sap.aii.mapping.lookup.XmlPayload;
    * @author Thorsten Nordholm Søbirk, AppliCon A/S
    * Helper class for using the XI Lookup API with XSLT mappings for calling RFCs.
    * The class is generic in that it can be used to call any remote-enabled
    * function module in R/3. Generation of the XML request document and parsing of
    * the XML response is left to the stylesheet, where this can be done in a very
    * natural manner.
    * TD:
    * Changed the class that request is sent as String, because of IndexOutOfBound-exception
    * When sending multiple requests in one XSLT mapping.
    public class RfcLookup {
         * Execute RFC lookup.
         * @param request RFC request - TD: changed to String
         * @param service name of service
         * @param channelName name of communication channel
         * @param inputParam mapping parameters
         * @return Node containing RFC response
         public static Node execute( String request,
                 String service,
                 String channelName,
                 Map inputParam)
              AbstractTrace trace = (AbstractTrace) inputParam.get(StreamTransformationConstants.MAPPING_TRACE);
              Node responseNode = null;
              try {
                  // Get channel and accessor
                  Channel channel = LookupService.getChannel(service, channelName);
                  RfcAccessor accessor = LookupService.getRfcAccessor(channel);
                   // Serialise request NodeList - TD: Not needed anymore as request is String
                   /*TransformerFactory factory = TransformerFactory.newInstance();
                   Transformer transformer = factory.newTransformer();
                   Source source = new DOMSource(request.item(0));
                   ByteArrayOutputStream baos = new ByteArrayOutputStream();
                   StreamResult streamResult = new StreamResult(baos);
                   transformer.transform(source, streamResult);*/
                    // TD: Add xml header and remove linefeeds for the request string
                    request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+request.replaceAll("[\r\n]+", ""); 
                    // TD: Get byte Array from request String to send afterwards
                    byte[] requestBytes = request.getBytes();
                   // TD: Not used anymore as request is String
                    //byte[] requestBytes = baos.toByteArray();
                    trace.addDebugMessage("RFC Request: " + new String(requestBytes));
                    // Create input stream representing the function module request message
                    InputStream inputStream = new ByteArrayInputStream(requestBytes);
                    // Create XmlPayload
                    XmlPayload requestPayload =LookupService.getXmlPayload(inputStream);
                    // Execute lookup
                    XmlPayload responsePayload = accessor.call(requestPayload);
                    InputStream responseStream = responsePayload.getContent();
                    TeeInputStream tee = new TeeInputStream(responseStream);
                    // Create DOM tree for response
                    DocumentBuilder docBuilder =DocumentBuilderFactory.newInstance().newDocumentBuilder();
                    Document document = docBuilder.parse(tee);
                    trace.addDebugMessage("RFC Response: " + tee.getStringContent());
                    responseNode = document.getFirstChild();
              } catch (Throwable t) {
                   StringWriter sw = new StringWriter();
                   t.printStackTrace(new PrintWriter(sw));
                   trace.addWarning(sw.toString());
              return responseNode;
         * Helper class which collects stream input while reading.
         static class TeeInputStream extends InputStream {
               private ByteArrayOutputStream baos;
               private InputStream wrappedInputStream;
               TeeInputStream(InputStream inputStream) {
                    baos = new ByteArrayOutputStream();
                    wrappedInputStream = inputStream;
               * @return stream content as String
               String getStringContent() {
                    return baos.toString();
              /* (non-Javadoc)
              * @see java.io.InputStream#read()
              public int read() throws IOException {
                   int r = wrappedInputStream.read();
                   baos.write(r);
                   return r;
    Then you need to compile and upload this class and it should work.
    I hope that this helps you.
    Best regards
    Till

  • How to use directory alias in Java stored procedure ?

    hi everyone !
    I want use Directory alias in Java strored procedure
    I 'hv created dir alias as
    Create Directory BFILE_DIR AS 'C:\MyImages'
    my java statements -
    myfile="C:\MyImages\myPH01.jpg"
    File binaryFile = new File(myFile);
    instead of giving absolute path I want give directory alias BFILE_DIR
    myfile= BFILE_DIR + "myPH01.jpg"
    File binaryFile = new File(myFile);
    can anyone pl suugest how should I write this in Java procedure
    thanks
    SPD

    hi everyone !
    I want use Directory alias in Java strored procedure
    I 'hv created dir alias as
    Create Directory BFILE_DIR AS 'C:\MyImages'
    my java statements -
    myfile="C:\MyImages\myPH01.jpg"
    File binaryFile = new File(myFile);
    instead of giving absolute path I want give directory alias BFILE_DIR
    myfile= BFILE_DIR + "myPH01.jpg"
    File binaryFile = new File(myFile);
    can anyone pl suugest how should I write this in Java procedure
    thanks
    SPD

  • Code Sample: Easy RFC Lookup From XSLT Mappings Using a Java Helper Class

    Hi everyone,
    This is just a shameless plug for my article: <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/05a3d62e-0a01-0010-14bc-adc8efd4ee14">Easy RFC Lookup From XSLT Mappings Using a Java Helper Class</a>. I hope you're interested in reading it, and I welcome your comments in this thread.
    Kind regards,
    Thorsten

    Hi Stefan. Thanks for your post. I have already done that. It still does not work. As a base for my java helper class I have usesd Thorstens code.
    The problem is quite confusing. I will try to ouline both issues here.
    First of all, when try to test from within the Operation Mapping, I always get a java error saying it cannot find the communication channel (it is there and working because I have tested it with the RFCLookup in graphical mapping). I have found a way to work around this, and that is to uncheck the "Use SAP XMLToolkit" checkbox --> switch to test tab, enter my ReceiverService in the parameter tab (header parameter) --> switch back to Definition tab, check the "Use SAP XMLToolkit" checkbox --> switch to Test tab and run the test. Then the XSLT and call to java helper class will work. Of course this is not really something you want to do all the time. Maybe there is a bug.
    Secondly, it never works when I try to do it "live". I am using a file adapter to pick up one file, convert it and a file adapter to drop the converted file. I get the following error code in SXMB_MONI.
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    <!--  Request Message Mapping   -->
    <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">
      <SAP:Category>Application</SAP:Category>
      <SAP:Code area="MAPPING">TRANSFORMER_CONF_EX</SAP:Code>
      <SAP:P1>ATJ_Accounting2XML_Accounting.xsl</SAP:P1>
      <SAP:P2>http://rd.accounting.logica.com</SAP:P2>
      <SAP:P3>fd552c30-bad9-11dd-9761-c21dac1b818c</SAP:P3>
      <SAP:P4>-1</SAP:P4>
      <SAP:AdditionalText />
      <SAP:Stack>TransformerConfigurationException triggered while loading XSLT mapping ATJ_Accounting2XML_Accounting.xsl; http://rd.accounting.logica.comfd552c30-bad9-11dd-9761-c21dac1b818c-1</SAP:Stack>
      <SAP:Retry>M</SAP:Retry>
      </SAP:Error>
    Using an XSLT without a call to a java helper class, works just fine.
    I am totally at a loss here. Any more input would be much appreciated.
    /Patrik

  • Java Help Exception in Linux

    Hi all, I have a piece of code that initializes Java help on windows perfectly but the same code causes an exception in Linux. below is the exception I am getting in Linux. because of this, the applications help is not appearing in Linux. Does anybody know why this happens only in Linux / has come across this or a fix for this earlier?
    Also I am working on Linux for the first time and I noticed that when i gave a couple of System.outs in the code to find out what was happening, they appeared allright in windows, but did not appear in Linux !! (then even the exception below disappeared, and that did not load help either !!)
    java.lang.NullPointerException
    at javax.help.HelpSet.parseInto(HelpSet.java:567)
    at javax.help.HelpSet.<init>(HelpSet.java:129)
    at com.mysoftware.util.MyJavaHelp.<init>(MyJavaHelp.java:52)
    at com.mysoftware.util.MyJavaHelp.getInstance(MyJavaHelp.java:64)
    Parsing failed for null
    Got an IOException (null)
    An answer to this will be highly appreciated...

    At present I am not sure if I can post code. I am trying to find that out. However, can u tell me what u mean by a Windows - window? I will try to figure that out...
    Thanks a lot..

  • Shutting Down a monitor in java

    hello.
    I just want to know how we can shut down our monitor in java?
    I mean the Computer Monitor -Screen-, not any kind of service.. :)
    if you can lead me i will appreciate it. thank you.

    You can do this in VBScript as far as I know, restarts also. Call your script using Runtime.exec();
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    With a script which is something like this:
    set objshell = wscript.CreateObject("Shell.Application")
    objshell.ShutdownWindowsSaved as scriptName.vbs
    EDIT: oops, just read you only need the monitor to be shutdown, still I think vb script is probably a good place to look. Google it!.
    Message was edited by:
    kikemelly

Maybe you are looking for

  • BI7.0 Process chain

    Hi All, Can any body tell me what is the difference between Direct Scheduling and Start Using Meta Chain or API. What I understand like, whenever we run independent process chain we will put Direct Scheduling option and If we run all local chains thr

  • Downloading itunes7 and ipod (1.4.1) problems

    i cannot download itunes7 or ipod software (1.4.1). after running the setup files it tells me i cannot do it because the software is from an unknown publisher. i then install the certificate manually and click ok. it then tells me thank you for downl

  • Which approach do you prefer for upgrade

    When upgrade 9.2 to 10.1 or 10.1 upgrade 10.2, which approach do you prefer, DBUA, manual ipgrade, export/import or data copying? Oracle document suggests to use DBUA, but from your experience, does it convince and why? Thank you for sharing,

  • IWeb / Non .mac website?

    I have the older version of iLife that didn't come with iWeb. I already have two websites with another hosting company. I wanted to know if I could use iWeb to create sites to put on my own existing (and already paid for) sites, or can you only uploa

  • Upgrading to SL suddenly "opened up" 30G's of HD space...

    Hi there I upgraded from Leopard to SL this morning. I had around 40Gigs of available HD space. I then installed iLife and iWork. After the installations had finished, I suddenly had 75Gigs of HD space. Panic set in. Where did the 35Gigs of extra spa