Пример #1
0
 protected URI launchDetachedCommand(String command, ParameterMap parameters) {
   CommandRunner cr = Globals.getDefaultHabitat().getService(CommandRunner.class);
   final RestActionReporter ar = new RestActionReporter();
   final CommandRunner.CommandInvocation commandInvocation =
       cr.getCommandInvocation(command, ar, getSubject()).parameters(parameters);
   final String jobId = DetachedCommandHelper.invokeAsync(commandInvocation);
   return getUri("jobs/id/" + jobId);
 }
Пример #2
0
 static {
   try {
     _iiopUtils = Globals.getDefaultHabitat().getService(IIOPUtils.class);
     Collection<org.glassfish.grizzly.config.dom.ThreadPool> tpCol =
         _iiopUtils.getAllThreadPools();
     org.glassfish.grizzly.config.dom.ThreadPool[] allThreadPools =
         tpCol.toArray(new org.glassfish.grizzly.config.dom.ThreadPool[tpCol.size()]);
     for (int i = 0; i < allThreadPools.length; i++) {
       createThreadPools(allThreadPools[i], i);
     }
     defaultID = (String) indexToIdTable.get(Integer.valueOf(0));
   } catch (NullPointerException npe) {
     _logger.log(Level.FINE, "Server Context is NULL. Ignoring and proceeding.");
   }
 }
Пример #3
0
  private String getApplicationName(String path) {
    Habitat habitat = Globals.getDefaultHabitat();

    Domain domain = habitat.getInhabitantByType(Domain.class).get();

    List<Application> applicationList = domain.getApplications().getApplications();

    // looks like path always ends with "/" .. but just to be sure..
    for (Application app : applicationList) {
      if (path.startsWith(app.getContextRoot() + "/") || path.equals(app.getContextRoot()))
        return app.getName();
    }

    return null;
  }
Пример #4
0
 ////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////
 /////////               ALL PRIVATE BELOW               ////////////////////
 ////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////
 private void init(AdminCommandContext context) throws IOException {
   logger = context.getLogger();
   props = Globals.get(StartupContext.class).getArguments();
   verbose = Boolean.parseBoolean(props.getProperty("-verbose", "false"));
   logger.info(strings.get("restart.server.init"));
 }
Пример #5
0
  /**
   * Lookup an object in the serial context.
   *
   * @return the object that is being looked up.
   * @throws NamingException if there is a naming exception.
   */
  @Override
  public Object lookup(String name) throws NamingException {
    if (_logger.isLoggable(Level.FINE))
      _logger.log(
          Level.FINE,
          "In javaURLContext.lookup, name = " + name + " serialcontext..." + serialContext);

    if (name.equals("")) {
      /**
       * javadocs for Context.lookup: If name is empty, returns a new instance of this context
       * (which represents the same naming context as this context, but its environment may be
       * modified independently and it may be accessed concurrently).
       */
      return new JavaURLContext(myName, myEnv);
    }

    String fullName = name;
    if (!myName.equals("")) {
      if (myName.equals("java:")) fullName = myName + name;
      else fullName = myName + "/" + name;
    }

    try {
      Object obj = null;
      // If we know for sure it's an entry within an environment namespace
      if (fullName.startsWith("java:comp/env/")
          || fullName.startsWith("java:module/env/")
          || fullName.startsWith("java:app/env/")) {
        // refers to a dependency defined by the application
        obj = namingManager.lookup(fullName, serialContext);
      } else {
        // It's either an application-defined dependency in a java:
        // namespace or a special EE platform object.
        // Check for EE platform objects first to prevent overriding.
        obj = NamedNamingObjectManager.tryNamedProxies(name);
        if (obj == null) {
          // try GlassfishNamingManager
          obj = namingManager.lookup(fullName, serialContext);
        }
      }

      if (obj == null) {
        throw new NamingException("No object found for " + name);
      }

      return obj;
    } catch (NamingException ex) {

      Habitat habitat = Globals.getDefaultHabitat();
      ProcessEnvironment processEnv = habitat.getComponent(ProcessEnvironment.class);
      if (fullName.startsWith("java:app/") && processEnv.getProcessType() == ProcessType.ACC) {

        // This could either be an attempt by an app client to access a portable
        // remote session bean JNDI name via the java:app namespace or a lookup of
        // an application-defined java:app environment dependency.  Try them in
        // that order.

        Context ic = namingManager.getInitialContext();
        String appName = (String) namingManager.getInitialContext().lookup("java:app/AppName");

        Object obj = null;

        if (!fullName.startsWith("java:app/env/")) {
          try {

            // Translate the java:app name into the equivalent java:global name so that
            // the lookup will be resolved by the server.
            String newPrefix = "java:global/" + appName + "/";

            int javaAppLength = "java:app/".length();
            String globalLookup = newPrefix + fullName.substring(javaAppLength);

            obj = ic.lookup(globalLookup);

          } catch (NamingException javaappenvne) {
            _logger.log(Level.FINE, "Trying global version of java:app ejb lookup", javaappenvne);
          }
        }

        if (obj == null) {
          ComponentNamingUtil compNamingUtil = habitat.getByContract(ComponentNamingUtil.class);
          String internalGlobalJavaAppName =
              compNamingUtil.composeInternalGlobalJavaAppName(appName, fullName);

          obj = ic.lookup(internalGlobalJavaAppName);
        }

        if (obj == null) {
          throw new NamingException("No object found for " + name);
        }

        return obj;
      }

      throw ex;
    } catch (Exception ex) {
      throw (NamingException)
          (new NameNotFoundException("No object bound for " + fullName)).initCause(ex);
    }
  }
