Esempio n. 1
0
  public void runProcess() {
    try {
      try {
        process().run();
      } catch (ExitingException e) {
      }
      for (SessionListener listener : listeners) {
        listener.onSessionExecuted(this);
      }
    } catch (FaultException f) {
      Process p = null;
      while (hasScope() && (p = getFaultHandler(f.faultName(), true)) == null) {
        popScope();
      }

      try {
        if (p == null) {
          Interpreter.getInstance().logUnhandledFault(f);
          throw f;
        } else {
          Value scopeValue =
              new VariablePathBuilder(false).add(currentScopeId(), 0).toVariablePath().getValue();
          scopeValue.getChildren(f.faultName()).set(0, f.value());
          try {
            p.run();
          } catch (ExitingException e) {
          }
        }
      } catch (FaultException fault) {
        for (SessionListener listener : listeners) {
          listener.onSessionError(this, fault);
        }
      }

      for (SessionListener listener : listeners) {
        listener.onSessionExecuted(this);
      }
    }
  }
Esempio n. 2
0
  public Value getNetworkInterfaceNames() throws FaultException {

    Value response = Value.create();
    ValueVector interfaces = response.getChildren("interfaceName");

    try {
      Enumeration<NetworkInterface> list = NetworkInterface.getNetworkInterfaces();
      int index = 0;
      while (list.hasMoreElements()) {
        NetworkInterface n = list.nextElement();
        interfaces.get(index).setValue(n.getName());
        if (n.getDisplayName() == null) {
          interfaces.get(index).getFirstChild("displayName").setValue("");
        } else {
          interfaces.get(index).getFirstChild("displayName").setValue(n.getDisplayName());
        }
        index++;
      }
    } catch (SocketException e) {
      throw new FaultException(e);
    }
    return response;
  }
Esempio n. 3
0
  public Value getIPAddresses(Value request) throws FaultException {

    Value response = Value.create();

    try {
      Enumeration<NetworkInterface> list = NetworkInterface.getNetworkInterfaces();
      boolean found = false;
      while (list.hasMoreElements()) {
        NetworkInterface n = list.nextElement();

        if (n.getName().equals(request.getFirstChild("interfaceName").strValue())) {
          found = true;

          Enumeration<InetAddress> ad = n.getInetAddresses();
          while (ad.hasMoreElements()) {
            InetAddress ia = ad.nextElement();

            if (ia.getHostName().contains(".")) {
              // it is an IP4 address
              response.getFirstChild("ip4").setValue(ia.getHostName());
            } else {
              // it is an IP6
              response.getFirstChild("ip6").setValue(ia.getHostName());
            }
          }
        }
      }
      if (!found) {

        throw new FaultException("InterfaceNotFound", new Exception());
      }
    } catch (SocketException e) {
      throw new FaultException(e);
    }
    return response;
  }