Changeset 4551


Ignore:
Timestamp:
Mar 25, 2014, 11:02:42 AM (8 years ago)
Author:
Fredrik Levander
Message:

Refs #630. Added support for URIs with basic authentication. Refs #823. Added possibilities to specify alternate URIs in connection-properties file. Updated installation scripts for the connection-properties file.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/api/core/src/org/proteios/core/Application.java

    r4543 r4551  
    167167   */
    168168  private static SSLSocketFactory sSLSocketFactory;
    169 
     169  /**
     170   * Alternate URIs. Used when fetching remote files in the File class.
     171   */
     172  private static Map<String,String> alternateURIs;
    170173
    171174  /**
     
    876879  }
    877880
     881  public static Map<String,String> getAlternateURIs()
     882  {
     883    return alternateURIs;
     884  }
     885 
    878886
    879887  public static SSLSocketFactory getSSLSocketFactory()
     
    890898    ConnectionPropertiesFile pf = new ConnectionPropertiesFile();
    891899    boolean replaceEmptyStringWithNull = true;
     900    int i=1;
     901    alternateURIs = new HashMap<String,String>();
     902    String originalURI;
     903    while ((originalURI = pf.getProperty("alternate.location.source."+i)) !=null)
     904    {
     905      String alternateURI = pf.getProperty("alternate.location.target."+i);
     906      if (!originalURI.equals("")) alternateURIs.put(originalURI, alternateURI);
     907      i++;
     908    }
    892909    String keyStoreFileName = fetchProperty(pf, "javax.net.ssl.keyStore", replaceEmptyStringWithNull);
    893910    String keyStorePassword = fetchProperty(pf, "javax.net.ssl.keyStorePassword", replaceEmptyStringWithNull);
  • trunk/api/core/src/org/proteios/core/File.java

    r4432 r4551  
    272272  public String getUniformResourceIdentifier()
    273273  {
    274     // Temporary fix for BILS
    275274    String uri = getData().getUniformResourceIdentifier();
    276     if (uri != null && uri.startsWith("http://proteomics.bils.se"))
    277     {
    278       uri = uri.replace("http://proteomics.bils.se",
    279         "https://srm.swegrid.se/snic/bils");
    280     }
    281275    return uri;
    282276  }
    283277
    284 
     278  /**
     279   * @return the uniform resource identifier of this file if one is set, null
     280   *         otherwise
     281   */
     282  public String getAlternativeUniformResourceIdentifier()
     283  {
     284    String uri = getData().getUniformResourceIdentifier();
     285    for (String original : Application.getAlternateURIs().keySet())
     286    {
     287      if (uri.startsWith(original)) uri = uri.replace(original, Application.getAlternateURIs().get(original));
     288    }
     289    return uri;
     290  }
     291 
    285292  /**
    286293   * Set the URI for this <code>File</code> item. The value may be null but
     
    11161123        try
    11171124        {
    1118           int attempts = 3;
     1125          int attempts = 4;
    11191126          HttpURLConnection connection = null;
     1127          InputStream fis = null;
    11201128          while (connection == null && attempts > 0) {
    11211129            try {
    1122               connection = getConnection(getUniformResourceIdentifier());
     1130              if (attempts==4) connection = getConnection(getAlternativeUniformResourceIdentifier());
     1131              else connection = getConnection(getUniformResourceIdentifier());
     1132              fis = connection.getInputStream();
    11231133            } catch (Exception e) {
    11241134              log.warn(e);
    11251135              log.warn("Attempts left:"+attempts);
    11261136              --attempts;
     1137              connection=null;
    11271138              if (attempts==0) throw new BaseException(e);
    11281139            }
    11291140          }
    11301141          // HttpURLConnection connection = getConnection(getUniformResourceIdentifier());
    1131           InputStream fis = connection.getInputStream();
    11321142          if (isCompressed())
    11331143          {
     
    13521362  {
    13531363    log.debug("# Enter getConnection()\n#   URL=" + url_str);
     1364    String basicAuth = "";
     1365    if (url_str.matches(".*:\\/\\/.*:.*@.*"))
     1366    {
     1367      String userAndPw = url_str.substring(url_str.indexOf("://")+3,url_str.indexOf("@"));
     1368      url_str = url_str.replace("userAndPassword"+"@", "");
     1369      basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userAndPw.getBytes());
     1370    }
    13541371    URL url = new URL(url_str);
    13551372    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
     1373    if (!basicAuth.equals("")) connection.setRequestProperty ("Authorization", basicAuth);
    13561374    if (connection instanceof HttpsURLConnection)
    13571375    {
  • trunk/client/servlet/conf/connection.properties.in

    r4542 r4551  
    5151# If a file URL starts with a listed 'source' path, the path with the
    5252# source path exchanged for the corresponding target path is tried first.
     53# For URLs requiring authentication it can be written into the URL:
     54# https://USERNAME:PASSWORD@www.example.org/
    5355#
    54 # Default settings for BILS project:
     56# Example settings for BILS project:
    5557#
    5658# alternate.location.source.1 = https://srm.swegrid.se/snic/bils/lu_proteomics/external/raw/
    57 # alternate.location.target.1 = http://synology.immunoprot.lth.se/external/
     59# alternate.location.target.1 = http://user:pass@local.storage.lu.se/external/
    5860# alternate.location.source.2 = https://srm.swegrid.se/snic/bils/lu_proteomics/external/mzml/
    5961# alternate.location.target.2 = http://synology.immunoprot.lth.se/external/mzml/
  • trunk/client/servlet/www/WEB-INF/init.sh

    r4430 r4551  
    114114fi
    115115
     116# Create proteios connection.properties file if not existing.
     117if [ ! -f connection.properties ]; then
     118  cp -p connection.properties.in connection.properties
     119fi
     120
     121
    116122# Update proteios Proteios FTP Server start script
    117123java -jar ../lib/Replace.jar \
  • trunk/misc/install/update_proteios-win.bat

    r4181 r4551  
    158158:step_1c10
    159159
     160set filename=connection.properties
     161set rel_path="."
     162set next_step=step_1c11
     163goto copy_file_from_tomcat_installation
     164:step_1c11
     165
    160166rem
    161167rem Check if necessary configuration files exist.
     
    244250goto create_config_file_if_not_existing
    245251:step_3c7
     252
     253set filename=connection.properties
     254set rel_path="."
     255set file_title="Connection"
     256set next_step=step_3c8
     257goto create_config_file_if_not_existing
     258:step_3c8
    246259
    247260rem
Note: See TracChangeset for help on using the changeset viewer.