@Before
  public void setup() {
    r = new Router();
    HttpClientConfiguration httpClientConfig = new HttpClientConfiguration();
    httpClientConfig.setMaxRetries(1);
    r.setHttpClientConfig(httpClientConfig);
    r.setHotDeploy(false);
    r.setRetryInit(true);

    sp = new SOAPProxy();
    sp.setPort(2000);
    sp.setWsdl("http://localhost:2001/axis2/services/BLZService?wsdl");

    sp3 = new ServiceProxy();
    sp3.setPort(2000);
    sp3.setTarget(new AbstractServiceProxy.Target("localhost", 2001));
    ValidatorInterceptor v = new ValidatorInterceptor();
    v.setWsdl("http://localhost:2001/axis2/services/BLZService?wsdl");
    sp3.getInterceptors().add(v);

    SOAPProxy sp2 = new SOAPProxy();
    sp2.setPort(2001);
    sp2.setWsdl("http://www.thomas-bayer.com/axis2/services/BLZService?wsdl");
    r2 = new Router();
    r2.setHotDeploy(false);
    r2.getRules().add(sp2);
    // r2 will be started during the test

  }
Пример #2
0
  private void createNotification() {
    Log.v(this.toString(), "createNotification");
    //
    notificationBuilder = new NotificationCompat.Builder(this.context);

    Intent resultIntent = new Intent(this.context, ActivityLauncher.class);
    resultIntent.setAction("android.intent.action.MAIN");
    resultIntent.addCategory("android.intent.category.LAUNCHER");

    resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent resultPendingIntent =
        PendingIntent.getActivity(this.context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    notificationBuilder.setContentIntent(resultPendingIntent);

    this.notificationIntent =
        ServiceProxy.getPendingIntentForService(
            this.context,
            ServiceProxy.SERVICE_LOCATOR,
            Defaults.INTENT_ACTION_PUBLISH_LASTKNOWN,
            null);
    notificationBuilder.addAction(
        R.drawable.ic_action_upload,
        this.context.getString(R.string.publish),
        this.notificationIntent);
    updateNotification();
  }
Пример #3
0
  @Override
  public void onCreate(ServiceProxy context) {
    this.context = context;
    checkPlayServices();

    this.notificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationBuilder = new NotificationCompat.Builder(context);

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);

    this.preferencesChangedListener =
        new SharedPreferences.OnSharedPreferenceChangeListener() {
          @Override
          public void onSharedPreferenceChanged(SharedPreferences sharedPreference, String key) {
            if (key.equals(Preferences.getKey(R.string.keyNotificationEnabled)))
              handleNotification();
            else if (key.equals(Preferences.getKey(R.string.keyNotificationGeocoderEnabled)))
              handleNotification();
            else if (key.equals(Preferences.getKey(R.string.keyNotificationLocationEnabled)))
              handleNotification();
            else if (key.equals(Preferences.getKey(R.string.keyContactsLinkCloudStorageEnabled)))
              updateAllContacts();
          }
        };

    this.handler = new StaticHandler(this);

    sharedPreferences.registerOnSharedPreferenceChangeListener(this.preferencesChangedListener);
    handleNotification();

    this.mContactCount = getContactCount();
    context
        .getContentResolver()
        .registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, this.mObserver);
  }
  /*
   * Called retroactively to determine if a class loader was required,
   * after we have failed to create one.
   */
  private boolean needClassLoader(String procNames, Iterable<? extends File> workingpath) {
    if (procNames != null) return true;

    String procPath;
    URL[] urls = new URL[1];
    for (File pathElement : workingpath) {
      try {
        urls[0] = pathElement.toURI().toURL();
        if (ServiceProxy.hasService(Processor.class, urls)) return true;
      } catch (MalformedURLException ex) {
        throw new AssertionError(ex);
      } catch (ServiceProxy.ServiceConfigurationError e) {
        log.error("proc.bad.config.file", e.getLocalizedMessage());
        return true;
      }
    }

    return false;
  }
