private static OseeServerInfoMutable createOseeServerInfo(
      Log logger, ApplicationServerDataStore dataStore, Set<String> defaultVersions) {
    String serverAddress = "127.0.0.1";
    try {
      serverAddress = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException ex) {
      //
    }
    int port = OseeServerProperties.getOseeApplicationServerPort();

    String checkSum = "-1";
    try {
      String address = String.format("%s:%s", serverAddress, port);
      ByteArrayInputStream inputStream = new ByteArrayInputStream(address.getBytes("UTF-8"));
      checkSum = ChecksumUtil.createChecksumAsString(inputStream, ChecksumUtil.MD5);
    } catch (Exception ex) {
      logger.error(ex, "Error generating application server id");
    }
    OseeServerInfoMutable toReturn =
        new OseeServerInfoMutable(
            checkSum,
            serverAddress,
            port,
            new String[0],
            GlobalTime.GreenwichMeanTimestamp(),
            false);
    toReturn.setVersions(defaultVersions);
    return toReturn;
  }
  public void start() throws Exception {
    defaultVersions.clear();
    String[] userSpecifiedVersion = OseeServerProperties.getOseeVersion();
    if (Conditions.hasValues(userSpecifiedVersion)) {
      for (String version : userSpecifiedVersion) {
        defaultVersions.add(version);
      }
    } else {
      defaultVersions.add(OseeCodeVersion.getVersion());
    }

    dataStore = new ApplicationServerDataStore(getLogger(), getDatabaseService());
    serverInfo = createOseeServerInfo(getLogger(), dataStore, defaultVersions);

    timer = new Timer();
    timer.schedule(
        new TimerTask() {
          @Override
          public void run() {
            if (isDbInitialized()) {
              try {
                boolean wasRegistered = executeLookupRegistration();
                setServletRequestsAllowed(wasRegistered);
              } catch (Exception ex) {
                getLogger().error(ex, "Error during lookup registration");
              } finally {
                timer.cancel();
              }
            } else {
              setServletRequestsAllowedNoDbUpdate(true);
            }
          }

          private boolean isDbInitialized() {
            boolean result = false;
            try {
              String id = OseeInfo.getDatabaseGuid();
              if (Strings.isValid(id)) {
                result = true;
              }
            } catch (Exception ex) {
              // Do nothing - no need to log exception
            }
            return result;
          }
        },
        5 * 1000);
  }
Пример #3
0
/** @author Roberto E. Escobar */
public class AtsResourceProvider implements IResourceProvider {
  private static final String BASE_PATH = OseeServerProperties.getOseeApplicationServerData(null);
  private static final String RESOLVED_PATH =
      BASE_PATH + File.separator + AtsResourceLocatorProvider.PROTOCOL + File.separator;

  public AtsResourceProvider() {}

  public static String getExchangeFilePath() {
    return RESOLVED_PATH;
  }

  private URI resolve(IResourceLocator locator) throws OseeCoreException {
    URI toReturn = null;
    StringBuilder builder = new StringBuilder();
    String rawPath = locator.getRawPath();
    if (!rawPath.startsWith("file:/")) {
      builder.append(RESOLVED_PATH);
      builder.append(rawPath);
      toReturn = new File(builder.toString()).toURI();
    } else {
      rawPath = rawPath.replaceAll(" ", "%20");
      try {
        toReturn = new URI(rawPath);
      } catch (URISyntaxException ex) {
        throw new MalformedLocatorException(ex);
      }
    }
    return toReturn;
  }

  @Override
  public IResource acquire(IResourceLocator locator, PropertyStore options)
      throws OseeCoreException {
    IResource toReturn = null;
    OptionsProcessor optionsProcessor =
        new OptionsProcessor(resolve(locator), locator, null, options);
    toReturn = optionsProcessor.getResourceToServer();
    return toReturn;
  }

  @Override
  public int delete(IResourceLocator locator) {
    throw new UnsupportedOperationException();
  }

  @Override
  public boolean isValid(IResourceLocator locator) {
    return locator != null && getSupportedProtocols().contains(locator.getProtocol());
  }

  @Override
  public IResourceLocator save(
      IResourceLocator locator, IResource resource, PropertyStore options) {
    throw new UnsupportedOperationException();
  }

  @Override
  public boolean exists(IResourceLocator locator) throws OseeCoreException {
    URI uri = resolve(locator);
    File testFile = new File(uri);
    return testFile.exists();
  }

  @Override
  public Collection<String> getSupportedProtocols() {
    return Arrays.asList(AtsResourceLocatorProvider.PROTOCOL);
  }
}