Changeset 1789


Ignore:
Timestamp:
11/13/06 17:25:11 (13 years ago)
Author:
curtis
Message:

Add Ilya's -http-response flag.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/OmeisImporter.java

    r1723 r1789  
    4747  /** Network path to OMEIS. */ 
    4848  private static final String OMEIS_PATH = "http://localhost/cgi-bin/omeis"; 
     49 
     50  // -- Static fields -- 
     51 
     52  /** 
     53   * Whether or not to print an HTTP header, 
     54   * specified by -http-response CLI flag. 
     55   */ 
     56  private static boolean httpResponse = false; 
    4957 
    5058  // -- Fields -- 
     
    8290    for (int i=0; i<fileIds.length; i++) { 
    8391      if (ids[i] != null && reader.isThisType(ids[i])) { 
     92        if (httpResponse) printHttpResponseHeader(); 
    8493        System.out.println(fileIds[i]); 
    8594      } 
     
    254263    try { 
    255264      xml.close(); 
     265      if (httpResponse) printHttpResponseHeader(); 
    256266      System.out.println(new String(xml.toByteArray())); 
    257267    } 
     
    450460    else System.err.print(msg); 
    451461  } 
     462   
     463  /** Prints an HTTP error response header. */ 
     464  private void printHttpErrorHeader() { 
     465    System.out.print ("Status: 500 Server Error\r\n"); 
     466    System.out.print ("Content-Type: text/plain\r\n\r\n"); 
     467  } 
     468   
     469  /** Prints an HTTP response header. */ 
     470  private void printHttpResponseHeader() { 
     471    System.out.print ("Status: 200 OK\r\n"); 
     472    System.out.print ("Content-Type: text/plain\r\n\r\n"); 
     473  } 
    452474 
    453475  // -- Main method -- 
     
    461483    OmeisImporter importer = new OmeisImporter(); 
    462484    boolean test = false; 
     485    boolean fatal_stdout = false; 
    463486    int[] fileIds = new int[args.length]; 
    464487 
     
    467490    for (int i=0; i<args.length; i++) { 
    468491      if ("-test".equalsIgnoreCase(args[i])) test = true; 
     492      else if ("-http-response".equalsIgnoreCase(args[i])) httpResponse = true; 
    469493      else { 
    470494        try { 
     
    487511    } 
    488512    catch (Exception exc) { 
     513      if (httpResponse) { 
     514        importer.printHttpErrorHeader(); 
     515        System.out.println("An exception occurred while processing FileIDs:"); 
     516        exc.printStackTrace(System.out); 
     517      } 
    489518      System.err.println("An exception occurred:"); 
    490519      exc.printStackTrace(); 
Note: See TracChangeset for help on using the changeset viewer.