예제 #1
0
  /**
   * Предполагается, что на этапе запуска приожения, если с MainUrl что-то не так то контейнер не
   * запустится :-)
   */
  @PostConstruct
  public void init() {
    try {
      mainURI = new URI(properties.getProperty("MainUrl"), true, "UTF-8");
    } catch (Exception e) {
      throw new RuntimeException(ERR_MSG + e.getMessage());
    }
    if (!mainURI.isAbsoluteURI()) {
      throw new RuntimeException(ERR_MSG + "URI not absolute path");
    }

    try {
      String mainHost = mainURI.getHost();
      if (mainHost == null) {
        throw new RuntimeException(ERR_MSG + "bad URI host");
      }
    } catch (URIException e) {
      throw new RuntimeException(ERR_MSG + e.getMessage());
    }

    try {
      secureURI =
          new URI(
              properties.getProperty("SecureUrl", mainURI.toString().replaceFirst("http", "https")),
              true,
              "UTF-8");
    } catch (Exception e) {
      throw new RuntimeException(ERR_MSG + e.getMessage());
    }
  }
예제 #2
0
 private static String createBaseUri(org.apache.commons.httpclient.URI uri) throws URIException {
   StringBuilder baseUriBuilder = new StringBuilder();
   baseUriBuilder.append(uri.getScheme()).append("://").append(uri.getHost());
   if (uri.getPort() != -1) {
     baseUriBuilder.append(':').append(uri.getPort());
   }
   return baseUriBuilder.toString();
 }
 /**
  * Returns the normalised form of the host of the given {@code uri}.
  *
  * <p>The normalisation process consists in converting the host to lowercase, if {@code null} it
  * is returned an empty {@code String}.
  *
  * @param uri the URI whose host will be extracted and normalised
  * @return a {@code String} with the host normalised, never {@code null}
  * @throws URIException if the host of the given {@code uri} is malformed
  */
 private static String normalisedHost(URI uri) throws URIException {
   if (uri.getRawHost() == null) {
     return "";
   }
   return uri.getHost().toLowerCase(Locale.ROOT);
 }