Example #1
0
 private synchronized void addWsClient() {
   if (stat != Stat.INC) {
     return;
   }
   int size = clients.size();
   if ((size % 100) == 0 || size == count) {
     publish(size, failCount, false);
   }
   if (size >= count) {
     if (timerId == TimerManager.INVALID_ID) {
       stop();
     } else {
       stat = Stat.KEEP;
     }
     return;
   }
   WsClientHandler wsClientHandler =
       WsClientHandler.create(false, config.getSelfDomain(), config.getInt(Config.SELF_PORT));
   wsClientHandler.ref();
   wsClientHandler.startRequest(
       this, wsClientHandler, 10000, "/connect", "connect", config.getAdminUrl());
   clients.add(wsClientHandler);
 }
Example #2
0
  private void loadMapping(Mapping mapping) {
    entryMappings.add(mapping);
    if (!mapping.isEnabled()) {
      return;
    }
    if (Boolean.FALSE.equals(mapping.getOption(OPTION_PEEK))) {
      synchronized (activeSslProxyMappings) { // ssl proxyは特殊なため別管理
        activeSslProxyMappings.add(mapping);
      }
    } else {
      synchronized (activeMappings) {
        activeMappings.add(mapping);
      }
    }
    String selfDomain = config.getSelfDomain();
    RealHost realHost = RealHost.getRealHost(mapping.getRealHostName());
    if (Boolean.TRUE.equals(mapping.getOption(OPTION_ADMIN_HANDLER))) {
      StringBuilder sb = new StringBuilder();
      String sourceServer = mapping.getSourceServer();
      if (sourceServer == null || "".equals(sourceServer)) {
        sourceServer = selfDomain;
      }
      if (mapping.getSecureType() == SecureType.SSL) {
        sb.append("https://");
      } else {
        sb.append("http://");
      }
      sb.append(sourceServer);
      sb.append(":");
      sb.append(realHost.getBindPort());
      sb.append(mapping.getSourcePath());
      adminUrl = sb.toString();
      System.out.println("adminUrl:" + adminUrl);
    }

    Object publicWeb = mapping.getOption(OPTION_PUBLIC_WEB); // publicWebのportとプロトコルを知るため
    if (Boolean.TRUE.equals(publicWeb)) {
      StringBuilder sb = new StringBuilder();
      String sourceServer = mapping.getSourceServer();
      if (sourceServer == null || "".equals(sourceServer)) {
        sourceServer = selfDomain;
      }
      if (mapping.getSecureType() == SecureType.SSL) {
        sb.append("https://");
      } else {
        sb.append("http://");
      }
      sb.append(sourceServer);
      sb.append(":");
      sb.append(realHost.getBindPort());
      sb.append(mapping.getSourcePath());
      publicWebUrl = sb.toString();
    }
    // pacは複数のmappingにあってよいが、そのrealHostは同一である事
    //		Object authHandler=mapping.getOption(OPTION_AUTH_HANDLER);
    if (AuthHandler.class.getName().equals(mapping.getDestinationServer())) {
      setupAuthUrl(mapping); // authorizerにauthマッピング定義を教える
    }

    // mapping auth定義
    Object auth = mapping.getOption(OPTION_AUTH);
    if (auth != null && auth instanceof JSONObject) {
      MappingAuth mappingAuth = new MappingAuth(config.getAuthenticator());
      if (mappingAuth.init((JSONObject) auth, mapping.getSourceType() == SourceType.PROXY)) {
        mapping.setMappingAuth(mappingAuth);
      }
    }

    Object pac = mapping.getOption(OPTION_PAC); // pacに反映するか否か
    if (!Boolean.TRUE.equals(pac)) {
      return;
    }
    switch (mapping.getSourceType()) {
      case PROXY:
        switch (mapping.getSecureType()) {
          case PLAIN:
            httpPhantomDomains.add(mapping.getSourceServerHost());
            pacProxyPort = realHost.getBindPort();
            break;
          case SSL:
            securePhantomDomains.add(mapping.getSourceServerHost());
            pacProxyPort = realHost.getBindPort();
            break;
        }
        break;
      case WEB:
    }
  }