Пример #5
0
  protected Object doExecute() throws Exception {

    // prevent creating fabric if already created
    ServiceReference<FabricService> sref = bundleContext.getServiceReference(FabricService.class);
    FabricService fabricService = sref != null ? bundleContext.getService(sref) : null;
    if (!force
        && (fabricService != null && fabricService.getCurrentContainer().isEnsembleServer())) {
      System.out.println(
          "Current container "
              + fabricService.getCurrentContainerName()
              + " is already in the current fabric ensemble. Cannot create fabric.");
      System.out.println(
          "You can use the --force option, if you want to force re-create the fabric.");
      return null;
    }

    Configuration bootConfiguration =
        configAdmin.getConfiguration(BootstrapConfiguration.COMPONENT_PID, null);
    Dictionary<String, Object> bootProperties = bootConfiguration.getProperties();
    if (bootProperties == null) {
      bootProperties = new Hashtable<>();
    }

    String runtimeIdentity = runtimeProperties.getRuntimeIdentity();
    CreateEnsembleOptions.Builder<?> builder =
        CreateEnsembleOptions.builder()
            .zooKeeperServerTickTime(zooKeeperTickTime)
            .zooKeeperServerInitLimit(zooKeeperInitLimit)
            .zooKeeperServerSyncLimit(zooKeeperSyncLimit)
            .zooKeeperServerDataDir(zooKeeperDataDir)
            .fromRuntimeProperties(runtimeProperties)
            .bootstrapTimeout(bootstrapTimeout)
            .waitForProvision(waitForProvisioning)
            .clean(clean);

    builder.version(version);

    if (containers == null || containers.isEmpty()) {
      containers = Arrays.asList(runtimeIdentity);
    }

    if (!noImport && importDir != null) {
      builder.autoImportEnabled(true);
      builder.importPath(importDir);
    }

    if (globalResolver != null) {
      builder.globalResolver(globalResolver);
      bootProperties.put(ZkDefs.GLOBAL_RESOLVER_PROPERTY, globalResolver);
    }

    if (resolver != null) {
      builder.resolver(resolver);
      bootProperties.put(ZkDefs.LOCAL_RESOLVER_PROPERTY, resolver);
    }

    if (manualIp != null) {
      builder.manualIp(manualIp);
      bootProperties.put(ZkDefs.MANUAL_IP, manualIp);
    }

    if (bindAddress != null) {
      if (!bindAddress.contains(":")) {
        builder.bindAddress(bindAddress);
        bootProperties.put(ZkDefs.BIND_ADDRESS, bindAddress);
      } else {
        String[] parts = bindAddress.split(":");
        builder.bindAddress(parts[0]);
        builder.zooKeeperServerPort(Integer.parseInt(parts[1]));
        bootProperties.put(ZkDefs.BIND_ADDRESS, parts[0]);
      }
    }

    if (zooKeeperServerPort > 0) {
      // --zookeeper-server-port option has higher priority than
      // CreateEnsembleOptions.ZOOKEEPER_SERVER_PORT and
      // CreateEnsembleOptions.ZOOKEEPER_SERVER_CONNECTION_PORT
      // system/runtime properties
      builder.setZooKeeperServerPort(zooKeeperServerPort);
      builder.setZooKeeperServerConnectionPort(zooKeeperServerPort);
    }

    // Configure External Git Repository.
    if (externalGitUrl != null) {
      builder.dataStoreProperty(GIT_REMOTE_URL, externalGitUrl);
    }
    if (externalGitUser != null) {
      builder.dataStoreProperty(GIT_REMOTE_USER, externalGitUser);
    }
    if (externalGitPassword != null) {
      builder.dataStoreProperty(GIT_REMOTE_PASSWORD, externalGitPassword);
    }

    if (profiles != null && profiles.size() > 0) {
      builder.profiles(profiles);
    }

    if (nonManaged) {
      builder.agentEnabled(false);
    } else {
      builder.agentEnabled(true);
    }

    builder.minimumPort(minimumPort);
    builder.minimumPort(maximumPort);
    bootProperties.put(ZkDefs.MINIMUM_PORT, String.valueOf(minimumPort));
    bootProperties.put(ZkDefs.MAXIMUM_PORT, String.valueOf(maximumPort));

    newUser = newUser != null ? newUser : ShellUtils.retrieveFabricUser(session);
    newUserPassword =
        newUserPassword != null ? newUserPassword : ShellUtils.retrieveFabricUserPassword(session);

    Path propsPath = runtimeProperties.getConfPath().resolve("users.properties");
    Properties userProps = new Properties(propsPath.toFile());

    if (userProps.isEmpty()) {
      String[] credentials = promptForNewUser(newUser, newUserPassword);
      newUser = credentials[0];
      newUserPassword = credentials[1];
    } else {
      if (newUser == null || newUserPassword == null) {
        newUser = "" + userProps.keySet().iterator().next();
        newUserPassword = "" + userProps.get(newUser);
        if (newUserPassword.contains(ROLE_DELIMITER)) {
          newUserPassword = newUserPassword.substring(0, newUserPassword.indexOf(ROLE_DELIMITER));
        }
      }
      String passwordWithroles = userProps.get(newUser);
      if (passwordWithroles != null && passwordWithroles.contains(ROLE_DELIMITER)) {
        String[] infos = passwordWithroles.split(",");
        String oldUserRole = newUserRole;
        for (int i = 1; i < infos.length; i++) {
          if (infos[i].trim().startsWith(BackingEngine.GROUP_PREFIX)) {
            // it's a group reference
            String groupInfo = (String) userProps.get(infos[i].trim());
            if (groupInfo != null) {
              String[] roles = groupInfo.split(",");
              for (int j = 1; j < roles.length; j++) {
                if (!roles[j].trim().equals(oldUserRole)) {
                  newUserRole = newUserRole + ROLE_DELIMITER + roles[j].trim();
                }
              }
            }
          } else {
            // it's an user reference
            if (!infos[i].trim().equals(oldUserRole)) {
              newUserRole = newUserRole + ROLE_DELIMITER + infos[i].trim();
            }
          }
        }
      }
    }

    if (Strings.isNullOrEmpty(newUser)) {
      System.out.println("No user specified. Cannot create a new fabric ensemble.");
      return null;
    }

    StringBuilder sb = new StringBuilder();

    // session is unset when this is called from FMC
    if (session != null) {
      ShellUtils.storeFabricCredentials(session, newUser, newUserPassword);
    }

    if (generateZookeeperPassword) {
      // do nothing use the generated password.
    } else if (zookeeperPassword == null) {
      zookeeperPassword =
          PasswordEncoder.decode(
              runtimeProperties.getProperty(
                  CreateEnsembleOptions.ZOOKEEPER_PASSWORD,
                  PasswordEncoder.encode(newUserPassword)));
      builder.zookeeperPassword(zookeeperPassword);
    } else {
      builder.zookeeperPassword(zookeeperPassword);
    }

    bootConfiguration.update(bootProperties);
    CreateEnsembleOptions options =
        builder.users(userProps).withUser(newUser, newUserPassword, newUserRole).build();

    if (containers.size() == 1 && containers.contains(runtimeIdentity)) {
      bootstrap.create(options);
    } else {
      ServiceProxy<ZooKeeperClusterService> serviceProxy =
          ServiceProxy.createServiceProxy(bundleContext, ZooKeeperClusterService.class);
      try {
        serviceProxy.getService().createCluster(containers, options);
      } finally {
        serviceProxy.close();
      }
    }

    ShellUtils.storeZookeeperPassword(session, options.getZookeeperPassword());
    if (zookeeperPassword == null && !generateZookeeperPassword) {
      sb.append("Zookeeper password: (reusing users ")
          .append(newUser)
          .append(" password:"******")\n");
      sb.append(
          "(You can use the --zookeeper-password / --generate-zookeeper-password option to specify one.)\n");
    } else if (generateZookeeperPassword) {
      sb.append("Generated zookeeper password:"******"Using specified zookeeper password:"******"It may take a couple of seconds for the container to provision...");
      System.out.println(
          "You can use the --wait-for-provisioning option, if you want this command to block until the container is provisioned.");
    }

    return null;
  }
Пример #6
0
 public static void main(String[] args) {
   Service service = ServiceProxy.proxy(new ServiceImpl());
   service.div(10, 2);
   service.div(10, 0);
 }