Stuck writing a unit file which depends on a device

I have written the following:
[Unit]
Description=Resets the repeat delay in Xorg if the keyboard is re-attached
Requires=dev-daskeyboard.device
Wants=dev-daskeyboard.device graphical.target [email protected]
After=graphical.target
BindsTo=dev-daskeyboard.device
[Service]
Type=oneshot
ExecStart=/usr/bin/xset r rate 160
ExecStart=/usr/bin/xmodmap /mnt/old/home/napalm/.xmodmaprc
RemainAfterExit=yes
It's a unit service in ~/.config/systemd/user and I'd like it to run any time the keyboard is unplugged and plugged back in *or* any time graphical.target is met (startx is run for example, or xlogin is used in my case).
Can anybody point me as to why it isn't working?
Just to clarify if I run the following then the commands are run correctly
systemctl --user start keyboard-rate.service]

Napaim wrote:*or* any time graphical.target is met (startx is run for example, or xlogin is used in my case)
For this part of your request, it's easy to obtain by adding your 'xset' and 'xmodmap' commands in your .xinitrc file.
I'd like it to run any time the keyboard is unplugged and plugged back in
I presume you mean you want the service to run when the keyboard is plugged in (it's not quite clear).
It's also not clear how you reach graphical.target running startx or xlogin: be more precise how you do that please.
"why it isn't working?" Because it is not the way to do that.
First you need to be sure systemd creates a 'dev-daskeyboard.device' when you plug the keyboard in.
For that to occur the udev device needs to be tagged with TAG+="systemd";
so you need to write a udev rule matching your keyboard to add the tag and with:
ENV{SYSTEMD_USER_WANTS}="<your service name>" at the end;
your service doesn't need all the 'Requires', 'Wants' and 'Bindsto' lines.
The udev rule should be triggered each times the keyboard is plugged in and systemd should then starts the service with the commands you wish to run on it.
Last edited by berbae (2014-11-03 10:15:31)

Similar Messages

  • How to block writing to a file which is already in use?

    Hi all,
    There is a certain file on a network drive. Multiple users have the rights to read and write to this file.
    I want to acccess this file via a LabView VI.
    If someone is already accessing this file I want to create a message like "File is already in use by user XXX, therefore acccess is read-only".
    Something like this is implemented in Windows (e.g. Excel...).
    How can I implement this in LabView? The access from each user is done with the same VI running on different computers.
    Of course I can create an .ini file, where I write the user which is currently accessing the file and block write acces for others.
    Is there a better way to do this?
    Thank you for any hints,
    Tilman.

    Does Excel tell you who is using the other file?
    If yes, does it do this only for its own file types or also for files like CSV or TXT?
    If it only does it for its types, then this is probably built into the definition of the file somehow (although I would assume that would mean that everytime Excel opens the file it also needs to save it?).
    I would try checking in the MSDN whether this is something that Windows supports.
    If not, the only option that comes to mind is the INI file you suggested.
    Try to take over the world!

  • How to run sqlj.exe to translator Sqlj file which depends other file

    I want to use sqlj.exe to compile sqlj file. I don't know what option can be set for Sqlj.exe can automatically compile sqlj file and it's dependent file(sqlj or java).
    Here is one case:
    There are three six files.
    p1\A.sqlj
    p1\A1.sqlj
    p2\B.sqlj
    p3\C.java
    p3\DI.java
    p4\E.java
    1.the Class A has been declared as follow:
    public class A extends C implements DI{
    And in A.sqlj file, Class B and A1 will be used.
    2.the class E has been declared as follow:
    public class E extends C{
    I want run sqlj.exe as follow:
    sqlj -d=. A.sqlj
    Does it can auto compile C.java, DI.java and A1.sqlj, B.sqlj?
    We known, when java file is compiled, the dependent java file will be auto compiled,
    for example, the command,
    javac E.java
    will compile E.java and C.java.
    But how sqlj.exe automatically compile dependent file.
    Thanks,

    I want to run an exe file Runtime.exec()
    installed in a server from a client machine Server program that executes Runtime.exec() if told to do so by a client via a socket connection
    everyday at a particular (fixed) time.Look at System.currentTimeMillis(), Calendar, Date, Timer...

  • Replica stuck while closing db file which has not been completely sync

    Hi,
    My system has one master and one client running on two different node.
    The replication server is up and running, then I start the replica, but somehow the replica is not
    getting DB_EVENT_REP_STARTUPDONE event within 120 seconds, so the database is closed,
    but while closing the database it got stuck inside a loop that logs the following messages every minute
    "the DB_ENV handle waiting %d minutes for replication lockout to complete" forever.
    (1) In what "failure" scenario, will get the thread stuck inside this loop?
    (2) How to get out of this loop?
    Thanks.

    Hi Sandra,
    Sorry to hear you're having this problem.
    When a replica starts up, it communicates with the master and tries to
    decide if it can do a simple synchronization (if it already has enough
    log history in common with the master), or must instead do a complete
    re-initialization of the database environment ("internal init").
    In the latter case we (understandably) can't satisfy DB->get()
    operations until the internal init is complete. Rather than rejecting
    those operations, we block ("locking out" the API). The idea behind
    that design choice is that it relieves the application of having to
    deal with this peculiar error situation. Unfortunately the API
    lockout is crude, i.e., it affects almost all API methods, including
    DB_ENV->close().
    There is currently no supported, non-hacky way to break out of this
    situation prematurely; one can only wait for all the necessary
    messages to arrive from the master, and eventually complete internal
    init.
    We should probably investigate why the internal init seems to be
    getting stuck. (Presumably there is not so much data that it's simply
    taking more than 120 seconds to load, or you wouldn't be asking.) If
    you turn on verbose diagnostic output at the master, and repeat this
    experiment, by any chance do you see any messages saying "queue limit
    exceeded"?
    Alan Bram
    Oracle

  • File.WriteContents writing to hidden files?

    I have noticed that File.WriteContents writes to premade files or makes files but i was wondering if there was something that would allow writing to hidden files, is this possible?

    First NOTE what JJ said.
    Supposed a testfile "C:\Program Files\Microsoft\Small Basic\Projects\TestFile.txt"  (here with space(s) in path)
    and a original set attribute of +H for the testfile, you could use:
    '------------- SNIP -------------
    qu = Text.GetCharacter(34)
    txtFile = "C:\Program Files\Microsoft\Small Basic\Projects\TestFile.txt"
    txt = "My Text to write"
    cmdLine = "-H " +qu+ txtFile +qu   '' clears the 'hidden / H' attribute only
    cmdLine = qu+ cmdLine +qu
    LDProcess.Start("attrib.exe", cmdLine)
    res = File.WriteContents(txtFile, txt)
    TextWindow.WriteLine(res)
    ' -------- SNAP -----------
    Depending on the set attributes (can be checked with
    attr = LDShell.GetDetail(txtFile, 6)  '' or
    'attr2 = LDShell.GetDetail(txtFile, "Attributes")  ' on an
    engl. System
    you will have to ev. temporary set back others as well. eg. 'attrib.exe -H -S -R txtFile',
    remember the original attribute(s) and, after writing to txtFile,
    set back again (eg. attrib.exe +H +S +R txtFile) to the original attributes.
    PS: If you are on SB 1.0 there is Data extension's 'FilePlus' object, which supports some methods for attributes (like .ContainsAttiribute, AddAttiribute, RemoveAttiribute). Perhaps further ('old') extensions that support attributes (like 'Fremy' etx ??
    etc), but unfortunaltely the don't work any more for SB 1.1.
    At any rate: You should KNOW what you are doing !!

  • Trouble with some custom SystemD/User unit files

    Good evening all,
    I'm trying to move programs out of my .xinitrc file and my window manager's startup hooks into systemd user unit files for ease of management, and hopefully more resilient.  I have followed the setup on the wiki page for SystemD/User session (https://wiki.archlinux.org/index.php/Sy … asic_setup) and already have some services already running:
    ╭─vendion@tyre ~
    ╰─➤ systemctl --user status
    ● tyre
    State: degraded
    Jobs: 0 queued
    Failed: 4 units
    Since: Fri 2014-08-08 20:23:47 EDT; 4 days ago
    CGroup: /user.slice/user-1000.slice/[email protected]
    ├─3200 /usr/lib/systemd/systemd --user
    ├─3202 (sd-pam)
    ├─dbus.service
    │ ├─ 3623 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation
    │ ├─ 3711 /usr/lib/at-spi2-core/at-spi-bus-launcher
    │ ├─ 3728 /usr/bin/dbus-daemon --config-file=/etc/at-spi2/accessibility.conf --nofork --print-address 3
    │ ├─ 3996 /usr/lib/at-spi2-core/at-spi2-registryd --use-gnome-session
    │ ├─ 4184 /usr/lib/GConf/gconfd-2
    │ └─29638 /usr/bin/dunst
    ├─udiskie.service
    │ └─3389 /usr/bin/python /usr/bin/udiskie
    ├─spideroak.service
    │ ├─3394 /opt/SpiderOak/lib/SpiderOak
    │ └─3993 /opt/SpiderOak/lib/SpiderOak --spider
    ├─skype.service
    │ └─3396 /usr/lib32/skype/skype
    ├─mpd.service
    │ ├─3386 /usr/bin/mpd --no-daemon
    │ ├─3959 /usr/bin/pulseaudio --start --log-target=syslog
    │ └─4178 /usr/lib/pulse/gconf-helper
    ├─mpdscribble.service
    │ └─3544 /usr/bin/mpdscribble
    └─google-musicmanager.service
    └─3638 /usr/bin/google-musicmanager
    Some of them are using unit files provided by the package, others I wrote the unit file for.  The services that are failing that are causing the state to be degraded are:
    ╭─vendion@tyre ~
    ╰─➤ systemctl --user --failed
    UNIT LOAD ACTIVE SUB DESCRIPTION
    ●clipit.service loaded failed failed Clipboard manager
    ●pasystray.service loaded failed failed Pulseaudio system tray icon
    ●pidgin.service loaded failed failed Pidgin IM client
    ●redshift.service loaded failed failed Redshift display colour temperature adjustment
    LOAD = Reflects whether the unit definition was properly loaded.
    ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
    SUB = The low-level unit activation state, values depend on unit type.
    4 loaded units listed. Pass --all to see loaded but inactive units, too.
    To show all installed unit files use 'systemctl list-unit-files'.
    I had to write the unit files for each of these.
    clipit.service unit file: http://sprunge.us/Qjfd
    When I check the status for this here is what I get:
    ● clipit.service - Clipboard manager
    Loaded: loaded (/home/vendion/.config/systemd/user/clipit.service; enabled)
    Active: failed (Result: start-limit) since Fri 2014-08-08 20:24:04 EDT; 4 days ago
    Main PID: 3619 (code=exited, status=1/FAILURE)
    Aug 08 20:24:04 tyre systemd[3200]: clipit.service: main process exited, code=exited, status=1/FAILURE
    Aug 08 20:24:04 tyre systemd[3200]: Unit clipit.service entered failed state.
    Aug 08 20:24:04 tyre systemd[3200]: clipit.service holdoff time over, scheduling restart.
    Aug 08 20:24:04 tyre systemd[3200]: Stopping Clipboard manager...
    Aug 08 20:24:04 tyre systemd[3200]: Starting Clipboard manager...
    Aug 08 20:24:04 tyre systemd[3200]: clipit.service start request repeated too quickly, refusing to start.
    Aug 08 20:24:04 tyre systemd[3200]: Failed to start Clipboard manager.
    Aug 08 20:24:04 tyre systemd[3200]: Unit clipit.service entered failed state.
    pasystray.service unit file: http://sprunge.us/BWWR
    Status output
    ● pasystray.service - Pulseaudio system tray icon
    Loaded: loaded (/home/vendion/.config/systemd/user/pasystray.service; enabled)
    Active: failed (Result: start-limit) since Fri 2014-08-08 20:24:12 EDT; 4 days ago
    Main PID: 3769 (code=killed, signal=TRAP)
    Aug 08 20:24:12 tyre systemd[3200]: pasystray.service: main process exited, code=killed, status=5/TRAP
    Aug 08 20:24:12 tyre systemd[3200]: Unit pasystray.service entered failed state.
    Aug 08 20:24:12 tyre systemd[3200]: pasystray.service holdoff time over, scheduling restart.
    Aug 08 20:24:12 tyre systemd[3200]: Stopping Pulseaudio system tray icon...
    Aug 08 20:24:12 tyre systemd[3200]: Starting Pulseaudio system tray icon...
    Aug 08 20:24:12 tyre systemd[3200]: pasystray.service start request repeated too quickly, refusing to start.
    Aug 08 20:24:12 tyre systemd[3200]: Failed to start Pulseaudio system tray icon.
    Aug 08 20:24:12 tyre systemd[3200]: Unit pasystray.service entered failed state.
    pidgen.service unit file: http://sprunge.us/KgKV
    Status output
    ● pidgin.service - Pidgin IM client
    Loaded: loaded (/home/vendion/.config/systemd/user/pidgin.service; enabled)
    Active: failed (Result: start-limit) since Fri 2014-08-08 20:24:04 EDT; 4 days ago
    Main PID: 3620 (code=exited, status=1/FAILURE)
    Redshift.service unit file: http://sprunge.us/IDCC
    Status output:
    ● redshift.service - Redshift display colour temperature adjustment
    Loaded: loaded (/home/vendion/.config/systemd/user/redshift.service; enabled)
    Active: failed (Result: start-limit) since Fri 2014-08-08 20:23:58 EDT; 4 days ago
    Docs: http://jonls.dk/redshift/
    Main PID: 3517 (code=exited, status=1/FAILURE)
    Aug 08 20:23:57 tyre systemd[3200]: redshift.service: main process exited, code=exited, status=1/FAILURE
    Aug 08 20:23:57 tyre systemd[3200]: Unit redshift.service entered failed state.
    Aug 08 20:23:58 tyre systemd[3200]: redshift.service holdoff time over, scheduling restart.
    Aug 08 20:23:58 tyre systemd[3200]: Stopping Redshift display colour temperature adjustment...
    Aug 08 20:23:58 tyre systemd[3200]: Starting Redshift display colour temperature adjustment...
    Aug 08 20:23:58 tyre systemd[3200]: redshift.service start request repeated too quickly, refusing to start.
    Aug 08 20:23:58 tyre systemd[3200]: Failed to start Redshift display colour temperature adjustment.
    Aug 08 20:23:58 tyre systemd[3200]: Unit redshift.service entered failed state.
    I know that my unit files for these services work because if I manually start them with "systemctl --user start <service>" then they work just fine, but when systemD is trying to start them when I login they fail.  I have dbus setup like the wiki says to, and "DBUS_SESSION_BUS_ADDRESS" is defined.  I also have the DISPLAY environment variable set in /etc/systemd/system/[email protected]/display.conf like the wiki suggests as well.  I know that SystemD user sessions still may not be ready for prime time but I could use a better way to manage these startup programs than the .xinitrc file.
    Thanks in advance for any help

    i suppose there is a code whitch resets the default bounds when
    the component is beeing added to the JTable.Technically, the Component returned by the getCellRendererComponent() is not added to the JTable, it's just used as a rubber stamp.Mmm, I was wrong: at least with the basic L&F, the Component is (temporarily) added to a CellRendererPane, which is a children of the JTable.
    Moreover, I witnessed that both setBounds() and doLayout() are called before the component is actually painted...
    I've never used a compound component as a renderer, but I assume the issue is common (did not have time to search nor try it myself). You may investigate whether the JPanel is appropriately laid out, by inserting some breakpoints/logs at appropriate places (setBounds, doLayout,...)Did this on an extra-short example, and it did render correctly...
    somehow the textfield's bounds where not set anymore.Note that the Javadoc for Cellrendererpane states that +"After the component is painted it's bounds are reset to -w, -h, 0, 0 so that, if it's the last renderer component painted, it will not start consuming input"+.
    That does not explain why the w and h are 0, but at least it's clear that depending on where you put your logging statement makes a big difference about the accuracy of the bounds logged

  • I want to write in a XML file which is located on the TOMCAT server

    hello all,
    can anybody tell me or give me code snippet for writing some data through my application i.e from client side on te file which is located on the TOMCAT server(especially XML file).
    tell me how can i do that?
    it is urgent
    cya
    sush

    Hello sush,,,,
    I am sending you some API / classes that will definetely help you for writing XML file through java.
    1) TransformerFactory.newInstance();
    2)Transformer serializer
    3)StreamResult
    4)serializer.transform(source,result);
    5)DOMSource
    From Vikas_khengare
    [ [email protected] ]

  • Expdp with parallel writing in one file at a time on OS

    Hi friends,
    I am facing a strange issue.Despite giving parallel=x parameter the expdp is writing on only one file on OS level at a time,although it is writing into multiple files sequentially (not concurrently)
    While on other servers i see that expdp is able to start writing in multiple files concurrently. Following is the sample log
    of my expdp .
    ++++++++++++++++++++
    Export: Release 10.2.0.3.0 - 64bit Production on Friday, 15 April, 2011 3:06:50
    Copyright (c) 2003, 2005, Oracle. All rights reserved.
    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    Starting "CNVAPPDBO4"."EXPDP_BL1_DOCUMENT": CNVAPPDBO4/********@EXTTKS1 tables=BL1_DOCUMENT DUMPFILE=DUMP1_S:Expdp_BL1_DOCUMENT_%U.dmp LOGFILE=LOG1_S:Expdp_BL1_DOCUMENT.log CONTENT=DATA_ONLY FILESIZE=5G EXCLUDE=INDEX,STATISTICS,CONSTRAINT,GRANT PARALLEL=6 JOB_NAME=Expdp_BL1_DOCUMENT
    Estimate in progress using BLOCKS method...
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    Total estimation using BLOCKS method: 23.93 GB
    . . exported "CNVAPPDBO4"."BL1_DOCUMENT" 17.87 GB 150951906 rows
    Master table "CNVAPPDBO4"."EXPDP_BL1_DOCUMENT" successfully loaded/unloaded
    Dump file set for CNVAPPDBO4.EXPDP_BL1_DOCUMENT is:
    /tksmig/load2/oracle/postpaidamd/DUMP1_S/Expdp_BL1_DOCUMENT_01.dmp
    /tksmig/load2/oracle/postpaidamd/DUMP1_S/Expdp_BL1_DOCUMENT_02.dmp
    /tksmig/load2/oracle/postpaidamd/DUMP1_S/Expdp_BL1_DOCUMENT_03.dmp
    /tksmig/load2/oracle/postpaidamd/DUMP1_S/Expdp_BL1_DOCUMENT_04.dmp
    Job "CNVAPPDBO4"."EXPDP_BL1_DOCUMENT" successfully completed at 03:23:14
    ++++++++++++++++++++
    uname -aHP-UX ocsmigbrndapp3 B.11.31 U ia64 3522246036 unlimited-user license
    Is it hitting any known bug? Please suggest.
    regds,
    kunwar

    PARALLEL always using with DUMPFILE=filename_*%U*.dmp. Did yoy put the same parameter on target server?
    PARALLEL clause depend on server resources. If the system resources allow, the number of parallel processes should be set to the number of dump files being created.

  • Error while writing to a file

    Hi,
    I am getting an error while writing to a file.Here is the sample code in which I am getting error.The STDERR is getting printed to console but the same is not getting written to a file.
    package Sample;
    import java.util.*;
    import java.io.*;
    public class MediocreExecJavac
    public static void main(String args[])
    try
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("perl ic_start");
    InputStream stderr = proc.getErrorStream();
    InputStreamReader isr = new InputStreamReader(stderr);
    BufferedReader br = new BufferedReader(isr);
    FileWriter fw=new FileWriter("result.txt");
    String line = null;
    System.out.println("<ERROR>");
    while ( (line = br.readLine()) != null)
    System.out.println(line);
    fw.write(line);
    System.out.println("</ERROR>");
    int exitVal = proc.waitFor();
    System.out.println("Process exitValue: " + exitVal);
    fw.close();
    } catch (Throwable t)
    t.printStackTrace();
    }Below is the output -
    <ERROR>
    Can't open perl script "ic_start": No such file or directory
    java.lang.NullPointerException
    at java.io.Writer.write(Unknown Source)
    at Sample.MediocreExecJavac.main(MediocreExecJavac.java:21)
    Please tell where the program is going wrong.

    i think it is just the path of file that u r missing

  • Viewing a file which is in Application Server [al11]

    Hi All
    I have a file which is residing in Application Server [al11 tcode], how i can display the file using LinkToURL UI Element,
    what is the path which i need give in the REFERENCE parameter of the UI Element.
    Thanks in Advance
    Regards
    Chaitanya.A

    Just becuase the file is in the filesystem of the application server, doesn't necessarily mean that it is exposed to the network at all. This really depends upon your OS and if you have a file share or external web server connected to the OS of your application server.
    However if you want to temporarily create a URL via the ABAP application server for a file in the filesystem you can do so by placing the content into the ICM cache.
    So you would read the file from the filesystem using the normal ABAP dataset commands.
    Here is a small example where I am doing this with different image formats:
    ****Create the cached response object that we will insert our content into
      data: cached_response type ref to if_http_response.
      create object cached_response
        type
          cl_http_response
        exporting
          add_c_msg        = 1.
    *  cached_response->set_compression( options = cached_response->IF_HTTP_ENTITY~CO_COMPRESS_IN_ALL_CASES ).
    try. " ignore, if compression can not be switched on
          call method cached_response->set_compression
            exporting
              options = cached_response->co_compress_based_on_mime_type
            exceptions
              others  = 1.
        catch cx_root.
      endtry.
    ****set the data and the headers
      data: l_app_type type string.
      data: l_xstring type xstring.
      case i_format.
        when 'BMP'.
          cached_response->set_data( me->gx_content ).
          l_app_type = 'image/x-ms-bmp'.
        when 'GIF'.
          me->get_content_ext_format(
            exporting
              i_format  = i_format
            importing
              e_xstream = l_xstring ).
          cached_response->set_data( l_xstring ).
          l_app_type = 'image/gif'.
        when 'JPG'.
          me->get_content_ext_format(
            exporting
              i_format  = i_format
            importing
              e_xstream = l_xstring ).
          cached_response->set_data( l_xstring ).
          l_app_type = 'image/jpeg'.
        when 'TIF'.
          me->get_content_ext_format(
            exporting
              i_format  = i_format
            importing
              e_xstream = l_xstring ).
          cached_response->set_data( l_xstring ).
          l_app_type = 'image/tiff'.
        when 'PNG'.
          me->get_content_ext_format(
            exporting
              i_format  = i_format
            importing
              e_xstream = l_xstring ).
          cached_response->set_data( l_xstring ).
          l_app_type = 'image/png'.
        when others.
          raise exception type zcx_abap_bitmap.
      endcase.
      cached_response->set_header_field( name  = if_http_header_fields=>content_type
                                         value = l_app_type ).
    ******Set the filename into the response header
    *  cached_response->set_header_field( name  = 'Content-Encoding'
    *                                     value = 'compress' ).
    ****Set the Response Status
      cached_response->set_status( code = 200 reason = 'OK' ).
    ****Set the Cache Timeout - 60 seconds - we only need this in the cache
    ****long enough to build the page and allow the IFrame on the Client to request it.
      cached_response->server_cache_expire_rel( expires_rel = i_cache_timeout ).
    ****Create a unique URL for the object
      data: guid type guid_32.
      call function 'GUID_CREATE'
        importing
          ev_guid_32 = guid.
      concatenate i_path '/' guid '.' i_format into r_url.
    ****Cache the URL
      cl_http_server=>server_cache_upload( url      = r_url
                                           response = cached_response ).
    Another option would be to create a custom ICF handler class.  In this class you could pass the file name as URL parameters, read the content using ABAP DATASET commands and return the content in the response object. 
    Handler classes have to implement the IF_HTTP_EXTENSION Interface.  You implent the method HANDLE_REQUEST.
    Here is an example implementation of the HANDLE_REQUEST:
    * Inform ICF to "keep" (reuse) this handler, and that we answered the HTTP request
      if_http_extension~lifetime_rc = if_http_extension=>co_lifetime_keep.
      if_http_extension~flow_rc     = if_http_extension=>co_flow_ok.
    * Determine image name from URL ~script_name/~path_info (= image_name)
      data: name type string.
      name = server->request->get_header_field( name = if_http_header_fields_sap=>path_info ).
      translate name to upper case.
      if strlen( name ) >= 1 and name(1) = '/'.
        shift name left.
      endif.
    * Application logic
      data: content type xstring.
      content = me->load( name ).
      if xstrlen( content ) is initial.
        raise exception type cx_http_ext_exception exporting msg = 'Invalid URL!'.
      endif.
    * Set up HTTP response
      server->response->set_status( code = 200 reason = 'OK' ).
      server->response->set_header_field( name = if_http_header_fields=>content_type   value = 'image/png' ).
      server->response->server_cache_expire_rel( expires_rel = 86000 ).
      server->response->set_header_field( name = if_http_header_fields=>cache_control value = 'max-age=86000' ).
      server->response->set_data( content ).
    3rd option would be to create an ICM File Handler. I detailed this functionality in the SAP Press book Advanced BSP Programming.  It is covered in Chapter 16.2.  Here is an exerpt:
    The Internet Communication Manager (ICM) allows just such access to any file
    system accessible to the underlying operating system. You can map operating file
    system directories into ICM URL paths using the profile parameter icm/HTTP/
    file_access_<xx>.
    If you have never maintained one of the system-profile parameters, now is good
    time to make friends with your Basis administrator. With the following additions
    to our instance profile and a quick restart of the ICM, we are now able to access
    file system directories via HTTP.
    icm/HTTP/file_access_0 =
    PREFIX=/doc/, DOCROOT=/usr,BROWSEDIR=2
    icm/HTTP/file_access_1 =
    PREFIX=/doc2/,
    DOCROOT=
    server\SAPPatches\Netweaver04,BROWSEDIR=2
    In the first entry, we are just going to map to the local directory usr. We are able
    to control the useru2019s options to browser a directory via the additional parameter
    BROWSEDIR. The possible values are: 0 u2013 no browsing allowed, 1 u2013 only file names
    are displayed, and 2 u2013 file names along with their size and last change date are displayed.
    The second entry really shows off the power of this profile parameter. We are able
    to expose a directory on a remote server via UNC paths. Of course the security on
    that directory would have to be open to allow read-and-browse access. There is
    also no real mechanism to apply security to the ICM URL for this file access node,
    so you will want to be careful what you expose through it.

  • Reading a Compressed File from a ZIP File, which is an entry of ZIP File

    Hello, Experts,
    Would it be possible somebody to help me with code example for the following problem?
    I want to read a compressed file from a ZIP file, which is an entry of ZIP File, without extacting/writing files on file system. Is this possible?
    Lets say we have a ZipFile1. There is ZipFile2 inside ZipFile1. And inside ZipFile2 is FileA. The scenario is reading FileA without extracting on file system.
    Thank you in advance for your help.
    Cheers
    RADY

    The classes you want to be using are java.util.zip.ZipInputStream and and ZipEntry from the same package. Construct the ZipInputStream with the input you have for the outer zip. Loop with ZipInputStream.getNextEntry until you find the inner zip you're looking for - that method returns a ZipEntry, and you get the name of the zip entry with ZipEntry.getName. Read the ZipInputStream from that point into some buffer, and read that buffer into a new ZipInputStream - rinse and repeat until you have the contents of the file in the zip in the zip...

  • Records are missing in the File which XI has placed in Target FTP server

    Hi All,
    I have a scenario where in XI is transfering the files from ECC to Target System . No transformation required here . I am using AAE to run this scenario.
    Issue i am facing here is that i can see few records missing in the File  which XI had placed in the Target system FTP server . Same file if i check it in archive folder of ECC (which XI has archived after picking the file), complete set of records are present for the same file.
    Need your inputs please....
    Note : XI is using AAE to transfer the files and no mapping . Also i tried to check out the audit logs in the channel monitoring . Unforutanely i was not able to see the logs to check the bytes that was transferred while readng and writing the file . Sometimes i have faced audit logs issue in PI 7.1
    Regards
    Vinay P.

    Please use temporary name scheme
    http://help.sap.com/saphelp_nwpi711/helpdata/en/44/6830e67f2a6d12e10000000a1553f6/content.htm
    hope this helps
    regards
    Ninad

  • Writing double to file

    basically all i want to do is to write a double array in to a file and then read it back i actually want this to be a seperate class
    The problem
    First i enter 5 double all = 1; Then i read it back return all one, which is ok but then i try to write other number to the file it still returning all one
    public class Storage extends JFrame{
        double aiw[];                           //This is use to take data from Ai class
        File weightfile3 = new File("weightdata3.dat");
        File weightfile5 = new File("weightdata5.dat");       
         File weightfile10 = new File("weightdata10.dat");
            //= new File("weightdata.dat"); //This create a file for saving the weight
      //  private RandomAccessFile file;
    //    private JMenuItem newItem, updateItem,deleteItem,openItem,exitItem;
         Storage()
          //  weightfile3 = new File("weightdata3.dat");
            //weightfile5 = new File("weightdata5.dat");       
              //weightfile10 = new File("weightdata.dat");
        public void weightSave(double tempw[], int size)
        //This function save the data according to the information
         if(size == 3)
         File weightfile3 = new File("weightdata3.dat");
            try{//try to write data
                FileOutputStream file = new FileOutputStream(weightfile3, true);
                BufferedOutputStream buff = new BufferedOutputStream(file);//uses for buffering
                DataOutputStream weightdata = new DataOutputStream(buff);
                System.out.println("Inside weight function");//This is for debug//tested
                for(int i =0;i<6;i++){
                    System.out.println(tempw);//uses for debug//tested
    weightdata.writeDouble(tempw[i]);
    //finish writing information into the file
    weightdata.close();//close the file
    catch(IOException e)//if failed
    System.out.println("Error writing file :"+ e.toString());
         else if(size == 5)
         try{//try to write data
    FileOutputStream file = new FileOutputStream(weightfile5, true);
    BufferedOutputStream buff = new BufferedOutputStream(file);//uses for buffering
    DataOutputStream weightdata = new DataOutputStream(buff);
    //System.out.println("the weight that was saved");//This is for debug//tested
    for(int i =0;i<10;i++){
    System.out.println(tempw[i]);//uses for debug//tested
    weightdata.writeDouble(tempw[i]);
    //finish writing information into the file
    weightdata.close();//close the file
    catch(IOException e)//if failed
    System.out.println("Error writing file :"+ e.toString());
         else
         try{//try to write data
    FileOutputStream file = new FileOutputStream(weightfile10, true);
    BufferedOutputStream buff = new BufferedOutputStream(file);//uses for buffering
    DataOutputStream weightdata = new DataOutputStream(buff);
    //System.out.println("the weight that was saved");//This is for debug//tested
    for(int i =0;i<10;i++){
    System.out.println(tempw[i]);//uses for debug//tested
    weightdata.writeDouble(tempw[i]);
    //finish writing information into the file
    weightdata.close();//close the file
    catch(IOException e)//if failed
    System.out.println("Error writing file :"+ e.toString());
    }//the end of save file
    public double weightLoad(int nweight,int size)//this function require to know which weight need to be load
    //this function should read from the file and return one double at a time
         if(size == 3)
    double temp[] =new double[6];
    double retral =0;
    // System.out.println("int the weightLoad function");//uses for debug
    try{
         FileInputStream file = new FileInputStream(weightfile3);
         BufferedInputStream buff = new BufferedInputStream(file);
         DataInputStream weightdata = new DataInputStream(buff);
    // System.out.println("in the weightLoad function");//uses for debug
    for(int i =0;i<6;i++) {
    temp[i] = weightdata.readDouble();
    //System.out.println(temp[i]);//uses for debug
              // System.out.println("read all the data");
         weightdata.close();
         }catch (IOException e) {System.out.println("Error reading from file"+e.toString());}
    //System.out.println(temp);//This is for debug
    for(int i=0;i<=nweight;i++)
    retral = temp[i];
         System.out.println("The value that get return from load is : " + retral);
         return retral;
         else if(size == 5)
         double temp[] =new double[10];
    double retral =0;
    // System.out.println("int the weightLoad function");//uses for debug
    try{
         FileInputStream file = new FileInputStream(weightfile5);
         BufferedInputStream buff = new BufferedInputStream(file);
         DataInputStream weightdata = new DataInputStream(buff);
    System.out.println("in the weightLoad function");//uses for debug
    for(int i =0;i<10;i++) {
    temp[i] = weightdata.readDouble();
    System.out.println(temp[i]);//uses for debug
              System.out.println("read all the data");
         //weightdata.close();
         }catch (IOException e) {System.out.println("Error reading from file"+e.toString());}
    //System.out.println(temp);//This is for debug
    for(int i=0;i<=nweight;i++)
    retral = temp[i];
         System.out.println("The value that get return from load is : " + retral);
         return retral;
         else
         double temp[] =new double[10];
    double retral =0;
    // System.out.println("int the weightLoad function");//uses for debug
    try{
         FileInputStream file = new FileInputStream(weightfile10);
         BufferedInputStream buff = new BufferedInputStream(file);
         DataInputStream weightdata = new DataInputStream(buff);
    System.out.println("in the weightLoad function");//uses for debug
    for(int i =0;i<10;i++) {
    temp[i] = weightdata.readDouble();
    //System.out.println(temp[i]);//uses for debug
         System.out.println("read all the data");
         //weightdata.close();
         }catch (IOException e) {System.out.println("Error reading from file"+e.toString());}
    //System.out.println(temp);//This is for debug
    for(int i=0;i<=nweight;i++)
    retral = temp[i];
         System.out.println("The value that get return from load is : " + retral);
         return retral;

    Your problem is caused by the way you save the data:
    FileOutputStream file = new FileOutputStream(weightfile5, true);The argument "true" means that you append any data to the end of the file, rather than overwriting the current contents.
    Your reader just reads the first data in the file - which are the ones that you put in initially. Thats why it is always returning all one.
    To fix: remove the "true" from your call to FileOutputStream - it will then overwrite the current file.
    Cheers,
    evnafets

  • How to insert new line char while writing bytes into file

    Hello Sir,
    Is it possible to insert the new line character in set of String variables and stored them into bytearray ,then finally write into File?
    This is the sample code which i tried:
                 File f = new File(messagesDir,"msg" + msgnum + ".txt");
                 FileOutputStream fout = new FileOutputStream(f);
                    String fromString = "From:    "+msg.getFrom()+"\n";
                    String toString = "To:     "+msg.getTo()+"\n";
                    String dateString = "Sent:    "+msg.getDate()+"\n";
                      String msgString =msg.getBody()+"\n";
                    String finalString=fromString+toString+dateString+msgString;
                    byte[] msgBytes = finalString.getBytes();
                    fout.write(msgBytes);
                 fout.close();in the above code , i tried to add the new line as "\n" in end of each string. but when i look into the generated files msg1.txt , it contains some junk char [] .
    please provide me the help
    regards
    venki

    but it has still shown the the junk char, its not able
    to create the new line in the created file i am afraid
    how am i going to get the solution?:(Do not be afraid dear sir. You are obviously using a windows operating system or a mac operating system. On windows a newline is "\r\n" not '\n', and on a mac a newline is '\r', not '\n'. If you make that correction, dear sir, your program will work.
    However, there is a better way. First, you probably want to buffer your output if you are going to write more than one time to the file, which will make writing to the file more efficient. In addition, when you buffer your output, you can use the newLine() method of the BufferedWriter object to insert a newline. The newline will be appropriate for the operating system that the program is running on. Here is an example:
    File f = new File("C:/TestData/atest.txt");
    BufferedWriter out = new BufferedWriter(new FileWriter(f) );
    String fromString = "From: Jane";
    out.write(fromString);
    //Not written to the file until enough data accumulates.
    //The data is stored in a buffer until then.
    out.newLine();
    String toString = "To: Dick";
    out.write(toString);
    out.newLine();
    String dateString = "Sent: October 27, 2006";
    out.write(dateString);
    out.newLine();
    out.close(); 
    //Causes any unwritten data to be flushed from
    //the buffer and written to the file.

  • File Adapter not processing Files which has COMMA in it

    Hi Experts,
    I am working on Project in SOA 11.1.1.6.
    I am trying to process a file which has comma in it. for eg - XXXXXXX-XX_XX_XXX11,99.pdf
    I am picking the file using file adapter from SOURCE directory and using another file adapter to WRITE to destination directory. Polling processing is working fine.
    I am picking the file from SOURCE directory as ATTACHMENT and WRITING to DESTINATION folder through File Adapter
    While doing file WRITE its failing. While reading the file the values of Content Type, Character Set and Encoding are NULL for the ATTACHMENT as they are optional properties.
    The error I am getting while File WRITE is
    <remoteFault>
    <part name="summary">
    <summary>java.lang.RuntimeException: Failed to decode properties string att.encoding=null,att.charset=null,att.contentId=AReadFile/XXXXXXXX_XX_XXX11,99.pdf_1352184009640,att.contentType=null,att.partName=attach</summary>
    </part>
    <part name="detail">
    <detail>1</detail>
    </part>
    </remoteFault>

    Comma is usually treated as a separator/delimiter and hence it is not really common to have comma in filename. I think because of this reason File adapter does not support it (have to cross-verify). If you really have a requirement to read/write files with comma in filename then better log a SR with Oracle support.
    Regards,
    Anuj

Maybe you are looking for