Пример #6
0
 public WebServiceContextImpl() {
   if (Globals.getDefaultHabitat() != null) {
     secServ = Globals.get(org.glassfish.webservices.SecurityService.class);
   }
 }
Пример #7
0
/**
 * REST resource to get Log Names simple wrapper around internal LogFilter class
 *
 * @author ludovic Champenois
 */
public class LogNamesResource {

  protected ServiceLocator habitat = Globals.getDefaultBaseServiceLocator();

  @GET
  @Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
  public String getLogNamesJSON(@QueryParam("instanceName") String instanceName)
      throws IOException {
    return getLogNames(instanceName, "json");
  }

  @GET
  @Produces({MediaType.APPLICATION_XML})
  public String getLogNamesJXML(@QueryParam("instanceName") String instanceName)
      throws IOException {
    return getLogNames(instanceName, "xml");
  }

  private String getLogNames(String instanceName, String type) throws IOException {

    if (habitat.getService(LogManager.class) == null) {
      // the logger service is not install, so we cannot rely on it.
      // return an error
      throw new IOException("The GlassFish LogManager Service is not available. Not installed?");
    }

    LogFilter logFilter = habitat.getService(LogFilter.class);

    return convertQueryResult(logFilter.getInstanceLogFileNames(instanceName), type);
  }

  private String quoted(String s) {
    return "\"" + s + "\"";
  }

  private String convertQueryResult(Vector v, String type) {
    StringBuilder sb = new StringBuilder();
    String sep = "";
    if (type.equals("json")) {
      sb.append("{\"InstanceLogFileNames\": [");
    } else {
      sb.append("<InstanceLogFileNames>\n");
    }

    // extract every record
    for (int i = 0; i < v.size(); ++i) {
      String name = (String) v.get(i);

      if (type.equals("json")) {
        sb.append(sep);
        sb.append(quoted(name));
        sep = ",";
      } else {
        sb.append("<" + name + "/>");
      }
    }
    if (type.equals("json")) {
      sb.append("]}\n");
    } else {
      sb.append("\n</InstanceLogFileNames>\n");
    }

    return sb.toString();
  }
}
 /**
  * Do all ProtocolManager access lazily and only request orb if it has already been initialized so
  * that code doesn't make the assumption that an orb is available in this runtime.
  */
 private ProtocolManager getProtocolManager() {
   GlassFishORBHelper orbHelper =
       Globals.getDefaultHabitat().getComponent(GlassFishORBHelper.class);
   return orbHelper.isORBInitialized() ? orbHelper.getProtocolManager() : null;
 }